@Description(value="Opens an HTTP resource. Supports setting HTTP header fields `Accept`, `Accept-Charset` and `Content-Type`, as well as generic headers (separated by `\\n`). Defaults: request `method` = `GET`, request `url` = `@-` (input data), request `body` = `@-` (input data) if request method supports body and input data not already used, `Accept` header = `*/*`, `Accept-Charset` header (`encoding`) = `UTF-8`, `errorPrefix` = `ERROR: `.")
@In(value=java.lang.String.class)
@Out(value=java.io.Reader.class)
@FluxCommand(value="open-http")
public final class HttpOpener
extends org.metafacture.framework.helpers.DefaultObjectPipe<java.lang.String,org.metafacture.framework.ObjectReceiver<java.io.Reader>>
HttpURLConnection and passes a reader to the receiver.| Modifier and Type | Class and Description |
|---|---|
static class |
HttpOpener.Method |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACCEPT_DEFAULT |
static java.lang.String |
ACCEPT_HEADER |
static java.lang.String |
CONTENT_TYPE_HEADER |
static HttpOpener.Method |
DEFAULT_METHOD |
static java.lang.String |
DEFAULT_METHOD_NAME |
static java.lang.String |
DEFAULT_PREFIX |
static java.lang.String |
ENCODING_DEFAULT |
static java.lang.String |
ENCODING_HEADER |
static java.lang.String |
HEADER_FIELD_SEPARATOR |
static java.lang.String |
HEADER_VALUE_SEPARATOR |
static java.lang.String |
INPUT_DESIGNATOR |
| Constructor and Description |
|---|
HttpOpener()
Creates an instance of
HttpOpener. |
| Modifier and Type | Method and Description |
|---|---|
void |
process(java.lang.String input) |
void |
setAccept(java.lang.String accept)
Sets the HTTP "accept" header value.
|
void |
setBody(java.lang.String body)
Sets the HTTP request body.
|
void |
setContentType(java.lang.String contentType)
Sets the HTTP "content-type" header value.
|
void |
setEncoding(java.lang.String encoding)
Sets the HTTP "accept-charset" header value.
|
void |
setErrorPrefix(java.lang.String errorPrefix)
Sets the error prefix.
|
void |
setHeader(java.lang.String header)
Sets a request property (header), or multiple request properties
separated by "\n".
|
void |
setHeader(java.lang.String key,
java.lang.String value)
Sets a request property (header).
|
void |
setMethod(HttpOpener.Method method)
Sets the HTTP request method.
|
void |
setUrl(java.lang.String url)
Sets the HTTP request URL.
|
closeStream, getReceiver, isClosed, onCloseStream, onResetStream, onSetReceiver, resetStream, setReceiverpublic static final java.lang.String ACCEPT_DEFAULT
public static final java.lang.String ACCEPT_HEADER
public static final java.lang.String CONTENT_TYPE_HEADER
public static final java.lang.String DEFAULT_PREFIX
public static final java.lang.String ENCODING_DEFAULT
public static final java.lang.String ENCODING_HEADER
public static final java.lang.String INPUT_DESIGNATOR
public static final java.lang.String DEFAULT_METHOD_NAME
public static final HttpOpener.Method DEFAULT_METHOD
public static final java.lang.String HEADER_FIELD_SEPARATOR
public static final java.lang.String HEADER_VALUE_SEPARATOR
public HttpOpener()
HttpOpener.public void setAccept(java.lang.String accept)
text/plain or application/json. The default
value for the accept header is "*/*" which means
any MIME type.accept - MIME type to use for the HTTP accept headerpublic void setBody(java.lang.String body)
request
method accepts a request body, which means it will use the input data data as request body if the input has
not already been used; otherwise, no request body will be set by
default.
If a request body has been set, but the request method does not
accept a body, the method may be changed to POST.
body - the request bodypublic void setContentType(java.lang.String contentType)
text/plain or application/json.contentType - MIME type to use for the HTTP content-type headerpublic void setEncoding(java.lang.String encoding)
encoding - name of the encoding used for the accept-charset HTTP
headerpublic void setErrorPrefix(java.lang.String errorPrefix)
errorPrefix - the error prefixpublic void setHeader(java.lang.String header)
header - request property linesetHeader(String, String)public void setHeader(java.lang.String key,
java.lang.String value)
key - request property keyvalue - request property valuepublic void setMethod(HttpOpener.Method method)
method - the request methodpublic void setUrl(java.lang.String url)
input data as request URL.url - the request URLpublic void process(java.lang.String input)
process in interface org.metafacture.framework.ObjectReceiver<java.lang.String>process in class org.metafacture.framework.helpers.DefaultObjectPipe<java.lang.String,org.metafacture.framework.ObjectReceiver<java.io.Reader>>