com.ibm.wbi.protocol.http
Class FetchUrl

java.lang.Object
  |
  +--com.ibm.wbi.protocol.http.FetchUrl

public class FetchUrl
extends java.lang.Object

Used to fetch a URL specified by Proxy specific classes and using the proxy or socks server specified by the proxy configuration. There are a few different methods available, but they all accomplish pretty much the same thing. In order to make an HTTP request, we need a reference to the sublayer, an HTTP request header, and optionally some content (e.g., for a POST request).

The reference to the sublayer can be derived either from the RequestEvent or SystemContext. The RequestEvent is where this information once exclusively came from. Now the SystemContext is preferred because it is available everywhere (e.g., getSystemContext() is a method of Plugin) and at any time, not just while handling a request. Another reason that SystemContext is preferred is because the RequestEvent already contains an HTTP request, an input stream, and so-called transaction data (@see com.ibm.wbi.RequestInfo) -- so there is potential for confusion over whether these are utilized in the FetchUrl request (they are not). So in the interest of simplicity and clarity the new, non-deprecated API only supports the SystemContext argument.

Before the header code was updated (WBI4.4), the class HttpRequest was used to represent both a HTTP request header and (optional) content. In the new system, HttpRequestHeader is just that (a header), so we need to provide a place to include the content. Note that that the content can be null, and should be for all requests which do not use the POST or PUT methods. If just a URL is provided, then it is assumed to be a GET request, and the content is null. If content is provided, then the content-length header is set automatically.

The only other thing you need to think about is the first boolean argument, which specifies whether the request should "go through the wbi proxy". In other words, whether the request should be subject to the same rule evaluation and Meg execution that a normal browser request is. This often takes some thought, especially if you don't want your Editors to run twice on the same request. Sometimes it's desirable to set a flag to tell your Megs to ignore the ancillary FetchUrl event. If you decide to do this, recall that the transaction data associated with the current RequestEvent is not passed to the FetchUrl request -- you probably want to invent some HTTP header -- one of our favorites is "x--been-there".


Field Summary
static java.lang.String COPYRIGHT
           
 
Constructor Summary
FetchUrl()
           
 
Method Summary
static ServiceResult fetch(boolean thru_wbi, SystemContext context, HttpRequestHeader hReq, byte[] content)
          Make an HTTP request with HTTP request header and content.
static ServiceResult fetch(boolean thru_wbi, SystemContext context, java.lang.String url)
          Make an HTTP request to this URL.
static ServiceResult fetch(RequestEvent event, HttpRequest request)
          Deprecated. Don't use HttpRequest object
static ServiceResult fetch(RequestEvent event, HttpRequestHeader hReq)
           
static ServiceResult fetch(RequestEvent event, java.lang.String url)
          Deprecated. @see #fetch(boolean, RequestEvent, String)
static ServiceResult fetch(SystemContext context, HttpRequest request)
          Deprecated. Don't use HttpRequest object
static ServiceResult fetch(SystemContext context, HttpRequestHeader hReq)
           
static ServiceResult fetch(SystemContext context, java.lang.String url)
          Deprecated. @see #fetch(boolean, SystemContext, String)
static ServiceResult fetchThroughProxy(RequestEvent event, HttpRequest request)
          Deprecated. Use fetch(true/false, ...)
static ServiceResult fetchThroughProxy(RequestEvent event, java.lang.String url)
          Deprecated. Use fetch(true/false)...
static ServiceResult fetchThroughProxy(SystemContext context, HttpRequest request)
          Deprecated. Use fetch(true/false, ...)
static ServiceResult fetchThroughProxy(SystemContext context, java.lang.String url)
          Deprecated. Use fetch(true/false, ...)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
Constructor Detail

FetchUrl

public FetchUrl()
Method Detail

fetch

public static ServiceResult fetch(boolean thru_wbi,
                                  SystemContext context,
                                  java.lang.String url)
                           throws java.io.IOException,
                                  RequestRejectedException
Make an HTTP request to this URL.
Parameters:
thru_wbi - Whether to pass the request through WBI
context - The system context (get from Plugin or Meg)
url - The URL Request.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.

fetch

public static ServiceResult fetch(boolean thru_wbi,
                                  SystemContext context,
                                  HttpRequestHeader hReq,
                                  byte[] content)
                           throws java.io.IOException,
                                  RequestRejectedException
Make an HTTP request with HTTP request header and content. The content may be null, and is useful only in POST or PUT requests.
Parameters:
thru_wbi - Whether to pass the request through WBI
context - The system context (get from Plugin or Meg)
hReq - The HTTP request header
content - POST data (or null)
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.

fetch

public static ServiceResult fetch(RequestEvent event,
                                  java.lang.String url)
                           throws java.io.IOException,
                                  RequestRejectedException
Deprecated. @see #fetch(boolean, RequestEvent, String)

Get the URL specified.
Parameters:
event - This is the event that launched the MEG that is calling this method.
url - The URL Request.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.

fetch

public static ServiceResult fetch(SystemContext context,
                                  java.lang.String url)
                           throws java.io.IOException,
                                  RequestRejectedException
Deprecated. @see #fetch(boolean, SystemContext, String)

Get the URL specified.
Parameters:
context - The system context (get from Plugin or Meg)
url - The URL Request.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.

fetch

public static ServiceResult fetch(RequestEvent event,
                                  HttpRequest request)
                           throws java.io.IOException,
                                  RequestRejectedException
Deprecated. Don't use HttpRequest object

Get the URL specified by the HttpRequest object.
Parameters:
event - This is the event that launched the MEG that is calling this method.
request - The HttpRequest to make.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.
See Also:
fetch(boolean, RequestEvent, HttpRequestHeader)

fetch

public static ServiceResult fetch(SystemContext context,
                                  HttpRequest request)
                           throws java.io.IOException,
                                  RequestRejectedException
Deprecated. Don't use HttpRequest object

Get the URL specified by the HttpRequest object.
Parameters:
context - The system context (get from Meg or Plugin)
request - The HttpRequest to make.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.

fetch

public static ServiceResult fetch(RequestEvent event,
                                  HttpRequestHeader hReq)
                           throws java.io.IOException,
                                  RequestRejectedException

fetch

public static ServiceResult fetch(SystemContext context,
                                  HttpRequestHeader hReq)
                           throws java.io.IOException,
                                  RequestRejectedException

fetchThroughProxy

public static ServiceResult fetchThroughProxy(RequestEvent event,
                                              java.lang.String url)
                                       throws java.io.IOException,
                                              RequestRejectedException
Deprecated. Use fetch(true/false)...

Fetches the contents of a URL based on an HTTP request that describes the desired URL. The fetch is done through the Proxy, so it will be handled by the same chain of MEGs as if the request had come to the Proxy from a browser.
Parameters:
event - This is the event that launched the MEG that is calling this method.
url - The URL for the request.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.
See Also:
#fetch(boolean, RequestEvent, String)

fetchThroughProxy

public static ServiceResult fetchThroughProxy(SystemContext context,
                                              java.lang.String url)
                                       throws java.io.IOException,
                                              RequestRejectedException
Deprecated. Use fetch(true/false, ...)

Fetches the contents of a URL based on an HTTP request that describes the desired URL. The fetch is done through the Proxy, so it will be handled by the same chain of MEGs as if the request had come to the Proxy from a browser.
Parameters:
context - The system context (get from Plugin or Meg)
url - The URL Request.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.
See Also:
fetch(boolean, SystemContext, String)

fetchThroughProxy

public static ServiceResult fetchThroughProxy(RequestEvent event,
                                              HttpRequest request)
                                       throws java.io.IOException,
                                              RequestRejectedException
Deprecated. Use fetch(true/false, ...)

Fetches the contents of a URL based on an HTTP request that describes the desired URL. The fetch is done through the Proxy, so it will be handled by the same chain of MEGs as if the request had come to the Proxy from a browser.
Parameters:
event - This is the event that launched the MEG that is calling this method.
request - The HttpRequest object for the request.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.
See Also:
#fetch(boolean, RequestEvent, String)

fetchThroughProxy

public static ServiceResult fetchThroughProxy(SystemContext context,
                                              HttpRequest request)
                                       throws java.io.IOException,
                                              RequestRejectedException
Deprecated. Use fetch(true/false, ...)

Fetches the contents of a URL based on an HTTP request that describes the desired URL. The fetch is done through the Proxy, so it will be handled by the same chain of MEGs as if the request had come to the Proxy from a browser.
Parameters:
context - The system context (get from Plugin or Meg)
request - The HttpRequest object for the request.
Returns:
A ServiceResult that encapsulates the DocumentInfo and the stream to read the URL response from.
Throws:
java.io.IOException - If an error occurs.
See Also:
fetch(boolean, SystemContext, String)