Changeset 3449
- Timestamp:
- 18/02/08 15:22:24 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/DiscoveryServiceClient.java
r3054 r3449 1 1 package ndg.services.discovery; 2 3 import discoveryserviceapi.*; 4 import java.util.Date; 2 5 3 6 /** … … 38 41 DiscoveryServiceClient client = new DiscoveryServiceClient("http://glue.badc.rl.ac.uk/axis2/services/DiscoveryService"); 39 42 40 System.out.println( "Trying a doSearch..." ); 41 String doSearchResult = client.doSearch( 42 "<m:doSearch xmlns:m=\"urn:DiscoveryServiceAPI\"><m:term>*neodc*</m:term><m:termType>fullText</m:termType></m:doSearch>" 43 ); 44 System.out.println( doSearchResult ); 45 46 System.out.println( "Trying a doPresent..." ); 47 String doPresentResult = client.doPresent( 48 "<m:doPresent xmlns:m=\"urn:DiscoveryServiceAPI\"><m:documents><m:document>neodc.nerc.ac.uk__DIF__dataent_11924879127625221.xml</m:document></m:documents><m:presentFormat>original</m:presentFormat></m:doPresent>" 49 ); 50 System.out.println( doPresentResult ); 43 // Method 1: request documents passed as strings 44 if ( args[0].equals("string") ) 45 { 46 System.out.println( "Trying a doSearch..." ); 47 String doSearchResult = client.doSearch( 48 "<m:doSearch xmlns:m=\"urn:DiscoveryServiceAPI\"><m:term>*neodc*</m:term><m:termType>fullText</m:termType></m:doSearch>" 49 ); 50 System.out.println( doSearchResult ); 51 52 System.out.println( "Trying a doPresent..." ); 53 String doPresentResult = client.doPresent( 54 "<m:doPresent xmlns:m=\"urn:DiscoveryServiceAPI\"><m:documents><m:document>neodc.nerc.ac.uk__DIF__dataent_11924879127625221.xml</m:document></m:documents><m:presentFormat>original</m:presentFormat></m:doPresent>" 55 ); 56 System.out.println( doPresentResult ); 57 } 58 else if ( args[0].equals("helpers") ) 59 { 60 // Method 2: request documents construced using helper classes 61 System.out.println( "Trying a doSearch using helper classes" ); 62 DoSearchDocument reqDoc = DoSearchDocument.Factory.newInstance(); 63 SearchType doSearch = reqDoc.addNewDoSearch(); 64 doSearch.setTermType("fullText"); 65 doSearch.setTerm( args[1] ); 66 //if ( args.length == 2 ) 67 //{ 68 doSearch.setScopeArray( new String[]{ args[2] } ); 69 //} 70 System.out.println("doSearch request:\n" + reqDoc.toString() ); 71 72 Date dateBeforeSearch = new Date(); 73 DoSearchReturnDocument doSearchReturnDocument = client.getDoSearchReturnDocument( reqDoc ); 74 Date dateAfterSearch = new Date(); 75 76 System.out.println("doSearch result:\n" + doSearchReturnDocument.toString() ); 77 78 if ( doSearchReturnDocument != null) 79 { 80 System.out.println( doSearchReturnDocument.toString() ); 81 System.out.println( "Trying a doPresent using helper classes" ); 82 83 DoPresentDocument presReqDoc = DoPresentDocument.Factory.newInstance(); 84 PresentType doPresent = presReqDoc.addNewDoPresent(); 85 86 // Use document array in result of search as document array in request to doPresent 87 // (does not retrieve hits greater than default value of howMany, but works for this example) 88 SearchReturnType searchReturn = doSearchReturnDocument.getDoSearchReturn(); 89 if ( searchReturn.getHits() > 0 ) 90 { 91 doPresent.setDocuments( searchReturn.getDocuments() ); 92 doPresent.setFormat("DIF"); 93 System.out.println("doPresent request:\n" + presReqDoc.toString() ); 94 95 Date dateBeforePresent = new Date(); 96 DoPresentReturnDocument doPresentReturnDocument = client.getDoPresentReturnDocument( presReqDoc ); 97 Date dateAfterPresent = new Date(); 98 99 //System.out.println( doPresentReturnDocument.toString() ); 100 101 System.out.println("Before search\t" + dateBeforeSearch.getTime() ); 102 System.out.println("After search\t" + dateAfterSearch.getTime()); 103 104 System.out.println("Search duration\t" + (dateAfterSearch.getTime()-dateBeforeSearch.getTime() ) ); 105 106 System.out.println("Before present\t" + dateBeforePresent.getTime()); 107 System.out.println("After present\t" + dateAfterPresent.getTime()); 108 System.out.println("Present duration\t" + (dateAfterPresent.getTime()-dateBeforePresent.getTime()) ); 109 110 } 111 112 } 113 } 114 else 115 { 116 System.out.println("Usage : DiscoveryServiceClient string|helpers <term>"); 117 } 118 119 120 121 51 122 52 123 } … … 96 167 return resDoc.toString(); 97 168 } 169 170 /** 171 * Acts as proxy method for doSearch operation 172 * @param reqDocAsString String containing XML request doc (see WSDL for structure) 173 * @return DoSearchReturnDocument containing SearchReturn (see WSDL for structure) 174 */ 175 public DoSearchReturnDocument getDoSearchReturnDocument( 176 String reqDocAsString 177 ) throws java.rmi.RemoteException, org.apache.xmlbeans.XmlException 178 { 179 discoveryserviceapi.DoSearchDocument reqDoc= discoveryserviceapi.DoSearchDocument.Factory.parse( reqDocAsString ); 180 discoveryserviceapi.DoSearchReturnDocument resDoc= _service.doSearch( reqDoc ); 181 return resDoc; 182 } 183 184 /** 185 * Acts as proxy method for doPresent operation 186 * @param reqDocAsString String containing XML request doc (see WSDL for structure) 187 * @return DoPresentReturnDocument containing PresentReturn (see WSDL for structure) 188 */ 189 public DoPresentReturnDocument getDoPresentReturnDocument( 190 String reqDocAsString 191 ) throws java.rmi.RemoteException, org.apache.xmlbeans.XmlException 192 { 193 discoveryserviceapi.DoPresentDocument reqDoc= discoveryserviceapi.DoPresentDocument.Factory.parse( reqDocAsString ); 194 discoveryserviceapi.DoPresentReturnDocument resDoc= _service.doPresent( reqDoc ); 195 return resDoc; 196 } 197 198 /** 199 * Acts as proxy method for doSearch operation 200 * @param reqDoc DoSearchDocument containing request doc (see WSDL for structure) 201 * @return DoSearchReturnDocument containing SearchReturn (see WSDL for structure) 202 */ 203 public DoSearchReturnDocument getDoSearchReturnDocument( 204 DoSearchDocument reqDoc 205 ) throws java.rmi.RemoteException, org.apache.xmlbeans.XmlException 206 { 207 discoveryserviceapi.DoSearchReturnDocument resDoc= _service.doSearch( reqDoc ); 208 return resDoc; 209 } 210 211 /** 212 * Acts as proxy method for doPresent operation 213 * @param reqDoc DoPresentDocument containing request doc (see WSDL for structure) 214 * @return DoPresentReturnDocument containing PresentReturn (see WSDL for structure) 215 */ 216 public DoPresentReturnDocument getDoPresentReturnDocument( 217 DoPresentDocument reqDoc 218 ) throws java.rmi.RemoteException, org.apache.xmlbeans.XmlException 219 { 220 discoveryserviceapi.DoPresentReturnDocument resDoc= _service.doPresent( reqDoc ); 221 return resDoc; 222 } 223 98 224 };
Note: See TracChangeset
for help on using the changeset viewer.