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:

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

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

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

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

        @Deprecated
        @ConfigurationWarning("multipart has been replaced by postType=\'formdata\'")
        public void setMultipart​(boolean b)
        Deprecated.
        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
        false
      • setMultipartResponse

        @Deprecated
        @ConfigurationWarning("Unless set explicitly multipart response will be detected automatically")
        public void setMultipartResponse​(Boolean b)
        Deprecated.
        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 https://docs.oracle.com/javaee/7/api/javax/xml/soap/soapmessage.html). 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
        false
      • 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

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

        @Deprecated
        public String getStreamResultToFileNameSessionKey()
        Deprecated.
      • getStoreResultAsStreamInSessionKey

        @Deprecated
        public String getStoreResultAsStreamInSessionKey()
        Deprecated.
      • getStoreResultAsByteArrayInSessionKey

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