Class HttpSender

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, org.springframework.context.Phased, org.springframework.context.SmartLifecycle
Direct Known Subclasses:
MultipartHttpSender, RestSender, WebServiceSender

public class HttpSender extends HttpSenderBase
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:


POST AND PUT methods expect a message similar as GET, or looking like this:

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.

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
      configure in class HttpSenderBase
      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 a HttpRequest object.
      Specified by:
      getMethod in class HttpSenderBase
      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
      a HttpRequest object
    • 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
    • elementToFormBodyPart

      protected org.apache.http.entity.mime.FormBodyPart elementToFormBodyPart(Element element, PipeLineSession session) 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 the response will be read or will be closed.
      Specified by:
      extractResult in class HttpSenderBase
      responseHandler - HttpResponseHandler that contains the response information
      session - PipeLineSession which may be null
      a string that will be passed to the pipeline
    • getResponseBody

      public Message getResponseBody(HttpResponseHandler responseHandler)
    • setPostType

      public void setPostType(HttpSender.PostType type)
      If methodType=POST, PUT or PATCH, the type of post request
      Default value
    • 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
    • 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
      • 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
    • 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 HttpSender.PostType getPostType()