Hi Guys,
I try to send a binary file from server to client when invoking a web
service and but getting "Response already committed" exception on server
side.
here I have given a simple example for illustrate this problem ( I use
Axis2 1.4.1) . I'm really appreciate if some one can provide a direction
for this ?
Server side
----------------------------
ublic class BinaryService {
public static final String fileName1 =
"doBinaryWithDataHandler-outputfile.jpg";
public DataHandler doBinaryWithDataHandler() {
FileDataSource dataSource = new FileDataSource(fileName1);
System.out.println(" dataSource create ..........."+
dataSource.getName());
DataHandler fileDataHandler = new DataHandler(dataSource);
System.out.println(" fileDataHandler create ........."+
fileDataHandler.getName());
return fileDataHandler;
}
}
<service name="Binary-service2">
<parameter name="ServiceClass">service.BinaryService
</parameter>
<operation name="doBinaryWithDataHandler">
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
<parameter name="enableMTOM">true</parameter>
</service>
client side
------------------------------------
RPCServiceClient client;
try {
client = new RPCServiceClient();
Options opts = new Options();
opts.setAction("ns:doBinaryWithByteArray");
EndpointReference to = new EndpointReference();
to.setAddress("
http://localhost:8080/axis2/services/MTOM-service2");
opts.setTo(to);
client.setOptions(opts);
//DataHandler dh = new DataHandler(new
FileDataSource("/home/sagara/Desktop/img.jpg"));
OMElement node=client.invokeBlocking(new QName("http://service",
"doBinaryWithDataHandler"),
new Object[] { null});
_ _
}
error
---------------------------------------------
dataSource create ...........doBinaryWithDataHandler-outputfile.jpg
fileDataHandler create .........doBinaryWithDataHandler-outputfile.jpg
Exception in thread "HttpConnection-8080-2" java.lang.IllegalStateException:
Response already committed
at
org.apache.axis2.transport.http.server.AxisHttpResponseImpl.assertNotCommitted(AxisHttpResponseImpl.java:75)
at
org.apache.axis2.transport.http.server.AxisHttpResponseImpl.sendError(AxisHttpResponseImpl.java:110)
at
org.apache.axis2.transport.http.server.AxisHttpService.doService(AxisHttpService.java:313)
at
org.apache.axis2.transport.http.server.AxisHttpService.handleRequest(AxisHttpService.java:187)
at
org.apache.axis2.transport.http.server.HttpServiceProcessor.run(HttpServiceProcessor.java:82)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
at java.lang.Thread.run(Thread.java:595)
Thanks ,
Sagara Gunathunga
Blog - ssagara.blogspot.com
Web - http://sagaras.awardspace.com/