hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Kam" <moonblade.w...@gmail.com>
Subject URL to HttpUtil problem in http tunelling
Date Fri, 03 Aug 2007 07:47:32 GMT
Dear developers,

I've been trying to convert the following codes using the standard
java.net.URL to the HttpClient solution. It's just a simple http tunelling
solution, sending and receiving java objects using http protocol. Here's the
source code using the java.net.URL :

    public static void main(String[] args) throws IOException,
ClassNotFoundException {
        URL url = new URL("
http://hostname:8080/util/servlet/servlet.GetObjectServlet");
        URLConnection connection = url.openConnection();
        connection.setDoOutput(true);
        OutputStream outputStream = connection.getOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(new
BufferedOutputStream(outputStream));

          // creating an object to be sent to the servlet
        Map testMap = new HashMap();
        testMap.put("1", "one");
        testMap.put("2", "two");

        out.writeObject(testMap);
        out.flush();

          // read the object from the servlet
        InputStream inputStream = connection.getInputStream();
        ObjectInputStream in = new ObjectInputStream(new
BufferedInputStream(inputStream));
        Map map = (Map) in.readObject();
        System.out.println(map);
    }

I've been searching for solution, using the Apache HttpClient library,
because i need HttpClient's timeout feature. But so far, i'm stuck with how
to send a java object to another servlet. I have yet to find out how to get
the java object from the servlet using HttpUtil. I hope it's just as simple
as :

InputStream in = method.getResponseBodyAsStream();
BufferedInputStream bin = new BufferedInputStream(in);
ObjectInputStream objIn = new ObjectInputStream(bin);
GZIPInputStream gzipIn = new GZIPInputStream(objIn);
Object object = objIn.readObject();

Could please help me ? I dont know how to send a java object to a remote
servlet. I know it has something to do with the
PostMethod.setRequestEntity.. And i've seen the implementations of
RequestEntity like
InputStreamRequestEntity, FileRequestEntity, StringRequestEntity, but
there's no ObjectRequestEntity or something.

Any pointers ? Thank you.

Regards,
Albert Kam

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message