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 Mancinelli Elodie <el...@bull.net> on 2006/07/06 09:05:50 UTC

[Axis2]Save attachment MTOM

Hi all,

I have create a client-server which support WSRM and MTOM.
The client works, it send messages with attachment to the server. But I 
want to save the attachment on my server. When I launch my client, I 
have this error on my server:

java.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMTextImpl
        at 
fr.gouv.finances.dgme.presto.PrestoSvcSkeleton.saveImage(PrestoSvcSkeleton.java:169)
        at 
fr.gouv.finances.dgme.presto.PrestoSvcSkeleton.readSoapMessage(PrestoSvcSkeleton.java:136)
        at 
fr.gouv.finances.dgme.presto.PrestoSvcSkeleton.submit(PrestoSvcSkeleton.java:70)
        at 
fr.gouv.finances.dgme.presto.PrestoSvcMessageReceiverInOut.invokeBusinessLogic(PrestoSvcMessageReceiverInOut.java:46)
        at 
org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.receive(AbstractInOutSyncMessageReceiver.java:37)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:454)
        at 
org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:284)
        at 
org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:136)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
        at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at 
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)

I think it's when I want to get the attachment I should have an 
OMElement but I have a OMText. But I don't understand why?

Can someone have an idea?

I send a message saop and my server code.

- soap message:

POST /axis2/services/PrestoSvc HTTP/1.1
User-Agent: Axis2
SOAPAction: 
http://localhost:8080/axis2/services/PrestoSvc/__OPERATION_OUT_IN__
Cookie: JSESSIONID=BE98CB5DB8ABB0A61EE034F184334CCF
Cookie2: JSESSIONID=BE98CB5DB8ABB0A61EE034F184334CCF
Host: 127.0.0.1:8070
Transfer-Encoding: chunked
Content-Type: multipart/related; 
boundary=MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607; 
type="application/xop+xml"; 
start="<0....@apache.org>"; 
start-info="text/xml"; 
charset=UTF-8a96--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607content-type:application/xop+xml; 
charset=UTF-8; type="text/xml";content-transfer-encoding:binarycontent-id:
   <0....@apache.org>
      <?xml version='1.0' encoding='UTF-8'?>
         <soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:wsa="http://www.w3.org/2005/08/addressing">
            <soapenv:Header>
               
<wsa:To>http://localhost:8080/axis2/services/PrestoSvc</wsa:To>
               <wsa:ReplyTo>
                  
<wsa:Address>http://129.183.149.72:6060/axis2/services/__ANONYMOUS_SERVICE__/__OPERATION_OUT_IN__</wsa:Address>
               </wsa:ReplyTo>
               
<wsa:MessageID>urn:uuid:81AD7AC184DDB331FB11521686151086</wsa:MessageID>
               
<wsa:Action>http://localhost:8080/axis2/services/PrestoSvc/__OPERATION_OUT_IN__</wsa:Action>
               <wsrm:Sequence 
xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm" 
soapenv:mustUnderstand="1">
                  
<wsrm:Identifier>urn:uuid:162BCF2DBF2BF6B4C1115216861701538</wsrm:Identifier>
                  <wsrm:MessageNumber>2</wsrm:MessageNumber>
               </wsrm:Sequence>
            </soapenv:Header>
            <soapenv:Body>
               <m:submit 
xmlns:m="http://dgme.finances.gouv.fr/presto">&lt;pro:testDocIn 
xmlns:pro="http://dgme.finances.gouv.fr/prototype">    
&lt;pro:intStrElement>        
&lt;pro:intElement>12&lt;/pro:intElement>        &lt;pro:strElement>test 
de string&lt;/pro:strElement>    
&lt;/pro:intStrElement>&lt;pro:binaryElement>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAPAA0DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDp/FPjS1fWtUNtd6rcXGiahYQR2elLO6vmaMzb2jxGzOGaERyE4aI4wXIroJte10WdtfDVbEQ3W4pFa+HL29MJU4aN2jkBDKcqdyISVPyqQQNTW/DMLadctoWnabBqE97a3krFRALhorhJj5johJJ2tyQeW+tcXffEfwcl5IbnxRfeG9Z4TU7SztvOAnQBWVi8DozIQU3pjcFXJIVcAH//2Q==&lt;/pro:binaryElement>    
&lt;pro:anyElement>        &lt;test123>1 2 3 4 5 6&lt;/test123>    
&lt;/pro:anyElement>&lt;/pro:testDocIn>
                  <m:attachment>
                     <xop:Include 
href="cid:urn:uuid:4CDFC85751839D5E2111521686150992@apache.org" 
xmlns:xop="http://www.w3.org/2004/08/xop/include" />
                  </m:attachment>
               </m:submit>
            </soapenv:Body>
         
</soapenv:Envelope>12b--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607content-id:
         
<ur...@apache.org>content-type:text/plaincontent-transfer-encoding:binaryTable 
ASCII standard (codes de caractères de 0 à 
127)--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607--0

- server code:

public class PrestoSvcSkeleton {

    static String 
fileXMLName="/home/mancinee/workspace/testPresto/test_data_out.xml";
    static String 
nameNewFile="/home/mancinee/workspace/testPresto/soapmessout.xml";
    static String 
fileSaveName="/home/mancinee/workspace/testPresto/fileresult.txt";
    private MessageContext msgcts;

     public void setOperationContext(OperationContext oc) throws AxisFault {
            msgcts = 
oc.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        }
 
    public void submitOneWay(
        fr.gouv.finances.dgme.presto.SubmitOneWayDocument param2) throws 
IOException, InterruptedException {
        System.out.println("submit One Way METHOD CALL");
//      Recuperation et sauvegarde de l attachement

        readSoapMessage(param2);
        Thread.sleep(20000);
    }


//  Version fichier texte
    public static File createSoapBodyMessage (String nameFile){
        PrintWriter newFile = null;
        try
        {
            //Ajout de l'entete
            newFile =  new PrintWriter(new BufferedWriter(new 
FileWriter(nameNewFile)));
            newFile.println("<m:submitResponse 
xmlns:m='http://dgme.finances.gouv.fr/presto'>");
            //Ajout du contenu du body
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(
                          new FileInputStream(nameFile),"UTF-8"));
              String ligne;
              while((ligne = br.readLine())!=null){
                  newFile.println(ligne);
              }
//            Ajout de la fermeture des balises
              newFile.println("</m:submitResponse>");
              newFile.close();
        }
        catch (FileNotFoundException e)
        {
            System.out.println("Le fichier test_data_out.xml n'a pas été 
trouvé");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("Erreur de lecture-ecriture dans un 
fichier");
            e.printStackTrace();
        }
        File xmlFile = new File(nameNewFile);
        return xmlFile;
    }


    public void 
readSoapMessage(fr.gouv.finances.dgme.presto.SubmitOneWayDocument param2){
        OMFactory fac = OMAbstractFactory.getOMFactory();
        StAXOMBuilder builder = new StAXOMBuilder(fac,new 
StreamWrapper(param2.newXMLStreamReader())) ;
        OMElement payload = builder.getDocumentElement();
        ((OMNodeEx)payload).setParent(null);
        saveFile(payload);

    }

    public void saveFile(OMElement payload){

        try {
            OMElement attach = null;
            OMElement seq = null;
            for (Iterator it = payload.getChildElements();it.hasNext();) {
                OMElement el = (OMElement) it.next();
                if (el.getLocalName().equalsIgnoreCase("attachment")) {
                    attach = el;
                    System.out.println("attachment");
                }
                else return;
                if (el.getLocalName().equalsIgnoreCase("Sequence")) {
                    seq = el;
                    System.out.println("sequence:" + seq.getText());
                }
            }


            System.out.println("Save attachment");
            OMElement child = (OMElement) attach.getFirstOMChild(); 
//The problem is here
            OMAttribute attr = child.getAttribute(new QName("href"));
            String contentID = attr.getAttributeValue();
            Attachments attachment = (Attachments) 
msgcts.getProperty(MTOMConstants.ATTACHMENTS);
            contentID = contentID.trim();

            if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
                contentID = contentID.substring(4);

            }
            DataHandler dataHandler = attachment.getDataHandler(contentID);
            System.out.println("contentID: " + contentID);
            DataSource dataSource=dataHandler.getDataSource();
            System.out.println("dataSource: " + dataSource.toString());
            InputStream infile;

            infile = dataSource.getInputStream();

            System.out.println("infile: " + infile.toString());
            PrintWriter filetmp =  new PrintWriter(new 
BufferedWriter(new FileWriter(fileSaveName)));
            String ligne;
            BufferedReader br = new BufferedReader(new 
InputStreamReader(infile,"UTF-8"));
            while((ligne = br.readLine())!=null) filetmp.println(ligne);
            br.close();
            filetmp.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public static void deleteFile(String nameFile){
        File file = new File(nameFile);
        Boolean resultat = file.delete();
        System.out.println("The delete of file " + nameFile + " is " + 
resultat);
    }

}


Thanks for your help.
Regards,
Elodie


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2]Save attachment MTOM

Posted by Thilina Gunarathne <cs...@gmail.com>.
Change the problematic part of saveFile() as follows...........

        OMText child = (OMText) attach.getFirstOMChild();
        //Extracting the data and saving
        DataHandler actualDH;
        actualDH = (DataHandler) child .getDataHandler();

~Thilina

On 7/6/06, Thilina Gunarathne <cs...@gmail.com> wrote:
>
>  Hi,
>
> On 7/6/06, Mancinelli Elodie <el...@bull.net> wrote:
> >
> > Hi all,
>
>
>
> I think it's when I want to get the attachment I should have an
> OMElement but I have a OMText. But I don't understand why?
>
>
> Nope... U get an OMText... Binary is represented using an OMText
> eventhough on the wire it is an element.
> Have a look at http://ws.apache.org/axis2/1_0/mtom-guide.html#21
>
> Looks like you are doing way too much work to access the attachments. U
> can get the DataHandler directly from the created OMText...
> Have a look at the MTOMSample..
>
> ~Thilina
>
> Can someone have an idea?
> >
> > I send a message saop and my server code.
> >
> > - soap message:
> >
> > POST /axis2/services/PrestoSvc HTTP/1.1
> > User-Agent: Axis2
> > SOAPAction:
> > http://localhost:8080/axis2/services/PrestoSvc/__OPERATION_OUT_IN__
> > Cookie: JSESSIONID=BE98CB5DB8ABB0A61EE034F184334CCF
> > Cookie2: JSESSIONID=BE98CB5DB8ABB0A61EE034F184334CCF
> > Host: 127.0.0.1:8070
> > Transfer-Encoding: chunked
> > Content-Type: multipart/related;
> > boundary=MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607;
> > type="application/xop+xml";
> > start="<0....@apache.org>";
> > start-info="text/xml";
> >
> > charset=UTF-8a96--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607content-type:application/xop+xml;
> > charset=UTF-8;
> > type="text/xml";content-transfer-encoding:binarycontent-id:
> >   < 0.urn:uuid:4CDFC85751839D5E2111521686191608@apache.org>
> >      <?xml version='1.0' encoding='UTF-8'?>
> >         <soapenv:Envelope
> > xmlns:soapenv=" http://schemas.xmlsoap.org/soap/envelope/"
> > xmlns:wsa="http://www.w3.org/2005/08/addressing">
> >            <soapenv:Header>
> >
> > <wsa:To> http://localhost:8080/axis2/services/PrestoSvc</wsa:To>
> >               <wsa:ReplyTo>
> >
> > <wsa:Address>http://129.183.149.72:6060/axis2/services/__ANONYMOUS_SERVICE__/__OPERATION_OUT_IN__
> > </wsa:Address>
> >               </wsa:ReplyTo>
> >
> > <wsa:MessageID>urn:uuid:81AD7AC184DDB331FB11521686151086</wsa:MessageID>
> >
> >
> > <wsa:Action>
> > http://localhost:8080/axis2/services/PrestoSvc/__OPERATION_OUT_IN__
> > </wsa:Action>
> >               <wsrm:Sequence
> > xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"
> > soapenv:mustUnderstand="1">
> >
> > <wsrm:Identifier>urn:uuid:162BCF2DBF2BF6B4C1115216861701538</wsrm:Identifier>
> >
> >                  <wsrm:MessageNumber>2</wsrm:MessageNumber>
> >               </wsrm:Sequence>
> >            </soapenv:Header>
> >            <soapenv:Body>
> >               <m:submit
> > xmlns:m="http://dgme.finances.gouv.fr/presto">&lt;pro:testDocIn
> > xmlns:pro="http://dgme.finances.gouv.fr/prototype ">
> > &lt;pro:intStrElement>
> > &lt;pro:intElement>12&lt;/pro:intElement>        &lt;pro:strElement>test
> > de string&lt;/pro:strElement>
> > &lt;/pro:intStrElement>&lt;pro:binaryElement>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAPAA0DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDp/FPjS1fWtUNtd6rcXGiahYQR2elLO6vmaMzb2jxGzOGaERyE4aI4wXIroJte10WdtfDVbEQ3W4pFa+HL29MJU4aN2jkBDKcqdyISVPyqQQNTW/DMLadctoWnabBqE97a3krFRALhorhJj5johJJ2tyQeW+tcXffEfwcl5IbnxRfeG9Z4TU7SztvOAnQBWVi8DozIQU3pjcFXJIVcAH//2Q==&lt;/pro:binaryElement>
> >
> > &lt;pro:anyElement>        &lt;test123>1 2 3 4 5 6&lt;/test123>
> > &lt;/pro:anyElement>&lt;/pro:testDocIn>
> >                  <m:attachment>
> >                     <xop:Include
> > href="cid:urn:uuid:4CDFC85751839D5E2111521686150992@apache.org"
> > xmlns:xop=" http://www.w3.org/2004/08/xop/include" />
> >                  </m:attachment>
> >               </m:submit>
> >            </soapenv:Body>
> >
> > </soapenv:Envelope>12b--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607content-id:
> >
> >
> > <urn:uuid:4CDFC85751839D5E2111521686150992@apache.org
> > >content-type:text/plaincontent-transfer-encoding:binaryTable
> > ASCII standard (codes de caractères de 0 à
> > 127)--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607--0
> >
> > - server code:
> >
> > public class PrestoSvcSkeleton {
> >
> >    static String
> > fileXMLName="/home/mancinee/workspace/testPresto/test_data_out.xml";
> >    static String
> > nameNewFile="/home/mancinee/workspace/testPresto/soapmessout.xml";
> >    static String
> > fileSaveName="/home/mancinee/workspace/testPresto/fileresult.txt";
> >    private MessageContext msgcts;
> >
> >     public void setOperationContext(OperationContext oc) throws
> > AxisFault {
> >            msgcts =
> > oc.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
> >        }
> >
> >    public void submitOneWay(
> >        fr.gouv.finances.dgme.presto.SubmitOneWayDocument param2) throws
> > IOException, InterruptedException {
> >        System.out.println("submit One Way METHOD CALL");
> > //      Recuperation et sauvegarde de l attachement
> >
> >        readSoapMessage(param2);
> >        Thread.sleep(20000);
> >    }
> >
> >
> > //  Version fichier texte
> >    public static File createSoapBodyMessage (String nameFile){
> >        PrintWriter newFile = null;
> >        try
> >        {
> >            //Ajout de l'entete
> >            newFile =  new PrintWriter(new BufferedWriter(new
> > FileWriter(nameNewFile)));
> >            newFile.println("<m:submitResponse
> > xmlns:m=' http://dgme.finances.gouv.fr/presto'>");
> >            //Ajout du contenu du body
> >            BufferedReader br = new BufferedReader(
> >                    new InputStreamReader(
> >                          new FileInputStream(nameFile),"UTF-8"));
> >              String ligne;
> >              while((ligne = br.readLine())!=null){
> >                  newFile.println(ligne);
> >              }
> > //            Ajout de la fermeture des balises
> >              newFile.println ("</m:submitResponse>");
> >              newFile.close();
> >        }
> >        catch (FileNotFoundException e)
> >        {
> >            System.out.println("Le fichier test_data_out.xml n'a pas été
> > trouvé");
> >            e.printStackTrace();
> >        } catch (IOException e) {
> >            System.out.println("Erreur de lecture-ecriture dans un
> > fichier");
> >            e.printStackTrace();
> >        }
> >        File xmlFile = new File(nameNewFile);
> >        return xmlFile;
> >    }
> >
> >
> >    public void
> > readSoapMessage(fr.gouv.finances.dgme.presto.SubmitOneWayDocumentparam2){
> >        OMFactory fac = OMAbstractFactory.getOMFactory ();
> >        StAXOMBuilder builder = new StAXOMBuilder(fac,new
> > StreamWrapper(param2.newXMLStreamReader())) ;
> >        OMElement payload = builder.getDocumentElement();
> >        ((OMNodeEx)payload).setParent(null);
> >        saveFile(payload);
> >
> >    }
> >
> >    public void saveFile(OMElement payload){
> >
> >        try {
> >            OMElement attach = null;
> >            OMElement seq = null;
> >            for (Iterator it = payload.getChildElements ();it.hasNext();)
> > {
> >                OMElement el = (OMElement) it.next();
> >                if (el.getLocalName().equalsIgnoreCase("attachment")) {
> >                    attach = el;
> >                    System.out.println ("attachment");
> >                }
> >                else return;
> >                if (el.getLocalName().equalsIgnoreCase("Sequence")) {
> >                    seq = el;
> >                    System.out.println ("sequence:" + seq.getText());
> >                }
> >            }
> >
> >
> >            System.out.println("Save attachment");
> >            OMElement child = (OMElement) attach.getFirstOMChild();
> > //The problem is here
> >            OMAttribute attr = child.getAttribute(new QName("href"));
> >            String contentID = attr.getAttributeValue();
> >            Attachments attachment = (Attachments)
> > msgcts.getProperty (MTOMConstants.ATTACHMENTS);
> >            contentID = contentID.trim();
> >
> >            if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
> >                contentID = contentID.substring(4);
> >
> >            }
> >            DataHandler dataHandler = attachment.getDataHandler
> > (contentID);
> >            System.out.println("contentID: " + contentID);
> >            DataSource dataSource=dataHandler.getDataSource();
> >            System.out.println("dataSource: " + dataSource.toString());
> >            InputStream infile;
> >
> >            infile = dataSource.getInputStream();
> >
> >            System.out.println("infile: " + infile.toString ());
> >            PrintWriter filetmp =  new PrintWriter(new
> > BufferedWriter(new FileWriter(fileSaveName)));
> >            String ligne;
> >            BufferedReader br = new BufferedReader(new
> > InputStreamReader(infile,"UTF-8"));
> >            while((ligne = br.readLine())!=null) filetmp.println(ligne);
> >            br.close();
> >            filetmp.close();
> >
> >        } catch (Exception e) {
> >            e.printStackTrace();
> >        }
> >
> >    }
> >
> >
> >    public static void deleteFile(String nameFile){
> >        File file = new File(nameFile);
> >        Boolean resultat = file.delete();
> >        System.out.println("The delete of file " + nameFile + " is " +
> > resultat);
> >    }
> >
> > }
> >
> >
> > Thanks for your help.
> > Regards,
> > Elodie
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>
> --
> "May the SourcE be with u"
> http://webservices.apache.org/~thilina/
> http://thilinag.blogspot.com/
> http://www.bloglines.com/blog/Thilina
>



-- 
"May the SourcE be with u"
http://webservices.apache.org/~thilina/
http://thilinag.blogspot.com/
http://www.bloglines.com/blog/Thilina

Re: [Axis2]Save attachment MTOM

Posted by Thilina Gunarathne <cs...@gmail.com>.
Hi,

On 7/6/06, Mancinelli Elodie <el...@bull.net> wrote:
>
> Hi all,
>
> I think it's when I want to get the attachment I should have an
> OMElement but I have a OMText. But I don't understand why?


Nope... U get an OMText... Binary is represented using an OMText eventhough
on the wire it is an element.
Have a look at http://ws.apache.org/axis2/1_0/mtom-guide.html#21

Looks like you are doing way too much work to access the attachments. U can
get the DataHandler directly from the created OMText...
Have a look at the MTOMSample..

~Thilina

Can someone have an idea?
>
> I send a message saop and my server code.
>
> - soap message:
>
> POST /axis2/services/PrestoSvc HTTP/1.1
> User-Agent: Axis2
> SOAPAction:
> http://localhost:8080/axis2/services/PrestoSvc/__OPERATION_OUT_IN__
> Cookie: JSESSIONID=BE98CB5DB8ABB0A61EE034F184334CCF
> Cookie2: JSESSIONID=BE98CB5DB8ABB0A61EE034F184334CCF
> Host: 127.0.0.1:8070
> Transfer-Encoding: chunked
> Content-Type: multipart/related;
> boundary=MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607;
> type="application/xop+xml";
> start="<0....@apache.org>";
> start-info="text/xml";
>
> charset=UTF-8a96--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607content-type:application/xop+xml;
> charset=UTF-8; type="text/xml";content-transfer-encoding:binarycontent-id:
>   <0....@apache.org>
>      <?xml version='1.0' encoding='UTF-8'?>
>         <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:wsa="http://www.w3.org/2005/08/addressing">
>            <soapenv:Header>
>
> <wsa:To>http://localhost:8080/axis2/services/PrestoSvc</wsa:To>
>               <wsa:ReplyTo>
>
> <wsa:Address>
> http://129.183.149.72:6060/axis2/services/__ANONYMOUS_SERVICE__/__OPERATION_OUT_IN__
> </wsa:Address>
>               </wsa:ReplyTo>
>
> <wsa:MessageID>urn:uuid:81AD7AC184DDB331FB11521686151086</wsa:MessageID>
>
> <wsa:Action>
> http://localhost:8080/axis2/services/PrestoSvc/__OPERATION_OUT_IN__
> </wsa:Action>
>               <wsrm:Sequence
> xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"
> soapenv:mustUnderstand="1">
>
>
> <wsrm:Identifier>urn:uuid:162BCF2DBF2BF6B4C1115216861701538</wsrm:Identifier>
>                  <wsrm:MessageNumber>2</wsrm:MessageNumber>
>               </wsrm:Sequence>
>            </soapenv:Header>
>            <soapenv:Body>
>               <m:submit
> xmlns:m="http://dgme.finances.gouv.fr/presto">&lt;pro:testDocIn
> xmlns:pro="http://dgme.finances.gouv.fr/prototype">
> &lt;pro:intStrElement>
> &lt;pro:intElement>12&lt;/pro:intElement>        &lt;pro:strElement>test
> de string&lt;/pro:strElement>
>
> &lt;/pro:intStrElement>&lt;pro:binaryElement>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAPAA0DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDp/FPjS1fWtUNtd6rcXGiahYQR2elLO6vmaMzb2jxGzOGaERyE4aI4wXIroJte10WdtfDVbEQ3W4pFa+HL29MJU4aN2jkBDKcqdyISVPyqQQNTW/DMLadctoWnabBqE97a3krFRALhorhJj5johJJ2tyQeW+tcXffEfwcl5IbnxRfeG9Z4TU7SztvOAnQBWVi8DozIQU3pjcFXJIVcAH//2Q==&lt;/pro:binaryElement>
> &lt;pro:anyElement>        &lt;test123>1 2 3 4 5 6&lt;/test123>
> &lt;/pro:anyElement>&lt;/pro:testDocIn>
>                  <m:attachment>
>                     <xop:Include
> href="cid:urn:uuid:4CDFC85751839D5E2111521686150992@apache.org"
> xmlns:xop="http://www.w3.org/2004/08/xop/include" />
>                  </m:attachment>
>               </m:submit>
>            </soapenv:Body>
>
>
> </soapenv:Envelope>12b--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607content-id:
>
> <urn:uuid:4CDFC85751839D5E2111521686150992@apache.org
> >content-type:text/plaincontent-transfer-encoding:binaryTable
> ASCII standard (codes de caractères de 0 à
> 127)--MIMEBoundaryurn_uuid_4CDFC85751839D5E2111521686191607--0
>
> - server code:
>
> public class PrestoSvcSkeleton {
>
>    static String
> fileXMLName="/home/mancinee/workspace/testPresto/test_data_out.xml";
>    static String
> nameNewFile="/home/mancinee/workspace/testPresto/soapmessout.xml";
>    static String
> fileSaveName="/home/mancinee/workspace/testPresto/fileresult.txt";
>    private MessageContext msgcts;
>
>     public void setOperationContext(OperationContext oc) throws AxisFault
> {
>            msgcts =
> oc.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
>        }
>
>    public void submitOneWay(
>        fr.gouv.finances.dgme.presto.SubmitOneWayDocument param2) throws
> IOException, InterruptedException {
>        System.out.println("submit One Way METHOD CALL");
> //      Recuperation et sauvegarde de l attachement
>
>        readSoapMessage(param2);
>        Thread.sleep(20000);
>    }
>
>
> //  Version fichier texte
>    public static File createSoapBodyMessage (String nameFile){
>        PrintWriter newFile = null;
>        try
>        {
>            //Ajout de l'entete
>            newFile =  new PrintWriter(new BufferedWriter(new
> FileWriter(nameNewFile)));
>            newFile.println("<m:submitResponse
> xmlns:m='http://dgme.finances.gouv.fr/presto'>");
>            //Ajout du contenu du body
>            BufferedReader br = new BufferedReader(
>                    new InputStreamReader(
>                          new FileInputStream(nameFile),"UTF-8"));
>              String ligne;
>              while((ligne = br.readLine())!=null){
>                  newFile.println(ligne);
>              }
> //            Ajout de la fermeture des balises
>              newFile.println("</m:submitResponse>");
>              newFile.close();
>        }
>        catch (FileNotFoundException e)
>        {
>            System.out.println("Le fichier test_data_out.xml n'a pas été
> trouvé");
>            e.printStackTrace();
>        } catch (IOException e) {
>            System.out.println("Erreur de lecture-ecriture dans un
> fichier");
>            e.printStackTrace();
>        }
>        File xmlFile = new File(nameNewFile);
>        return xmlFile;
>    }
>
>
>    public void
> readSoapMessage(fr.gouv.finances.dgme.presto.SubmitOneWayDocument param2){
>        OMFactory fac = OMAbstractFactory.getOMFactory();
>        StAXOMBuilder builder = new StAXOMBuilder(fac,new
> StreamWrapper(param2.newXMLStreamReader())) ;
>        OMElement payload = builder.getDocumentElement();
>        ((OMNodeEx)payload).setParent(null);
>        saveFile(payload);
>
>    }
>
>    public void saveFile(OMElement payload){
>
>        try {
>            OMElement attach = null;
>            OMElement seq = null;
>            for (Iterator it = payload.getChildElements();it.hasNext();) {
>                OMElement el = (OMElement) it.next();
>                if (el.getLocalName().equalsIgnoreCase("attachment")) {
>                    attach = el;
>                    System.out.println("attachment");
>                }
>                else return;
>                if (el.getLocalName().equalsIgnoreCase("Sequence")) {
>                    seq = el;
>                    System.out.println("sequence:" + seq.getText());
>                }
>            }
>
>
>            System.out.println("Save attachment");
>            OMElement child = (OMElement) attach.getFirstOMChild();
> //The problem is here
>            OMAttribute attr = child.getAttribute(new QName("href"));
>            String contentID = attr.getAttributeValue();
>            Attachments attachment = (Attachments)
> msgcts.getProperty(MTOMConstants.ATTACHMENTS);
>            contentID = contentID.trim();
>
>            if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
>                contentID = contentID.substring(4);
>
>            }
>            DataHandler dataHandler = attachment.getDataHandler(contentID);
>            System.out.println("contentID: " + contentID);
>            DataSource dataSource=dataHandler.getDataSource();
>            System.out.println("dataSource: " + dataSource.toString());
>            InputStream infile;
>
>            infile = dataSource.getInputStream();
>
>            System.out.println("infile: " + infile.toString());
>            PrintWriter filetmp =  new PrintWriter(new
> BufferedWriter(new FileWriter(fileSaveName)));
>            String ligne;
>            BufferedReader br = new BufferedReader(new
> InputStreamReader(infile,"UTF-8"));
>            while((ligne = br.readLine())!=null) filetmp.println(ligne);
>            br.close();
>            filetmp.close();
>
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
>
>    }
>
>
>    public static void deleteFile(String nameFile){
>        File file = new File(nameFile);
>        Boolean resultat = file.delete();
>        System.out.println("The delete of file " + nameFile + " is " +
> resultat);
>    }
>
> }
>
>
> Thanks for your help.
> Regards,
> Elodie
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
"May the SourcE be with u"
http://webservices.apache.org/~thilina/
http://thilinag.blogspot.com/
http://www.bloglines.com/blog/Thilina