• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with SOAP attachments using JAXM

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to pass different files using a SOAP with attachments (JAXM). It works fine for an xml file as the attchment (for example) but any other type of file is causing the following error:
"java.net.SocketException: Unexpected end of file from server"
The code I am using to pass create the attachment is:
File outputFile = new File("C:/myfile.bmp");
//Build the call:-
//Get a connection
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection connSOAP = scf.createConnection();
//Create a message
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();
//Access the elements of the message
SOAPPart part = msg.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
//Add a new SOAP element
Name name = envelope.createName("loadFile");
SOAPElement child = body.addBodyElement(name);
//Add content
name = envelope.createName("filename");
SOAPElement filename = child.addChildElement(name);
filename.addTextNode(outputFile.getAbsolutePath());
//Add attachment
URL fileurl = outputFile.toURL();
DataHandler dh = new DataHandler(fileurl);

AttachmentPart attachment = msg.createAttachmentPart(dh);
attachment.setContentId("test_file");

msg.addAttachmentPart(attachment);

Any ideas as to where I'm going wrong? Or is this a known bug?
Any help, very much appreciated.
Cheers
Ste
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds suspiciously like it's not base-64 encoding the file. Could you show what's flowing over the wire to us (perhaps using Bill Brogden's handy snoop tool for SOAP)...
Kyle
 
Ste Lamb
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kyle
not exactly certain of what you mean, but below is the actual dump stack I get. If it isn't encoding it like you say, how do I go about encoding it? Alternatively how about I write the file to a byte array and attach that? Would that work.. although how to write a whole file to an an array I'm not sure...
Any advice appreciated...
Thanks Kyle

java.net.SocketException: Unexpected end of file from server
boolean sun.net.www.http.HttpClient.parseHTTPHeader(sun.net.www.MessageHeader, sun.net.ProgressEntry)
HttpClient.java:708
boolean sun.net.www.http.HttpClient.parseHTTP(sun.net.www.MessageHeader, sun.net.ProgressEntry)
HttpClient.java:613
boolean sun.net.www.http.HttpClient.parseHTTPHeader(sun.net.www.MessageHeader, sun.net.ProgressEntry)
HttpClient.java:706
boolean sun.net.www.http.HttpClient.parseHTTP(sun.net.www.MessageHeader, sun.net.ProgressEntry)
HttpClient.java:613
java.io.InputStream sun.net.www.protocol.http.HttpURLConnection.getInputStream()
HttpURLConnection.java:506
int java.net.HttpURLConnection.getResponseCode()
HttpURLConnection.java:230
javax.xml.soap.SOAPMessage com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(javax.xml.soap.SOAPMessage, java.net.URL)
HttpSOAPConnection.java:274
java.lang.Object com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run()
HttpSOAPConnection.java:142
java.lang.Object java.security.AccessController.doPrivileged(java.security.PrivilegedExceptionAction)
native code
javax.xml.soap.SOAPMessage com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(javax.xml.soap.SOAPMessage, java.lang.Object)
HttpSOAPConnection.java:115
boolean uk.gov.pro.arc.ClientInterfaces.LoadProcess.loadFiles()
LoadProcess.java:509
void uk.gov.pro.arc.ClientInterfaces.TestclientInterfaces.main(java.lang.String[])
TestclientInterfaces.java:81
java.security.PrivilegedActionException: javax.xml.soap.SOAPException: Message send failed
javax.xml.soap.SOAPMessage com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(javax.xml.soap.SOAPMessage, java.net.URL)
HttpSOAPConnection.java:289
java.lang.Object com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run()
HttpSOAPConnection.java:142
java.lang.Object java.security.AccessController.doPrivileged(java.security.PrivilegedExceptionAction)
native code
javax.xml.soap.SOAPMessage com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(javax.xml.soap.SOAPMessage, java.lang.Object)
HttpSOAPConnection.java:115
boolean uk.gov.pro.arc.ClientInterfaces.LoadProcess.loadFiles()
LoadProcess.java:509
void uk.gov.pro.arc.ClientInterfaces.TestclientInterfaces.main(java.lang.String[])
TestclientInterfaces.java:81
javax.xml.soap.SOAPException: java.security.PrivilegedActionException <<javax.xml.soap.SOAPException: Message send failed>>
javax.xml.soap.SOAPMessage com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(javax.xml.soap.SOAPMessage, java.lang.Object)
HttpSOAPConnection.java:121
boolean uk.gov.pro.arc.ClientInterfaces.LoadProcess.loadFiles()
LoadProcess.java:509
void uk.gov.pro.arc.ClientInterfaces.TestclientInterfaces.main(java.lang.String[])
TestclientInterfaces.java:81
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to me that if you are getting this:

Then the client isn't even getting through the headers before something odd happens.
I ran into the difficulty of figuring this kind of problem out when doing my SOAP book. I wrote a utility that lets you trap both sides of the client-server text stream and even alter and resend messages. With that you can see exactly what the server is sending back.
You can download it from a link at the bottom of this page.
Bill
 
Ste Lamb
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Kyle/William
I tried a different method using HTTP Post to get the file across and was coming up with a similar problem. This time I converted the file to a byte array before sending it. Unfotunately the same error was happening.
I resolved this problem by taking on board what you suggested Kyle which was to encode the byte array to base64 before sending it. And it worked!
I suspect but haven't tried yet that this is the same problem that is happening with the JAXM SOAP connection. When I've tried it I'll let you know.
Its strange that this isn't documented anywhere. I would have thought it encodes it automatically for you?
I guess though that most of this sort of thing is done direct from a JSP which encodes it automatically???
Thanks for your help...
reply
    Bookmark Topic Watch Topic
  • New Topic