Solved

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

Posted on 2008-10-20
1
1,492 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now