Class 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 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 Detail

      • HttpSender

        public HttpSender()
    • Method Detail

      • 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
      • 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
      • 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
      • setPostType

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

        public void setParamsInUrl​(boolean b)
        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
      • setStreamResultToFileNameSessionKey

        @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)
        If set, the result is streamed to a file (instead of passed as a string)
      • setStoreResultAsStreamInSessionKey

        @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)
        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

        @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)
      • 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
      • setMultipart

        @ConfigurationWarning("multipart has been replaced by postType=\'formdata\'")
        public void setMultipart​(boolean b)
        If true and methodType=POST and paramsInUrl=false, request parameters are put in a multipart/form-data entity instead of in the request body
        Default value
      • setMultipartResponse

        @ConfigurationWarning("Unless set explicitly multipart response will be detected automatically")
        public void setMultipartResponse​(Boolean b)
        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 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
      • 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.
      • setMtomEnabled

        @ConfigurationWarning("mtomEnabled has been replaced by postType=\'mtom\'")
        public void setMtomEnabled​(boolean b)
      • 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
      • getStreamResultToFileNameSessionKey

        public String getStreamResultToFileNameSessionKey()
      • getStoreResultAsStreamInSessionKey

        public String getStoreResultAsStreamInSessionKey()
      • getStoreResultAsByteArrayInSessionKey

        public String getStoreResultAsByteArrayInSessionKey()
      • 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()