I am currently trying to transmit large files via a Webservice method using MTOM. This method gets a StreamingDataHandler as parameter that contains an InputStream with the file. Anytime I run the client, it results in the following error on the client side:
Aug 30, 2016 10:52:44 AM sun.net.www.protocol.http.HttpURLConnection plainConnect
Am feinsten: ProxySelector Request for http://localhost:8082/?wsdl
Aug 30, 2016 10:52:44 AM sun.net.www.protocol.http.HttpURLConnection plainConnect
Am feinsten: Proxy used: DIRECT
Aug 30, 2016 10:52:44 AM sun.net.www.protocol.http.HttpURLConnection writeRequests
Fein: sun.net.www.MessageHeader@6521beab5 pairs: {GET /?wsdl HTTP/1.1: null}{User-Agent: Java/1.7.0_45}{Host: localhost:8082}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
Aug 30, 2016 10:52:44 AM sun.net.www.protocol.http.HttpURLConnection getInputStream
Fein: sun.net.www.MessageHeader@669b9a304 pairs: {null: HTTP/1.1 200 OK}{Transfer-encoding: chunked}{Content-type: text/xml;charset=utf-8}{Date: Tue, 30 Aug 2016 08:52:44 GMT}
Aug 30, 2016 10:52:45 AM sun.net.www.http.HttpClient logFinest
Am feinsten: KeepAlive stream retrieved from the cache, sun.net.www.http.HttpClient(http://localhost:8082/?wsdl)
Aug 30, 2016 10:52:45 AM sun.net.www.protocol.http.HttpURLConnection writeRequests
Fein: sun.net.www.MessageHeader@88135a08 pairs: {POST / HTTP/1.1: null}{Accept: text/xml, multipart/related}{Content-Type: multipart/related;start="<rootpart*3101fd50-4be6-42a2-b18f-d7669d41a459@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:3101fd50-4be6-42a2-b18f-d7669d41a459";start-info="text/xml"}{SOAPAction: "http://soaptest/WS/fooRequest"}{User-Agent: JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b}{Host: localhost:8082}{Connection: keep-alive}{Content-Length: 563506}
Aug 30, 2016 10:52:45 AM sun.net.www.protocol.http.HttpURLConnection writeRequests
Fein: sun.net.www.MessageHeader@88135a08 pairs: {POST / HTTP/1.1: null}{Accept: text/xml, multipart/related}{Content-Type: multipart/related;start="<rootpart*3101fd50-4be6-42a2-b18f-d7669d41a459@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:3101fd50-4be6-42a2-b18f-d7669d41a459";start-info="text/xml"}{SOAPAction: "http://soaptest/WS/fooRequest"}{User-Agent: JAX-WS RI 2.2.10 svn-revision#919b322c92f13ad085a933e8dd6dd35d4947364b}{Host: localhost:8082}{Connection: keep-alive}{Content-Length: 563506}
Exception in thread "main" javax.xml.ws.WebServiceException: java.io.IOException: Error writing to server
at com.sun.xml.ws.transport.http.client.HttpClientTransport.readResponseCodeAndMessage(HttpClientTransport.java:210)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:241)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:232)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:145)
at com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:110)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
at com.sun.xml.ws.api.pipe.helper.AbstractTubeImpl.process(AbstractTubeImpl.java:136)
at com.sun.xml.xwss.XWSSClientPipe.process(XWSSClientPipe.java:118)
at com.sun.xml.ws.api.pipe.helper.PipeAdapter.processRequest(PipeAdapter.java:119)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)
at com.sun.xml.ws.client.Stub.process(Stub.java:463)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:191)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:92)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:161)
at com.sun.proxy.$Proxy21.foo(Unknown Source)
at soaptest.Client.main(Client.java:39)
Caused by: java.io.IOException: Error writing to server
at sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:625)
at sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:637)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1321)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at com.sun.xml.ws.transport.http.client.HttpClientTransport.readResponseCodeAndMessage(HttpClientTransport.java:206)
... 22 more
The server side does not output anything.
I managed to compile the following sscce:
Webservice Interface
package soaptest;
import javax.activation.DataHandler;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlMimeType;
@WebService(name="WS", serviceName="WS")
@SOAPBinding(style=SOAPBinding.Style.RPC)
public interface WS {
@WebMethod(operationName="foo")
public void foo(@XmlMimeType("application/octet-stream") DataHandler file);
}
Implementation:
package soaptest;
import javax.activation.DataHandler;
import javax.jws.WebService;
import javax.xml.ws.soap.MTOM;
@MTOM
@WebService(endpointInterface = "soaptest.WS")
public class WSImpl implements WS {
@Override
public void foo(DataHandler file) {
System.out.println(file.getClass().toString());
}
}
Publisher
package soaptest;
import java.util.Properties;
import javax.xml.ws.Endpoint;
public class Publisher {
public static void main(String[] args) {
Properties p = System.getProperties();
p.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
p.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
p.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
System.setProperties(p);
Endpoint endpoint = Endpoint.create(new WSImpl());
endpoint.publish("http://localhost:8082/?wsdl");
System.out.println("published!");
}
}
Client
package soaptest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import com.sun.xml.ws.encoding.DataSourceStreamingDataHandler;
public class Client {
public static void main(String[] args) throws MalformedURLException, FileNotFoundException {
Properties p = System.getProperties();
p.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
p.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
p.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
System.setProperties(p);
URL url = new URL("http://localhost:8082/?wsdl");
QName qname = new QName("http://soaptest/", "WSImplService");
Service service = Service.create(url, qname);
WS ws = service.getPort(WS.class);
InputStream is = new FileInputStream(new File("C:\\file.txt"));
DataSource ds = new InputStreamDataSource(is);
DataHandler dh = new DataSourceStreamingDataHandler(ds);
ws.foo(dh);
}
public static class InputStreamDataSource implements DataSource {
private InputStream inputStream;
public InputStreamDataSource(InputStream inputStream) {
this.inputStream = inputStream;
}
public InputStream getInputStream() throws IOException {
return inputStream;
}
public OutputStream getOutputStream() throws IOException {
throw new UnsupportedOperationException("Not implemented");
}
public String getContentType() {
return "*/*";
}
public String getName() {
return "InputStreamDataSource";
}
}
}
Running the publisher and then the client should result in the above error (at least for me). The custom java properties for Transformers and Parsers are needed in our environment. Feel free to remove them if you feel they have nothing to do with the problem. Everything is running on Java 1.7.0_45 and 1.8.0_101, the problem shows up when run from inside Eclipse and on the command line on different Windows machines.
I've essentially compiled my methods from bits of code I found all over the web, so it's most like just a technology mixup or a left out annotation.
It would be nice if somebody who has done this before could have a quick look at it. Thanks in advance