• 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

Parsing content body from a GET request

 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We're working with a third party application that was sending us small XML files via HTTP post requests, which we were handling in a doPost() method of our servlet. They have decided to change it to a GET request. They claim that the XML won't be a parameter, it will still be in the body of the request, just as if it were a POST. I say they're insane. A GET request doesn't have a content body. Who's right?

Second question, if I do try to read the content body in the doGet() method, is it going to work?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are saying is a bit confusing as I'm not quite clear on who's initiating the request.

If you are making the GET request to them, the response body can contain the XML. Whether your request is a POST or a GET is immaterial and only affects the format of the request, not the response.

On the other hand, if they are sending you the XML by initiating a request, then yes, a GET request has no body.
[ June 20, 2007: Message edited by: Bear Bibeault ]
 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, they are sending the HTTP request. It used to be a POST request, so sending an XML file made sense. They have now changed it to a GET request, and swear the XML is stored in the content body of the request. Weird, huh?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A packet sniffer will show you exactly what's being sent and what isn't.

I like tcpflow on Linux myself but Ethereal has a good reputation among Windows users.
 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, I put a sniffer on, and damned if that's not what they're doing.



They swear they're building this with a commercial HTTP class library, as opposed to say writing to the socket. I guess I'll just see if I can parse it with the servlet libraries. It's not legal HTTP though, right? The RFC is somewhat vague on this point. I'd like to send them something authoritative to prove they're violating the protocol.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the body of the GET request will simply be ignored.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that the request body is read until a method such as getParameter is called. So you should be able to read the body. I'd be surprised if there was any code to prevent it.

But it is a whacky thing to do, so who knows.

What's their reasoning behind subverting the HTTP protocol to use GET?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
So you should be able to read the body. I'd be surprised if there was any code to prevent it.



The reason I wrote that the body might be ignored is , the body chunk is separated out according to the content-length header value.

So when the request is HTTP GET the container might not even bother to check for content length header and simple ignore the body of the request.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The initiation for request is just begining when the method "getParamet" was executed.So in J2EE system,if you want to handle the request_stream by yourself the only thing that you can do is those that developing a filter for handling when your request is send by post method.You need not to handle when it is get method
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the context type is text/xml then you wouldn't use getParameter anyway.
You would need to use getInputStream or getReader.

I won't even guess whether or not a GET request type will cause you problems.
The best you can hope for when relying on non-spec compliant behavior is unpredictability. It may work on one server and not work another (or a differernt release of the same server).
You'll have to test on each container that you plan to support..

Bear's question is still the most valid.
Why would they do that?
[ June 21, 2007: Message edited by: Ben Souther ]
 
Greg Charles
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, so far it's working on Weblogic 8.1, which is our current platform. I can simply call doPost() from doGet() and read the content body as I would from a POST. Essentially they are sending me a POST request, just with the word POST misspelled as GET.

Why are they doing that? They told me it was so they could make the request synchronous, and be able to handle error conditions ... which makes no sense, right? They say that's a function of their class libraries. The GET request is implemented as a call/response while the POST request is set up as an asynchronous broadcast, and event handlers have to be defined to handle the response. I'm skeptical, but what can I do? At least I can get it to work for now.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So their response to an inadequacy in their library is to subvert the HTTP protocol? I hope your business isn't relying upon them to survive.
 
wang godman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you must use ajax thing for synchronization things ,if you do ,you can set it when you use ajax to send a ajax request.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ajax has no relevance to this issue.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by wang godman:
I think you must use ajax thing for synchronization things ,if you do ,you can set it when you use ajax to send a ajax request.



AJAX will ultimately make HTTP get or POST requests.
 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic