Class WebServiceClient
java.lang.Object
org.dlese.dpc.serviceclients.webclient.WebServiceClient
- Direct Known Subclasses:
NCSWebServiceClient,SearchServiceClient
WebServiceClient provides helpers to communicate with webservices via timed connections (time out is adjustable).
The helper methods do the following:
- accept parameters,
- package the parameters into a webservice request url,
- submit the request URL to the service server
- parse the response into either a value or exception, which are returned to the caller.
The DDS helpers submit requests to the DDS Search Web Services and returns
responses as Document.
- UrlCheck - finds resources matching a URL (possibly wildcarded), and
- GetRecord - retrieves a given record by ID
The DCS helpers support the following repository services:
- PutRecord - inserts a metadata record into a specified collection in a remote DCS repository
- doGetId - returns a unique identifier for a specified collection of a remote DCS.
- Author:
- ostwald
$Id: WebServiceClient.java,v 1.23 2009/03/20 23:33:58 jweather Exp $
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionWebServiceClient(String baseWebServiceUrl) Constructor for the WebServiceClient object. -
Method Summary
Modifier and TypeMethodDescriptionRequests an id from DCS getId web service.doPutRecord(String recordXml, String xmlFormat, String collection) doPutRecord(String recordXml, String xmlFormat, String collection, String status, String statusNote) Generate an ID and insert it in the recordXML before calling the PutRecord web servicedoPutRecord(String recordXml, String xmlFormat, String collection, String id, String status, String statusNote) Assumes id is already placed in the xmlRecord.org.dom4j.DocumentSubmits a request to the GetRecord DDS Web Service and returns response as aDocument.Gets the requestUrl attribute of the WebServiceClient objectprotected org.dom4j.Documentretreives the contents of the requestUrl field as aDocumentstatic org.dom4j.DocumentgetResponseDoc(URL url) Static version of getResponseDoc.static StringSearches the response string for error elements and returns the contents of the error if one is found.static StringgetResponseError(org.dom4j.Document doc) Gets the responseError attribute of the WebServiceClient classprotected StringSubmits a Web Service and returns the result as a string.static StringgetTimedURL(URL url) Uses aTimedURLConnectionto get the repsonse from the web service (the request is a URL), which is returned as a String.static org.dom4j.DocumentgetTimedXmlDocument(URL url) gets the contents of a URL viagetTimedURL(URL)and then parses the contents into a dom4j Document, which is returnedintstatic voidThe main program for the WebServiceClient classstatic voidsetDebug(boolean db) Sets the debug attributevoidsetRequestUrl(String verb, String argStr) Sets the requestUrl attribute of the WebServiceClient objectvoidsetRequestUrl(URL url) Sets the requestUrl attribute of the WebServiceClient objectvoidsetTimeOutSecs(int i) static StringPlace the provided ID into the provided recordXml.org.dom4j.DocumentSubmit a request (query) to the UrlCheck Web service and return the response as aDocument.
-
Field Details
-
debug
protected static boolean debugDescription of the Field
-
-
Constructor Details
-
WebServiceClient
Constructor for the WebServiceClient object.Example baseWebServiceUrls:
- dds search: "http://dcs.dlese.org/roles/services/ddsws1-0"
- dcs put: "http://dcs.dlese.org/roles/services/dcsws1-0"
- Parameters:
baseWebServiceUrl- url of Web Service
-
-
Method Details
-
getBaseUrl
-
setTimeOutSecs
public void setTimeOutSecs(int i) -
getTimeOutSecs
public int getTimeOutSecs() -
urlCheck
Submit a request (query) to the UrlCheck Web service and return the response as aDocument. The UrlCheck service returns items that match the query. the query is a url and may contain asterisks as wildcards.- Parameters:
s- query to be submitted to UrlCheck service.- Returns:
- result from UrlCheck Service as Document
- Throws:
WebServiceClientException- Description of the Exception
-
doSearch
- Throws:
WebServiceClientException
-
stuffId
Place the provided ID into the provided recordXml. recordXml must be "delocalized" - it must contain namespace information in the rootElement. Currently supported xmlFormats are "adn" and "news_opps".- Parameters:
recordXml- Description of the Parameterid- Description of the Parameter- Returns:
- Description of the Return Value
- Throws:
Exception- Description of the Exception
-
doPutRecord
public String doPutRecord(String recordXml, String xmlFormat, String collection, String status, String statusNote) throws WebServiceClientException Generate an ID and insert it in the recordXML before calling the PutRecord web service- Parameters:
recordXml- xml record to be putxmlFormat- metadata format of xml record (e.g., "adn")collection- destination collection (e.g., "dcc")- Returns:
- ID of created record
- Throws:
WebServiceClientException- Description of the Exception
-
doPutRecord
public String doPutRecord(String recordXml, String xmlFormat, String collection) throws WebServiceClientException - Throws:
WebServiceClientException
-
doPutRecord
public String doPutRecord(String recordXml, String xmlFormat, String collection, String id, String status, String statusNote) throws WebServiceClientException Assumes id is already placed in the xmlRecord. Note - the ID within the recordXml is ultimately used by the indexer, NOT the provided id (see RepositoryManger.putRecord).- Parameters:
recordXml- xml record to be putxmlFormat- metadata format of xml record (e.g., "adn")collection- destination collection (e.g., "dcc")id- xml record id- Returns:
- ID of created record
- Throws:
WebServiceClientException- Description of the Exception
-
doGetId
Requests an id from DCS getId web service. Errors are signaled by an exception that contains the error message. otherwise, the Id is returned as a string- Parameters:
collection- Description of the Parameter- Returns:
- The id
- Throws:
WebServiceClientException- If unable to generate an ID
-
getRecord
Submits a request to the GetRecord DDS Web Service and returns response as aDocument. The GetRecord service returns an ADN record wrapped in a XML response.- Parameters:
id- id of the record to get- Returns:
- the response as a Document
- Throws:
WebServiceClientException- Description of the Exception
-
setRequestUrl
Sets the requestUrl attribute of the WebServiceClient object- Parameters:
url- The new requestUrl value
-
getRequestUrl
Gets the requestUrl attribute of the WebServiceClient object- Returns:
- The requestUrl value
-
setRequestUrl
Sets the requestUrl attribute of the WebServiceClient object- Parameters:
verb- The new requestUrl valueargStr- The new requestUrl value
-
getResponseStr
Submits a Web Service and returns the result as a string. Throws a WebServiceClientException if the response contains an error element.- Returns:
- The responseStr value
- Throws:
WebServiceClientException- Description of the Exception
-
getResponseError
Searches the response string for error elements and returns the contents of the error if one is found.- Parameters:
s- Web service response as string- Returns:
- contents of error if found or empty string if not found
-
getResponseDoc
retreives the contents of the requestUrl field as aDocument- Returns:
- dom4j Document representation of response
- Throws:
WebServiceClientException- if unsuccessful retrieving url or parsing doc
-
getResponseDoc
Static version of getResponseDoc.- Parameters:
url- Description of the Parameter- Returns:
- The responseDoc value
- Throws:
WebServiceClientException- Description of the Exception
-
getResponseError
Gets the responseError attribute of the WebServiceClient class- Parameters:
doc- Description of the Parameter- Returns:
- The responseError value
-
getTimedURL
Uses aTimedURLConnectionto get the repsonse from the web service (the request is a URL), which is returned as a String.- Parameters:
url- Description of the Parameter- Returns:
- The timedURL value
- Throws:
WebServiceClientException- Description of the Exception
-
getTimedXmlDocument
public static org.dom4j.Document getTimedXmlDocument(URL url) throws WebServiceClientException, org.dom4j.DocumentException gets the contents of a URL viagetTimedURL(URL)and then parses the contents into a dom4j Document, which is returned- Parameters:
url- url to retrieve- Returns:
- contents of url as dom4j Document, or null if unsuccessful
- Throws:
WebServiceClientException- Description of the Exceptionorg.dom4j.DocumentException- Description of the Exception
-
main
The main program for the WebServiceClient class- Parameters:
args- The command line arguments
-
setDebug
public static void setDebug(boolean db) Sets the debug attribute- Parameters:
db- The new debug value
-