dimanche 18 mai 2014

Java - type de contenu de la demande de plusieurs partie dans les services web soap - Stack Overflow


I am writing a Java client to call a SOAP web service.It accepts a file as an attachment so in java, I need to declare the content type as multipart.I am using apache http library to write Java client.


I specified it i Java as below



httppost.setHeader( "Content-Type", "multipart/related" );



but I got the below error


Couldn't create SOAP message due to exception: javax.xml.ws.WebServiceException: MIME boundary parameter not foundmultipart/related

Please let me know how to resolve this error. What should be the content type to be specified in Java.


When I specified it as


httppost.setHeader( "Content-Type", "text/xml; charset=utf-8" ); 

Again, i got the below exception


 Caused by: com.sun.xml.ws.streaming.XMLStreamReaderException: XML reader error: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '-' (code 45) in prolog; expected '<'

Which one should i go ahead with and how to resolve the respective exception?




I assume you are trying to use MTOM+XOP?


The first error is clear: you have no boundary. A multipart is more than simply a content-type, it requires you to mark the different parts with a boundary that has to be declared in the headers and requires linefeeds etc to be in the correct place.


Secondly, you can't just send a file to a SOAP endpoint if that is what you are trying to do, you need to have a soap body in the first part that references the file in the second part.



I am writing a Java client to call a SOAP web service.It accepts a file as an attachment so in java, I need to declare the content type as multipart.I am using apache http library to write Java client.


I specified it i Java as below



httppost.setHeader( "Content-Type", "multipart/related" );



but I got the below error


Couldn't create SOAP message due to exception: javax.xml.ws.WebServiceException: MIME boundary parameter not foundmultipart/related

Please let me know how to resolve this error. What should be the content type to be specified in Java.


When I specified it as


httppost.setHeader( "Content-Type", "text/xml; charset=utf-8" ); 

Again, i got the below exception


 Caused by: com.sun.xml.ws.streaming.XMLStreamReaderException: XML reader error: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '-' (code 45) in prolog; expected '<'

Which one should i go ahead with and how to resolve the respective exception?



I assume you are trying to use MTOM+XOP?


The first error is clear: you have no boundary. A multipart is more than simply a content-type, it requires you to mark the different parts with a boundary that has to be declared in the headers and requires linefeeds etc to be in the correct place.


Secondly, you can't just send a file to a SOAP endpoint if that is what you are trying to do, you need to have a soap body in the first part that references the file in the second part.


0 commentaires:

Enregistrer un commentaire