I've a problem when I try to send a file (DataHandler) to a web service deployed under axis2.
This is my client code (only the part regarding the web service call):
DataHandler dh = new DataHandler(new FileDataSource("file"));
appStub serviceStub = new appStub("http://localhost:3333/axis2/services/myApp");
ServiceClient serviceClient = serviceStub._getServiceClient();
Options options = new Options();
options.setTo(new EndpointReference("http://localhost:3333/axis2/services/myApp"));
options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
serviceClient.setOptions(options);
serviceStub._setServiceClient(serviceClient);
appStub.sendFileData req = new appStub.sendFileData ();
req.setId(clientId);
req.setLoginName(loginName);
req.setPassword(password);
req.setFile(dh);
appStub.sendFileDataResponse res = serviceStub.setUELData(req);
This is the SOAP message that the client send (Intercepted via TCP MON):
POST /axis2/services/myApp HTTP/1.1
Content-Type: multipart/related; boundary="MIMEBoundary_7129fcac678a04aa6ca900d73cbc34c19867765e3d9ab5e9"; type="application/xop+xml"; start="<[email protected]>"; start-info="text/xml"
SOAPAction: "urn:sendFileData"
User-Agent: Axis2
Host: 127.0.0.1:3333
Transfer-Encoding: chunked
649
--MIMEBoundary_7129fcac678a04aa6ca900d73cbc34c19867765e3d9ab5e9
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <[email protected]>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns3:sendFileData xmlns:ns3="http://myApp">
<ns3:id>12</ns3:id>
<ns3:loginName>Admin</ns3:loginName>
<ns3:password>pass</ns3:password>
<ns3:file>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:[email protected]" />
</ns3:file>
</ns3:sendFileData >
</soapenv:Body>
</soapenv:Envelope>--MIMEBoundary_7129fcac678a04aa6ca900d73cbc34c19867765e3d9ab5e9Content-Type: application/octet-streamContent-Transfer-Encoding: binaryContent-ID:
<[email protected]>20110412080306;98.8952;NOLA DIR SUD;Marcia20110412080958;97.6259;PALMA CAMPANIA DIR SUD;Marcia20110412081306;101.7761;SARNO DIR SUD;Marcia20110412081530;97.9944;NOCERA PAGANI DIR SUD;Marcia20110412081808;89.6547;CASTEL SAN GIORGIO DIR SUD;Marcia20110412082309;89.4068;NOCERA PAGANI DIR NORD;Marcia20110412082446;103.7815;SARNO DIR NORD;Marcia20110412082829;94.6448;PALMA CAMPANIA DIR NORD;Marcia20110412083333;92.4737;ALL A30 A16 DIR NORD;Marcia20110412084337;113.5370;ALL A30 A1 DIR NORD;Marcia20110412085201;121.0054;CASERTA NORD DIR NORD;Emergenza--MIMEBoundary_7129fcac678a04aa6ca900d73cbc34c19867765e3d9ab5e9--0
And this is the web service class:
@MTOM
@WebService(serviceName = "myApp")
public class myApp{
@WebMethod(operationName = "sendFileData")
public boolean sendFileData(@WebParam(name = "id") int id, @WebParam(name = "loginName") String loginName, @WebParam(name = "password") String password, @WebParam(name = "file") @XmlMimeType("application/octet-stream") DataHandler dh) throws InternalServerException, InvalidSentDataException {
logger.info(locale.getString("WEB SERVICE REQUEST SETUELDATA"));
...
As you can see from the soap message the file is correctly attached by client. But when the web service receive the soap message it throws the following exception:
[ERROR] 4
java.lang.ArrayIndexOutOfBoundsException: 4
at org.apache.axis2.databinding.utils.BeanUtil.deserialize(BeanUtil.java:630)
at org.apache.axis2.rpc.receivers.RPCUtil.processRequest(RPCUtil.java:153)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:206)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
at java.lang.Thread.run(Thread.java:724)
I think that the problem is due to the DataHandler parameter because if I send null as DataHandler from the client the exception on web service is not thrown. What is wrong in my code?!
EDIT: I noticed that in SOAP message I can see the attached file (a simple csv file) but if I try from webService to take it as OMElement and print the text of the OMElement I have a string like this: MjAxMTA0MTIwODAzMDY7OTguODk1MjtOT0xBIERJUiBTVUQ7TWFyY2lhDQoyMDExMDQxMjA4MDk1ODs5Ny42MjU5O1BBTE1BIENB...