Package org.frankframework.http
Class AbstractHttpSender
java.lang.Object
org.frankframework.http.AbstractHttpSession
org.frankframework.http.AbstractHttpSender
- All Implemented Interfaces:
AdapterAware
,CanUseSharedResource<HttpSession>
,HasPhysicalDestination
,IConfigurable
,IConfigurationAware
,INamedObject
,IScopeProvider
,ISender
,ISenderWithParameters
,IWithParameters
,HasKeystore
,HasTruststore
,ConfigurableLifecycle
,HasStatistics
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.context.Lifecycle
,org.springframework.context.Phased
,org.springframework.context.SmartLifecycle
- Direct Known Subclasses:
HttpSender
@Forward(name="*",
description="statuscode of the HTTP response")
public abstract class AbstractHttpSender
extends AbstractHttpSession
implements HasPhysicalDestination, ISenderWithParameters, CanUseSharedResource<HttpSession>
Sender for the HTTP protocol using
HttpMethod
. By default, any response code outside the 2xx or 3xx range
is considered an error and the exception
forward of the SenderPipe is followed if present and if there
is no forward for the specific HTTP status code. Forwards for specific HTTP codes (e.g. "200", "201", ...)
are returned by this sender, so they are available to the SenderPipe.
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
- Since:
- 7.0
- Author:
- Niels Meijer
- Parameters
- Any parameters present are appended to the request (when method is
GET
as request-parameters, when methodPOST
as body part) except theheadersParams
list, which are added as HTTP headers, and theurlParam
header
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
protected ParameterList
protected URI
protected IParameter
Fields inherited from class org.frankframework.http.AbstractHttpSession
log
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
protected boolean
appendParameters
(boolean parametersAppended, StringBuilder path, ParameterValueList parameters) void
Configure this component.protected abstract Message
extractResult
(HttpResponseHandler responseHandler, PipeLineSession session) Custom implementation to extract the response and format it to a String result.org.apache.http.entity.ContentType
protected String
Returns the true name of the class and notXsltPipe$$EnhancerBySpringCGLIB$$563e6b5d
.protected abstract org.apache.http.client.methods.HttpRequestBase
getMethod
(URI uri, Message message, ParameterValueList parameters, PipeLineSession session) Custom implementation to create aHttpRequest
object.Used to validate the expected type so now unexpected ClassCastExceptions can occur.return the ParametersgetUrl()
boolean
isXhtml()
sendMessage
(Message message, PipeLineSession session) Send a message to some destination (as configured in the Sender object).void
setCertificate
(String string) Deprecated, for removal: This API element is subject to removal in a future version.void
setCertificateAuthAlias
(String string) Deprecated, for removal: This API element is subject to removal in a future version.void
setCertificatePassword
(String string) Deprecated, for removal: This API element is subject to removal in a future version.void
setCertificateType
(KeystoreType value) Deprecated, for removal: This API element is subject to removal in a future version.void
setCharSet
(String string) Charset of the request.void
setContentType
(String string) Content-Type (superset of mimetype + charset) of the request, forPOST
,PUT
andPATCH
methodsvoid
setHeadersParams
(String headersParams) Comma separated list of parameter names which should be set as HTTP headersvoid
The HTTP Method used to execute the requestvoid
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
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
setSharedResourceRef
(String sharedResourceRef) void
setStyleSheetName
(String stylesheetName) (Only used when xHtml=true
) stylesheet to apply to the HTML responsevoid
URL or base of URL to be usedvoid
setUrlParam
(String urlParam) Parameter that is used to obtain URL; overrides url-attribute.void
setXhtml
(boolean xHtml) Iftrue
, the HTML response is transformed to XHTMLvoid
start()
This method will be called to start the sender.void
stop()
Stop/close the sender and deallocate resources.protected boolean
validateResponseCode
(int statusCode) Methods inherited from class org.frankframework.http.AbstractHttpSession
areCookiesDisabled, execute, getAdapter, getApplicationContext, getAuthAlias, getAuthDomain, getClientAuthAlias, getClientId, getClientSecret, getConfigurationClassLoader, getConnectionIdleTimeout, getConnectionTimeToLive, getDefaultHttpClientContext, getHttpClient, getKeyManagerAlgorithm, getKeystore, getKeystoreAlias, getKeystoreAliasAuthAlias, getKeystoreAliasPassword, getKeystoreAuthAlias, getKeystorePassword, getKeystoreType, getMaxConnections, getMaxExecuteRetries, getName, getPassword, getProxyAuthAlias, getProxyHost, getProxyPassword, getProxyPort, getProxyRealm, getProxyUsername, getScope, getSSLConnectionSocketFactory, getStaleTimeout, getTimeout, getTokenEndpoint, getTokenExpiry, getTrustManagerAlgorithm, getTruststore, getTruststoreAuthAlias, getTruststorePassword, getTruststoreType, getURI, getUsername, isAllowSelfSignedCertificates, isAuthenticatedTokenRequest, isFollowRedirects, isIgnoreCertificateExpiredException, isIgnoreRedirects, isPrefillProxyAuthCache, isRunning, isStaleChecking, isVerifyHostname, setAdapter, setAllowSelfSignedCertificates, setApplicationContext, setAuthAlias, setAuthDomain, setAuthenticatedTokenRequest, setClientAlias, setClientId, setClientSecret, setConfigurationMetrics, setConnectionIdleTimeout, setConnectionTimeToLive, setDisableCookies, setFollowRedirects, setHttpClient, setHttpContext, setIgnoreCertificateExpiredException, setIgnoreRedirects, setKeyManagerAlgorithm, setKeystore, setKeystoreAlias, setKeystoreAliasAuthAlias, setKeystoreAliasPassword, setKeystoreAuthAlias, setKeystorePassword, setKeystoreType, setMaxConnections, setMaxExecuteRetries, setName, setPassword, setPrefillProxyAuthCache, setProtocol, setProxyAuthAlias, setProxyHost, setProxyPassword, setProxyPort, setProxyRealm, setProxyUsername, setScope, setStaleChecking, setStaleTimeout, setSupportedCipherSuites, setTimeout, setTokenEndpoint, setTokenExpiry, setTrustManagerAlgorithm, setTruststore, setTruststoreAuthAlias, setTruststorePassword, setTruststoreType, setUsername, setVerifyHostname
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.context.ApplicationContextAware
setApplicationContext
Methods inherited from interface org.frankframework.core.CanUseSharedResource
getSharedResource
Methods inherited from interface org.frankframework.lifecycle.ConfigurableLifecycle
getPhase, isAutoStartup
Methods inherited from interface org.frankframework.core.IConfigurationAware
getApplicationContext, getName
Methods inherited from interface org.frankframework.core.INamedObject
getName, setName
Methods inherited from interface org.frankframework.core.IScopeProvider
getConfigurationClassLoader
Methods inherited from interface org.frankframework.core.ISender
isSynchronous, sendMessageOrThrow
Methods inherited from interface org.frankframework.core.ISenderWithParameters
consumesSessionVariable
Methods inherited from interface org.springframework.context.Lifecycle
isRunning
Methods inherited from interface org.springframework.context.SmartLifecycle
stop
-
Field Details
-
MESSAGE_ID_HEADER
- See Also:
-
CORRELATION_ID_HEADER
- See Also:
-
urlParameter
-
staticUri
-
requestOrBodyParamsSet
-
headerParamsSet
-
parametersToSkipWhenEmptySet
-
paramList
-
-
Constructor Details
-
AbstractHttpSender
public AbstractHttpSender()
-
-
Method Details
-
addParameter
- Specified by:
addParameter
in interfaceIWithParameters
-
getParameterList
return the Parameters- Specified by:
getParameterList
in interfaceIWithParameters
-
configure
Description copied from interface:ConfigurableLifecycle
Configure this component.In the case of a container, this will propagate the start signal to all components that apply.
- Specified by:
configure
in interfaceConfigurableLifecycle
- Specified by:
configure
in interfaceIConfigurable
- Specified by:
configure
in interfaceISender
- Overrides:
configure
in classAbstractHttpSession
- Throws:
ConfigurationException
- in case it was not able to configure the component.
-
getObjectType
Description copied from interface:CanUseSharedResource
Used to validate the expected type so now unexpected ClassCastExceptions can occur. May be NULL in which case this check will be skipped and the SharedResource will be returned regardless.- Specified by:
getObjectType
in interfaceCanUseSharedResource<HttpSession>
-
start
public void start()Description copied from interface:ISender
This method will be called to start the sender. After this method is called the sendMessage method may be called. Purpose of this method is to reduce creating connections to databases etc. in thesendMessage()
method.- Specified by:
start
in interfaceISender
- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
- Overrides:
start
in classAbstractHttpSession
-
stop
public void stop()Description copied from interface:ISender
Stop/close the sender and deallocate resources.- Specified by:
stop
in interfaceISender
- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
- Overrides:
stop
in classAbstractHttpSession
-
appendParameters
protected boolean appendParameters(boolean parametersAppended, StringBuilder path, ParameterValueList parameters) throws SenderException - Throws:
SenderException
-
getLogPrefix
Returns the true name of the class and notXsltPipe$$EnhancerBySpringCGLIB$$563e6b5d
.ClassUtils.nameOf(Object)
makes sure the original class will be used.- Returns:
- className + name of the ISender
-
getMethod
protected abstract org.apache.http.client.methods.HttpRequestBase getMethod(URI uri, Message message, ParameterValueList parameters, PipeLineSession session) throws SenderException Custom implementation to create aHttpRequest
object.- Parameters:
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 set- Returns:
- a
HttpRequest
object - Throws:
SenderException
-
extractResult
protected abstract Message extractResult(HttpResponseHandler responseHandler, PipeLineSession session) throws SenderException, IOException Custom implementation to extract the response and format it to a String result.
It is important that theresponse
will be read or will beclosed
.- Parameters:
responseHandler
-HttpResponseHandler
that contains the response informationsession
-PipeLineSession
which may be null- Returns:
- a string that will be passed to the pipeline
- Throws:
SenderException
IOException
-
validateResponseCode
protected boolean validateResponseCode(int statusCode) -
sendMessage
@Nonnull public SenderResult sendMessage(@Nonnull Message message, @Nonnull PipeLineSession session) throws SenderException, TimeoutException Description copied from interface:ISender
Send a message to some destination (as configured in the Sender object). This method may only be called after theconfigure()
method is called.The following table shows the difference between synchronous and a-synchronous senders:
synchronous a-synchronous ISender.isSynchronous()
returnstrue
false
return value of sendMessage()
isthe 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
.- Specified by:
sendMessage
in interfaceISender
- Throws:
SenderException
TimeoutException
-
getPhysicalDestinationName
- Specified by:
getPhysicalDestinationName
in interfaceHasPhysicalDestination
-
setUrl
URL or base of URL to be used -
setUrlParam
Parameter that is used to obtain URL; overrides url-attribute.- Default value
- url
-
setMethodType
The HTTP Method used to execute the request- Default value
GET
-
setContentType
Content-Type (superset of mimetype + charset) of the request, forPOST
,PUT
andPATCH
methods- Default value
- text/html, when postType=
RAW
-
setCharSet
Charset of the request. Typically only used onPUT
andPOST
requests.- Default value
- UTF-8
-
setCertificate
@Deprecated(forRemoval=true, since="7.7.0") @ConfigurationWarning("Please use attribute keystore instead") public void setCertificate(String string) Deprecated, for removal: This API element is subject to removal in a future version. -
setCertificateType
@Deprecated(forRemoval=true, since="7.7.0") @ConfigurationWarning("has been replaced with keystoreType") public void setCertificateType(KeystoreType value) Deprecated, for removal: This API element is subject to removal in a future version. -
setCertificateAuthAlias
@Deprecated(forRemoval=true, since="7.7.0") @ConfigurationWarning("Please use attribute keystoreAuthAlias instead") public void setCertificateAuthAlias(String string) Deprecated, for removal: This API element is subject to removal in a future version. -
setCertificatePassword
@Deprecated(forRemoval=true, since="7.7.0") @ConfigurationWarning("Please use attribute keystorePassword instead") public void setCertificatePassword(String string) Deprecated, for removal: This API element is subject to removal in a future version. -
setHeadersParams
Comma separated list of parameter names which should be set as HTTP headers -
setParametersToSkipWhenEmpty
Comma separated list of parameter names that should not be added as request or body parameter, or as HTTP header, if they are empty. Set to '*' for this behaviour for all parameters -
setXhtml
public void setXhtml(boolean xHtml) Iftrue
, the HTML response is transformed to XHTML- Default value
- false
-
setStyleSheetName
(Only used when xHtml=true
) stylesheet to apply to the HTML response -
setResultStatusCodeSessionKey
If set, the status code of the HTTP response is put in the specified sessionKey and the (error or okay) response message is returned. Setting this property has a side effect. If a 4xx or 5xx result code is returned and if the configuration does not implement the specific forward for the returned HTTP result code, then the success forward is followed instead of the exception forward. -
getDomain
- Specified by:
getDomain
in interfaceHasPhysicalDestination
-
getUrl
-
getUrlParam
-
getHttpMethod
-
getCharSet
-
getFullContentType
public org.apache.http.entity.ContentType getFullContentType() -
getContentType
-
getHeadersParams
-
isXhtml
public boolean isXhtml() -
getStyleSheetName
-
getResultStatusCodeSessionKey
-
getParametersToSkipWhenEmpty
-