Friday, September 30, 2016

My SOAP based web service client development and test note

My SOAP based web service client development and test note:
1. If wsdl is available, SOAP UI is a good tool for the test. If there's error, then use local wsdl file and it could be fixed
2. If SOAP request file is available (you can get it from the server side or SOAP UI), then Apache Common http client is good to post the SOAP request
    to the end point directly:
String strURL = "https://...";
String strSoapAction = "retrieve";
File input = new File(strXMLFilename);
PostMethod post = new PostMethod(strURL);
RequestEntity entity = new FileRequestEntity(input,
"text/xml; charset=UTF-8");
post.setRequestEntity(entity);
post.setRequestHeader("SOAPAction", strSoapAction);
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);
...
Still, the response could be parsed by JAXB like (Use the regular expression "<soapenv:Body>(.*?)</soapenv:Body>" to get the body part retrieveResponseStr):
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(retrieveResponseStr);
RetrieveResponse retrieveResponse = ((JAXBElement<RetrieveResponse>) unmarshaller
.unmarshal(reader)).getValue();


3. Or SAAJ could be used to construct the SOAP message as this link shows
http://stackoverflow.com/questions/15940234/how-to-do-a-soap-web-service-call-from-java-class
4. The most common way is to generate the client by invoking "wsimport -keep ...", and then
   If need customize SOAP header, then implement javax.xml.ws.handler.soap.SOAPHandler, call service's method setHandlerResolver before getPort
   Be careful not to introduce WAS_V7JAXWS_WEBSERVICES_THINCLIENT if you use IBM RAD. Or you may get error "WSWS7130E: No Secure Sockets Layer (SSL) configuration is available"
   or "IOException: Connection close: Read failed.  Possible end of stream encountered".

TCP/IP monitor in Eclipse cannot support https monitor
I cannot enable Fiddler to monitor Java web service client for https

No comments:

Post a Comment