Class HttpSender

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:
MultipartHttpSender, RestSender, WebServiceSender

public class HttpSender extends AbstractHttpSender
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
Version:
2.0
Author:
Niels Meijer
  • Constructor Details

    • HttpSender

      public HttpSender()
  • Method Details

    • 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 AbstractHttpSender
      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: AbstractHttpSender
      Custom implementation to create a HttpRequest object.
      Specified by:
      getMethod in class AbstractHttpSender
      Parameters:
      url - 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
    • createRequestMethod

      protected org.apache.http.client.methods.HttpRequestBase createRequestMethod(URI uri, Message message, ParameterValueList parameters, PipeLineSession session) throws SenderException
      Returns HttpRequestBase, with (optional) RAW or as BINARY content
      Throws:
      SenderException
    • extractResult

      protected Message extractResult(HttpResponseHandler responseHandler, PipeLineSession session) throws SenderException, IOException
      Description copied from class: AbstractHttpSender
      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.
      Specified by:
      extractResult in class AbstractHttpSender
      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
    • getResponseBody

      public Message getResponseBody(HttpResponseHandler responseHandler)
    • setPostType

      public void setPostType(HttpEntityType type)
      If methodType=POST, PUT or PATCH, the type of post request
      Default value
      RAW
    • setParamsInUrl

      @Deprecated(forRemoval=true, since="7.6.0") public void setParamsInUrl(boolean b)
      Deprecated, for removal: This API element is subject to removal in a future version.
      If false and methodType=POST, request parameters are put in the request body instead of in the url
      Default value
      true
    • setFirstBodyPartName

      public void setFirstBodyPartName(String firstBodyPartName)
      (Only used when methodType=POST and postType=URLENCODED, FORM-DATA or MTOM) Prepends a new BodyPart using the specified name and uses the input of the Sender as content
    • setMultipartXmlSessionKey

      public void setMultipartXmlSessionKey(String multipartXmlSessionKey)
      If set and methodType=POST and paramsInUrl=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
      • value: optional, the contents of the part if the sessionKey specified contains no data
      • mimeType: optional MIME type
      The name of the part is determined by the name attribute, unless that is empty, or the contents is binary. In those cases the sessionKey name is used as name of the part.
    • 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)
      If true, the input will be added to the URL for methodType=GET, or for methodType=POST, PUT or PATCH if postType=RAW. This used to be the default behaviour in framework version 7.7 and earlier
      Default value
      for methodType=GET: false,
      for methodTypes POST, PUT, PATCH: true
    • isParamsInUrl

      public boolean isParamsInUrl()
    • getFirstBodyPartName

      public String getFirstBodyPartName()
    • getMultipartXmlSessionKey

      public String getMultipartXmlSessionKey()
    • getMtomContentTransferEncoding

      public String getMtomContentTransferEncoding()
    • isEncodeMessages

      public boolean isEncodeMessages()
    • getTreatInputMessageAsParameters

      public Boolean getTreatInputMessageAsParameters()
    • getPostType

      public HttpEntityType getPostType()