• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

SAAJ (SOAP 1.1) incompatibility with Java 1.6

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Building a simple SOAP client using SAAJ which has both a SOAPBody and one attachment using Java 1.6.

Was successful in running the SAAJ tutorial in j2eetutorial14\examples\saaj\attachments\src\Attachments.java.

But after adding some elements to the SOAPBody and adding some code to display MimeHeaders, I find the "content-length" hasn't increased. The Content-Length continues to show 271 --> The "attachment" addr.txt which shipped with the sample has not increased the content-lenght??

I am using Windows with C:\jdk1.6.0_13 and jre.





Here is the output (with Java 1.6):
*********New Body
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body>
<CarTypes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Audi><type>TT</type><version>V6</version></Audi></CarTypes>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
*********End New Body

**********Before attachments ***********
Accept ---> text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type ---> text/xml; charset=utf-8
Content-Length ---> 271
SOAPAction ---> ""

**********After string attachments - MIMES ***********
Accept ---> text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type ---> text/xml; charset=utf-8
Content-Length ---> 271
SOAPAction ---> ""


 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mind formatting your code with the code tags?
 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
edited the first message with code tags..
 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Executing the same code earlier with Java JDK 1.5 with additional libraries - saaj-api.jar, saaj-impl.jar (from SAAJ 1.1), activation.jar, mail.jar, xercesImpl.jar gave the following output after the "text" attachment: Note the increase in "Content-Length".

I believe Java 1.6 comes packaged with all the above libraries - but that makes the saaj version 1.3 (not sure). Thanks for your time.

Output:


**********After string attachments - MIMES ***********
Content-Type ---> multipart/related; type="text/xml";
boundary="----=_Part_0_15959960.1243221255000"
Content-Length ---> 563
SOAPAction ---> ""

 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't seem anything wrong with your code. But the attachment isn't added to your message since the content type didn't change to multipart. Can you print out the message.getClass() for both case (version 5 and 6) to see what implementation that it is using?
 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
message.getClass() gives --> class com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl in both Java 5 and Java 6 versions.

The content type has changed to "multipart/related" in Java 6 also. I think my earlier output was while trying to download and setting saaj-1.3 files etc explicitly.

By setting nothing but the default Java 6 libraries, the output is:

Java 6 Output (After attachment):

**********After string attachments - MIMES ***********
Accept ---> text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type ---> multipart/related; type="text/xml"; boundary="----=_Part_0_9605638.1243233492577"
Content-Length ---> 271
SOAPAction ---> ""


Java 5 Output (After attachment):

**********After string attachments - MIMES ***********
Content-Type ---> multipart/related; type="text/xml";
boundary="----=_Part_0_15959960.1243233334898"
Content-Length ---> 563
SOAPAction ---> ""

 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could someone execute the above code in the first post (on Java 1.6 with the default libraries on Windows) and send their output. I'd like to check what the "Content-type" and "Content-length" is after the attachment is added.

Thanks in advance...
 
Ranch Hand
Posts: 69
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am in Linux and in Java 6 the output is (if this helps)

*********New Body
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><CarTypes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Audi><type>TT</type><version>V6</version></Audi></CarTypes></SOAP-ENV:Body></SOAP-ENV:Envelope>
*********End New Body

**********Before attachments ***********
Accept ---> text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type ---> text/xml; charset=utf-8
Content-Length ---> 271
SOAPAction ---> ""
java.io.FileNotFoundException: addr.txt (No such file or directory)


Than I gave it another file in my local machine to see if the content length changed. It did not however the content type is multipart.
*********New Body
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><CarTypes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Audi><type>TT</type><version>V6</version></Audi></CarTypes></SOAP-ENV:Body></SOAP-ENV:Envelope>
*********End New Body

**********Before attachments ***********
Accept ---> text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type ---> text/xml; charset=utf-8
Content-Length ---> 271
SOAPAction ---> ""

**********After string attachments - MIMES ***********
Accept ---> text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Content-Type ---> multipart/related; type="text/xml"; boundary="----=_Part_0_3736006.1243243989305"
Content-Length ---> 271
SOAPAction ---> ""
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom,

It seems the newer implementation isn't correct. I've checked the implementation source code, it seems they've only calculated the Content-Length when attachment size is zero hence the problem. However, it does seem the attachment has been added correctly. I've saved the message to a text file. It works OK. If you post the message to a web service, it should work OK, try it first.

Hope it help,

Duc
 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for trying this out on Linux too.
So there is a bug in the "Content-Length" not increasing in Java 6 both Windows and Linux. I uninstalled my JDK version and re-installed it, but still couldn't get the Mimeheader to display the right content size.

If the Attachment is indeed there, could you please verify if it will be send out the door too? In trying the very same code in a real-world application (with different body part and attachment), the application fails when trying to do the SOAPConnection.call.

(the output below is from my real world application and not the code above):

Do I have a workaround to this? I already tried downloading SAAJ 1.2, SAAJ 1.3 and referring to them explicitly, also the newest activation.jar and mail.jar but can't figure out a way to send any SOAPMessage with a "body" and an "Attachment" in Java 6.


EXCEPTION:

May 25, 2009 9:19:27 AM com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection post
SEVERE: SAAJ0009: Message send failed
com.sun.xml.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException:
com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:186)

Caused by: java.security.PrivilegedActionException: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:180)
... 2 more
Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:384)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConnection.java:209)
... 4 more
Caused by: java.lang.NullPointerException
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:86)
at sun.net.www.http.PosterOutputStream.write(PosterOutputStream.java:61)
at com.sun.xml.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1251)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:342)
... 5 more

CAUSE:


Caused by: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Message send failed
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:384)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection$PriviledgedPost.run(HttpSOAPConnection.java:209)
... 4 more
Caused by: java.lang.NullPointerException
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:86)
at sun.net.www.http.PosterOutputStream.write(PosterOutputStream.java:61)
at com.sun.xml.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1251)
at com.sun.xml.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:342)
... 5 more
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've seen that before. Just remove the line similar to below, doesn't seem you need to save change either.

It should work.
 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Duc - I tried removing the saveChanges(), but that didn't work. Any further suggestions? Appreciate your help.

I haven't been able to get a solution after quite a bit of research on the internet.

Is it possible that nobody uses attachments with SAAJ 1.3 (Java 6)?
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom, what did you change? You should've only removed the saveChanges() method after adding attachment. The exception came from message.writeTo(OutStream) method. Try to write to System.out to see if it works.

If it works, then the problem is somewhere else. You may want to post the message without any attachment to test as well.

Anyway, what's the new error now?
 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the analyis.

I removed the saveChanges() and the msg.writeTo() all across the code, exception changed to :

SEVERE: SAAJ0537: Invalid Content-Type. Could be an error message instead of a SOAP message
com.sun.xml.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionExce
ption: com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?

After some research, it seems the mime header SOAPAction was mandatory to fix this, hence added:

MimeHeaders headers = msg.getMimeHeaders();
headers.addHeader("SOAPAction", "\"\"");

The code now works fine. Can you explain what saveChanges() did to the message? The javadoc isn't very clear.
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tom,

Glad to hear it works.

The javadoc says

This method is called automatically when writeTo(OutputStream) is called.

So you shouldn't call saveChanges() if writeTo(OutputStream) is about to execute. I think the implementation somehow clear off some variables once saveChanges() is triggered hence the NullPointerException. Google the source code if you want to investigate more.

Cheers,

 
Lalit Bhatt
Ranch Hand
Posts: 69
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tom,

glad to hear it works.

Just for understanding I have a question.
-Is your server SOAP 1.1 or SOAP 1.2 compliant? I think Soap action header is mandatory for SOAP 1.1 only.
 
Tom Davis Sr
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. It is SOAP 1.1. The content-length field not increasing probably needs some fixing too - Fortunately that is not a problem for me but there may be services that may rely on the content-length for processing.
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic