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
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:

    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
  • 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 HttpSenderBase
      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 a HttpRequest object.
      Specified by:
      getMethod in class HttpSenderBase
      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
    • 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 the response will be read or will be closed.
      Specified by:
      extractResult in class HttpSenderBase
      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)
    • 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, String redirectLocation) throws IOException
      Throws:
      IOException
    • setPostType

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

      @Deprecated public void setParamsInUrl(boolean b)
      Deprecated.
      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
      • 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 HttpSender.PostType getPostType()