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

A weird java web service client error

When I developed web service client in Rational Application Developer, I got the below error:
Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.axis2.AxisFault: WSWS7130E: No Secure Sockets Layer (SSL) configuration is available for the https://... endpoint.

After searching the google, got a useful article "Using Secure Web Services HTTPs (SSL)":
http://btarlton.blogspot.ca/2013/03/ever-have-trouble-using-ssl-to-call-web.html
So I exported the certificate and add the below to VM arguments:
-Djavax.net.ssl.trustStore=C:\temp\myTrustStore -Djavax.net.ssl.trustStorePassword=changeit
Then the error "No Secure Sockets Layer ... " is gone.
However, another error is raised: "java.io.IOException: Connection close: Read failed.  Possible end of stream encountered. "

I searched a lot and tried some ways like setting com.ibm.websphere.webservices.http.requestResendEnabled but still got the error.

Finally I decided to regenerate the client from scratch using wsimport -keep, and copy them into RAD7.5, Phew, everything works perfect.

So what's the problem? I compared the two projects source code until they are all identical through WinMerge. But their behavior are still different.
Then I checked the projects setting in RAD and removed the auto introduced WAS_V7JAXWS_WEBSERVICES_THINCLIENT, now both of them works like a charm.

It's so misleading and confusing for the IDE especially if it involves IBM product. Under such case, should remove the dependency on IDE as much as possible
so that we can isolate the issue.

Sunday, September 25, 2016

My Plan

1. Sleep before/at 11:00 and get up at 6:30
2. Play basketball at Monday & Wednesday evening, 8:15 - 09:45
    swim at Saturday morning 7:00-8:30
3. Push-up and other physical exercise at Tuesday, Thursday and Saturday evening
Runtastic 6 packs and push-up at Tuesday and Thursday
4. Improve English
a. Watch TV more and surf the web less
b. Read English news instead of Chinese news
c. Jerry English