Package org.apache.camel.component.http
Class HttpProducer
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.DefaultProducer
org.apache.camel.component.http.HttpProducer
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.EndpointAware,org.apache.camel.IsSingleton,org.apache.camel.LineNumberAware,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
implements org.apache.camel.LineNumberAware
-
Field Summary
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.hc.core5.http.HttpHostcreateHost(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest) Creates the HttpHost to use to call the remote serverprotected org.apache.hc.client5.http.classic.methods.HttpUriRequestcreateMethod(org.apache.camel.Exchange exchange) Creates the HttpMethod to use to call the remote server, either its GET or POST.protected org.apache.hc.core5.http.HttpEntitycreateRequestEntity(org.apache.camel.Exchange exchange) Creates a holder object for the data to send to the remote server.protected voiddoInit()protected <T> TexecuteMethod(org.apache.camel.Exchange exchange, org.apache.hc.core5.http.HttpHost httpHost, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest, org.apache.hc.core5.http.io.HttpClientResponseHandler<T> handler) Strategy when executing the method (calling the remote server).protected ObjectextractResponseBody(org.apache.hc.core5.http.ClassicHttpResponse httpResponse, org.apache.camel.Exchange exchange, boolean ignoreResponseBody) Extracts the response from the method as a InputStream.extractResponseHeaders(org.apache.hc.core5.http.Header[] responseHeaders) Extracts the response headersorg.apache.hc.client5.http.classic.HttpClientintprotected ExceptionpopulateHttpOperationFailedException(org.apache.camel.Exchange exchange, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest, org.apache.hc.core5.http.ClassicHttpResponse httpResponse, int responseCode) protected voidpopulateResponse(org.apache.camel.Exchange exchange, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest, org.apache.hc.core5.http.ClassicHttpResponse httpResponse, org.apache.camel.spi.HeaderFilterStrategy strategy, int responseCode) voidprocess(org.apache.camel.Exchange exchange) voidsetHttpClient(org.apache.hc.client5.http.classic.HttpClient httpClient) voidsetLineNumber(int lineNumber) voidsetLocation(String location) Methods inherited from class org.apache.camel.support.DefaultProducer
createExchange, doStart, doStop, isSingleton, toStringMethods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
HttpProducer
-
-
Method Details
-
doInit
- Overrides:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
process
- Specified by:
processin interfaceorg.apache.camel.Processor- Throws:
Exception
-
getEndpoint
- Specified by:
getEndpointin interfaceorg.apache.camel.EndpointAware- Overrides:
getEndpointin classorg.apache.camel.support.DefaultProducer
-
populateResponse
protected void populateResponse(org.apache.camel.Exchange exchange, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest, org.apache.hc.core5.http.ClassicHttpResponse httpResponse, org.apache.camel.spi.HeaderFilterStrategy strategy, int responseCode) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
populateHttpOperationFailedException
protected Exception populateHttpOperationFailedException(org.apache.camel.Exchange exchange, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest, org.apache.hc.core5.http.ClassicHttpResponse httpResponse, int responseCode) throws IOException, ClassNotFoundException - Throws:
IOExceptionClassNotFoundException
-
executeMethod
protected <T> T executeMethod(org.apache.camel.Exchange exchange, org.apache.hc.core5.http.HttpHost httpHost, org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest, org.apache.hc.core5.http.io.HttpClientResponseHandler<T> handler) throws IOException, org.apache.hc.core5.http.HttpException Strategy when executing the method (calling the remote server).- Parameters:
httpHost- the http host to callhttpRequest- the http request to executehandler- the response handler- Returns:
- the response
- Throws:
IOException- can be thrownorg.apache.hc.core5.http.HttpException
-
extractResponseHeaders
protected static Map<String,String> extractResponseHeaders(org.apache.hc.core5.http.Header[] responseHeaders) Extracts the response headers- Parameters:
responseHeaders- the headers- Returns:
- the extracted headers or an empty map if no headers existed
-
extractResponseBody
protected Object extractResponseBody(org.apache.hc.core5.http.ClassicHttpResponse httpResponse, org.apache.camel.Exchange exchange, boolean ignoreResponseBody) throws IOException, ClassNotFoundException Extracts the response from the method as a InputStream.- Throws:
IOExceptionClassNotFoundException
-
createHost
protected org.apache.hc.core5.http.HttpHost createHost(org.apache.hc.client5.http.classic.methods.HttpUriRequest httpRequest) Creates the HttpHost to use to call the remote server -
createMethod
protected org.apache.hc.client5.http.classic.methods.HttpUriRequest 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 invalidException- is thrown if error creating RequestEntity
-
createRequestEntity
protected org.apache.hc.core5.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.hc.client5.http.classic.HttpClient getHttpClient() -
setHttpClient
public void setHttpClient(org.apache.hc.client5.http.classic.HttpClient httpClient) -
getLineNumber
public int getLineNumber()- Specified by:
getLineNumberin interfaceorg.apache.camel.LineNumberAware
-
setLineNumber
public void setLineNumber(int lineNumber) - Specified by:
setLineNumberin interfaceorg.apache.camel.LineNumberAware
-
getLocation
- Specified by:
getLocationin interfaceorg.apache.camel.LineNumberAware
-
setLocation
- Specified by:
setLocationin interfaceorg.apache.camel.LineNumberAware
-