Class HttpProducer

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.EndpointAware, org.apache.camel.IsSingleton, org.apache.camel.Processor, org.apache.camel.Producer, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

    public class HttpProducer
    extends org.apache.camel.support.DefaultProducer
    • Field Summary

      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILDED, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTINGDOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.http.client.methods.HttpRequestBase createMethod​(org.apache.camel.Exchange exchange)
      Creates the HttpMethod to use to call the remote server, either its GET or POST.
      protected org.apache.http.HttpEntity createRequestEntity​(org.apache.camel.Exchange exchange)
      Creates a holder object for the data to send to the remote server.
      protected org.apache.http.HttpResponse executeMethod​(org.apache.http.client.methods.HttpUriRequest httpRequest)
      Strategy when executing the method (calling the remote server).
      protected Object extractResponseBody​(org.apache.http.client.methods.HttpRequestBase httpRequest, org.apache.http.HttpResponse httpResponse, org.apache.camel.Exchange exchange, boolean ignoreResponseBody)
      Extracts the response from the method as a InputStream.
      protected static Map<String,​String> extractResponseHeaders​(org.apache.http.Header[] responseHeaders)
      Extracts the response headers
      HttpEndpoint getEndpoint()  
      org.apache.http.client.HttpClient getHttpClient()  
      protected Exception populateHttpOperationFailedException​(org.apache.camel.Exchange exchange, org.apache.http.client.methods.HttpRequestBase httpRequest, org.apache.http.HttpResponse httpResponse, int responseCode)  
      protected void populateResponse​(org.apache.camel.Exchange exchange, org.apache.http.client.methods.HttpRequestBase httpRequest, org.apache.http.HttpResponse httpResponse, org.apache.camel.Message in, org.apache.camel.spi.HeaderFilterStrategy strategy, int responseCode)  
      void process​(org.apache.camel.Exchange exchange)  
      void setHttpClient​(org.apache.http.client.HttpClient httpClient)  
      • Methods inherited from class org.apache.camel.support.DefaultProducer

        createExchange, doStart, doStop, isSingleton, toString
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
      • Methods inherited from interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Constructor Detail

      • HttpProducer

        public HttpProducer​(HttpEndpoint endpoint)
    • Method Detail

      • process

        public void process​(org.apache.camel.Exchange exchange)
                     throws Exception
        Throws:
        Exception
      • getEndpoint

        public HttpEndpoint getEndpoint()
        Specified by:
        getEndpoint in interface org.apache.camel.EndpointAware
        Overrides:
        getEndpoint in class org.apache.camel.support.DefaultProducer
      • populateResponse

        protected void populateResponse​(org.apache.camel.Exchange exchange,
                                        org.apache.http.client.methods.HttpRequestBase httpRequest,
                                        org.apache.http.HttpResponse httpResponse,
                                        org.apache.camel.Message in,
                                        org.apache.camel.spi.HeaderFilterStrategy strategy,
                                        int responseCode)
                                 throws IOException,
                                        ClassNotFoundException
        Throws:
        IOException
        ClassNotFoundException
      • executeMethod

        protected org.apache.http.HttpResponse executeMethod​(org.apache.http.client.methods.HttpUriRequest httpRequest)
                                                      throws IOException
        Strategy when executing the method (calling the remote server).
        Parameters:
        httpRequest - the http Request to execute
        Returns:
        the response
        Throws:
        IOException - can be thrown
      • extractResponseHeaders

        protected static Map<String,​String> extractResponseHeaders​(org.apache.http.Header[] responseHeaders)
        Extracts the response headers
        Parameters:
        responseHeaders - the headers
        Returns:
        the extracted headers or null if no headers existed
      • extractResponseBody

        protected Object extractResponseBody​(org.apache.http.client.methods.HttpRequestBase httpRequest,
                                             org.apache.http.HttpResponse httpResponse,
                                             org.apache.camel.Exchange exchange,
                                             boolean ignoreResponseBody)
                                      throws IOException,
                                             ClassNotFoundException
        Extracts the response from the method as a InputStream.
        Throws:
        IOException
        ClassNotFoundException
      • createMethod

        protected org.apache.http.client.methods.HttpRequestBase createMethod​(org.apache.camel.Exchange exchange)
                                                                       throws Exception
        Creates the HttpMethod to use to call the remote server, either its GET or POST.
        Parameters:
        exchange - the exchange
        Returns:
        the created method as either GET or POST
        Throws:
        URISyntaxException - is thrown if the URI is invalid
        Exception - is thrown if error creating RequestEntity
      • createRequestEntity

        protected org.apache.http.HttpEntity createRequestEntity​(org.apache.camel.Exchange exchange)
                                                          throws org.apache.camel.CamelExchangeException
        Creates a holder object for the data to send to the remote server.
        Parameters:
        exchange - the exchange with the IN message with data to send
        Returns:
        the data holder
        Throws:
        org.apache.camel.CamelExchangeException - is thrown if error creating RequestEntity
      • getHttpClient

        public org.apache.http.client.HttpClient getHttpClient()
      • setHttpClient

        public void setHttpClient​(org.apache.http.client.HttpClient httpClient)