• 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

Incomplete Request At Server

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
I have a problem while sending large requests(in XML format) to a servlet over a secure http connection. I am using HttpsURLConnection to send the request.
At the server end, when i try to get the content length using getContentLength(), it shows correct value. But the InputStream object's available() method returns a smaller value and so does the read method when trying to read the data. I have tried using readFully to read getContentLength() amount of data, but with the same result.
Servlet works fine with smaller requests.
The client side code for sending the request is as follows:
HttpsURLConnection objConnection = ...
OutputStream out = objConnection.getOutputStream();
byte buffer[]=strRequestXML.getBytes();
out.write(buffer);
out.flush();
out.close();
Are there any properties to be set at either client or server end?
ANY HELP IS VERY MUCH APPRECIATED.
Regards,
Roshan
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Poruporuthan"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Roshan,
Good 2 meet you here
I dunno the exact nature of your problem. Hope you must've solved it now. If yes please post what went wrong.
First of all at the client side, make sure that the xml string you r writing to outputStream is of the proper size. print the byte[] size and verify.
Next, If you are getting proper size @ the server side, but available() is returning lesser value, applying a small time delay could help before reading the string at the server side.
If you could show the server side snippet for reading the data, then could apply some thoughts.
 
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
The available method only shows whats currently in the input buffer, given the way that TCP/IP sends chunks of data, this will only be the entire message for very small messages.
The simplest thing to do is read and parse the data as a stream until the end is hit.
If you absolutely have to have all the text in memory in a single chunk, you must repeatedly read characters as they come in and assemble the chunk yourself.
 
reply
    Bookmark Topic Watch Topic
  • New Topic