SOAPSender

public abstract class SOAPSender extends Component implements Runnable

The SOAPSender is a abstract class for the SOAP-Based protocol client. It reduces the complexity and version incompatible induced from the apache AXIS by using only Built-in java SOAP XML Package. The target developer is for those whose are not familiar with the complex AXIS framework. It is implemented using the event-driven model so that developer are only required to implement several event method. The package is under development and will be standardized in the future release.

Author:Twinsen Tsang

Fields

NS_PREFIX

protected static final String NS_PREFIX

The namespace prefix

log

protected FileLogger log

The logger used for log message and exception

See also: hk.hku.cecid.corvus.util.FileLogger

properties

protected Data properties

The data properties for this sender.

request

protected SOAPMessage request

The SOAP request

response

protected SOAPMessage response

The SOAP response

serviceEndPoint

protected URL serviceEndPoint

The url of service end point.

Constructors

SOAPSender

public SOAPSender()

SPA Constructor. It is used when the SOAP Sender is a component in the spa.

SOAPSender

public SOAPSender(FileLogger l, Data d)

Constructor

Parameters:
  • l – The logger used for log message and exception.

SOAPSender

public SOAPSender(FileLogger l, Data d, String endpoint)

Constructor

Parameters:
  • l – The logger used for log message and exception.
  • endpoint – The url of service end point.

SOAPSender

public SOAPSender(FileLogger l, Data d, URL endpoint)

Constructor.

Parameters:
  • l – The logger used for log message and exception.
  • endpoint – The url of service end point.

Methods

addRequestElementText

public boolean addRequestElementText(String tagName, String tagValue, String nsPrefix, String nsURI)

Add SOAP element to body with name and value.

Parameters:
  • tagName – The tag name of element to be retrieved.
  • tagValue – The value of the element to be added.
  • nsPrefix – The namespace Prefix
  • nsURI – The namespace URI.
Throws:
  • SOAPException
Returns:

true if the creation and addition is successfully.

addRequestElementText

public boolean addRequestElementText(String parentTagName, String parentNsURI, String tagName, String tagValue, String nsPrefix, String nsURI)

Add SOAP element to specify parent element

Parameters:
  • parentTagName – The tag name of parent element.
  • parentNsURI – The namespace URI of parent element.
  • tagName – The tag name of element to be retrieved.
  • tagValue – The value of the element to be added.
  • nsPrefix – The namespace Prefix
  • nsURI – The namespace URI.
Throws:
  • SOAPException
Returns:

true if the creation and linking is successfully.

countResponseElementText

public int countResponseElementText(String tagname, String nsURI)

This methods count number of specified tagname in the response. It should only be called inside onResponse().

Parameters:
  • tagname – The tag name of element to be retrieved.
  • nsURI – The namespace URI.
Throws:
  • SOAPException
Returns:

The element text in the tagname specified.

getCurrentLoopTimes

public int getCurrentLoopTimes()

Get what is the current loop times for looping

getLoopTimes

public int getLoopTimes()

Get how many times should the sender to be send.

getRequestElementText

public String getRequestElementText(String tagname, String nsURI, int whichOne)

This method should only be called inside onCreateRequest(). because the request object will be deleted upon each ws call.

Parameters:
  • tagname – The tag name of element to be retrieved.
  • nsURI – The namespace URI.
  • whichOne – The nth child element to be returned.

getResponseElementAsList

public String[] getResponseElementAsList(String tagname, String nsURI)

This method should only be called inside onResponse(). because the response object will be deleted upon each ws call. This method get the element by it’s tagname and return a list of text value inside.

Parameters:
  • tagname – The name of the XML tag to be extraceted.
  • nsURI – The namespace URI.
Throws:
  • SOAPException
Returns:

The elements’ text in the tagname specified.

getResponseElementText

public String getResponseElementText(String tagname, String nsURI, int whichOne)

This method should only be called inside onResponse(). because the response object will be deleted upon each ws call.

Parameters:
  • tagname – The tag name of element to be retrieved.
  • nsURI – The namespace URI.
  • whichOne – The nth child element to be returned.
Returns:

The element text in the tagname specified.

getSOAPRequest

protected SOAPMessage getSOAPRequest()

Get the SOAP request.

Returns:The SOAP Request Body.

getSOAPResponse

protected SOAPMessage getSOAPResponse()

Get the SOAP response. The method should only be called inside onResponse().

Returns:The SOAP Response Body.

getServiceEndPoint

public URL getServiceEndPoint()

Get the service end-point.

Returns:the service endpoint URL.

getUserObject

public Object getUserObject()

Get a user object.

initializeMessage

public void initializeMessage()

Implements this method if you want to send messages without much different between other message to sent.

isRequestDirty

public boolean isRequestDirty()
Returns:return true if the request is dirty.

isRequireXMLDeclaraction

public boolean isRequireXMLDeclaraction()

return return true if the request requires the XML declaration to sent.

onBeforeRequest

public void onBeforeRequest(SOAPConnection conn, SOAPMessage request)

[@EVENT] This method is invoked just before sending the request to Web service endpoints.

Parameters:
  • conn – The SOAP Connection used for sending SOAP request.
  • request – The request created by onCreateRequest().
Throws:
  • Exception – Any type of exception will be processed at onError(throwable t).

onCreateRequest

public SOAPMessage onCreateRequest()

[@EVENT] This method is invoked when the sender is required to sent a SOAP Request for configuration. The default return value is the request in the sender. If developer want to send a custom SOAP request other than the sender SOAP request, override the function and return your customizing SOAP Request. For example, if you want to send a SOAP request always with soap element “test”. Then you should override this function called.

public SOAPMessage onCreateRequest() throws Exception{
    SOAPMessage request = MessageFactory.newInstance().createMessage();
             ..
             ..
           add the element "test".
    return request;
}
Throws:
  • Exception – Any type of exception will be processed at onError(throwable t).
Returns:

javax.xml.SOAPMessage

onEachLoopStart

public void onEachLoopStart()

[@EVENT] This method is invoked when each loop iteration start.

Throws:
  • Exception – Any type of exception will be processed at onError(throwable t).

onEnd

public void onEnd()

[@EVENT] This method is invoked when the sending execution is ended.

onError

public void onError(Throwable t)

[@EVENT] This method is invoked when there is any exception thrown during web service call.

onResponse

public void onResponse()

[@EVENT] This method is invoked when received the reply SOAP response from the server Developer can use getSOAPResponse() to get the SOAP response for self-handling. Otherwise, developer can use getResponseElementText(String,String,int) to get the response element text from the response object.

Throws:
  • Exception – Any type of exception will be processed at onError(throwable t).

onStart

public void onStart()

[@EVENT] This method is invoked when the sender begins to execute the run method.

resetSOAPRequest

protected void resetSOAPRequest()

Reset the request to empty SOAP Body. It is commonly used when for each loop times the request

Throws:
  • SOAPException

resetSOAPResponse

protected void resetSOAPResponse()

Reset the request to empty SOAP Body. It is commonly used when for each loop times the response.

run

public void run()

The thread execution method.

setBasicAuthentication

public void setBasicAuthentication(String username, String password)

Set to use the basic authentication when calling the web service.

Parameters:
  • username – The username for basic authentication.
  • password – The password for basic authentication.

setLoopTimes

public void setLoopTimes(int loopTimes)

Set how many times should the sender to be send.

Parameters:
  • loopTimes – the new loopTimes.

setRequestDirty

public void setRequestDirty(boolean dirty)

Set if the request is dirty. We considered “dirty” as the request has been modified by someone during last sending.

setRequireXMLDeclaraction

public void setRequireXMLDeclaraction(boolean require)

Set if the request requires XML declaration at the top of the request. This is equivalent to:

SOAPRequest.setProperty(WRITE_XML_DECLARATION, "true");
Parameters:
  • require – true if requires XML declaration.

See also: javax.xml.soap.SOAPMessage.setProperty(String,Object), javax.xml.soap.SOAPMessage.WRITE_XML_DECLARATION

setServiceEndPoint

public void setServiceEndPoint(URL endpoint)

Set the service endpoint.

Parameters:
  • endpoint – The URL of the web service endpoint.

setServiceEndPoint

public void setServiceEndPoint(String endpoint)

Set the service endpoint.

Parameters:
  • endpoint – The String of the web service endpoint.

setUserObject

public void setUserObject(Object obj)

Set a user object for callback.

Parameters:
  • obj – The user object.

transformResponseContent

public PropertyTree transformResponseContent()

Transform the response into a property tree. It should only be called inside onResponse().

Returns:An XML Property tree having the same tag content in the response.