Solved

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

Posted on 2008-10-20
1
1,514 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 99
Facing this issue for maven proxy setting 2 12
Glassfish admin console not working 1 15
Is there a simpler dropbox system? 10 22
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

810 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