commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew van der Voort" <>
Subject RE: [HttpClient] Can't even Post Data
Date Thu, 01 Jul 2004 02:40:49 GMT
Hi Mike.

I've downloaded version 3.0-alpha and gave it a go. Initial feedback is
that the javadocs are out of date. I had to regenerate them to get javadocs
for things like RequestEntity.

One of the transactions we need to process is to get calendar information
about a project. So I send up a request to get project calendar data and
pass it a projectId, which is a String. I thought this would be a good
start as there is already a StringRequestEntity class. My code follows:

HttpClient httpClient = new HttpClient();
httpClient.setState( this.clientState ); // I have previously logged on and
obtained a sessinid
PostMethod method = new PostMethod(completeURL);
// I set this content-type header in my existing app to tell everyone I am
sending a String up the wire.
Header contentType = new Header("Content-Type", "java-internal/" +
String.class.getName() ); 
method.setRequestHeader( contentType );
method.setRequestEntity( new StringRequestEntity( "1234567" ) ); //
int statusCode = httpClient.executeMethod( method );
As soon as I execute the method I get taken up to my (struts) servlet.
Everything works insofar as I get to the servlet method I expect where I do
the following:
private ActionForward processGetCalendarData( ActionMapping mapping,
ActionForm form,
    HttpServletRequest request, HttpServletResponse response )
        ServletInputStream s         = request.getInputStream();
        ObjectInputStream  ois       = new ObjectInputStream( s );
        String             projectId = (String) ois.readObject();
        // etc etc

As soon as I try to construct the ObjectInputStream I get a
StreamCorruptedException with a message of "invalid stream header". 
- When I look at StringRequestEntity::writeRequest I see that it is writing
the String out with an OutputStreamWriter. 
- My current, working, code gets an ObjectOutputStream from the open
HttpURLConnection, and calls writeObject on the String.

I think that is the problem. StringRequestEntity object is not being
serialised to the output stream, it is just being written. However I
created a new StringObjectRequestEntity class that just overrode
writeRequest to instantiate an ObjectOutputStream from the supplied
OutputStream and called writeObject on the content. 

This has got me past the instantiating of ObjectInputStream at the other
end but there's no data (get an EOFException on readObject()). I've tried
removing the content-type header but it made no difference and in any case
at some stage you have to be able to tell the code at the other end what
the object is.

Am I missing something?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message