Package nl.nn.adapterframework.http
Class HttpSender
- java.lang.Object
-
- nl.nn.adapterframework.http.HttpSessionBase
-
- nl.nn.adapterframework.http.HttpSenderBase
-
- nl.nn.adapterframework.http.HttpSender
-
- All Implemented Interfaces:
CanUseSharedResource<org.apache.http.impl.client.CloseableHttpClient>
,HasPhysicalDestination
,IConfigurable
,IConfigurationAware
,INamedObject
,IScopeProvider
,ISender
,ISenderWithParameters
,IWithParameters
,HasKeystore
,HasTruststore
,ConfigurableLifecycle
,org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.context.Lifecycle
- Direct Known Subclasses:
MultipartHttpSender
,RestSender
,WebServiceSender
public class HttpSender extends HttpSenderBase
Sender for the HTTP protocol usingHttpMethod
. By default, any response code outside the 2xx or 3xx range is considered an error and theexception
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
Note: When used as MTOM sender and MTOM receiver doesn't support Content-Transfer-Encoding "base64", messages without line feeds will give an error. This can be fixed by setting the Content-Transfer-Encoding in the MTOM sender.- Since:
- 7.0
- Version:
- 2.0
- Author:
- Niels Meijer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpSender.PostType
-
Nested classes/interfaces inherited from class nl.nn.adapterframework.http.HttpSenderBase
HttpSenderBase.HttpMethod
-
-
Field Summary
-
Fields inherited from class nl.nn.adapterframework.http.HttpSenderBase
CORRELATION_ID_HEADER, headerParamsSet, MESSAGE_ID_HEADER, parametersToSkipWhenEmptySet, paramList, requestOrBodyParamsSet, staticUri, urlParameter
-
Fields inherited from class nl.nn.adapterframework.http.HttpSessionBase
log
-
-
Constructor Summary
Constructors Constructor Description HttpSender()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
configure()
Configure this component.protected org.apache.http.entity.mime.FormBodyPart
elementToFormBodyPart(Element element, PipeLineSession session)
protected Message
extractResult(HttpResponseHandler responseHandler, PipeLineSession session)
Custom implementation to extract the response and format it to a String result.String
getFirstBodyPartName()
protected org.apache.http.client.methods.HttpRequestBase
getMethod(URI uri, Message message, ParameterValueList parameters)
Returns HttpRequestBase, with (optional) RAW or as BINAIRY contentprotected org.apache.http.client.methods.HttpRequestBase
getMethod(URI url, Message message, ParameterValueList parameters, PipeLineSession session)
Custom implementation to create aHttpRequest
object.String
getMtomContentTransferEncoding()
Boolean
getMultipartResponse()
String
getMultipartXmlSessionKey()
HttpSender.PostType
getPostType()
Message
getResponseBody(HttpResponseHandler responseHandler)
String
getStoreResultAsByteArrayInSessionKey()
Deprecated.String
getStoreResultAsStreamInSessionKey()
Deprecated.String
getStreamResultToFileNameSessionKey()
Deprecated.Boolean
getTreatInputMessageAsParameters()
static Message
handleMultipartResponse(String mimeType, InputStream inputStream, PipeLineSession session)
return the first part as Message and put the other parts as InputStream in the PipeLineSessionboolean
isEncodeMessages()
boolean
isParamsInUrl()
boolean
isStreamResultToServlet()
void
setEncodeMessages(boolean b)
Specifies whether messages will encoded, e.g.void
setFirstBodyPartName(String firstBodyPartName)
(Only used whenmethodType
=POST
andpostType
=URLENCODED
,FORM-DATA
orMTOM
) Prepends a new BodyPart using the specified name and uses the input of the Sender as contentvoid
setInputMessageParam(String inputMessageParam)
Deprecated.void
setMtomContentTransferEncoding(String mtomContentTransferEncoding)
void
setMtomEnabled(boolean b)
Deprecated.void
setMultipart(boolean b)
Deprecated.void
setMultipartResponse(Boolean b)
Deprecated.void
setMultipartXmlSessionKey(String multipartXmlSessionKey)
If set andmethodType
=POST
andparamsInUrl
=false
, a multipart/form-data entity is created instead of a request body.void
setParamsInUrl(boolean b)
Deprecated.void
setPostType(HttpSender.PostType type)
IfmethodType
=POST
,PUT
orPATCH
, the type of post requestvoid
setStoreResultAsByteArrayInSessionKey(String storeResultAsByteArrayInSessionKey)
Deprecated.void
setStoreResultAsStreamInSessionKey(String storeResultAsStreamInSessionKey)
Deprecated.void
setStreamResultToFileNameSessionKey(String string)
Deprecated.void
setStreamResultToServlet(boolean b)
If set, the result is streamed to the HhttpServletResponse object of the RestServiceDispatcher (instead of passed as a string)void
setTreatInputMessageAsParameters(Boolean b)
Iftrue
, the input will be added to the URL formethodType
=GET
, or formethodType
=POST
,PUT
orPATCH
ifpostType
=RAW
.static void
streamResponseBody(InputStream is, String contentType, String contentDisposition, javax.servlet.http.HttpServletResponse response, org.apache.logging.log4j.Logger log, String logPrefix)
static void
streamResponseBody(InputStream is, String contentType, String contentDisposition, javax.servlet.http.HttpServletResponse response, org.apache.logging.log4j.Logger log, String logPrefix, String redirectLocation)
-
Methods inherited from class nl.nn.adapterframework.http.HttpSenderBase
addParameter, appendParameters, close, getCharSet, getContentType, getDomain, getFullContentType, getHeadersParams, getHttpMethod, getLogPrefix, getObjectType, getParameterList, getParametersToSkipWhenEmpty, getPhysicalDestinationName, getResultStatusCodeSessionKey, getStyleSheetName, getUrl, getUrlParam, isXhtml, open, sendMessage, setCertificate, setCertificateAuthAlias, setCertificatePassword, setCertificateType, setCharSet, setContentType, setHeadersParams, setMethodType, setParametersToSkipWhenEmpty, setProxyUserName, setResultStatusCodeSessionKey, setSharedResourceRef, setStyleSheetName, setUrl, setUrlParam, setUserName, setXhtml, start, validateResponseCode
-
Methods inherited from class nl.nn.adapterframework.http.HttpSessionBase
areCookiesDisabled, buildHttpClient, configureConnectionManager, execute, getApplicationContext, getAuthAlias, getAuthDomain, getClientAuthAlias, getClientId, getClientSecret, getConfigurationClassLoader, getConnectionIdleTimeout, getConnectionTimeToLive, 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, preAuthenticate, setAllowSelfSignedCertificates, setApplicationContext, setAuthAlias, setAuthDomain, setAuthenticatedTokenRequest, setClientAlias, setClientId, setClientSecret, setConnectionIdleTimeout, setConnectionTimeToLive, setDisableCookies, setFollowRedirects, setHttpClient, 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, stop
-
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 nl.nn.adapterframework.core.CanUseSharedResource
getSharedResource
-
Methods inherited from interface nl.nn.adapterframework.core.IConfigurationAware
getApplicationContext, getName
-
Methods inherited from interface nl.nn.adapterframework.core.INamedObject
getName, setName
-
Methods inherited from interface nl.nn.adapterframework.core.IScopeProvider
getConfigurationClassLoader
-
Methods inherited from interface nl.nn.adapterframework.core.ISender
isSynchronous, sendMessageOrThrow
-
Methods inherited from interface nl.nn.adapterframework.core.ISenderWithParameters
consumesSessionVariable
-
-
-
-
Method Detail
-
configure
public void configure() throws ConfigurationException
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 classHttpSenderBase
- Throws:
ConfigurationException
- in case it was not able to configure the component.
-
getMethod
protected org.apache.http.client.methods.HttpRequestBase getMethod(URI url, Message message, ParameterValueList parameters, PipeLineSession session) throws SenderException
Description copied from class:HttpSenderBase
Custom implementation to create aHttpRequest
object.- Specified by:
getMethod
in classHttpSenderBase
- Parameters:
url
- 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
-
getMethod
protected org.apache.http.client.methods.HttpRequestBase getMethod(URI uri, Message message, ParameterValueList parameters) throws SenderException
Returns HttpRequestBase, with (optional) RAW or as BINAIRY content- Throws:
SenderException
-
elementToFormBodyPart
protected org.apache.http.entity.mime.FormBodyPart elementToFormBodyPart(Element element, PipeLineSession session) throws IOException
- Throws:
IOException
-
extractResult
protected Message extractResult(HttpResponseHandler responseHandler, PipeLineSession session) throws SenderException, IOException
Description copied from class:HttpSenderBase
Custom implementation to extract the response and format it to a String result.
It is important that theresponse
will be read or will beclosed
.- Specified by:
extractResult
in classHttpSenderBase
- 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
-
getResponseBody
public Message getResponseBody(HttpResponseHandler responseHandler)
-
handleMultipartResponse
public static Message handleMultipartResponse(String mimeType, InputStream inputStream, PipeLineSession session) throws IOException
return the first part as Message and put the other parts as InputStream in the PipeLineSession- Throws:
IOException
-
streamResponseBody
public static void streamResponseBody(InputStream is, String contentType, String contentDisposition, javax.servlet.http.HttpServletResponse response, org.apache.logging.log4j.Logger log, String logPrefix) throws IOException
- Throws:
IOException
-
streamResponseBody
public static void streamResponseBody(InputStream is, String contentType, String contentDisposition, javax.servlet.http.HttpServletResponse response, org.apache.logging.log4j.Logger log, String logPrefix, String redirectLocation) throws IOException
- Throws:
IOException
-
setPostType
public void setPostType(HttpSender.PostType type)
IfmethodType
=POST
,PUT
orPATCH
, the type of post request- Default value
- RAW
-
setParamsInUrl
@Deprecated public void setParamsInUrl(boolean b)
Deprecated.If false andmethodType
=POST
, request parameters are put in the request body instead of in the url- Default value
- true
-
setInputMessageParam
@Deprecated @ConfigurationWarning("Use the firstBodyPartName attribute instead") public void setInputMessageParam(String inputMessageParam)
Deprecated.
-
setFirstBodyPartName
public void setFirstBodyPartName(String firstBodyPartName)
(Only used whenmethodType
=POST
andpostType
=URLENCODED
,FORM-DATA
orMTOM
) Prepends a new BodyPart using the specified name and uses the input of the Sender as content
-
setStreamResultToFileNameSessionKey
@Deprecated @ConfigurationWarning("no longer required to store the result as a file in the PipeLineSession, the sender can return binary data") public void setStreamResultToFileNameSessionKey(String string)
Deprecated.If set, the result is streamed to a file (instead of passed as a string)
-
setStoreResultAsStreamInSessionKey
@Deprecated @ConfigurationWarning("no longer required to store the result as a stream in the PipeLineSession, the sender can return binary data") public void setStoreResultAsStreamInSessionKey(String storeResultAsStreamInSessionKey)
Deprecated.If set, a pointer to an input stream of the result is put in the specified sessionkey (as the sender interface only allows a sender to return a string a sessionkey is used instead to return the stream)
-
setStoreResultAsByteArrayInSessionKey
@Deprecated @ConfigurationWarning("no longer required to store the result as a byte array in the PipeLineSession, the sender can return binary data") public void setStoreResultAsByteArrayInSessionKey(String storeResultAsByteArrayInSessionKey)
Deprecated.
-
setStreamResultToServlet
public void setStreamResultToServlet(boolean b)
If set, the result is streamed to the HhttpServletResponse object of the RestServiceDispatcher (instead of passed as a string)- Default value
- false
-
setMultipart
@Deprecated @ConfigurationWarning("multipart has been replaced by postType=\'formdata\'") public void setMultipart(boolean b)
Deprecated.If true andmethodType
=
POST
andparamsInUrl
=false
, request parameters are put in a multipart/form-data entity instead of in the request body- Default value
- false
-
setMultipartResponse
@Deprecated @ConfigurationWarning("Unless set explicitly multipart response will be detected automatically") public void setMultipartResponse(Boolean b)
Deprecated.If true the response body is expected to be in mime multipart which is the case when a soap message with attachments is received (see also https://docs.oracle.com/javaee/7/api/javax/xml/soap/soapmessage.html). the first part will be returned as result of this sender. other parts are returned as streams in sessionkeys with names multipart1, multipart2, etc. the http connection is held open until the last stream is read.- Default value
- false
-
setMultipartXmlSessionKey
public void setMultipartXmlSessionKey(String multipartXmlSessionKey)
If set andmethodType
=POST
andparamsInUrl
=false
, a multipart/form-data entity is created instead of a request body. For each part element in the session key a part in the multipart entity is created. Part elements can contain the following attributes:- name: optional, used as 'filename' in Content-Disposition
- sessionKey: mandatory, refers to contents of part
- mimeType: optional MIME type
-
setMtomEnabled
@Deprecated @ConfigurationWarning("mtomEnabled has been replaced by postType=\'mtom\'") public void setMtomEnabled(boolean b)
Deprecated.
-
setMtomContentTransferEncoding
public void setMtomContentTransferEncoding(String mtomContentTransferEncoding)
-
setEncodeMessages
public void setEncodeMessages(boolean b)
Specifies whether messages will encoded, e.g. spaces will be replaced by '+' etc.- Default value
- false
-
setTreatInputMessageAsParameters
public void setTreatInputMessageAsParameters(Boolean b)
Iftrue
, the input will be added to the URL formethodType
=GET
, or formethodType
=POST
,PUT
orPATCH
ifpostType
=RAW
. This used to be the default behaviour in framework version 7.7 and earlier- Default value
- for methodType=
GET
:false
,
for methodTypesPOST
,PUT
,PATCH
:true
-
getStreamResultToFileNameSessionKey
@Deprecated public String getStreamResultToFileNameSessionKey()
Deprecated.
-
getStoreResultAsStreamInSessionKey
@Deprecated public String getStoreResultAsStreamInSessionKey()
Deprecated.
-
getStoreResultAsByteArrayInSessionKey
@Deprecated public String getStoreResultAsByteArrayInSessionKey()
Deprecated.
-
isStreamResultToServlet
public boolean isStreamResultToServlet()
-
isParamsInUrl
public boolean isParamsInUrl()
-
getFirstBodyPartName
public String getFirstBodyPartName()
-
getMultipartResponse
public Boolean getMultipartResponse()
-
getMultipartXmlSessionKey
public String getMultipartXmlSessionKey()
-
getMtomContentTransferEncoding
public String getMtomContentTransferEncoding()
-
isEncodeMessages
public boolean isEncodeMessages()
-
getTreatInputMessageAsParameters
public Boolean getTreatInputMessageAsParameters()
-
getPostType
public HttpSender.PostType getPostType()
-
-