HTTP Client Connector
Overview
The HTTP client Connector allows greater control on HTTP sessions than the
URLConnector provides. With the HTTP Connector you can set HTTP headers and body
using predefined attributes. Also, any request to a server that returns data is
available for the user as attributes.
Modes
The HTTP client Connector can be used in three different AssemblyLine modes.
These are
- Iterator
Each call to the Connector requests the same URL configured for the Connector. This will cause the
Connector to run forever requesting the same
page unless you include a Parser in the Connector's configuration. If you
include a Parser, the Parser will notify when the last entry has been read
from the connection and the Connector will eventually cause an AssemblyLine to terminate.
- Lookup
In this mode the Connector will request a page every time the lookup
function is called. In your search criteria you can specify either which
page/URL to request, and include any number of parameters all of which are
appended to the base URL as request parameters.
- AddOnly
In this mode the Connector request is performed much like the Iterator mode.
Special Attributes
When using the Connector in Iterator or Lookup mode the following set of
attributes/properties will be returned in the Connector entry:
Attribute/Property |
Description |
http.responseCode |
The HTTP response code as an Integer object.
200 OK ---> 200 |
http.responseMsg |
The HTTP response message as a String object.
200 OK ---> OK |
http.content-type |
The content type for the returned http.body (if any) |
http.content-encoding |
The encoding of the returned http.body (if any) |
http.content-length |
The number of bytes in http.body |
http.body |
This object is an instance/subclass of java.io.InputStream class that can be
used to read bytes of the returned body.var body = conn.getObject ("http.body");
var ch;
while ( (ch = body.read()) != -1 ) {
task.logmsg ("Next character: " + ch);
}
Consult the Java documentation for the InputStream classes and their
methods. |
http.text-body |
If the http.content-type starts with the sequence
"text/", the Connector assumes the body is textual data and
reads the http.body stream object into this attribute. |
When using the Connector in AddOnly mode the Connector will transmit
any attribute named "http." as a header. Thus, to set the content type
for a request name the attribute "http.content-type" and provide the
value as usual. One special attribute is http.body that may contain a
string or any java.io.InputStream or java.io.Reader subclass.
For all modes the Connector will always set the http.responseCode and
http.responseMsg attributes. In AddOnly mode this is a bit special since
the "conn" object being passed to the Connector is the object being
populated with these attributes. To access these you must obtain the value in
the Connector's After Add hook.
Configuration
Connector has the following parameters:
Parameter |
Description |
connectorType |
com.architech.connector.HTTPConnector |
url |
The HTTP page to request |
username |
If set the HTTP Authorization header will be
set using this parameter along with the password parameter. |
password |
Used if username is specifed. |
parser |
If specified this Parser will be used to
generate the posted data for an Add operation. |
Samples
In your attribute map you can use the following assignment to post the
contents of a file to the HTTP server:
// Attribute assignment for "http.body"
ret.value = new java.io.FileInputStream ("myfile.txt");
// Attribute assignment for "http.content-type"
ret.value = "text/plain";
The Connector will compute the "http.content-length" attribute for
you. There is no need to specify this attribute.
Lookup Mode
In lookup mode you can dynamically change the request URL by setting the
search criteria as follows:
- If you have one and only one criteria and the attribute is named "url"
then the value specified in the criteria will be used as the request URL.
url
equals $url
- If you have more than one or the only criteria is anything but "url",
then all attribute names and values are appended to the URL given by the Connector
configuration as the request URL.
Base URL: http://www.metamerge.com/lookup.cgi
Search Criteria:
name
equals john
mail equals doe.com
Resulting URL:
http://www.metamerge.com/lookup.cgi?name=john&mail=doe.com
The Lookup function will ignore the operand. So if you specify contains
instead of equals the Connector will still construct the URL as if
equals where used.
Downloads
Included in base product since 4.0.3
See Also
URLConnector, HTTP
Server Connector,
|