Hi,
Please see my comments in line...

On 3/5/07, holodok <[EMAIL PROTECTED]> wrote:

I used the example from http://ws.apache.org/axis2/1_1_1/mtom-guide.html#32
to get pdf file from server. My server looks like:

public OMElement getPDFDocument(OMElement root) {
        try {
            JAXBContext _jaxbContext =
JAXBContext.newInstance(DocumentRequest.class, Documents.class,
BillingRequest.class, BillingResponse.class);
            Unmarshaller _unmarshaller =_jaxbContext.createUnmarshaller();
            DocumentRequest _request = (DocumentRequest)
_unmarshaller.unmarshal(root.getXMLStreamReader());
            Documents _response = new Documents();
            int i = 0;
            MessageContext _ctx = MessageContext.getCurrentMessageContext();
Here you are accessing the incoming message context. But in this case
you need to get hold of the outgoing message context in order to set
the attachments to the response..
You can use the following code to access the our messagecontext...

        MessageContext inMessageContext = 
MessageContext.getCurrentMessageContext();
        OperationContext operationContext = 
inMessageContext.getOperationContext();
        MessageContext outMessageContext =
operationContext                
.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);

            for(DocumentRequest.RequestParameters _param :
_request.getRequestParameters()){
                Documents.Document _doc = new Documents.Document();
                _response.getDocument().add(_doc);
                DataSource _ds = new FileDataSource(new
File("C:\\dev\\axis2-1.1.1\\out\\", "test_" + (i+1) + ".pdf"));
                String _contentId = String.valueOf(i+1);
                _ctx.addAttachment(_contentId, new DataHandler(_ds));
                _doc.setDocumentReference(_contentId);
            }

            Marshaller _marshaller = _jaxbContext.createMarshaller();
            SAXOMBuilder _builder = new SAXOMBuilder();
            _marshaller.marshal(_response, _builder);
            OMElement _root = _builder.getRootElement();
            return _root;
        } catch (JAXBException e) {
            e.printStackTrace();
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }


My client is like:

EndpointReference _targetEPR = new
EndpointReference("http://localhost:8080/axis2/services/TestServer";);
        Options options = new Options();
        options.setTo(_targetEPR);
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(Constants.Configuration.ENABLE_SWA,
Constants.VALUE_TRUE);
No need to enable SwA to receive attachments... It is needed only when
you need to send attachments from the client side...

Please post the message snapshots in case you went it to trouble
again... You can use http://ws.apache.org/tcpmon  to capture the
messages..

Thanks,
Thilina

options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);

        try {
            options.setAction("getPDFDocument");
            ServiceClient _sender = new ServiceClient();
            _sender.setOptions(options);

            OMElement _result = _sender.sendReceive(_root);

            OperationClient _mepClient =
_sender.createClient(ServiceClient.ANON_OUT_IN_OP);
            _mepClient.addMessageContext(new MessageContext());
            _mepClient.execute(true);
            MessageContext _ctx = _mepClient.getMessageContext("Out");
            DataHandler _dataHandler = _ctx.getAttachment("1");
            System.out.println(_ctx.getAttachmentMap().getContentIDSet());
            FileOutputStream _stream = new FileOutputStream(new
File("in/test_1.pdf"));
            _dataHandler.writeTo(_stream);
            _stream.close();

            System.out.println(_result);
        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use
File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use
File | Settings | File Templates.
        }

When I run it I get exception at server:
Mar 5, 2007 2:40:04 PM
org.apache.axis2.transport.http.server.DefaultHttpService
Processor logIOException
WARNING: Chunked stream ended unexpectedly
org.apache.http.io.MalformedChunkCodingException: Chunked stream ended
unexpectedly
        at
org.apache.http.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:273)
        at
org.apache.http.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:234)
        at
org.apache.http.io.ChunkedInputStream.read(ChunkedInputStream.java:206)
        at
org.apache.http.io.ChunkedInputStream.read(ChunkedInputStream.java:226)
        at
org.apache.http.io.ChunkedInputStream.exhaustInputStream(ChunkedInputStream.java:339)
        at
org.apache.http.io.ChunkedInputStream.close(ChunkedInputStream.java:312)
        at
org.apache.http.entity.BasicHttpEntity.consumeContent(BasicHttpEntity.java:140)
        at
org.apache.http.protocol.HttpService.handleRequest(HttpService.java:129)

And exception at client:
Exception in thread "main" java.lang.NullPointerException
        at
org.apache.axis2.transport.http.SOAPOverHTTPSender$AxisSOAPRequestEntity.handleOMOutput(SOAPOverHTTPSender.java:183)
        at
org.apache.axis2.transport.http.SOAPOverHTTPSender$AxisSOAPRequestEntity.writeRequest(SOAPOverHTTPSender.java:232)
        at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(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(HttpMethodDirector.java:397)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
        at
org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:541)
        at
org.apache.axis2.transport.http.SOAPOverHTTPSender.send(SOAPOverHTTPSender.java:119)
        at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:335)
        at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:204)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:674)
        at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:237)
        at
org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:202)
        at Main.main(Main.java:110)

Please, tell me, what I'm doing wrong...
--
View this message in context: 
http://www.nabble.com/axs2-and-attachments-tf3348698.html#a9311000
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Thilina Gunarathne
WSO2, Inc.; http://www.wso2.com/
Home page: http://webservices.apache.org/~thilina/
Blog: http://thilinag.blogspot.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to