• 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

HttpClient and MultipartEntity vs. Jersey Multipart

 
Ranch Hand
Posts: 68
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a rest webservice that takes a POST metod with multipart message:

Now I am trying to write a java client for that. I started with a simple jersey client:

This works great - everything is ok. However I need this client working on Android and I have trouble with using jersey on that platform. So I used the normal way to send multipart message on android:

An this gives an annoying response from the server :


I check the server log files but there is nothing there. So I don't know what's the origin of this error. I have wrote a simple html page with a post formula and 'multipart/form-data' content-type and it also works! An auto-generated request from soapUI also works! Why my client does not work? Can anybody help? (For the record - tried also without Base64encoding - no change).
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I don't know what causes the problem, but have you tried to write a servlet filter to examine the requests to your web service?
This way you can compare the requests from the Jersey client and the Android phone to see where the difference is and, hopefully, solve the problem.
Best wishes!
 
Adam Kronicki
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ivan Krizsan wrote:Hi!
I don't know what causes the problem, but have you tried to write a servlet filter to examine the requests to your web service?
This way you can compare the requests from the Jersey client and the Android phone to see where the difference is and, hopefully, solve the problem.
Best wishes!


Thank you for the response. I used tcpmon to look at what is sended:

The working Jersey version:

And the not working HttpClient approach:

However that does not tell me anything about how to modify the HttpClient code to make it work.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Does the Android framework use MIME-envelopes?
The Jersey request reminds me of something I have seen in connection to SOAP with attachments, which uses MIME envelopes to wrap the SOAP request and the attached data.
Apart from that, I must admit that I am not familiar with Android client programming.
Best wishes!
 
Adam Kronicki
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ivan Krizsan wrote:Hi!
Does the Android framework use MIME-envelopes?
The Jersey request reminds me of something I have seen in connection to SOAP with attachments, which uses MIME envelopes to wrap the SOAP request and the attached data.
Apart from that, I must admit that I am not familiar with Android client programming.
Best wishes!


The client which is not working and giving me this error message is also running on PC and still NOT working. It is just written in a way Android should accept. So fro now it is not even the case of android environment. If i can get this message through with HttpClient it should also work on Android. So the question is - can I use MIME envelope with HttpClient and MultipartEntity...
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Have you seen this web page: http://hc.apache.org/httpclient-3.x/methods/multipartpost.html
?
Best wishes!
 
Adam Kronicki
Ranch Hand
Posts: 68
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ivan Krizsan wrote:Hi!
Have you seen this web page: http://hc.apache.org/httpclient-3.x/methods/multipartpost.html
?
Best wishes!


Yes I also have tried this approach though the Multipart Post class is (I think) depreciated now. But thank you for the contribution Ivan, seems that no one else is willing to help.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was this ever resolved? Just starting down a very similar path and stumbled into this post. Did notice that the HTTP that works does declare the boundary marker, though not sure how significant that is.
 
Adam Kronicki
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

J Butenhoff wrote:Was this ever resolved? Just starting down a very similar path and stumbled into this post. Did notice that the HTTP that works does declare the boundary marker, though not sure how significant that is.



I ended up generating the multipart request 'manually' by submitting string sings to the connection stream. However later on I succeed with the jersey library on Android so I don't have this code any more. But I think you could find some similar solution for dealing with multipart messages with URLConnection class or just read the spec like I did.
reply
    Bookmark Topic Watch Topic
  • New Topic