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

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

Changed default port 9090 to 8080

File size: 39.4 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:8080/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 /**
525 * This method is used to perform the most basic query:
526 * it assumes defaults for all other parameters and provides only
527 * the query string. It is built on top of a TextQuery.
528 * @param collection is the Greenstone collection to be searched
529 * @param lang is the preferred language of the display content in
530 * the response to be returned.
531 * @param query is the string to be sought in the Greenstone collection
532 * @return a Greenstone 3 XML response message for the query specifying
533 * the search results.
534 */
535 public String basicQuery(String collection, String lang, String query) {
536 call.setOperationName( "basicQuery" );
537 addStringParam("collection");
538 addStringParam("lang");
539 addStringParam("query");
540 return invokeWith(new Object[]{collection, lang, query});
541 }
542
543 /* (3) RETRIEVE PROCESS METHODS - pp.47-49 */
544 /** (a) DocumentContentRetrieve request sent to a collection's
545 * DocumentContentRetrieve service (p.48)
546 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 48</a>
547 * @param collection is the name of the Collection whose
548 * DocumentContentRetrieve is requested
549 * @param lang is the language of the display content in the response
550 * @param docNodeIDs is the list of documentNodeIDs for which the
551 * content ought to be retrieved.
552 */
553 public String retrieveDocumentContent(
554 String collection, String lang, String[] docNodeIDs)
555 {
556 call.setOperationName( "retrieveDocumentContent" );
557
558 addStringParam("collection");
559 addStringParam("lang");
560 addArrayParam("docNodeIDs");
561
562 return invokeWith(new Object[] {collection, lang, docNodeIDs});
563 }
564
565 /** (b) DocumentStructureRetrieve request sent to a collection's
566 * DocumentStructureRetrieve service (manual pp.48, 49) to retrieve
567 * the entire document structure.
568 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 48, 49</a>
569 * @param collection is the name of the Collection whose
570 * DocumentStructureRetrieve is requested
571 * @param lang is the language of the display content in the response
572 * @param docNodeIDs is the list of documentNodeIDs for which the
573 * entire structure ought to be retrieved.
574 */
575 public String retrieveEntireDocumentStructure(String collection,
576 String lang, String[] docNodeIDs)
577 {
578 call.setOperationName( "retrieveEntireDocumentStructure" );
579
580 addStringParam("collection");
581 addStringParam("lang");
582 addArrayParam("docNodeIDs");
583
584 return invokeWith(new Object[] {collection, lang, docNodeIDs});
585 }
586
587 /** DocumentStructureRetrieve request sent to a collection's
588 * DocumentStructureRetrieve service (manual pp.48, 49) to retrieve
589 * the specified part of the document's structure.
590 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 48, 49</a>
591 * @param collection is the name of the Collection whose
592 * DocumentStructureRetrieve is requested
593 * @param lang is the language of the display content in the response
594 * @param docNodeIDs is the list of documentNodeIDs for which the
595 * structure ought to be retrieved.
596 * @param structure specifies what structure information needs to
597 * be retrieved. The values can be one or more of ancestors, parent,
598 * siblings, children, descendents (NOTE SPELLING), entire.
599 * @param info - for specifying extra information to be retrieved.
600 * Possible values for info parameters are numSiblings, siblingPosition,
601 * numChildren.
602 */
603 public String retrieveDocumentStructure(String collection, String lang,
604 String[] docNodeIDs, String[] structure, String[] info)
605 {
606 call.setOperationName( "retrieveDocumentStructure" );
607
608 addStringParam("collection");
609 addStringParam("lang");
610 addArrayParam("docNodeIDs");
611 addArrayParam("structure");
612 addArrayParam("info");
613
614 return invokeWith(new Object[] {
615 collection, lang, docNodeIDs, structure, info});
616 }
617
618 /** (c) DocumentMetadataRetrieve request sent to a collection's
619 * DocumentMetadataRetrieve service to retrieve all of a document's metadata.
620 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 47</a>
621 * @param collection is the name of the Collection whose
622 * DocumentMetadataRetrieve is requested
623 * @param lang is the language of the display content in the response
624 * @param docNodeIDs is the list of documentNodeIDs for which the
625 * structure ought to be retrieved.
626 */
627 public String retrieveAllDocumentMetadata(String collection, String lang,
628 String[] docNodeIDs)
629 {
630 call.setOperationName( "retrieveAllDocumentMetadata" );
631
632 addStringParam("collection");
633 addStringParam("lang");
634 addArrayParam("docNodeIDs");
635
636 return invokeWith(new Object[] {collection, lang, docNodeIDs});
637 }
638
639 /** DocumentMetadataRetrieve service to retrieve some specific
640 * metadata values of a document. (Manual on page 47.)
641 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 47</a>
642 * @param collection is the name of the Collection whose
643 * DocumentContentRetrieve is requested
644 * @param lang is the language of the display content in the response
645 * @param docNodeIDs is the list of documentNodeIDs for which the
646 * structure ought to be retrieved.
647 * @param metaNames is a list of metadata names which are requested
648 * to be fetched for the specified documents.
649 */
650 public String retrieveDocumentMetadata(String collection, String lang,
651 String[] docNodeIDs, String[] metaNames)
652 {
653 call.setOperationName( "retrieveDocumentMetadata" );
654
655 addStringParam("collection");
656 addStringParam("lang");
657 addArrayParam("docNodeIDs");
658 addArrayParam("metaNames");
659
660 return invokeWith(new Object[] {collection, lang, docNodeIDs, metaNames});
661 }
662
663 /** Retrieve all classification Metadata for browsing (sent to the
664 * ClassifierBrowseMetadataRetrieve service).
665 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 47, 48</a>
666 * @param collection is the name of the Collection whose
667 * ClassifierBrowseMetadataRetrieve service is called
668 * @param categoryName - name of the browsing category, usually
669 * ClassifierBrowse. (If left as "", then it defaults to ClassifierBrowse)
670 * @param lang is the language of the display content in the response
671 * @param nodeIDs is the list of document or classifier NodeIDs
672 * for which the metadata ought to be retrieved.
673 */
674 public String retrieveAllBrowseMetadata(String collection,
675 String categoryName, String lang, String[] nodeIDs)
676 {
677 call.setOperationName( "retrieveAllBrowseMetadata" );
678
679 addStringParam("collection");
680 addStringParam("categoryName");
681 addStringParam("lang");
682 addArrayParam("nodeIDs");
683
684 return invokeWith(new Object[] {collection, categoryName, lang, nodeIDs});
685 }
686
687 /** ClassifierBrowseMetadataRetrieve service to retrieve some specific
688 * metadata values of a document.
689 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - pages 47, 48</a>
690 * @param collection is the name of the Collection whose
691 * ClassifierBrowseMetadataRetrieve service is called
692 * @param categoryName - name of the browsing category, usually
693 * "ClassifierBrowse". (If left as "", then it defaults to ClassifierBrowse)
694 * @param lang is the language of the display content in the response
695 * @param nodeIDs is the list of document or classifier NodeIDs
696 * for which the metadata ought to be retrieved.
697 * @param metaNames is a list of metadata names which are requested
698 * to be fetched for the specified documents or classifiers */
699 public String retrieveBrowseMetadata(String collection, String categoryName,
700 String lang, String[] nodeIDs, String[] metaNames)
701 {
702 call.setOperationName( "retrieveBrowseMetadata" );
703
704 addStringParam("collection");
705 addStringParam("categoryName");
706 addStringParam("lang");
707 addArrayParam("nodeIDs");
708 addArrayParam("metaNames");
709
710 return invokeWith(new Object[] {collection, categoryName, lang,
711 nodeIDs, metaNames});
712 }
713
714 /* (4) Classifier BROWSE PROCESS METHODS */
715 /** To send a browse request for all the descendants of a classifier node.
716 * Useful for getting the entire structure of a top-level
717 * &lt;classificationNode&gt;.
718 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 46</a>
719 * @param collection is the name of the Collection whose browse Classifier
720 * Browse Service is called
721 * @param browseService is the name of the (Classifier) Browse Service (of
722 * the given collection) to which this request message is sent.
723 * @param lang is the language of the display content in the response
724 * @param classifierNodeIDs is an array of classifierNodeIDs for which the
725 * structures ought to be retrieved.
726 */
727 public String browseDescendants(String collection, String browseService,
728 String lang, String[] classifierNodeIDs)
729 {
730 call.setOperationName( "browseDescendants" );
731
732 addStringParam("collection");
733 addStringParam("browseService");
734 addStringParam("lang");
735 addArrayParam("classifierNodeIDs");
736
737 return invokeWith(new Object[] {
738 collection, browseService, lang, classifierNodeIDs});
739 }
740
741 /** To send a browse request for specific parts of a classifier node
742 * (children, ancestors, descendants). Useful for getting specific parts
743 * of the structure of a top-level &lt;classificationNode&gt;.
744 * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 46</a>
745 * @param collection is the name of the Collection whose browse Classifier
746 * Browse Service is called
747 * @param browseService is the name of the (Classifier) Browse Service (of
748 * the given collection) to which this request message is sent.
749 * @param lang is the language of the display content in the response
750 * @param classifierNodeIDs is the list of classifierNodeIDs for which the
751 * structure ought to be retrieved.
752 * @param structureParams the list of parameters indicating what structure
753 * information is requested. Accepted values are ancestors, parent, siblings,
754 * children, descendants.
755 */
756 public String browse(String collection, String browseService, String lang,
757 String[] classifierNodeIDs, String[] structureParams)
758 {
759 call.setOperationName( "browse" );
760
761 addStringParam("collection");
762 addStringParam("browseService");
763 addStringParam("lang");
764 addArrayParam("classifierNodeIDs");
765 addArrayParam("structureParams");
766
767 return invokeWith(new Object[] {collection, browseService, lang,
768 classifierNodeIDs, structureParams});
769 }
770
771 /** @return a help string for listing all the web service methods. */
772 public String help() {
773 call.setOperationName( "help" );
774 return invokeWith(new Object[] {});
775 }
776
777 /** @param methodname is the name of the method to be described.
778 * @return a help string for the given method, explaining what the method
779 * does, what parameters it expects and their types and what it returns.
780 */
781 public String helpWithMethod(String methodname) {
782 call.setOperationName( "helpWithMethod" );
783 addStringParam("methodname");
784 return invokeWith(new Object[] {methodname});
785 }
786
787 public static void main(String args[]) {
788 try{
789 GS3WebServicesQBRAPI ws = new GS3WebServicesQBRAPI(GS3ServicesAPIA.showWsdlInputDialog());
790
791 // (1) trying 4 describe methods
792 System.out.println(ws.describe("", ""));
793 System.out.println(ws.describeCollection("gs2mgppdemo", "", ""));
794 // ? //System.out.println(ws.describeServiceCluster("gs2mgppdemo", "", ""));
795 System.out.println(ws.describeCollectionService("gs2mgppdemo", "AdvancedFieldQuery", "", ""));
796 System.out.println(ws.describeService("AddItem", "", ""));
797
798 // (2) try 2 query methods: query and basicQuery
799 HashMap map = new HashMap();
800 map.put("maxDocs", "100");
801 map.put("level", "Sec");
802 map.put("accent", "1");
803 map.put("matchMode", "some");
804 map.put("fqf", "ZZ,ZZ,ZZ,ZZ");
805 map.put("case", "1");
806 map.put("sortBy", "1");
807 map.put("fqv", "snail,water,,");
808
809 String response = ws.query("gs2mgppdemo", "FieldQuery", "", map);
810 System.out.println("Regular query: " + response);
811
812 // basicQuery
813 response = ws.basicQuery("gs2mgppdemo", "", "cat");
814 System.out.println("Basic query on 'cat' over collection gs2mgppdemo:"
815 + response);
816
817 // (3) try 2 browse
818 System.out.println("describe browse:\n"
819 + ws.describeCollectionService("gs2mgppdemo", "ClassifierBrowse", "", ""));
820
821 System.out.println("browse children of CL1-CL4:\n" +
822 ws.browse("gs2mgppdemo", "ClassifierBrowse", "",
823 new String[]{"CL1", "CL2", "CL3", "CL4"}, new String[]{"children"}));
824
825 System.out.println("browse descendants of CL2.3:\n" +
826 ws.browseDescendants("gs2mgppdemo", "ClassifierBrowse", "",
827 new String[]{"CL2.3"}));
828
829 // (4) try 2 DocStructure
830 System.out.println("retrieve ancestors and children structure of HASH016193b2847874f3c956d22e.4:\n" +
831 ws.retrieveDocumentStructure("gs2mgppdemo", "",
832 new String[]{"HASH016193b2847874f3c956d22e.4"},
833 new String[]{"ancestors", "children"}, new String[]{"numSiblings"}));
834
835
836 System.out.println("retrieve entire structure of HASH016193b2847874f3c956d22e.4.1:\n" +
837 ws.retrieveEntireDocumentStructure(
838 "gs2mgppdemo", "", new String[]{"HASH016193b2847874f3c956d22e.4.1"}));
839
840
841 // (5) try the 1 DocumentContent retrieve
842 System.out.println("retrieve content of HASH016193b2847874f3c956d22e.4:\n" +
843 ws.retrieveDocumentContent("gs2mgppdemo", "",
844 new String[]{"HASH016193b2847874f3c956d22e.4", "HASH016193b2847874f3c956d22e.4.1",
845 "HASH016193b2847874f3c956d22e.4.2"}));
846
847
848 // (6) try 2 DocumentMeta
849 System.out.println("retrieve title meta of HASH016193b2847874f3c956d22e.4 children:\n" +
850 ws.retrieveDocumentMetadata("gs2mgppdemo", "",
851 new String[]{"HASH016193b2847874f3c956d22e.4.1", "HASH016193b2847874f3c956d22e.4.2",
852 "HASH016193b2847874f3c956d22e.4.3"}, new String[]{"Title"}));
853
854 System.out.println("retrieve all meta of HASH016193b2847874f3c956d22e.4 children:\n" +
855 ws.retrieveAllDocumentMetadata("gs2mgppdemo", "",
856 new String[]{"HASH016193b2847874f3c956d22e.4",
857 "HASH016193b2847874f3c956d22e.4.1", "HASH016193b2847874f3c956d22e.4.2",
858 "HASH016193b2847874f3c956d22e.4.3"}));
859
860 // (7) try 2 BrowseMeta
861 System.out.println("retrieve all browse meta of CL1, CL2, CL2.1, CL3:\n" +
862 ws.retrieveAllBrowseMetadata("gs2mgppdemo", "", "",
863 new String[]{"CL1", "CL2",
864 "CL2.1", "CL3"}));
865
866 System.out.println("retrieve Title, hastxt browse meta of CL1, CL2, CL2.1, CL3:\n" +
867 ws.retrieveBrowseMetadata("gs2mgppdemo", "", "",
868 new String[]{"CL1", "CL2","CL2.1", "CL3"}, new String[]{"Title", "hastxt"}));
869
870 // (8) try help
871 System.out.println(ws.help());
872 System.out.println(ws.helpWithMethod("describe"));
873
874 /*
875 // need to make <something>SOAPServer's "properties" member variable public
876 // before these can be tested:
877 System.out.println("Calling webservices HELP:\n" + org.greenstone.gs3services.QBRSOAPServer.help());
878 java.util.Enumeration props = org.greenstone.gs3services.QBRSOAPServer.properties.keys();
879 while(props.hasMoreElements()){
880 String methodName = (String)props.nextElement();
881 System.out.println(//"method: " + methodName + "\n" +
882 org.greenstone.gs3services.QBRSOAPServer.helpWithMethod(methodName));
883 }
884 System.out.println("Calling webservices HELP:\n" + org.greenstone.gs3services.AdminSOAPServer.help());
885 java.util.Enumeration props = org.greenstone.gs3services.AdminSOAPServer.properties.keys();
886 while(props.hasMoreElements()){
887 String methodName = (String)props.nextElement();
888 System.out.println(//"method: " + methodName + "\n" +
889 org.greenstone.gs3services.AdminSOAPServer.helpWithMethod(methodName));
890 }*/
891
892 }catch(Exception e) {
893 System.out.println("Problem accessing service\n" + e.getMessage());
894 e.printStackTrace();
895 }
896 }
897}
Note: See TracBrowser for help on using the repository browser.