commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Becke <be...@u.washington.edu>
Subject Re: [HttpClient] Can't even Post Data
Date Thu, 01 Jul 2004 03:00:11 GMT
Hi Andrew,

My guess is that you need to flush the ObjectOutputStream on the client 
side once you're done writing the String.

Mike

On Jun 30, 2004, at 10:40 PM, Andrew van der Voort wrote:

> 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" ) ); //
> projectId
> 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 )
> {
>     try
>     {
>         ServletInputStream s         = request.getInputStream();
>         ObjectInputStream  ois       = new ObjectInputStream( s );
>         String             projectId = (String) ois.readObject();
>         ois.close();
>         // 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?
>
> Andrew
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message