Class HttpSenderBase

java.lang.Object
org.frankframework.http.HttpSessionBase
org.frankframework.http.HttpSenderBase
All Implemented Interfaces:
CanUseSharedResource<HttpSession>, 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:
HttpSender

public abstract class HttpSenderBase extends HttpSessionBase implements HasPhysicalDestination, ISenderWithParameters, CanUseSharedResource<HttpSession>
Sender for the HTTP protocol using GET, POST, PUT or DELETE using httpclient 4+

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 method POST as body part) except the headersParams list, which are added as HTTP headers, and the urlParam header
  • Field Details

    • MESSAGE_ID_HEADER

      public static final String MESSAGE_ID_HEADER
      See Also:
    • CORRELATION_ID_HEADER

      public static final String CORRELATION_ID_HEADER
      See Also:
    • urlParameter

      protected Parameter urlParameter
    • staticUri

      protected URI staticUri
    • requestOrBodyParamsSet

      protected Set<String> requestOrBodyParamsSet
    • headerParamsSet

      protected Set<String> headerParamsSet
    • parametersToSkipWhenEmptySet

      protected Set<String> parametersToSkipWhenEmptySet
    • paramList

      protected ParameterList paramList
  • Constructor Details

    • HttpSenderBase

      public HttpSenderBase()
  • Method Details

    • addParameter

      public void addParameter(Parameter p)
      Specified by:
      addParameter in interface IWithParameters
    • getParameterList

      public ParameterList getParameterList()
      return the Parameters
      Specified by:
      getParameterList in interface IWithParameters
    • 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 interface ConfigurableLifecycle
      Specified by:
      configure in interface IConfigurable
      Specified by:
      configure in interface ISender
      Overrides:
      configure in class HttpSessionBase
      Throws:
      ConfigurationException - in case it was not able to configure the component.
    • open

      public void open() throws SenderException
      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 the sendMessage() method.
      Specified by:
      open in interface ISender
      Throws:
      SenderException
    • getObjectType

      public Class<HttpSession> 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 interface CanUseSharedResource<HttpSession>
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
      Overrides:
      start in class HttpSessionBase
    • close

      public void close()
      Description copied from interface: ISender
      Stop/close the sender and deallocate resources.
      Specified by:
      close in interface ISender
    • appendParameters

      protected boolean appendParameters(boolean parametersAppended, StringBuilder path, ParameterValueList parameters) throws SenderException
      Throws:
      SenderException
    • getLogPrefix

      protected String getLogPrefix()
      Returns the true name of the class and not XsltPipe$$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 a HttpRequest object.
      Parameters:
      uri - endpoint to send the message to
      message - to be sent
      parameters - ParameterValueList that contains all the senders parameters
      session - 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 the response will be read or will be closed.
      Parameters:
      responseHandler - HttpResponseHandler that contains the response information
      session - 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

      public SenderResult sendMessage(Message message, 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 the configure() method is called.

      The following table shows the difference between synchronous and a-synchronous senders:

       synchronousa-synchronous
      ISender.isSynchronous() returnstruefalse
      return value of sendMessage() isthe reply-messagethe messageId of the message sent
      the correlationID specified with sendMessage()may be ignoredis sent with the message
      a {link TimeOutException}may be thrown if a timeout occurs waiting for a replyshould 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 interface ISender
      Throws:
      SenderException
      TimeoutException
    • getPhysicalDestinationName

      public String getPhysicalDestinationName()
      Specified by:
      getPhysicalDestinationName in interface HasPhysicalDestination
    • setUrl

      public void setUrl(String string)
      URL or base of URL to be used
    • setUrlParam

      public void setUrlParam(String urlParam)
      Parameter that is used to obtain URL; overrides url-attribute.
      Default value
      url
    • setMethodType

      public void setMethodType(HttpSenderBase.HttpMethod method)
      The HTTP Method used to execute the request
      Default value
      GET
    • setContentType

      public void setContentType(String string)
      Content-Type (superset of mimetype + charset) of the request, for POST, PUT and PATCH methods
      Default value
      text/html, when postType=RAW
    • setCharSet

      public void setCharSet(String string)
      Charset of the request. Typically only used on PUT and POST requests.
      Default value
      UTF-8
    • setCertificate

      @Deprecated @ConfigurationWarning("Please use attribute keystore instead") public void setCertificate(String string)
      Deprecated.
    • setCertificateType

      @Deprecated @ConfigurationWarning("has been replaced with keystoreType") public void setCertificateType(KeystoreType value)
      Deprecated.
    • setCertificateAuthAlias

      @Deprecated @ConfigurationWarning("Please use attribute keystoreAuthAlias instead") public void setCertificateAuthAlias(String string)
      Deprecated.
    • setCertificatePassword

      @Deprecated @ConfigurationWarning("Please use attribute keystorePassword instead") public void setCertificatePassword(String string)
      Deprecated.
    • setHeadersParams

      public void setHeadersParams(String headersParams)
      Comma separated list of parameter names which should be set as HTTP headers
    • setParametersToSkipWhenEmpty

      public 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. Set to '*' for this behaviour for all parameters
    • setXhtml

      public void setXhtml(boolean xHtml)
      If true, the HTML response is transformed to XHTML
      Default value
      false
    • setStyleSheetName

      public void setStyleSheetName(String stylesheetName)
      (Only used when xHtml=true) stylesheet to apply to the HTML response
    • setResultStatusCodeSessionKey

      public 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. 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

      public String getDomain()
      Specified by:
      getDomain in interface HasPhysicalDestination
    • setSharedResourceRef

      public void setSharedResourceRef(String sharedResourceRef)
      Specified by:
      setSharedResourceRef in interface CanUseSharedResource<HttpSession>
    • getUrl

      public String getUrl()
    • getUrlParam

      public String getUrlParam()
    • getHttpMethod

      public HttpSenderBase.HttpMethod getHttpMethod()
    • getCharSet

      public String getCharSet()
    • getFullContentType

      public org.apache.http.entity.ContentType getFullContentType()
    • getContentType

      public String getContentType()
    • getHeadersParams

      public String getHeadersParams()
    • isXhtml

      public boolean isXhtml()
    • getStyleSheetName

      public String getStyleSheetName()
    • getResultStatusCodeSessionKey

      public String getResultStatusCodeSessionKey()
    • getParametersToSkipWhenEmpty

      public String getParametersToSkipWhenEmpty()