public abstract class HttpSenderBase extends SenderWithParametersBase implements HasPhysicalDestination, HasKeystore, HasTruststore
Expected message format:
GET methods expect a message looking like this
param_name=param_value&another_param_name=another_param_value
POST AND PUT methods expect a message similar as GET, or looking like this
param_name=param_value another_param_name=another_param_value
Note 1:
Some certificates require the <java_home>/jre/lib/security/xxx_policy.jar files to be upgraded to unlimited strength. Typically, in such a case, an error message like
Error in loading the keystore: Private key decryption error: (java.lang.SecurityException: Unsupported keysize or algorithm parameters
is observed.
For IBM JDKs these files can be downloaded from http://www.ibm.com/developerworks/java/jdk/security/50/ (scroll down to 'IBM SDK Policy files')
Note 2: To debug ssl-related problems, set the following system property:
-Djavax.net.debug=true
-Djavax.net.debug=all
Note 3:
In case javax.net.ssl.SSLHandshakeException: unknown certificate
-exceptions are thrown,
probably the certificate of the other party is not trusted. Try to use one of the certificates in the path as your truststore by doing the following:
keytool
as follows:
keytool -import -alias yourAlias -file pathToSavedCertificate
Note 4:
In case cannot create or initialize SocketFactory: (IOException) Unable to verify MAC
-exceptions are thrown,
please check password or authAlias configuration of the corresponding certificate.
GET
as request-parameters, when method POST
as body part) except the headersParams
list, which are added as HTTP headers, and the urlParam
headerModifier and Type | Class and Description |
---|---|
static class |
HttpSenderBase.HttpMethod |
Modifier and Type | Field and Description |
---|---|
static String |
CORRELATION_ID_HEADER |
protected Set<String> |
headerParamsSet |
static String |
MESSAGE_ID_HEADER |
protected Set<String> |
parametersToSkipWhenEmptySet |
protected Set<String> |
requestOrBodyParamsSet |
protected URI |
staticUri |
protected Parameter |
urlParameter |
parameterNamesMustBeUnique, paramList
log
Constructor and Description |
---|
HttpSenderBase() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
appendParameters(boolean parametersAppended,
StringBuffer path,
ParameterValueList parameters) |
boolean |
areCookiesDisabled() |
void |
close()
Stop/close the sender and deallocate resources.
|
void |
configure()
configure() is called once at startup of the framework in the configure method of the owner of this sender. |
protected abstract Message |
extractResult(HttpResponseHandler responseHandler,
PipeLineSession session)
Custom implementation to extract the response and format it to a String result.
|
protected abstract org.apache.http.client.methods.HttpRequestBase |
getMethod(URI uri,
Message message,
ParameterValueList parameters,
PipeLineSession session)
Custom implementation to create a
HttpRequest object. |
String |
getPhysicalDestinationName() |
protected int |
getPort(URI uri) |
protected org.apache.http.conn.ssl.SSLConnectionSocketFactory |
getSSLConnectionSocketFactory() |
protected URI |
getURI(String url)
Makes sure only http(s) requests can be performed.
|
void |
open()
This method will be called to start the sender.
|
boolean |
prefillProxyAuthCache()
TODO: make this configurable
|
SenderResult |
sendMessage(Message message,
PipeLineSession session)
Send a message to some destination (as configured in the Sender object).
|
void |
setAllowSelfSignedCertificates(boolean allowSelfSignedCertificates)
If
true , self signed certificates are accepted |
void |
setAuthAlias(String string)
Authentication alias used for authentication to the host
|
void |
setAuthDomain(String string)
Deprecated.
|
void |
setAuthenticatedTokenRequest(boolean authenticatedTokenRequest)
if set true, clientId and clientSecret will be added as Basic Authentication header to the tokenRequest, instead of as request parameters
|
void |
setCertificate(String string)
Deprecated.
|
void |
setCertificateAuthAlias(String string)
Deprecated.
|
void |
setCertificatePassword(String string)
Deprecated.
|
void |
setCertificateType(KeystoreType value)
Deprecated.
|
void |
setCharSet(String string)
Charset of the request.
|
void |
setClientAlias(String clientAuthAlias)
Alias used to obtain client_id and client_secret for authentication to
tokenEndpoint |
void |
setClientId(String clientId)
Client_id used in authentication to
tokenEndpoint |
void |
setClientSecret(String clientSecret)
Client_secret used in authentication to
tokenEndpoint |
void |
setConnectionIdleTimeout(int idleTimeout)
Maximum Time for connection to stay idle in the pool.
|
void |
setConnectionTimeToLive(int timeToLive)
Maximum Time to Live for connections in the pool.
|
void |
setContentType(String string)
Content-Type (superset of mimetype + charset) of the request, for
POST , PUT and PATCH methods |
void |
setDisableCookies(boolean disableCookies)
Disables the use of cookies, making the sender completely stateless
|
void |
setFollowRedirects(boolean b)
If
true , a redirect request will be honoured, e.g. |
void |
setHeadersParams(String headersParams)
Comma separated list of parameter names which should be set as HTTP headers
|
void |
setIgnoreCertificateExpiredException(boolean b)
If
true , CertificateExpiredExceptions are ignored |
void |
setIgnoreRedirects(boolean b)
If true, besides http status code 200 (OK) also the code 301 (MOVED_PERMANENTLY), 302 (MOVED_TEMPORARILY) and 307 (TEMPORARY_REDIRECT) are considered successful
|
void |
setKeyManagerAlgorithm(String keyManagerAlgorithm)
Key manager algorithm.
|
void |
setKeystore(String string)
resource URL to keystore or certificate to be used for authentication.
|
void |
setKeystoreAlias(String string)
Alias to obtain specific certificate or key in keystore
|
void |
setKeystoreAliasAuthAlias(String string)
Authentication alias to authenticate access to certificate or key indicated by
keystoreAlias |
void |
setKeystoreAliasPassword(String string)
Default password to authenticate access to certificate or key indicated by
keystoreAlias |
void |
setKeystoreAuthAlias(String string)
Authentication alias used to obtain keystore password
|
void |
setKeystorePassword(String string)
Default password to access keystore
|
void |
setKeystoreType(KeystoreType value)
Type of keystore
|
void |
setMaxConnections(int i)
The maximum number of concurrent connections
|
void |
setMaxExecuteRetries(int i)
The maximum number of times the execution is retried
|
void |
setMethodType(HttpSenderBase.HttpMethod method)
The HTTP Method used to execute the request
|
void |
setParametersToSkipWhenEmpty(String parametersToSkipWhenEmpty)
Comma separated list of parameter names that should not be added as request or body parameter, or as HTTP header, if they are empty.
|
void |
setPassword(String string)
Password used for authentication to the host
|
void |
setProtocol(String protocol)
Secure socket protocol (such as 'SSL' and 'TLS') to use when a SSLContext object is generated.
|
void |
setProxyAuthAlias(String string)
Alias used to obtain credentials for authentication to proxy
|
void |
setProxyHost(String string)
Proxy host
|
void |
setProxyPassword(String string)
Proxy password
|
void |
setProxyPort(int i)
Proxy port
|
void |
setProxyRealm(String string)
Proxy realm
|
void |
setProxyUsername(String string)
Proxy username
|
void |
setProxyUserName(String string)
Deprecated.
|
void |
setResultStatusCodeSessionKey(String resultStatusCodeSessionKey)
If set, the status code of the HTTP response is put in the specified sessionKey and the (error or okay) response message is returned.
|
void |
setScope(String string)
Space or comma separated list of scope items requested for accessToken, e.g.
|
void |
setStaleChecking(boolean b)
Controls whether connections checked to be stale, i.e.
|
void |
setStaleTimeout(int timeout)
Used when StaleChecking=
true . |
void |
setStyleSheetName(String stylesheetName)
(Only used when xHtml=
true ) stylesheet to apply to the HTML response |
void |
setTimeout(int i)
Timeout in ms of obtaining a connection/result.
|
void |
setTokenEndpoint(String string)
Endpoint to obtain OAuth accessToken.
|
void |
setTokenExpiry(int value)
If set to a non-negative value, then determines the time (in seconds) after which the token will be refreshed.
|
void |
setTrustManagerAlgorithm(String trustManagerAlgorithm)
Trust manager algorithm.
|
void |
setTruststore(String string)
Resource url to truststore.
|
void |
setTruststoreAuthAlias(String string)
Authentication alias used to obtain truststore password
|
void |
setTruststorePassword(String string)
Default password to access truststore
|
void |
setTruststoreType(KeystoreType value)
Type of truststore
|
void |
setUrl(String string)
URL or base of URL to be used
|
void |
setUrlParam(String urlParam)
Parameter that is used to obtain URL; overrides url-attribute.
|
void |
setUsername(String username)
Username used for authentication to the host
|
void |
setUserName(String username)
Deprecated.
|
void |
setVerifyHostname(boolean b)
If
true , the hostname in the certificate will be checked against the actual hostname of the peer |
void |
setXhtml(boolean xHtml)
If
true , the HTML response is transformed to XHTML |
protected boolean |
validateResponseCode(int statusCode) |
addParameter, checkStringAttributeOrParameter, consumesSessionVariable, getParameterList, getParameterOverriddenAttributeValue, getParameterOverriddenAttributeValue, getParameterValueList
createBean, getLogPrefix, getName, isSynchronous, setApplicationContext, setName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getDomain
getKeyManagerAlgorithm, getKeystore, getKeystoreAlias, getKeystoreAliasAuthAlias, getKeystoreAliasPassword, getKeystoreAuthAlias, getKeystorePassword, getKeystoreType
getApplicationContext, getName
getConfigurationClassLoader
setApplicationContext
getTrustManagerAlgorithm, getTruststore, getTruststoreAuthAlias, getTruststorePassword, getTruststoreType, isAllowSelfSignedCertificates, isIgnoreCertificateExpiredException, isVerifyHostname
isSynchronous, sendMessageOrThrow
getName, setName
public static final String MESSAGE_ID_HEADER
public static final String CORRELATION_ID_HEADER
protected Parameter urlParameter
protected URI staticUri
protected URI getURI(String url) throws URISyntaxException
URISyntaxException
protected int getPort(URI uri)
public void configure() throws ConfigurationException
ISender
configure()
is called once at startup of the framework in the configure method of the owner of this sender.
Purpose of this method is to check whether the static configuration of the sender is correct.
As much as possible class-instantiating should take place in the configure()
or open()
method, to improve performance.configure
in interface IConfigurable
configure
in interface ISender
configure
in class SenderWithParametersBase
ConfigurationException
public void open() throws SenderException
ISender
sendMessage()
method.open
in interface ISender
open
in class SenderBase
SenderException
public void close() throws SenderException
ISender
close
in interface ISender
close
in class SenderBase
SenderException
protected org.apache.http.conn.ssl.SSLConnectionSocketFactory getSSLConnectionSocketFactory() throws SenderException
SenderException
protected boolean appendParameters(boolean parametersAppended, StringBuffer path, ParameterValueList parameters) throws SenderException
SenderException
protected abstract org.apache.http.client.methods.HttpRequestBase getMethod(URI uri, Message message, ParameterValueList parameters, PipeLineSession session) throws SenderException
HttpRequest
object.uri
- endpoint to send the message tomessage
- to be sentparameters
- ParameterValueList that contains all the senders parameterssession
- PipeLineSession to retrieve or store data from, or NULL when not setHttpRequest
objectSenderException
protected abstract Message extractResult(HttpResponseHandler responseHandler, PipeLineSession session) throws SenderException, IOException
response
will be read or will be closed
.responseHandler
- HttpResponseHandler
that contains the response informationsession
- PipeLineSession
which may be nullSenderException
IOException
protected boolean validateResponseCode(int statusCode)
public SenderResult sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException
ISender
configure()
method is called.
The following table shows the difference between synchronous and a-synchronous senders:
synchronous | a-synchronous | |
---|---|---|
ISender.isSynchronous() returns | true | false |
return value of sendMessage() is | the reply-message | the messageId of the message sent |
the correlationID specified with sendMessage() | may be ignored | is sent with the message |
a {link TimeOutException} | may be thrown if a timeout occurs waiting for a reply | should not be expected |
Multiple objects may try to call this method at the same time, from different threads.
Implementations of this method should therefore be thread-safe, or synchronized
.
sendMessage
in interface ISender
SenderException
TimeoutException
public String getPhysicalDestinationName()
getPhysicalDestinationName
in interface HasPhysicalDestination
public void setUrl(String string)
public void setUrlParam(String urlParam)
public void setMethodType(HttpSenderBase.HttpMethod method)
GET
public void setContentType(String string)
POST
, PUT
and PATCH
methodsRAW
public void setCharSet(String string)
PUT
and POST
requests.public void setTimeout(int i)
public void setMaxConnections(int i)
public void setMaxExecuteRetries(int i)
public void setAuthAlias(String string)
public void setUsername(String username)
@Deprecated @ConfigurationWarning(value="Please use attribute username instead") public void setUserName(String username)
public void setPassword(String string)
@Deprecated @ConfigurationWarning(value="Please use the UPN or the full sAM-AccountName instead") public void setAuthDomain(String string)
john.doe
CORPDOMAIN
public void setTokenEndpoint(String string)
authAlias
or username
( and password
) are specified,
then a PasswordGrant is used, otherwise a ClientCredentials grant. The obtained accessToken will be added to the regular requests
in an HTTP Header 'Authorization' with a 'Bearer' prefix.public void setTokenExpiry(int value)
expires_in
clause of the token response,
or when the regular server returns a 401 status with a challenge.
If not specified, and the accessTokens lifetime is not found in the token response, the accessToken will not be refreshed preemptively.public void setClientAlias(String clientAuthAlias)
tokenEndpoint
public void setClientId(String clientId)
tokenEndpoint
public void setClientSecret(String clientSecret)
tokenEndpoint
public void setScope(String string)
read write
. Only used when tokenEndpoint
is specifiedpublic void setAuthenticatedTokenRequest(boolean authenticatedTokenRequest)
public void setProxyHost(String string)
public void setProxyPort(int i)
public void setProxyAuthAlias(String string)
public void setProxyUsername(String string)
@Deprecated @ConfigurationWarning(value="Please use \"proxyUsername\" instead") public void setProxyUserName(String string)
public void setProxyPassword(String string)
public void setProxyRealm(String string)
public boolean prefillProxyAuthCache()
public void setDisableCookies(boolean disableCookies)
public boolean areCookiesDisabled()
@Deprecated @ConfigurationWarning(value="Please use attribute keystore instead") public void setCertificate(String string)
@Deprecated @ConfigurationWarning(value="has been replaced with keystoreType") public void setCertificateType(KeystoreType value)
@Deprecated @ConfigurationWarning(value="Please use attribute keystoreAuthAlias instead") public void setCertificateAuthAlias(String string)
@Deprecated @ConfigurationWarning(value="Please use attribute keystorePassword instead") public void setCertificatePassword(String string)
public void setKeystore(String string)
setKeystore
in interface HasKeystore
public void setKeystoreType(KeystoreType value)
HasKeystore
setKeystoreType
in interface HasKeystore
public void setKeystoreAuthAlias(String string)
HasKeystore
setKeystoreAuthAlias
in interface HasKeystore
public void setKeystorePassword(String string)
HasKeystore
setKeystorePassword
in interface HasKeystore
public void setKeyManagerAlgorithm(String keyManagerAlgorithm)
HasKeystore
setKeyManagerAlgorithm
in interface HasKeystore
public void setKeystoreAlias(String string)
HasKeystore
setKeystoreAlias
in interface HasKeystore
public void setKeystoreAliasAuthAlias(String string)
HasKeystore
keystoreAlias
setKeystoreAliasAuthAlias
in interface HasKeystore
public void setKeystoreAliasPassword(String string)
HasKeystore
keystoreAlias
setKeystoreAliasPassword
in interface HasKeystore
public void setTruststore(String string)
HasTruststore
setTruststore
in interface HasTruststore
public void setTruststoreAuthAlias(String string)
HasTruststore
setTruststoreAuthAlias
in interface HasTruststore
public void setTruststorePassword(String string)
HasTruststore
setTruststorePassword
in interface HasTruststore
public void setTruststoreType(KeystoreType value)
HasTruststore
setTruststoreType
in interface HasTruststore
public void setTrustManagerAlgorithm(String trustManagerAlgorithm)
HasTruststore
setTrustManagerAlgorithm
in interface HasTruststore
public void setVerifyHostname(boolean b)
HasTruststore
true
, the hostname in the certificate will be checked against the actual hostname of the peersetVerifyHostname
in interface HasTruststore
public void setAllowSelfSignedCertificates(boolean allowSelfSignedCertificates)
HasTruststore
true
, self signed certificates are acceptedsetAllowSelfSignedCertificates
in interface HasTruststore
public void setIgnoreCertificateExpiredException(boolean b)
HasTruststore
true
, CertificateExpiredExceptions are ignoredsetIgnoreCertificateExpiredException
in interface HasTruststore
public void setHeadersParams(String headersParams)
public void setParametersToSkipWhenEmpty(String parametersToSkipWhenEmpty)
public void setFollowRedirects(boolean b)
true
, a redirect request will be honoured, e.g. to switch to HTTPSpublic void setIgnoreRedirects(boolean b)
public void setStaleChecking(boolean b)
public void setStaleTimeout(int timeout)
true
. Timeout after which an idle connection will be validated before being used.public void setConnectionTimeToLive(int timeToLive)
public void setConnectionIdleTimeout(int idleTimeout)
public void setXhtml(boolean xHtml)
true
, the HTML response is transformed to XHTMLpublic void setStyleSheetName(String stylesheetName)
true
) stylesheet to apply to the HTML responsepublic void setProtocol(String protocol)
public void setResultStatusCodeSessionKey(String resultStatusCodeSessionKey)
Copyright © 2023 Frank!Framework. All rights reserved.