Solved

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

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 121
Way to decrease size of apk file 9 87
Fulfillment API php code sample 1 58
SequenceInputStream example 3 19
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

828 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