You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Shalab Goel <Sh...@hyperion.com> on 2007/06/21 20:53:33 UTC

[Axis2] Streaming dynamically generated large sized content

Hello Everyone,

 

I am looking for some assistance with streaming large sized dynamically
generated content.

 

I have defined an 'echoString' operation, which takes two request
arguments a string to repeat, and count of number of times to repeat.
This is a service which replicates somewhat the requirement I am working
on - to be able to stream dynamically generated content (size in order
of 50 to 200 MBs). 

 

            public OMElement echoString (String echo, String count)
throws Exception

            {

                        PipedInputStream inStream = new
PipedInputStream();

                        PipedOutputStream outStream = new
PipedOutputStream(inStream);

 

                        DataHandler dh = new DataHandler(inStream,
"text/plain");

 

                        MessageContext inCtx =
MessageContext.getCurrentMessageContext();

                       OperationContext operationContext =
inCtx.getOperationContext();

                       MessageContext outCtx = operationContext

 
.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);

                        

                        String attachmentID = outCtx.addAttachment(dh);

 

                        OMFactory fac =
OMAbstractFactory.getOMFactory();

                        OMNamespace omNs = fac.createOMNamespace(

 
"http://service.soapwithattachments.sample/xsd", "swa");

                        OMElement echoStringOp =
fac.createOMElement("echoStringResponse", omNs);

                        OMElement idEle =
fac.createOMElement("attchmentID", omNs);

                        idEle.addAttribute("href",
"cid:"+attachmentID,null);

                        echoStringOp.addChild(idEle);

 

                        byte bytes[] = strArg.getBytes();

                        try

                        {

                              for (int i=0; i < cntArg; i++)

                                      outStream.write(bytes);

                              outStream.flush();

                              outStream.close();

                        }

                        catch (Exception e) {};

 

                        return echoStringOp;

            }

 

In the services.xml, I have added parameter for enabling SWA

 

         <parameter name="enableSwA">true</parameter>

 

 

When I run my client code, I get the following exception trace:

 

contentID <0....@apache.org>

Exception in thread "main" java.io.IOException: eosBeforeMarker

      at
org.apache.axiom.attachments.BoundaryDelimitedStream.read(BoundaryDelimi
tedStream.java:300)

      at
org.apache.axiom.attachments.IncomingAttachmentInputStream.read(Incoming
AttachmentInputStream.java:121)

      at
sample.soapwithattachments.client.SWAClient.callEchoManyTimes(SWAClient.
java:212)

      at
sample.soapwithattachments.client.SWAClient.main(SWAClient.java:59)

 

 

Following is how the attachment is being accessed in client code:

 

                        MessageContext response = mepClient

 
.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

                        Attachments attachments =
response.getAttachmentMap();

                        IncomingAttachmentStreams streams =
attachments.getIncomingAttachmentStreams();

                        IncomingAttachmentInputStream inStream = null;

                        if (streams != null)

                        {

                                    inStream = streams.getNextStream();

                                    System.out.println("contentID " +
inStream.getContentId());

                        }

 

Following is the SOAP request (in TCPMonitor):

---------------------------------------------------------------------  

 

POST /axis2/services/SWASampleService HTTP/1.1

Content-Type: multipart/related;
boundary=MIMEBoundaryurn_uuid_C2F2DEF18072BF88741182450074533;
type="text/xml";
start="<0....@apache.org>";
charset=UTF-8

SOAPAction: "urn:echoString"

User-Agent: Axis2

Host: 127.0.0.1:8081

Transfer-Encoding: chunked

 

231

--MIMEBoundaryurn_uuid_C2F2DEF18072BF88741182450074533

Content-Type: text/xml; charset=UTF-8

Content-Transfer-Encoding: 8bit

Content-ID: <0....@apache.org>

   <?xml version='1.0' encoding='UTF-8'?>

      <soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

         <soapenv:Body>

            <swa:echoString
xmlns:swa="http://service.soapwithattachments.sample/xsd">

               <swa:echo>howdy</swa:echo>

               <swa:count>45</swa:count>

            </swa:echoString>

         </soapenv:Body>

 
</soapenv:Envelope>--MIMEBoundaryurn_uuid_C2F2DEF18072BF8874118245007453
3-0

 

 

Following is the SOAP response (showing Fault)

----------------------------------------------------------------------


 

HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Content-Type: multipart/related;
boundary=MIMEBoundaryurn_uuid_DFCA23517587D8F2141182450081761;
type="text/xml";
start="<0....@apache.org>";charset=
UTF-8Transfer-Encoding: chunkedDate: Thu, 21 Jun 2007 18:21:21
GMT29a--MIMEBoundaryurn_uuid_DFCA23517587D8F2141182450081761Content-Type
: text/xml; charset=UTF-8Content-Transfer-Encoding: 8bitContent-ID: 

   <0....@apache.org>

      <?xml version='1.0' encoding='UTF-8'?>

         <soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

            <soapenv:Body>

               <ns:echoStringResponse
xmlns:ns="http://service.soapwithattachments.sample/xsd">

                  <ns:return>

                     <swa:echoStringResponse
xmlns:swa="http://service.soapwithattachments.sample/xsd">

                        <swa:attchmentID
href="cid:urn:uuid:DFCA23517587D8F2141182450081744" />

                     </swa:echoStringResponse>

                  </ns:return>

               </ns:echoStringResponse>

            </soapenv:Body>

         </soapenv:Envelope>

38

 

--MIMEBoundaryurn_uuid_DFCA23517587D8F2141182450081761

1fa

--MIMEBoundaryurn_uuid_DFCA23517587D8F2141182450082013

Content-Type: text/xml; charset=UTF-8

Content-Transfer-Encoding: 8bit

Content-ID: 

         <0....@apache.org>

            <?xml version='1.0' encoding='UTF-8'?>

               <soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

                  <soapenv:Body>

                     <soapenv:Fault>

                        <faultcode>soapenv:Client</faultcode>

                        <faultstring>Error while writing to the
OutputStream.</faultstring>

                        <detail />

                     </soapenv:Fault>

                  </soapenv:Body>

               </soapenv:Envelope>

38

 

--MIMEBoundaryurn_uuid_DFCA23517587D8F2141182450082013

2

--

0

 

 

 

 

________________________________

From: Shalab Goel 
Sent: Wednesday, June 20, 2007 1:59 PM
To: 'axis-user@ws.apache.org'
Subject: Sample application demo-ing attachments functionality

 

Hello,

 

Thanks in advance if this already is available and you can point to the
proper location.

 

I am looking for a sample web service that would take a file path on
server as request, and respond with contents of the file as a SOAP
attachment. Any pointers on anything similar will be appreciated.

 

Is streaming of the file contents possible, as the file in my case is
expected to be plus 100 MB potentially?

 

In the samples/userguide directory of the distribution, I see a little
different variation, where client sends the file contents in attachment,
and web service consumes it.

 

 



If you have received this e-mail in error, please delete it and notify the sender as soon as possible. The contents of this e-mail may be confidential and the unauthorized use, copying, or dissemination of it and any attachments to it, is prohibited. Internet communications are not secure and Hyperion does not, therefore, accept legal responsibility for the contents of this message nor for any damage caused by viruses. The views expressed here do not necessarily represent those of Hyperion. For more information about Hyperion, please visit our Web site at: www.hyperion.com