source: other-projects/trunk/gs3-webservices-democlient/src/GS3DemoClient/org/greenstone/gs3client/dlservices/GS3WebServicesQBRAPI.java@ 15222

Last change on this file since 15222 was 15222, checked in by ak19, 16 years ago

Greenstone3 web services demo-clientadded to GS3's other-projects

File size: 38.5 KB
Line 
1/**
2 *#########################################################################
3 * GS3WebServicesAPI.java - part of the demo-client for Greenstone 3,
4 * of the Greenstone digital library suite from the New Zealand Digital
5 * Library Project at the * University of Waikato, New Zealand.
6 * <BR><BR>
7 * Copyright (C) 2008 New Zealand Digital Library Project
8 * <BR><BR>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 * <BR><BR>
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *########################################################################
19 */
20
21package org.greenstone.gs3client.dlservices;
22
23import java.io.IOException;
24import java.io.InputStreamReader;
25import java.net.MalformedURLException;
26import java.net.URL;
27import java.util.Vector;
28import java.util.Map;
29import java.util.HashMap;
30
31import javax.xml.namespace.QName;
32import javax.xml.parsers.DocumentBuilder;
33import javax.xml.parsers.DocumentBuilderFactory;
34import javax.xml.parsers.ParserConfigurationException;
35import javax.xml.rpc.ServiceException;
36
37import org.apache.axis.client.Call;
38import org.apache.axis.client.Service;
39import org.apache.axis.encoding.XMLType;
40import org.w3c.dom.Document;
41import org.w3c.dom.Element;
42import org.w3c.dom.Node;
43import org.w3c.dom.NodeList;
44import org.xml.sax.InputSource;
45import org.xml.sax.SAXException;
46
47import org.apache.log4j.Logger; //Import log4j classes
48
49/**
50 * GS3WebServicesQBRAPI deals with invoking the Greenstone 3 web services
51 * functionality through use of Apache Axis' Service and Call objects.
52 * Each Greenstone 3 web service operation has an equivalent method here
53 * that invokes it, even if some of these web service operations are never
54 * called by the Java-client and therefore not prescribed by the
55 * DigitalLibraryServicesAPIA interface.
56 * @author ak19
57*/
58public class GS3WebServicesQBRAPI {
59 /** The Logger for this class */
60 static Logger LOG = Logger.getLogger(GS3WebServicesQBRAPI.class);
61
62 /** The value that the input dialog's field wsdlURL will default
63 * to if there is (no properties file and) no wsdlURL property */
64 public static final String defaultWsdlURL =
65 "http://localhost:9090/greenstone3/services/QBRSOAPServerlocalsite?wsdl";
66
67 // Service and Call objects
68 /** Axis Service object for connecting to invoking Greenstone 3's WebServices
69 * using its WSDL file */
70 protected Service service;
71 /** Axis Call object for invoking Greenstone 3's WebServices
72 * using its WSDL file */
73 protected Call call;
74
75 //maybe unnecessary to store these?
76 /** port Name of Greenstone 3's WebServices, as given in the WSDL file */
77 protected String portName;
78 /** namespace of Greenstone 3's WebServices, as given in the WSDL file */
79 protected String namespace;
80 /** service Name of Greenstone 3's WebServices, as given in the WSDL file */
81 protected String serviceName;
82 /** Url of the Greenstone 3 WebServices' WSDL */
83 protected String wsdlURLName;
84
85
86 /** GS3ServicesAPIA constructor, that given the url to the wsdl file, finds
87 * either service and port or the service's endpoint of the GS3 Web Services
88 * and instantiates the associated Service and Call objects.
89 * @param wsdlURLName - location of the WSDL URL for Greenstone 3's
90 * web services */
91 public GS3WebServicesQBRAPI(String wsdlURLName)
92 throws ServiceException, MalformedURLException,
93 ParserConfigurationException, IOException, SAXException
94 {
95 this.wsdlURLName = wsdlURLName;
96 try {
97 // (1) Try assuming that the wsdlFile URL name is of the form
98 // http://<host>:<port>/greenstone3/services/QBRSOAPServerlocalsite?wsdl
99 // (http://localhost:9090/greenstone3/services/QBRSOAPServerlocalsite?wsdl)
100 // then the namespace, serviceName and portName are *likely* to be:
101 // - namespace: http://localhost:9090/greenstone3/services/QBRSOAPServerlocalsite
102 // - serviceName: QBRSOAPServerlocalsiteService
103 // - portName: QBRSOAPServerlocalsite
104 this.namespace = wsdlURLName;
105 int index = namespace.indexOf("?wsdl");
106 if(index != -1)
107 namespace = namespace.substring(0, index);
108 //namespace = "http://gsdl3.greenstone.org";
109
110 this.portName = namespace;
111 index = portName.lastIndexOf('/');
112 if(index != -1)
113 portName = portName.substring(index+1, portName.length());
114
115 this.serviceName = portName + "Service";
116
117 service = new Service(wsdlURLName, new QName(namespace, serviceName));
118 call = (Call)service.createCall(new QName(namespace, portName));
119
120 } catch(ServiceException e) {
121 // If we're here, then (1) didn't work. Need to do it the long way
122 // (2) Let's read from the wsdl file and try working out the
123 // <service> and <port> elements. Some of these have their own
124 // prefixes: <wsdl:service> and <wsdl:port>, so we need to
125 // take that into account.
126
127 // Read from the wsdl file at the URL. There's two ways:
128 // EITHER:
129 //HttpURLConnection wsdlCon = (HttpURLConnection) wsdlURL.openConnection();
130 //InputStreamReader reader = new InputStreamReader(wsdlCon.getInputStream());
131 // OR:
132 URL wsdlURL = new URL(wsdlURLName);
133 InputStreamReader reader = new InputStreamReader(wsdlURL.openStream());
134
135 // Turn the String xml response into a DOM tree:
136 DocumentBuilder builder =
137 DocumentBuilderFactory.newInstance().newDocumentBuilder();
138 Document doc
139 = builder.parse(new InputSource(reader));
140 Element documentElement = doc.getDocumentElement();
141 reader.close();
142
143 // local element names (without any namespace prefixes)
144 final String SERVICE = "service";
145 final String PORT = "port";
146
147 // Search for <(any namespace prefix:)service> elements:
148 // Note that the API method
149 // Element.getElementsByTagNameNS("*", SERVICE)
150 // does not return anything because our documentElement is not
151 // created with DOM Level 2 but DOM Level 1. It won't work therefore.
152 // See the API for Element, spefically for method getElementsByTagNameNS.
153 Vector v = getElementsByTagNameNS(documentElement, "*", SERVICE);
154 if(v.size() == 0)
155 throw new ServiceException(
156 "No <(namespace:)"+SERVICE+"> defined in wsdl");
157 Element serviceEl = (Element)v.get(0);
158
159 // search for <(any namespace prefix:)port> elements:
160 v = getElementsByTagNameNS(serviceEl, "*", PORT);
161 if(v.size() == 0)
162 throw new ServiceException("No <(namespace:)"+PORT
163 +"> defined in wsdl for <(namespace:)service>");
164 Element portEl = (Element)v.get(0); //otherwise
165
166 final String nameAtt = "name";
167 final String targetNamespace = "targetNamespace";
168 this.serviceName = serviceEl.hasAttribute(nameAtt) ?
169 serviceEl.getAttribute(nameAtt) : "";
170 this.portName = portEl.hasAttribute(nameAtt) ?
171 portEl.getAttribute(nameAtt) : "";
172
173 // reset the namespace, we'll manually try to find it
174 this.namespace = "";
175 // generally namespace is an attribute of the root element
176 // of the wsdl doc
177 if(documentElement.hasAttribute(targetNamespace))
178 this.namespace = documentElement.getAttribute(targetNamespace);
179
180 if(this.namespace.equals("")) { // we'll still keep looking
181 NodeList nl = documentElement.getChildNodes();
182 for(int i = 0; i < nl.getLength(); i++) {
183 Node n = nl.item(i);
184 if(n.getNodeType() == Node.ELEMENT_NODE) {
185 Element el = (Element)n;
186 if(el.hasAttribute(targetNamespace))
187 this.namespace = el.getAttribute(targetNamespace);
188 }
189 }
190 }
191
192 // If any of targetNamespace, <service> or <port> were not found,
193 // look for endpointLocation and create empty service and call objects
194 if(namespace.equals("") || serviceName.equals("") || portName.equals("")) {
195 LOG.debug("Namespace " + namespace + "; service "
196 + serviceName + "; port " + portName);
197 LOG.debug("Create empty service and call");
198 boolean found = false;
199 // Try to locate the <(wsdl)soap:address> tag.
200 final String SOAP_ADDRESS = "soap:address";
201 final String LOCATION = "location";
202 String endpointLocation = "";
203 // The following method returns all descendent Elements of document element
204 // where the element's tagname *ends* on SOAP_ADDRESS
205 v = getElementsByTagNameNS(portEl, "*", SOAP_ADDRESS);
206 if(v.size() > 0) { //there should be 1 and only 1 such
207 Element soapAddressEl = (Element)v.get(0);
208 if(soapAddressEl.hasAttribute(LOCATION)) {
209 endpointLocation = soapAddressEl.getAttribute(LOCATION);
210 found = true;
211 }
212 }
213 if(!found) { // haven't found endpointLocation, try brute force
214 // Look through all port's *element* children to find some element
215 // with attribute "location". That could then be the service endpoint...
216 NodeList nl = portEl.getChildNodes();
217 for(int i = 0; !found && i < nl.getLength(); i++) {
218 Node n = nl.item(i);
219 if(n.getNodeType() == Node.ELEMENT_NODE) {
220 Element el = (Element)n; // we know it's an element
221 if(el.hasAttribute(LOCATION)) {
222 endpointLocation = el.getAttribute(LOCATION);
223 found = true; // found the service endpoint
224 }
225 }
226 }
227 }
228 if(!found) { // still not found any service endpoint
229 throw new ServiceException(
230 "Unable to find service endpoint address. " +
231 "No <(soap:address) location=\"endpoint\" /> in wsdl file"
232 );
233 }
234 service = new Service();
235 call = (Call)service.createCall();
236 call.setTargetEndpointAddress(endpointLocation);
237 } else { // if we had found namespace, serviceName and portName
238 LOG.debug("Namespace " + namespace + "; service "
239 + serviceName + "; port " + portName);
240 LOG.debug("Found service, port and namespace");
241 service = new Service(wsdlURL, new QName(namespace, serviceName));
242 call = (Call)service.createCall(new QName(namespace, portName));
243 }
244 } // end catch stmt, which can itself throw ServiceExceptions
245 }
246
247 /** Static method that gets all the descendant elements of a portion of XMl
248 * within the same namespace as indicated by parameters namespacePrefix and
249 * localName.
250 * @param namespacePrefix - a String for the namespacePrefix to search for.
251 * This can be the wildcard * for any/allnamespaces.
252 * @param localName - the suffix of the namespaceprefix. For instance, localName
253 * "soap" will return elements that have the tag wsdlsoap.
254 * @param parentElement - the XML element whose descendants will be returned if
255 * their element names conform to the specified namespacePrefix and localName
256 * parameters.
257 * @return a Vector of all descendant elements whose namespace-qualfied tag
258 * names are as specified by the parameters namespacePrefix and localName.
259 * Had to implement my own getElementsByTagNameNS() method since the original
260 * Element.getElementsByTagNameNS() does not work for Elements created using
261 * DOM level 1 (such as with document.createElement()). See the API for Element.
262 * This method is slightly more generic, as it returns all descendent elements
263 * in a vector where the element name is prefixed by "namespacePrefix" (which
264 * need not be a namespace uri at all) and is suffixed by an equally arbitrary
265 * String called localName.
266 * If "*" is passed instead of namespacePrefix, this method will ignore any
267 * prefixes and check only for element names that end on the suffix localName.
268 *
269 * Old versions of this method had all the same functionality in one method,
270 * but it was not so optimised (several if-statement checks would have been executed an unnecessary
271 * number of times. This (current) version is split into 3 methods: this one
272 * and two helper functions that deal with the case where namespacePrefix can
273 * be anything and where it is particularly specified.*/
274 protected static Vector getElementsByTagNameNS(Element parentElement,
275 String namespacePrefix, String localName)
276 {
277 Vector v = new Vector();
278 if(namespacePrefix.equals("*"))
279 getElementsByTagNameSuffix(parentElement, localName, v);
280 else // namespacePrefix is specified as something particular
281 getElementsByTagNameNS(parentElement, namespacePrefix, localName, v);
282 return v;
283 }
284
285 /** Recursive method.
286 * At method's end, Vector v will contain those descendent elements of
287 * parentElement where the element's name is suffixed by/ends with parameter
288 * localName.
289 * Related to local method getElementsByTagNameNS(). Deals with the case
290 * where any and all (namespace)Prefix of an element is accepted, but where
291 * an element name's suffix should match with the given localName.
292 * @param parentElement us the XML element whose descendants are to be
293 * retrieved by the given TagNameSuffix.
294 * @param localName is the tagName suffix to retrieve the descendants of
295 * parentElement by.
296 * @param v is a Vector of all the previously retrieved elements whose tag
297 * names are suffixed by localName. This Vector is appended to by recursive
298 * calls to this method. */
299 protected static void getElementsByTagNameSuffix(Element parentElement,
300 String localName, Vector v)
301 {
302 NodeList allTags = parentElement.getChildNodes();
303 for(int i = 0; i < allTags.getLength(); i++) {
304 Node n = allTags.item(i);
305 if(n.getNodeType() == Node.ELEMENT_NODE) {
306 Element e = (Element)n;
307 if(e.getNodeName().endsWith(localName))
308 v.add(e);
309 if(e.hasChildNodes()) // recursive call on all children
310 getElementsByTagNameSuffix(e, localName, v);
311 }
312 }
313 }
314
315 /** At method's end, Vector v will contain those descendent elements of
316 * parentElement where the element's name is prefixed by namespacePrefix
317 * and suffixed by localName.
318 * Related to local method getElementsByTagNameNS(). Deals with the case
319 * where a particular (namespace)Prefix of an element and suffix (localname)
320 * are given and an element's name should match both prefix and suffix.
321 * @param parentElement is the XML element whose descendants are to be
322 * retrieved by the given TagNameSuffix.
323 * @param namespacePrefix is the namespace prefix to look for in the
324 * descendants of parentElement that will be collected in Vector v.
325 * @param localName is the tagName suffix to look for in the descendants of
326 * parentElement that will be collected in Vector v.
327 * @param v is a Vector of all the previously retrieved elements whose tag
328 * names are prefixed by namespacePrefix and suffixed by localName.
329 * This Vector is appended to by recursive calls to this method. */
330 protected static void getElementsByTagNameNS(Element parentElement,
331 String namespacePrefix, String localName, Vector v)
332 {
333 NodeList allTags = parentElement.getChildNodes();
334 for(int i = 0; i < allTags.getLength(); i++) {
335 Node n = allTags.item(i);
336 if(n.getNodeType() == Node.ELEMENT_NODE) {
337 Element e = (Element)n;
338 if(e.getNodeName().endsWith(localName)
339 && e.getNodeName().startsWith(namespacePrefix))
340 v.add(e);
341 if(e.hasChildNodes()) // recursive call on all children
342 getElementsByTagNameNS(e, namespacePrefix, localName, v);
343 }
344 }
345 }
346
347 /** @return the namespace of the wsdl file. */
348 public String getNamespace() { return namespace; }
349 /** @return the web service's serviceName without the namespace */
350 public String getService() { return serviceName; }
351 /** @return the web service's portName without the namespace */
352 public String getPort() { return portName; }
353 /** @return the the URL of the wsdl file. */
354 public String getWsdl() { return wsdlURLName; }
355
356 //*****************GS3 WEB SERVICE INVOCATION RELATED******************//
357 /** Helper method. Uses the Call object to invoke the operation (already
358 * set prior to calling invokeWith()) with the given parameters. */
359 protected String invokeWith(Object[] params) {
360 // the GS3 web service methods all return a String:
361 call.setReturnType( XMLType.XSD_STRING );
362 try {
363 // now call the web service and pass it the parameters
364 String response = (String) call.invoke(params);
365 return response;
366 } catch(Exception e) {
367 return "ERROR trying to invoke web service - in "
368 + this.getClass().getName()
369 + " invokeWith(Object[] params):\n" + e;
370 } finally { // always executed (before return statement/upon completion,
371 // regardless of whether an exception occurs or not:
372
373 // after invoking, remove all params so that next call to a web
374 // service starts at initial state (no parameters from last time)
375 call.removeAllParameters();
376 }
377 }
378
379 /** Helper method. Adds a string parameter by the name of paramName to
380 * the Call object.
381 * @param paramName - the name of the String parameter to add to the call
382 * object */
383 protected void addStringParam(String paramName) {
384 call.addParameter( paramName,
385 XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN );
386 }
387
388 /** Helper method. Adds an array parameter by the name of arrayParamName
389 * to the Call object.
390 * @param arrayParamName - the name of the Array parameter to add to the
391 * Call object */
392 protected void addArrayParam(String arrayParamName) {
393 call.addParameter( arrayParamName,
394 XMLType.SOAP_ARRAY, javax.xml.rpc.ParameterMode.IN );
395 }
396
397 /* (1) DESCRIBE MESSAGES, manual pages 35-41 */
398 /** Describe request message sent to the Message Router.
399 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 35-41</a>
400 * @param lang is the language of the display content in the response
401 * @param subsetOption is the requested list of items to return in the response
402 * For the Message Router this can be collectionList, serviceClusterList,
403 * serviceList, siteList */
404 public String describe(String lang, String subsetOption) {
405 call.setOperationName( "describe" ); //method name is "describe"
406
407 addStringParam("lang"); //first param called "lang"
408 addStringParam("subsetOption"); //second param called "subsetOption"
409
410 return invokeWith(new Object[] {lang, subsetOption});
411 }
412
413 /** For sending Describe messages to ServiceClusters.
414 * @param serviceCluster is the name of the Service Cluster that this describe
415 * request is sent to.
416 * @param lang is the language of the display content in the response
417 * @param subsetOption is the requested list of items to return in the response
418 * For Service Clusters this can be metadataList, serviceList, displayItemList.
419 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 35-41</a>
420 */
421 public String describeServiceCluster(String serviceCluster,
422 String lang, String subsetOption)
423 {
424 call.setOperationName( "describeServiceCluster" );
425
426 addStringParam("serviceCluster");
427 addStringParam("lang");
428 addStringParam("subsetOption");
429
430 return invokeWith(new Object[] { serviceCluster, lang, subsetOption });
431 }
432
433 /** For sending Describe messages to Collections.
434 * @param collection is the name of the Collection that this describe request
435 * is sent to.
436 * @param lang is the language of the display content in the response
437 * @param subsetOption is the requested list of items to return in the response
438 * For Collections this can be metadataList, serviceList and displayItemList.
439 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 35-41</a>
440 */
441 public String describeCollection(
442 String collection, String lang, String subsetOption)
443 {
444 call.setOperationName( "describeCollection" );
445
446 addStringParam("collection");
447 addStringParam("lang");
448 addStringParam("subsetOption");
449
450 return invokeWith(new Object[] { collection, lang, subsetOption });
451 }
452
453 /**
454 * For sending a describe message to a Collection's Service.
455 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 35-41</a>
456 * @param collection is the name of the Collection whose service
457 * this describe request is sent to.
458 * @param service is the name of the Service (of that collection) to
459 * which this describe request is sent.
460 * @param lang is the language of the display content in the response
461 * @param subsetOption is the requested list of items to return in the response
462 * For Services this can be paramList, displayItemList */
463 public String describeCollectionService(String collection, String service,
464 String lang, String subsetOption)
465 {
466 call.setOperationName( "describeCollectionService" );
467
468 addStringParam("collection");
469 addStringParam("service");
470 addStringParam("lang");
471 addStringParam("subsetOption");
472
473 return invokeWith(new Object[] {collection, service, lang, subsetOption});
474 }
475
476 /**
477 * For sending a describe message to a Service hosted by the Message Router
478 * (no collection).
479 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 35-41</a>
480 * @param service is the name of the MessageRouter's Service to which this
481 * describe request is sent.
482 * @param lang is the language of the display content in the response
483 * @param subsetOption is the requested list of items to return in the response
484 * For Services this can be paramList, displayItemList */
485 public String describeService(String service, String lang, String subsetOption)
486 {
487 call.setOperationName( "describeService" );
488
489 addStringParam("service");
490 addStringParam("lang");
491 addStringParam("subsetOption");
492
493 return invokeWith(new Object[] {service, lang, subsetOption});
494 }
495
496 /* (2) Process-type message, QUERY-TYPE SERVICES - p.45 */
497 /** For executing a (process-type message) query-type service.
498 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 45</a>
499 * @param collection is the name of the Collection whose query service this
500 * query-process request is sent to. If "", then the Message Router is assumed.
501 * @param service is the name of the Query Service (of that collection) to
502 * which this request is sent.
503 * @param lang is the language of the display content in the response
504 * @param nameToValsMap is a Map of the (fieldname, value) pairs for the
505 * parameters of the query. The field names should be those recognised by
506 * Greenstone 3. That is, the names must exist for the (Collection-)Service Query that this
507 * message is sent To (as given in 'to' argument).
508 * For names of arguments,
509 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Actions_and_Arguments">Greenstone wiki - Actions and Arguments</a>
510 * @see <a href="http://mail-archives.apache.org/mod_mbox/ws-axis-user/200204.mbox/%[email protected]%3E">How to use XMLType.SOAP_MAP</a>
511 */
512 public String query(String collection, String service,
513 String lang, Map nameToValsMap)
514 {
515 call.setOperationName( "query" );
516 addStringParam("collection");
517 addStringParam("service");
518 addStringParam("lang");
519 call.addParameter("nameToValsMap", XMLType.SOAP_MAP,
520 java.util.Map.class, javax.xml.rpc.ParameterMode.IN);
521 return invokeWith(new Object[]{collection, service, lang, nameToValsMap});
522 }
523
524 /* (3) RETRIEVE PROCESS METHODS - pp.47-49 */
525 /** (a) DocumentContentRetrieve request sent to a collection's
526 * DocumentContentRetrieve service (p.48)
527 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 48</a>
528 * @param collection is the name of the Collection whose
529 * DocumentContentRetrieve is requested
530 * @param lang is the language of the display content in the response
531 * @param docNodeIDs is the list of documentNodeIDs for which the
532 * content ought to be retrieved.
533 */
534 public String retrieveDocumentContent(
535 String collection, String lang, String[] docNodeIDs)
536 {
537 call.setOperationName( "retrieveDocumentContent" );
538
539 addStringParam("collection");
540 addStringParam("lang");
541 addArrayParam("docNodeIDs");
542
543 return invokeWith(new Object[] {collection, lang, docNodeIDs});
544 }
545
546 /** (b) DocumentStructureRetrieve request sent to a collection's
547 * DocumentStructureRetrieve service (manual pp.48, 49) to retrieve
548 * the entire document structure.
549 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 48, 49</a>
550 * @param collection is the name of the Collection whose
551 * DocumentStructureRetrieve is requested
552 * @param lang is the language of the display content in the response
553 * @param docNodeIDs is the list of documentNodeIDs for which the
554 * entire structure ought to be retrieved.
555 */
556 public String retrieveEntireDocumentStructure(String collection,
557 String lang, String[] docNodeIDs)
558 {
559 call.setOperationName( "retrieveEntireDocumentStructure" );
560
561 addStringParam("collection");
562 addStringParam("lang");
563 addArrayParam("docNodeIDs");
564
565 return invokeWith(new Object[] {collection, lang, docNodeIDs});
566 }
567
568 /** DocumentStructureRetrieve request sent to a collection's
569 * DocumentStructureRetrieve service (manual pp.48, 49) to retrieve
570 * the specified part of the document's structure.
571 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 48, 49</a>
572 * @param collection is the name of the Collection whose
573 * DocumentStructureRetrieve is requested
574 * @param lang is the language of the display content in the response
575 * @param docNodeIDs is the list of documentNodeIDs for which the
576 * structure ought to be retrieved.
577 * @param structure specifies what structure information needs to
578 * be retrieved. The values can be one or more of ancestors, parent,
579 * siblings, children, descendents (NOTE SPELLING), entire.
580 * @param info - for specifying extra information to be retrieved.
581 * Possible values for info parameters are numSiblings, siblingPosition,
582 * numChildren.
583 */
584 public String retrieveDocumentStructure(String collection, String lang,
585 String[] docNodeIDs, String[] structure, String[] info)
586 {
587 call.setOperationName( "retrieveDocumentStructure" );
588
589 addStringParam("collection");
590 addStringParam("lang");
591 addArrayParam("docNodeIDs");
592 addArrayParam("structure");
593 addArrayParam("info");
594
595 return invokeWith(new Object[] {
596 collection, lang, docNodeIDs, structure, info});
597 }
598
599 /** (c) DocumentMetadataRetrieve request sent to a collection's
600 * DocumentMetadataRetrieve service to retrieve all of a document's metadata.
601 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 47</a>
602 * @param collection is the name of the Collection whose
603 * DocumentMetadataRetrieve is requested
604 * @param lang is the language of the display content in the response
605 * @param docNodeIDs is the list of documentNodeIDs for which the
606 * structure ought to be retrieved.
607 */
608 public String retrieveAllDocumentMetadata(String collection, String lang,
609 String[] docNodeIDs)
610 {
611 call.setOperationName( "retrieveAllDocumentMetadata" );
612
613 addStringParam("collection");
614 addStringParam("lang");
615 addArrayParam("docNodeIDs");
616
617 return invokeWith(new Object[] {collection, lang, docNodeIDs});
618 }
619
620 /** DocumentMetadataRetrieve service to retrieve some specific
621 * metadata values of a document. (Manual on page 47.)
622 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 47</a>
623 * @param collection is the name of the Collection whose
624 * DocumentContentRetrieve is requested
625 * @param lang is the language of the display content in the response
626 * @param docNodeIDs is the list of documentNodeIDs for which the
627 * structure ought to be retrieved.
628 * @param metaNames is a list of metadata names which are requested
629 * to be fetched for the specified documents.
630 */
631 public String retrieveDocumentMetadata(String collection, String lang,
632 String[] docNodeIDs, String[] metaNames)
633 {
634 call.setOperationName( "retrieveDocumentMetadata" );
635
636 addStringParam("collection");
637 addStringParam("lang");
638 addArrayParam("docNodeIDs");
639 addArrayParam("metaNames");
640
641 return invokeWith(new Object[] {collection, lang, docNodeIDs, metaNames});
642 }
643
644 /** Retrieve all classification Metadata for browsing (sent to the
645 * ClassifierBrowseMetadataRetrieve service).
646 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 47, 48</a>
647 * @param collection is the name of the Collection whose
648 * ClassifierBrowseMetadataRetrieve service is called
649 * @param categoryName - name of the browsing category, usually
650 * ClassifierBrowse. (If left as "", then it defaults to ClassifierBrowse)
651 * @param lang is the language of the display content in the response
652 * @param nodeIDs is the list of document or classifier NodeIDs
653 * for which the metadata ought to be retrieved.
654 */
655 public String retrieveAllBrowseMetadata(String collection,
656 String categoryName, String lang, String[] nodeIDs)
657 {
658 call.setOperationName( "retrieveAllBrowseMetadata" );
659
660 addStringParam("collection");
661 addStringParam("categoryName");
662 addStringParam("lang");
663 addArrayParam("nodeIDs");
664
665 return invokeWith(new Object[] {collection, categoryName, lang, nodeIDs});
666 }
667
668 /** ClassifierBrowseMetadataRetrieve service to retrieve some specific
669 * metadata values of a document.
670 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 47, 48</a>
671 * @param collection is the name of the Collection whose
672 * ClassifierBrowseMetadataRetrieve service is called
673 * @param categoryName - name of the browsing category, usually
674 * "ClassifierBrowse". (If left as "", then it defaults to ClassifierBrowse)
675 * @param lang is the language of the display content in the response
676 * @param nodeIDs is the list of document or classifier NodeIDs
677 * for which the metadata ought to be retrieved.
678 * @param metaNames is a list of metadata names which are requested
679 * to be fetched for the specified documents or classifiers */
680 public String retrieveBrowseMetadata(String collection, String categoryName,
681 String lang, String[] nodeIDs, String[] metaNames)
682 {
683 call.setOperationName( "retrieveBrowseMetadata" );
684
685 addStringParam("collection");
686 addStringParam("categoryName");
687 addStringParam("lang");
688 addArrayParam("nodeIDs");
689 addArrayParam("metaNames");
690
691 return invokeWith(new Object[] {collection, categoryName, lang,
692 nodeIDs, metaNames});
693 }
694
695 /* (4) Classifier BROWSE PROCESS METHODS */
696 /** To send a browse request for all the descendants of a classifier node.
697 * Useful for getting the entire structure of a top-level
698 * &lt;classificationNode&gt;.
699 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 46</a>
700 * @param collection is the name of the Collection whose browse Classifier
701 * Browse Service is called
702 * @param browseService is the name of the (Classifier) Browse Service (of
703 * the given collection) to which this request message is sent.
704 * @param lang is the language of the display content in the response
705 * @param classifierNodeIDs is an array of classifierNodeIDs for which the
706 * structures ought to be retrieved.
707 */
708 public String browseDescendants(String collection, String browseService,
709 String lang, String[] classifierNodeIDs)
710 {
711 call.setOperationName( "browseDescendants" );
712
713 addStringParam("collection");
714 addStringParam("browseService");
715 addStringParam("lang");
716 addArrayParam("classifierNodeIDs");
717
718 return invokeWith(new Object[] {
719 collection, browseService, lang, classifierNodeIDs});
720 }
721
722 /** To send a browse request for specific parts of a classifier node
723 * (children, ancestors, descendants). Useful for getting specific parts
724 * of the structure of a top-level &lt;classificationNode&gt;.
725 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 46</a>
726 * @param collection is the name of the Collection whose browse Classifier
727 * Browse Service is called
728 * @param browseService is the name of the (Classifier) Browse Service (of
729 * the given collection) to which this request message is sent.
730 * @param lang is the language of the display content in the response
731 * @param classifierNodeIDs is the list of classifierNodeIDs for which the
732 * structure ought to be retrieved.
733 * @param structureParams the list of parameters indicating what structure
734 * information is requested. Accepted values are ancestors, parent, siblings,
735 * children, descendants.
736 */
737 public String browse(String collection, String browseService, String lang,
738 String[] classifierNodeIDs, String[] structureParams)
739 {
740 call.setOperationName( "browse" );
741
742 addStringParam("collection");
743 addStringParam("browseService");
744 addStringParam("lang");
745 addArrayParam("classifierNodeIDs");
746 addArrayParam("structureParams");
747
748 return invokeWith(new Object[] {collection, browseService, lang,
749 classifierNodeIDs, structureParams});
750 }
751
752 /** @return a help string for listing all the web service methods. */
753 public String help() {
754 call.setOperationName( "help" );
755 return invokeWith(new Object[] {});
756 }
757
758 /** @param methodname is the name of the method to be described.
759 * @return a help string for the given method, explaining what the method
760 * does, what parameters it expects and their types and what it returns.
761 */
762 public String helpWithMethod(String methodname) {
763 call.setOperationName( "helpWithMethod" );
764 addStringParam("methodname");
765 return invokeWith(new Object[] {methodname});
766 }
767
768 public static void main(String args[]) {
769 try{
770 GS3WebServicesQBRAPI ws = new GS3WebServicesQBRAPI(GS3ServicesAPIA.showWsdlInputDialog());
771
772 // (1) trying 4 describe methods
773 System.out.println(ws.describe("", ""));
774 System.out.println(ws.describeCollection("gs2mgppdemo", "", ""));
775 // ? //System.out.println(ws.describeServiceCluster("gs2mgppdemo", "", ""));
776 System.out.println(ws.describeCollectionService("gs2mgppdemo", "AdvancedFieldQuery", "", ""));
777 System.out.println(ws.describeService("AddItem", "", ""));
778
779 // (2) try 3 query methods (simplerFieldQuery twice) + getFieldNameMappings()
780 HashMap map = new HashMap();
781 map.put("maxDocs", "100");
782 map.put("level", "Sec");
783 map.put("accent", "1");
784 map.put("matchMode", "some");
785 map.put("fqf", "ZZ,ZZ,ZZ,ZZ");
786 map.put("case", "1");
787 map.put("sortBy", "1");
788 map.put("fqv", "snail,water,,");
789
790 String response = ws.query("gs2mgppdemo", "FieldQuery", "", map);
791 System.out.println("Regular query: " + response);
792
793
794 // (3) try 2 browse
795 System.out.println("describe browse:\n"
796 + ws.describeCollectionService("gs2mgppdemo", "ClassifierBrowse", "", ""));
797
798 System.out.println("browse children of CL1-CL4:\n" +
799 ws.browse("gs2mgppdemo", "ClassifierBrowse", "",
800 new String[]{"CL1", "CL2", "CL3", "CL4"}, new String[]{"children"}));
801
802 System.out.println("browse descendants of CL2.3:\n" +
803 ws.browseDescendants("gs2mgppdemo", "ClassifierBrowse", "",
804 new String[]{"CL2.3"}));
805
806 // (4) try 2 DocStructure
807 System.out.println("retrieve ancestors and children structure of HASH016193b2847874f3c956d22e.4:\n" +
808 ws.retrieveDocumentStructure("gs2mgppdemo", "",
809 new String[]{"HASH016193b2847874f3c956d22e.4"},
810 new String[]{"ancestors", "children"}, new String[]{"numSiblings"}));
811
812
813 System.out.println("retrieve entire structure of HASH016193b2847874f3c956d22e.4.1:\n" +
814 ws.retrieveEntireDocumentStructure(
815 "gs2mgppdemo", "", new String[]{"HASH016193b2847874f3c956d22e.4.1"}));
816
817
818 // (5) try the 1 DocumentContent retrieve
819 System.out.println("retrieve content of HASH016193b2847874f3c956d22e.4:\n" +
820 ws.retrieveDocumentContent("gs2mgppdemo", "",
821 new String[]{"HASH016193b2847874f3c956d22e.4", "HASH016193b2847874f3c956d22e.4.1",
822 "HASH016193b2847874f3c956d22e.4.2"}));
823
824
825 // (6) try 2 DocumentMeta
826 System.out.println("retrieve title meta of HASH016193b2847874f3c956d22e.4 children:\n" +
827 ws.retrieveDocumentMetadata("gs2mgppdemo", "",
828 new String[]{"HASH016193b2847874f3c956d22e.4.1", "HASH016193b2847874f3c956d22e.4.2",
829 "HASH016193b2847874f3c956d22e.4.3"}, new String[]{"Title"}));
830
831 System.out.println("retrieve all meta of HASH016193b2847874f3c956d22e.4 children:\n" +
832 ws.retrieveAllDocumentMetadata("gs2mgppdemo", "",
833 new String[]{"HASH016193b2847874f3c956d22e.4",
834 "HASH016193b2847874f3c956d22e.4.1", "HASH016193b2847874f3c956d22e.4.2",
835 "HASH016193b2847874f3c956d22e.4.3"}));
836
837 // (7) try 2 BrowseMeta
838 System.out.println("retrieve all browse meta of CL1, CL2, CL2.1, CL3:\n" +
839 ws.retrieveAllBrowseMetadata("gs2mgppdemo", "", "",
840 new String[]{"CL1", "CL2",
841 "CL2.1", "CL3"}));
842
843 System.out.println("retrieve Title, hastxt browse meta of CL1, CL2, CL2.1, CL3:\n" +
844 ws.retrieveBrowseMetadata("gs2mgppdemo", "", "",
845 new String[]{"CL1", "CL2","CL2.1", "CL3"}, new String[]{"Title", "hastxt"}));
846
847 // (8) try help
848 System.out.println(ws.help());
849 System.out.println(ws.helpWithMethod("describe"));
850
851 /*
852 // need to make <something>SOAPServer's "properties" member variable public
853 // before these can be tested:
854 System.out.println("Calling webservices HELP:\n" + org.greenstone.gs3services.QBRSOAPServer.help());
855 java.util.Enumeration props = org.greenstone.gs3services.QBRSOAPServer.properties.keys();
856 while(props.hasMoreElements()){
857 String methodName = (String)props.nextElement();
858 System.out.println(//"method: " + methodName + "\n" +
859 org.greenstone.gs3services.QBRSOAPServer.helpWithMethod(methodName));
860 }
861 System.out.println("Calling webservices HELP:\n" + org.greenstone.gs3services.AdminSOAPServer.help());
862 java.util.Enumeration props = org.greenstone.gs3services.AdminSOAPServer.properties.keys();
863 while(props.hasMoreElements()){
864 String methodName = (String)props.nextElement();
865 System.out.println(//"method: " + methodName + "\n" +
866 org.greenstone.gs3services.AdminSOAPServer.helpWithMethod(methodName));
867 }*/
868
869 }catch(Exception e) {
870 System.out.println("Problem accessing service\n" + e.getMessage());
871 e.printStackTrace();
872 }
873 }
874}
Note: See TracBrowser for help on using the repository browser.