Hi Paul,
Thanks for the link... I will try to use the xmime:expectedContentTypes="*/*", it should work. Using application/octet-stream will be the content type of the Data Handler object in any case. But I will test the difference by using just xmime:expectedContentTypes="*/*".
And yesterday, I was able to clear my doubts. So here it goes...
1. Is using xmime:expectedContentTypes="application/octet-stream" , the correct/best way to do it?
Not sure yet, but will try the above mentioned suggestion.
2. When "webServiceTemplate.marshalSendAndReceive(request)" is invoked, what happens exactly? Does the request become a part of the SoapBody?
Yes it does. Initially I was trying to debug and find the content of the SoapMessage, but when I printed the SoapMessage to a file, I was able to verify that these request object we sent via the marshalling, becomes a part of the SoapBody.
NOTE: In order to print the request/response/fault object, I have written a custom interceptor class which implements the org.springframework.ws.server.EndpointInterceptor Interface and implemented the methods, handleRequest,handleResponse and handleFault. I invoke the following method from these individual handler method. Also in the spring-servlet.xml this custom interceptor nees to be included in the org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping.
private void writeSoapMessage(MessageContext messageContext,
String fileName) {
try {
SoapMessage soapMessage = null;
if (fileName.equals("Soap_Request.xml")) {
soapMessage = (SoapMessage) messageContext.getRequest();
} else if (fileName.equals("Soap_Response.xml")) {
soapMessage = (SoapMessage) messageContext.getResponse();
} else if (fileName.equals("Soap_Fault.xml")) {
soapMessage = (SoapMessage) messageContext.getResponse();
}
File msgFile = new File("D:\\", fileName);
FileOutputStream fos = new FileOutputStream(msgFile);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
soapMessage.writeTo(baos);
baos.writeTo(fos);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
3.a) Now when testing for this exception, I expect that the exception thrown will be UploadFault at the client side. But the exception thrown is SoapFaultClientException. Am I missing some configuration? Do I need to add UploadFault to SoapFault separately?
Well now my requirement has changed, i do not need to throw my custom exception to the client anymore. The client is ok with the SoapFaultClientException. I am still not sure how to achieve this, may be will test later.
As far as configuration goes, I did the following:
1. Create CustomException class, which extends RuntimeException.
2. Add @SoapFault(fault= FaultCode.CLIENT) annotation to it.
3. Add the following to the spring-servlet.xml. This will resolve the @SoapFault annotation mentioned above.
<bean class="org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver" />
4. Throw the CustomException, when required. And the spring-ws framework takes care of the rest. This exception becomes a part of the SoapFault. The exception message, will be the FaultString, and the fault code = CLIENT.
Hope this explanation helps other newbie like me.