DLESE Tools
v1.6.0

org.dlese.dpc.serviceclients.webclient
Class WebServiceClient

java.lang.Object
  extended by org.dlese.dpc.serviceclients.webclient.WebServiceClient
Direct Known Subclasses:
NCSWebServiceClient, SearchServiceClient

public class WebServiceClient
extends Object

WebServiceClient provides helpers to communicate with webservices via timed connections (time out is adjustable).

The helper methods do the following:

  1. accept parameters,
  2. package the parameters into a webservice request url,
  3. submit the request URL to the service server
  4. parse the response into either a value or exception, which are returned to the caller.
Currently two DDS and two DCS webservices are supported:

The DDS helpers submit requests to the DDS Search Web Services and returns responses as Document.

  1. UrlCheck - finds resources matching a URL (possibly wildcarded), and
  2. GetRecord - retrieves a given record by ID

The DCS helpers support the following repository services:

  1. PutRecord - inserts a metadata record into a specified collection in a remote DCS repository
  2. 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
protected static boolean debug
          Description of the Field
 
Constructor Summary
WebServiceClient(String baseWebServiceUrl)
          Constructor for the WebServiceClient object.
 
Method Summary
 String doGetId(String collection)
          Requests an id from DCS getId web service.
 String doPutRecord(String recordXml, String xmlFormat, String collection)
           
 String 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 service
 String doPutRecord(String recordXml, String xmlFormat, String collection, String id, String status, String statusNote)
          Assumes id is already placed in the xmlRecord.
 Document doSearch(String queryStr)
           
 String getBaseUrl()
           
 GetRecordResponse getRecord(String id)
          Submits a request to the GetRecord DDS Web Service and returns response as a Document.
 URL getRequestUrl()
          Gets the requestUrl attribute of the WebServiceClient object
protected  Document getResponseDoc()
          retreives the contents of the requestUrl field as a Document
static Document getResponseDoc(URL url)
          Static version of getResponseDoc.
static String getResponseError(Document doc)
          Gets the responseError attribute of the WebServiceClient class
static String getResponseError(String s)
          Searches the response string for error elements and returns the contents of the error if one is found.
protected  String getResponseStr()
          Submits a Web Service and returns the result as a string.
static String getTimedURL(URL url)
          Uses a TimedURLConnection to get the repsonse from the web service (the request is a URL), which is returned as a String.
static Document getTimedXmlDocument(URL url)
          gets the contents of a URL via getTimedURL(URL) and then parses the contents into a dom4j Document, which is returned
 int getTimeOutSecs()
           
static void main(String[] args)
          The main program for the WebServiceClient class
static void setDebug(boolean db)
          Sets the debug attribute
 void setRequestUrl(String verb, String argStr)
          Sets the requestUrl attribute of the WebServiceClient object
 void setRequestUrl(URL url)
          Sets the requestUrl attribute of the WebServiceClient object
 void setTimeOutSecs(int i)
           
static String stuffId(String recordXml, String xmlFormat, String id)
          Place the provided ID into the provided recordXml.
 Document urlCheck(String s)
          Submit a request (query) to the UrlCheck Web service and return the response as a Document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

protected static boolean debug
Description of the Field

Constructor Detail

WebServiceClient

public WebServiceClient(String baseWebServiceUrl)
Constructor for the WebServiceClient object.

Example baseWebServiceUrls:

Parameters:
baseWebServiceUrl - url of Web Service
Method Detail

getBaseUrl

public String getBaseUrl()

setTimeOutSecs

public void setTimeOutSecs(int i)

getTimeOutSecs

public int getTimeOutSecs()

urlCheck

public Document urlCheck(String s)
                  throws WebServiceClientException
Submit a request (query) to the UrlCheck Web service and return the response as a Document. 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

public Document doSearch(String queryStr)
                  throws WebServiceClientException
Throws:
WebServiceClientException

stuffId

public static String stuffId(String recordXml,
                             String xmlFormat,
                             String id)
                      throws Exception
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 Parameter
id - 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 put
xmlFormat - 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 put
xmlFormat - 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

public String doGetId(String collection)
               throws WebServiceClientException
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

public GetRecordResponse getRecord(String id)
                            throws WebServiceClientException
Submits a request to the GetRecord DDS Web Service and returns response as a Document. 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

public void setRequestUrl(URL url)
Sets the requestUrl attribute of the WebServiceClient object

Parameters:
url - The new requestUrl value

getRequestUrl

public URL getRequestUrl()
Gets the requestUrl attribute of the WebServiceClient object

Returns:
The requestUrl value

setRequestUrl

public void setRequestUrl(String verb,
                          String argStr)
Sets the requestUrl attribute of the WebServiceClient object

Parameters:
verb - The new requestUrl value
argStr - The new requestUrl value

getResponseStr

protected String getResponseStr()
                         throws WebServiceClientException
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

public static String getResponseError(String s)
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

protected Document getResponseDoc()
                           throws WebServiceClientException
retreives the contents of the requestUrl field as a Document

Returns:
dom4j Document representation of response
Throws:
WebServiceClientException - if unsuccessful retrieving url or parsing doc

getResponseDoc

public static Document getResponseDoc(URL url)
                               throws WebServiceClientException
Static version of getResponseDoc.

Parameters:
url - Description of the Parameter
Returns:
The responseDoc value
Throws:
WebServiceClientException - Description of the Exception

getResponseError

public static String getResponseError(Document doc)
Gets the responseError attribute of the WebServiceClient class

Parameters:
doc - Description of the Parameter
Returns:
The responseError value

getTimedURL

public static String getTimedURL(URL url)
                          throws WebServiceClientException
Uses a TimedURLConnection to 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 Document getTimedXmlDocument(URL url)
                                    throws WebServiceClientException,
                                           DocumentException
gets the contents of a URL via getTimedURL(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 Exception
DocumentException - Description of the Exception

main

public static void main(String[] args)
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

DLESE Tools
v1.6.0