Create a HttpURLConnection wrapping default impl


Performance and scalability: Create a HttpURLConnection wrapping default impl

  1. Create a HttpURLConnection wrapping default impl (1 messages)

    I have coded my own HTTP Server.
    I want to make access the HTTP Server using HttpURLConnection class faster. I think I can provide a customized URLStreamHandler which created a customized HttpURLConnection object wrapping an object of the jdk default implementation. This HttpURLConnection checks whether the target server is within a same jvm (My HTTP Server provide a inquery API). If no, it will create a Socket object, and if yes, it will create a inmemory pipe instead of a socket for use. After that, all methods invocation are delegate to the wrapped default implementation. (That is to say, I still want to reuse default HttpURLConnection implementation instead of creating everything)

    Can I make all of this totally transparent to typical client code written as below ?

    URL url =new URL("http://someserver/file ");
    URLConnection urlconn =url.openConnection();
    urlconn.setRequestHeader("METHOD ","POST ");
             application/x-www-form-urlencoded ");
    OutputStream os =urlconn.getOutputStream();
    InputStream response =urlconn.getInputStream();
  2. Not sure why u would want to code your own HTTP Server. :)...Apache is free.

    If this is for production shoudl use the HTTPClient pacakage its free also..