You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Na...@emc.com on 2008/03/18 02:21:37 UTC

Send/Receive serialized object using Apache's httpclient package

Hi,

Is it possible send/receive serialized object using HttpClient? I always
get java.io.StreamCorruptedException: invalid stream header  Exception.

Here is my server side (servlet code)

    public void doPost (
        HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException
    {
        response.setContentType("application/x-www-form-urlencoded");
        ObjectOutputStream oos = new
ObjectOutputStream(response.getOutputStream());
        ArrayList l = new ArrayList();
        l.add("Index Server is running");
        oos.writeObject(l);
    }

Client side code that access this servlet

    public OutputStream sendRequest (String method, HashMap args)
        throws IOException, IndexServerCommunicationException
    {
        PostMethod post = new PostMethod(m_url);
        try
        {
		post.setRequestEntity(new
StringRequestEntity("something"));
            m_client.executeMethod(post);
            ObjectInputStream ois = new
ObjectInputStream(post.getResponseBodyAsStream());
		return ois;
        }
        finally
        {
            post.releaseConnection();
        }
    }

Any help is appreciated.

Thanks
-Valli

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org