Class Proxy

java.lang.Object
net.targetr.wtm3.net.http.proxy.Proxy
Direct Known Subclasses:
CachingProxy

public class Proxy extends Object
Opens a connection to another web server and streams response to client.
Author:
Dr Michael Gardiner
  • Constructor Details

    • Proxy

      public Proxy(HttpRequest httpReq, String target)
      Creates a new Proxy for relaying a request to the target web server.
      Parameters:
      httpReq - Request from the client to be proxied.
      target - The address of the target web server. Must include protocol and host.
  • Method Details

    • getResponse

      public HttpResponse getResponse() throws Exception
      Makes the connection, sends request and returns a ProxyResponse object suitable for returning the proxied response to the client.
      Returns:
      Response for proxying data from the target address. Or ErrorResponse.
      Throws:
      Exception - An exception occured while connecting to the target or sending request.
    • makeResponse

      protected ProxyResponse makeResponse() throws Exception
      Creates a ProxyResponse to stream the response back.
      Returns:
      A new ProxyResponse instance.
      Throws:
      Exception - If an error occurs creating the response.
    • getRequest

      public HttpRequest getRequest()
      Gets the original HTTP request.
      Returns:
      The HTTP request.
    • getTarget

      public String getTarget()
      Gets the target URL.
      Returns:
      The target URL.
    • getTargetConnection

      public HttpURLConnection getTargetConnection()
      Gets the target HTTP connection.
      Returns:
      The HttpURLConnection to the target.