You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "reddy, ramachandra" <ra...@anacomp.com> on 2008/04/04 20:56:26 UTC

Axis Error while writing to the OutputStream in MTOM

Hi Folks,
We are using Webservices for sending a File and an XML String as
parameters. The code we wrote works fine for any type of file attachment
on windows but when we deployed our webservice on Sunone on Linux and
when we try to invoke our client from windows machine we are getting
this error. Any hints on whats going on ?
( At the bottom I have added  the code) 


org.apache.axiom.om.OMException: Error while writing to the
OutputStream.

      at
org.apache.axiom.om.impl.MIMEOutputUtils.complete(MIMEOutputUtils.java:7
5)

      at
org.apache.axiom.om.impl.MTOMXMLStreamWriter.flush(MTOMXMLStreamWriter.j
ava:126)

      at
org.apache.axiom.om.impl.llom.OMNodeImpl.serializeAndConsume(OMNodeImpl.
java:422)

      at
org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessage
Formatter.java:68)

      at
org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisReque
stEntity.java:84)

      at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequest
Body(EntityEnclosingMethod.java:495)

      at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase
.java:1973)

      at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java
:993)

      at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMe
thodDirector.java:397)

      at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMetho
dDirector.java:170)

      at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
96)

      at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
46)

      at
org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(Abstrac
tHTTPSender.java:520)

      at
org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:1
91)

      at
org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:77)

      at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageW
ithCommons(CommonsHTTPTransportSender.java:327)

      at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(Common
sHTTPTransportSender.java:206)

      at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:396)

      at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOper
ation.java:374)

      at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInA
xisOperation.java:211)

      at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163
)

      at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:528
)

      at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:508
)

      at
com.docharbor.bpms.webservice.SAILWebServiceClient.sendServiceRequest(SA
ILWebServiceClient.java:106)

      at
com.docharbor.bpms.webservice.SAILWebServiceClient.service(SAILWebServic
eClient.java:48)

      at
com.docharbor.bpms.webservice.SAILWebServiceClient.main(SAILWebServiceCl
ient.java:160)

Caused by: java.net.SocketException: Software caused connection abort:
socket write error

      at java.net.SocketOutputStream.socketWrite0(Native Method)

      at java.net.SocketOutputStream.socketWrite(Unknown Source)

      at java.net.SocketOutputStream.write(Unknown Source)

      at java.io.BufferedOutputStream.flushBuffer(Unknown Source)

      at java.io.BufferedOutputStream.write(Unknown Source)

      at
org.apache.commons.httpclient.WireLogOutputStream.write(WireLogOutputStr
eam.java:67)

      at
org.apache.commons.httpclient.ChunkedOutputStream.flushCacheWithAppend(C
hunkedOutputStream.java:120)

      at
org.apache.commons.httpclient.ChunkedOutputStream.write(ChunkedOutputStr
eam.java:178)

      at javax.activation.DataHandler.writeTo(DataHandler.java:308)

      at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)

      at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:845)

      at
org.apache.axiom.om.impl.MIMEOutputUtils.writeBodyPart(MIMEOutputUtils.j
ava:131)

      at
org.apache.axiom.om.impl.MIMEOutputUtils.complete(MIMEOutputUtils.java:6
8)

      ... 25 more

 

 

CODE:

CLIENT

====================

private   ISAILObject sendServiceRequest(String
sailWebSvcUrl,ISAILObject obj) throws Exception{
         SAILTransferObject tranobj = new SAILTransferObject();

         System.out.println(":: Entering SAIL WebService Request ()::");
   ServiceClient serviceClient = new ServiceClient ();
   Options options = new Options();
   EndpointReference targetEPR = new EndpointReference(sailWebSvcUrl);
         options.setTo(targetEPR);
         options.setProperty(Constants.Configuration.ENABLE_MTOM,
Constants.VALUE_TRUE);
         serviceClient .setOptions(options);
         
         
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMNamespace omNs =
fac.createOMNamespace("http://webservices.sail.docharbor.com", "SAIL");
   OMElement method = fac.createOMElement("receiveRequest", omNs);
   
   //Parameter  - XML
         OMElement value1 = fac.createOMElement("genericRequestXML",
omNs);
         value1.addChild(fac.createOMText(value1, obj.getXMLMessage()));
   method.addChild(value1);
   
   
   //Parameter  - Stream
   //If true - MTOM else  Base64  encoding
   if(obj.getDocStream()!=null){
    OMElement fileElement = fac.createOMElement("inputfile", omNs);
    //DataHandler dataHandler = new DataHandler(new
FileDataSource("C:\\dist.zip"));
    byte[] byteArray = IOUtils.getStreamAsByteArray(obj.getDocStream());
    DataHandler dataHandler = new DataHandler(new
ByteArrayDataSource(byteArray));
    OMText textData = fac.createOMText(dataHandler, true);
    fileElement.addChild(textData);
    method.addChild(fileElement);
   }
   //System.out.println(":: XML Request :: "+obj.getXMLMessage());
   //CALL
   OMElement result = serviceClient.sendReceive(method);
   DataHandler actualDH;

   //Read First Parameter from Response. - String
   OMText firstParam =
(OMText)result.getFirstElement().getFirstOMChild();
   //OMText responseXML =
(OMText)((OMElementImpl)result.getFirstElement().getNextOMSibling()).get
FirstOMChild();
   if (!firstParam.isBinary()) {
    String responseXML = firstParam.getText(); 
    //System.out.println("Received from server
responseXML:"+responseXML);
          tranobj.setXMLMessage(responseXML);
   } else {
    actualDH = (DataHandler)firstParam.getDataHandler();
          //System.out.println("Received from server Stream:"+
actualDH.getInputStream().toString());
          tranobj.setDocStream(actualDH.getInputStream());
   }
   //Read second parameter from Response if present- must be Stream
   OMNode nextNode =  result.getFirstElement().getNextOMSibling();
   if(nextNode != null)
   {
    OMText secondParam =
(OMText)((OMElementImpl)nextNode).getFirstOMChild();
    if(secondParam!=null && secondParam.isBinary()){
     actualDH = (DataHandler)secondParam.getDataHandler();
           //readFileFromStream(actualDH.getInputStream());
          // System.out.println("Received from server Stream:"+
actualDH.getInputStream().toString());
           tranobj.setDocStream(actualDH.getInputStream());
    } else {
     String responseXML = firstParam.getText(); 
     //System.out.println("Received from server
responseXML:"+responseXML);
           tranobj.setXMLMessage(responseXML);
    }
   } 
   return tranobj;
   }


SERVER:

================================================================

 

 

private ISAILObject receiveRequest(OMElement element) throws
IOException{
  element.build();
  element.detach();
  String genericRequestXML =null;
  DataHandler actualDH = null;
  
  //Get First Param - Can be xml or Stream
  OMElement firstElement = element.getFirstElement();
  if (firstElement != null) {
   OMText firstParam  = (OMText)firstElement.getFirstOMChild();
   //System.out.println("First Param::"+firstParam.isBinary());
   if (firstParam != null) {
    if(firstParam.isBinary())
    {
     //We got some binary data 
     actualDH = (DataHandler)firstParam.getDataHandler();
    }
    else
    { 
     genericRequestXML = firstParam.getText();
    }
   }
  }
  //Get  Second Param id present - Can be xml or Stream
  OMNode nextNode = element.getFirstElement().getNextOMSibling();
  if(nextNode!=null)
  { 
   OMElementImpl nextSibling = (OMElementImpl)nextNode;
 
//((OMElementImpl)element.getFirstElement().getNextOMSibling()).getFirst
OMChild();
   if(nextSibling != null){
    OMText secondParam = (OMText)(nextSibling).getFirstOMChild();
    if(secondParam != null){
     //System.out.println("Second Param::"+ secondParam.isBinary());
     if(secondParam.isBinary())
     {
      //We got some binary data 
      actualDH = (DataHandler)secondParam.getDataHandler();
     }
     else
     { 
      genericRequestXML = secondParam.getText();
     }
    }
   }
  }
  //System.out.println("First Param:: actualDH" + actualDH);
  //System.out.println("Second Param:: genericRequestXML" +
genericRequestXML);

  //Create SAIL DTO
  SAILTransferObject request = new SAILTransferObject();
  request.setXMLMessage(genericRequestXML);
  if(actualDH!=null){
   request.setDocStream(actualDH.getInputStream());
  }
  return request;
 }


RE: Axis Error while writing to the OutputStream in MTOM

Posted by "reddy, ramachandra" <ra...@anacomp.com>.
We found a fix for this issue.
The problem was some how on windows when use tomcat it works fine but
when we use Linux box in the client side you need to set 
options.setProperty(HTTPConstants.CHUNKED,false);

By doing this we were able to send documents of any size else after 3 kb
it fails .Hope this helps.

-Ramachandra Reddy
 

________________________________

From: reddy, ramachandra [mailto:ramachandra.reddy@anacomp.com] 
Sent: Friday, April 04, 2008 2:56 PM
To: axis-user@ws.apache.org; axis-dev@ws.apache.org
Subject: Axis Error while writing to the OutputStream in MTOM


Hi Folks,
We are using Webservices for sending a File and an XML String as
parameters. The code we wrote works fine for any type of file attachment
on windows but when we deployed our webservice on Sunone on Linux and
when we try to invoke our client from windows machine we are getting
this error. Any hints on whats going on ?
( At the bottom I have added  the code) 


org.apache.axiom.om.OMException: Error while writing to the
OutputStream.

      at
org.apache.axiom.om.impl.MIMEOutputUtils.complete(MIMEOutputUtils.java:7
5)

      at
org.apache.axiom.om.impl.MTOMXMLStreamWriter.flush(MTOMXMLStreamWriter.j
ava:126)

      at
org.apache.axiom.om.impl.llom.OMNodeImpl.serializeAndConsume(OMNodeImpl.
java:422)

      at
org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessage
Formatter.java:68)

      at
org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisReque
stEntity.java:84)

      at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequest
Body(EntityEnclosingMethod.java:495)

      at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase
.java:1973)

      at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java
:993)

      at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMe
thodDirector.java:397)

      at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMetho
dDirector.java:170)

      at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
96)

      at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
46)

      at
org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(Abstrac
tHTTPSender.java:520)

      at
org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:1
91)

      at
org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:77)

      at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageW
ithCommons(CommonsHTTPTransportSender.java:327)

      at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(Common
sHTTPTransportSender.java:206)

      at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:396)

      at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOper
ation.java:374)

      at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInA
xisOperation.java:211)

      at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:163
)

      at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:528
)

      at
org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:508
)

      at
com.docharbor.bpms.webservice.SAILWebServiceClient.sendServiceRequest(SA
ILWebServiceClient.java:106)

      at
com.docharbor.bpms.webservice.SAILWebServiceClient.service(SAILWebServic
eClient.java:48)

      at
com.docharbor.bpms.webservice.SAILWebServiceClient.main(SAILWebServiceCl
ient.java:160)

Caused by: java.net.SocketException: Software caused connection abort:
socket write error

      at java.net.SocketOutputStream.socketWrite0(Native Method)

      at java.net.SocketOutputStream.socketWrite(Unknown Source)

      at java.net.SocketOutputStream.write(Unknown Source)

      at java.io.BufferedOutputStream.flushBuffer(Unknown Source)

      at java.io.BufferedOutputStream.write(Unknown Source)

      at
org.apache.commons.httpclient.WireLogOutputStream.write(WireLogOutputStr
eam.java:67)

      at
org.apache.commons.httpclient.ChunkedOutputStream.flushCacheWithAppend(C
hunkedOutputStream.java:120)

      at
org.apache.commons.httpclient.ChunkedOutputStream.write(ChunkedOutputStr
eam.java:178)

      at javax.activation.DataHandler.writeTo(DataHandler.java:308)

      at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1350)

      at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:845)

      at
org.apache.axiom.om.impl.MIMEOutputUtils.writeBodyPart(MIMEOutputUtils.j
ava:131)

      at
org.apache.axiom.om.impl.MIMEOutputUtils.complete(MIMEOutputUtils.java:6
8)

      ... 25 more

 

 

CODE:

CLIENT

====================

private   ISAILObject sendServiceRequest(String
sailWebSvcUrl,ISAILObject obj) throws Exception{
         SAILTransferObject tranobj = new SAILTransferObject();

         System.out.println(":: Entering SAIL WebService Request ()::");
   ServiceClient serviceClient = new ServiceClient ();
   Options options = new Options();
   EndpointReference targetEPR = new EndpointReference(sailWebSvcUrl);
         options.setTo(targetEPR);
         options.setProperty(Constants.Configuration.ENABLE_MTOM,
Constants.VALUE_TRUE);
         serviceClient .setOptions(options);
         
         
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMNamespace omNs =
fac.createOMNamespace("http://webservices.sail.docharbor.com", "SAIL");
   OMElement method = fac.createOMElement("receiveRequest", omNs);
   
   //Parameter  - XML
         OMElement value1 = fac.createOMElement("genericRequestXML",
omNs);
         value1.addChild(fac.createOMText(value1, obj.getXMLMessage()));
   method.addChild(value1);
   
   
   //Parameter  - Stream
   //If true - MTOM else  Base64  encoding
   if(obj.getDocStream()!=null){
    OMElement fileElement = fac.createOMElement("inputfile", omNs);
    //DataHandler dataHandler = new DataHandler(new
FileDataSource("C:\\dist.zip"));
    byte[] byteArray = IOUtils.getStreamAsByteArray(obj.getDocStream());
    DataHandler dataHandler = new DataHandler(new
ByteArrayDataSource(byteArray));
    OMText textData = fac.createOMText(dataHandler, true);
    fileElement.addChild(textData);
    method.addChild(fileElement);
   }
   //System.out.println(":: XML Request :: "+obj.getXMLMessage());
   //CALL
   OMElement result = serviceClient.sendReceive(method);
   DataHandler actualDH;

   //Read First Parameter from Response. - String
   OMText firstParam =
(OMText)result.getFirstElement().getFirstOMChild();
   //OMText responseXML =
(OMText)((OMElementImpl)result.getFirstElement().getNextOMSibling()).get
FirstOMChild();
   if (!firstParam.isBinary()) {
    String responseXML = firstParam.getText(); 
    //System.out.println("Received from server
responseXML:"+responseXML);
          tranobj.setXMLMessage(responseXML);
   } else {
    actualDH = (DataHandler)firstParam.getDataHandler();
          //System.out.println("Received from server Stream:"+
actualDH.getInputStream().toString());
          tranobj.setDocStream(actualDH.getInputStream());
   }
   //Read second parameter from Response if present- must be Stream
   OMNode nextNode =  result.getFirstElement().getNextOMSibling();
   if(nextNode != null)
   {
    OMText secondParam =
(OMText)((OMElementImpl)nextNode).getFirstOMChild();
    if(secondParam!=null && secondParam.isBinary()){
     actualDH = (DataHandler)secondParam.getDataHandler();
           //readFileFromStream(actualDH.getInputStream());
          // System.out.println("Received from server Stream:"+
actualDH.getInputStream().toString());
           tranobj.setDocStream(actualDH.getInputStream());
    } else {
     String responseXML = firstParam.getText(); 
     //System.out.println("Received from server
responseXML:"+responseXML);
           tranobj.setXMLMessage(responseXML);
    }
   } 
   return tranobj;
   }


SERVER:

================================================================

 

 

private ISAILObject receiveRequest(OMElement element) throws
IOException{
  element.build();
  element.detach();
  String genericRequestXML =null;
  DataHandler actualDH = null;
  
  //Get First Param - Can be xml or Stream
  OMElement firstElement = element.getFirstElement();
  if (firstElement != null) {
   OMText firstParam  = (OMText)firstElement.getFirstOMChild();
   //System.out.println("First Param::"+firstParam.isBinary());
   if (firstParam != null) {
    if(firstParam.isBinary())
    {
     //We got some binary data 
     actualDH = (DataHandler)firstParam.getDataHandler();
    }
    else
    { 
     genericRequestXML = firstParam.getText();
    }
   }
  }
  //Get  Second Param id present - Can be xml or Stream
  OMNode nextNode = element.getFirstElement().getNextOMSibling();
  if(nextNode!=null)
  { 
   OMElementImpl nextSibling = (OMElementImpl)nextNode;
 
//((OMElementImpl)element.getFirstElement().getNextOMSibling()).getFirst
OMChild();
   if(nextSibling != null){
    OMText secondParam = (OMText)(nextSibling).getFirstOMChild();
    if(secondParam != null){
     //System.out.println("Second Param::"+ secondParam.isBinary());
     if(secondParam.isBinary())
     {
      //We got some binary data 
      actualDH = (DataHandler)secondParam.getDataHandler();
     }
     else
     { 
      genericRequestXML = secondParam.getText();
     }
    }
   }
  }
  //System.out.println("First Param:: actualDH" + actualDH);
  //System.out.println("Second Param:: genericRequestXML" +
genericRequestXML);

  //Create SAIL DTO
  SAILTransferObject request = new SAILTransferObject();
  request.setXMLMessage(genericRequestXML);
  if(actualDH!=null){
   request.setDocStream(actualDH.getInputStream());
  }
  return request;
 }