Thursday, October 27, 2011

CMAF5. Dynamic Web Service Client

In the previous article, I covered how to make generic Web Service Server. Now let’s move on to Generic Web Service Client over HTTP/HTTPS. In this article, I will cover two different kinds of Generic Web Service Clients. 
·   With HTTP Client Adapter (e*Way)
·   Java API for Generic Web Service Client

1. Generic Web Service Clients with HTTP Adapter 
  • svcWebServiceClient : Multithread Supports
  • svcWebServiceClientSequence : Single Thread to support sequential message orders
  • svcWebServiceClientSSL : Supports HTTPS protocol
2. Java API for Generic Web Service Client over HTTP - com.wwlee.jcaps.cs.webservice.WebServiceClient
- WebServiceClient API is Java API to invoke any kind of Web Service Server.
- This API also supports SAAJ (SOAP with Attachments API for Java) in order to download and upload file(s) through Web Service.
- Example
private void invokeDirectWebService( com.stc.connectors.jms.Message input, com.wwlee.jcaps.otd.common.eaicommonheader.ServiceInterface otdEAICommonHeaderIn, com.wwlee.jcaps.soap.envelope.Envelope_ otdSOAPEnvelope ) throws Exception{
 com.wwlee.jcaps.otd.common.eaisoapcommonbody.SOAPCommonBody otdSOAPCommonBody = new com.wwlee.jcaps.otd.common.eaisoapcommonbody.SOAPCommonBody();
 WebServiceClient webService = new WebServiceClient();
 String soapAction = otdEAICommonHeaderIn.getWebService().getWebServiceOutbound().getSOAPAction();
 webService.setRequestSOAPMessage( otdSOAPEnvelope, soapAction );
 String endpointURL = otdEAICommonHeaderIn.getWebService().getWebServiceOutbound().getEndPointLocation();
 String timeOutSeconds = StringUtil.setDefaultStringValue( otdEAICommonHeaderIn.getWebService().getWebServiceOutbound().getEndPointTimeoutSeconds(), "10" );
 webService.invoke( endpointURL, Integer.parseInt( timeOutSeconds ) );
 byte[] soapEnvelopeMessageBytes = webService.getResponseBytesSOAPMessage();
 otdSOAPEnvelope = (Envelope_) webService.getResponseOTDSOAPMessage();
 webService.getElapsedInvokingTime();
 /* Set Invoking Time */
otdEAICommonHeaderIn.getTimeTrackingsHeader().getComponentTimeTracking( countComponentTimeTracking ).setStartInvokingTime( webService.getStartInvokingTime() ); otdEAICommonHeaderIn.getTimeTrackingsHeader().getComponentTimeTracking( countComponentTimeTracking ).setEndInvokingTime( webService.getEndInvokingTime() ); otdEAICommonHeaderIn.getTimeTrackingsHeader().getComponentTimeTracking( countComponentTimeTracking ).setElapsedInvokingTime( webService.getElapsedInvokingTime() );
 if (webService.hasFault()) {
     logger.error( "+++++ Received Fault Message from WebService : " + otdSOAPEnvelope.getBody().getX__AnyText__( 0 ) + " +++++" );
     setEAPReprocess( input, otdEAICommonHeaderIn, "Fault Response Message", "Refer to Fault Message in CMSF" );
     logger.warn( "+++++ It will be sent to Common EAIReprocess Project in CMSF +++++" );
 } else {
     otdSOAPCommonBody.unmarshalFromString( otdSOAPEnvelope.getBody().getX__AnyText__( 0 ) );
     String status = otdSOAPCommonBody.getStatus();
     if (status.equalsIgnoreCase( "ERROR" )) {
         setEAPReprocess( input, otdEAICommonHeaderIn, "ERROR Response", otdSOAPCommonBody.getExceptionInfo().getExceptionMessage() );
         logger.warn( "+++++ It will be sent to Common EAIReprocess Project in CMSF +++++" );
     }
 }
}
Refer to the below article for Generic Web Service Client
CMAF5_Generic_Web_Service_Client_For_JCAF.doc

No comments:

Post a Comment