Solved

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

Posted on 2008-10-20
1
1,533 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 111
how to debug htl and js pages 8 80
Passing client data from form to server 5 56
Overriding a method 3 13
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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

751 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