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 12:14:57 GMT
No worries.  What are you using as the content length? I would suggest 
using chunked content length unless you buffer the content to byte[] 
first.  Just to note, this is what java.net does.  When you write to 
the java.net output stream is just buffers all content to memory so 
that it can get the content length before sending the request.

Mike

On Jun 30, 2004, at 11:15 PM, Andrew van der Voort wrote:

> Already doing that, sorry, Mike. The overridden method in my
> StringObjectRequestEntity (extends StringRequestEntity) is:
> public void writeRequest(OutputStream out) throws IOException
> {
>     ObjectOutputStream oos = new ObjectOutputStream( out );
>
>     oos.writeObject( this.getContent() );
>     oos.flush();
> }
> I subsequently tried oos.close(), then both together with flush() first
> then close() first. Same result every time except when I try them both
> together I'm getting SocketExceptions on the client.
>
>> -----Original Message-----
>> From: Michael Becke [mailto:becke@u.washington.edu]
>> Sent: Thursday, 1 July 2004 3:00 p.m.
>> To: Jakarta Commons Users List
>> Subject: Re: [HttpClient] Can't even Post Data
>>
>>
>> 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
>>
>>
>
> ---------------------------------------------------------------------
> 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