On Thursday 22 April 2010 12:00:16 pm Thomas Koenig wrote: > Thanks for the quick reply. > > So, is there any other way that MTOM attachments are made available through > the Dispatch SPI (i.e. I don't want to do JAXB data binding).
Normally, you would add a field like: @Resource WebServiceContext ctx; which CXF would inject in. In your invoke method, you would do: ctx.getMessageContext().get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS); which would return a java.util.Map<String,DataHandler>. From that map, you could map the xop include hrefs to the appropriate DataHandler in the Map. Again this is by FAR the most efficient way to do this. It's a bit more work for the Provider writer, but it performance is a ton better. Dan > > On Thu, Apr 22, 2010 at 11:45 AM, Daniel Kulp <[email protected]> wrote: > > > I had hoped that the Apache runtime would process the attachment and > > > > inline > > > > > it into the > > > 'DOMSource request' before the 'invoke' method is called, but it > > > appears that no mtom > > > processing takes place. > > > > Well, the main reason we don't do this is that in many cases we COULDN'T > > do it > > without a ton of memory available and it also would be extremely > > inefficient > > for most use cases. At some point, I do think we COULD wrapper the > > XMLStreamReader with one that would do the mtom processing, but that > > would half to be made optional somehow. > > > > For example, lets pretend your attachment is a 500MB file. With the > > current > > setup, you would have the WebServiceContext injected where you could get > > the > > Attachment and an input stream to get the raw data. That input stream > > would > > be a wrapper to the raw HttpInputStream so the data would be streamed in > > not > > consuming any memory and not involving any processor time to encode and > > such. > > > > If we processed it, we would need to pull the 500MB in, run a base64 > > encode on > > it to create a base64 string (which, since it's unicode, would take 1.3GB > > of > > memory) to add to the DOM. To use that data, you would NORMALLY then > > decode > > it back to the byte[] data thus wasting more cpu time. > > > > Dan > > > > On Thursday 22 April 2010 11:29:55 am Thomas Koenig wrote: > > > Is MTOM attachment handling supported through the Dispatch SPI? > > > > > > I have modified the jaxws_dispatch_provider CXF sample, to accept/send > > > payloads that contain Base64Binary data. > > > > > > ####################################################################### > > > Schema: > > > ####### > > > <complexType name="DocumentDetailType"> > > > > > > <sequence> > > > > > > <element name="identifier" type="xsd:string"/> > > > <element name="content" type="xsd:base64Binary"/> > > > > > > </sequence> > > > > > > </complexType> > > > > > > <complexType name="DocumentType"> > > > > > > <sequence> > > > > > > <element name="name" type="xsd:string"/> > > > <element name="id" type="xsd:string"/> > > > <element name="detail" type="types:DocumentDetailType"/> > > > > > > </sequence> > > > > > > </complexType> > > > > > > <element name="testDocumentRequest" type="types:DocumentType" /> > > > <element name="testDocumentResponse" type="types:DocumentType" /> > > > ####################################################################### > > > > > > > > > ####################################################################### > > > Request Message sample: > > > ####### > > > ------=_Part_4_8271067.1271948982000 > > > Content-Type: application/xop+xml; charset=UTF-8; type="text/xml" > > > Content-Transfer-Encoding: 8bit > > > Content-ID: <[email protected]> > > > > > > <soapenv:Envelope xmlns:soapenv=" > > > > http://schemas.xmlsoap.org/soap/envelope/" > > > > > xmlns:typ="http://cxf.apache.org/mime/types"> > > > > > > <soapenv:Header/> > > > <soapenv:Body> > > > > > > <typ:testDocument> > > > > > > <typ:name>RequestSOAPUI_01</typ:name> > > > <typ:id>RequestSOAPUI_01_id</typ:id> > > > <typ:detail> > > > > > > <typ:identifier>RequestSOAPUI_01_identifier</typ:identifier > > > > <typ:content><inc:Include href="cid:217539756627" > > > xmlns:inc=" > > > > > > http://www.w3.org/2004/08/xop/include"/></typ:content> > > > > > > </typ:detail> > > > > > > </typ:testDocument> > > > > > > </soapenv:Body> > > > > > > </soapenv:Envelope> > > > ------=_Part_4_8271067.1271948982000 > > > Content-Type: text/xml; charset=us-ascii > > > Content-Transfer-Encoding: 7bit > > > Content-ID: <217539756627> > > > > > > PGE+DQogIDxiIG5hbWU9IlRob21hcyIvPg0KPGE+ > > > ------=_Part_4_8271067.1271948982000-- > > > ####################################################################### > > > > > > > > > ####################################################################### > > > Apache CXF dispatch provider: > > > ####### > > > @MTOM(threshold = 0, enabled = true) > > > @WebServiceProvider( > > > > > > portName = "TestDocumentPort", > > > serviceName = "TestDocumentService", > > > targetNamespace = "http://cxf.apache.org/mime", > > > wsdlLocation = "wsdl/mtom_xop.wsdl") > > > > > > @ServiceMode(value = Service.Mode.MESSAGE) > > > public class TestDocumentDomSourceMessageProvider implements > > > Provider<DOMSource> { > > > > > > public TestDocumentDomSourceMessageProvider() { > > > } > > > > > > public DOMSource invoke(DOMSource request) { > > > > > > DOMSource response = new DOMSource(); > > > try { > > > > > > MessageFactory factory = MessageFactory.newInstance(); > > > SOAPMessage soapReq = factory.createMessage(); > > > soapReq.getSOAPPart().setContent(request); > > > > > > System.out.println("Incoming Client Request as a DOMSource > > > > data > > > > > in MESSAGE Mode"); > > > > > > soapReq.writeTo(System.out); > > > System.out.println("\n"); > > > > > > InputStream is = > > > > > > getClass().getResourceAsStream("TestDocumentResponse.xml"); > > > > > > SOAPMessage testDocumentResponse = > > > > factory.createMessage(null, > > > > > is); > > > > > > is.close(); > > > > > > response.setNode(testDocumentResponse.getSOAPPart()); > > > > > > } catch (Exception ex) { > > > > > > ex.printStackTrace(); > > > > > > } > > > return response; > > > > > > } > > > > > > } > > > > > > Object implementor = new TestDocumentDomSourceMessageProvider(); > > > String address = "http://localhost:9000/document-test"; > > > Endpoint ep = Endpoint.publish(address, implementor); > > > ((SOAPBinding)ep.getBinding()).setMTOMEnabled(true); > > > > #######################################################################xm > > ln > > > > > s:soapenv=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ=" > > > http://cxf.apache.org/mime/types"> > > > > > > I had hoped that the Apache runtime would process the attachment and > > > > inline > > > > > it into the > > > 'DOMSource request' before the 'invoke' method is called, but it > > > appears that no mtom > > > processing takes place. > > > > -- > > Daniel Kulp > > [email protected] > > http://dankulp.com/blog -- Daniel Kulp [email protected] http://dankulp.com/blog
