Open Tomas-Kraus opened 14 years ago
@glassfishrobot Commented Reported by opalka@java.net
@glassfishrobot Commented opalka@java.net said: I spent some time to help you with this issue and here are my investigations:
Before starting please have a look to:
JAXB 2.2 javadoc for the following annotations:
JAX-WS 2.2 javadoc for the following annotations:
The following objects can be sent as MTOM/XOP attachments:
Enabling MTOM on JAX-WS endpoint can be achieved:
Enabling MTOM on JAX-WS client can be achieved:
If you don't specify @XmlMimeType on getter or if you specify both @XmlMimeType and @XmlInlineBinaryData on getter the attachment object will always be inlined on the wire.
If you specify only @javax.xml.bind.annotation.XmlMimeType on getter the attachment object will always be sent as MIME attachment on the wire.
@XmlMimeType is used in JAXB schema generator and adds xmlmime:expectedContentTypes to WSDL. Here's example: — <?xml version="1.0" encoding="UTF-8"?> <definitions ...>
... —
Conclusion:
JAXB un/marshalling violates MTOM/XOP specifications and generates invalid MTOM/XOP messages. JAXB should generate in XML schema and process xmlmime:contentType attribute on XML elements wrapping binary data (regardless of the fact they are sent as inlined base64Binary or MIME attachments - see MTOM/XOP specifications).
Example of broken message being exchanged: —
@glassfishrobot Commented snajper said: reassigning
@glassfishrobot Commented snajper said: will try to address for 2.2.2
@glassfishrobot Commented @pavelbucek said: metro2.1-waived
@glassfishrobot Commented Was assigned to snajper
@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-766
I have a test client that sends WS attachment using DataHandler like this:
MTOMEndpoint mtomEndpoint = getEndpointPort(); DataHandler send = new DataHandler(new FileDataSource(PNG_FILE)); DHRequest request = new DHRequest(send); DHResponse response = mtomEndpoint.echoData(request); DataHandler recv = response.getDataHandler();
The server WS just sends back what it receives: byte[] echoFile = StreamUtils.readStream((InputStream)(request.getDataHandler().getContent())); DataHandler o = new DataHandler(new ByteArrayInputStream(echoFile), request.getDataHandler().getContentType()); return new DHResponse(o);
The issue is in DHRequest and DHResponse classes I use. They are simple classes: @XmlType(name = "dataRequest", namespace = "http://mycompany/xop/doclit") public class DHRequest { private DataHandler dataHandler; public DHRequest() { } public DHRequest(DataHandler dataHandler)
{ this.dataHandler = dataHandler; }
// @XmlMimeType("image/png") public DataHandler getDataHandler() { System.out.println(dataHandler.getContentType()); return dataHandler; }
public void setDataHandler(DataHandler dataHandler) { this.dataHandler = dataHandler; }
}
DHResponse is the same if you replace Reuest with Response.
Without setting the @XmlMimeType annotation everything works and the message on the server side looks like this: