Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

making use of jax-ws and wsimport to have an attachment webservice method

Posted on 2008-10-20
1
Medium Priority
?
1,576 Views
Last Modified: 2013-11-23
Hi everyone. I want to have a webservice client that reads in a file (could be everything) and sends it to my webservice over SOAP with Attachments. I am able to create the sources and everything for the client directly from the wsdl. The message when sending is created as follows:

POST /ftpSoap/ HTTP/1.1
SOAPAction: "[removedNS]/putFile"
Content-Type: multipart/related; boundary="uuid:5828c7f2-7512-4fd9-b435-bca57a6205f7"
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
User-Agent: JAX-WS RI 2.1.4-b01-
Host: [removedHostname]:12345
Connection: keep-alive
Content-Length: 658920

--uuid:5828c7f2-7512-4fd9-b435-bca57a6205f7
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><PutRequest xmlns="[removedNS]/wsdl"><File folder="componentTest" name="Browser282b2.zip"/></PutRequest></S:Body></S:Envelope>
--uuid:5828c7f2-7512-4fd9-b435-bca57a6205f7
Content-Id:<data=f01fad99-4d00-40a5-88f2-80f9612ea06c@jaxws.sun.com>
Content-Type: application/binary
Content-Transfer-Encoding: binary

[binary data begins here]

To me this looks like it should. But back to the problem: When on the server side jax-ws tries to read the message (create the envelope object), I get the following error message:

java.io.IOException: Unexpected characters before XML declaration
 at com.sun.xml.messaging.saaj.util.XMLDeclarationParser.parse(XMLDeclarationParser.java:152)
at com.sun.xml.messaging.saaj.soap.SOAPPartImpl.lookForXmlDecl(SOAPPartImpl.java:670)

Can anybody tell me, why I get this error? Should I have to tell the SOAP Body, or SOAP message object somehow, that it is multipart? but there is no method to do so. I am a bit desperate, since you can not really debug this.

The Code on the Server looks like this:

SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(new
MimeHeaders(),request.getInputStream());
SOAPPart soapPart = message.getSOAPPart();
SOAPBody soapBody = soapPart.getEnvelope().getBody();

Do I have to set the MimeHeaders in a different way? Do I have to manually extract the SOAP part from the request? OR is it in the end just an encoding problem?

Any help is greatly appreciated.
Thanks Alex
0
Comment
Question by:heppa
1 Comment
 
LVL 4

Accepted Solution

by:
heppa earned 0 total points
ID: 22756576
I was able to find the problem myself!

this was the problem:

MessageFactory.newInstance().createMessage(new MimeHeaders(),request.getInputStream());

you need to set the headers from the HTTP Request.
I did so with:

MimeHeaders soapHeader = new MimeHeaders();
          
Enumeration<String> httpReqHeaders = request.getHeaderNames();
while(httpReqHeaders.hasMoreElements()) {
  String actHeader = httpReqHeaders.nextElement();
  soapHeader.addHeader(actHeader, request.getHeader(actHeader));
}

MessageFactory.newInstance().createMessage(soapHeader,request.getInputStream());
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question