Open glassfishrobot opened 12 years ago
Reported by jfk9
jfk9 said: A more complete description, including a comparison with swaRef approach which does what I want can be found at http://stackoverflow.com/questions/10700340/how-can-i-parse-an-inbound-message-with-mtom-attachments-under-metro-without-pul
jfk9 said: Metro 2.2 February 20, 2012
This issue was imported from java.net JIRA JAX_WS-1070
Using JAX-WS-RI or Metro I can write a WebService using the com.sun.xml.ws.api.server.AsyncProvider interface.
I can choose to get the whole message including the SOAP headers
import javax.xml.transform.Source; import com.sun.xml.ws.api.server.AsyncProvider; import com.sun.xml.ws.api.server.AsyncProviderCallback;
import javax.xml.ws.ServiceMode; import javax.xml.ws.WebServiceContext; import javax.xml.ws.WebServiceProvider;
@ServiceMode(value=Service.Mode.MESSAGE) @WebServiceProvider() public class AddNumbersAsynchImpl implements AsyncProvider
I can then write something which parses the message and processes accordingly
public void invoke(Source source, AsyncProviderCallback
XPath xpath = XPathFactory.newInstance().newXPath(); xpath.setNamespaceContext(new MyNamespaceContext());
String opName = (String) xpath.evaluate("name(/S:Envelope/S:Body/X:*[1])", dom.getNode(), XPathConstants.STRING);
if(knownOp(opName))
{ doOp(opName, dom.getNode(), cbak); }
else
{ doFault("Unknown operation " + opName, cbak); }
}
However part of the reason for doing this is to adapt an existing XML based application into the SOAP stack. The application defines a complete set of schemas for the messages that it takes and it easy to generate a WSDL to define the service.
For small XML messages this all works fine.
However if I wish to process the XML in a more stream orientated fashion in some operations where the messages are bulky I come across two problems using MTOM attachments. I change the set up of my Provider as follows;
import com.sun.xml.ws.api.message.Message; import javax.xml.ws.soap.MTOM; import com.sun.xml.ws.developer.StreamingAttachment; import com.sun.xml.ws.developer.StreamingDataHandler;
ServiceMode(value=Service.Mode.MESSAGE) @WebServiceProvider() @StreamingAttachment(parseEagerly=true, memoryThreshold=1000L) @MTOM(enabled=true, threshold=1000) public class AddNumbersAsynchImplMessage implements AsyncProvider {
...
I Add the appropriate MTOM policy to my WSDL;
<definitions name="AddNumbersAsynch" targetNamespace="http://asynch.duke.example.org" xmlns:tns="http://asynch.duke.example.org" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsrm="http://docs.oasis-open.org/ws-rx/wsrmp/200702" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">