public abstract class HttpRequestHandlingEndpointSupport extends BaseHttpInboundEndpoint
By default GET and POST requests are accepted via a supplied default instance
of RequestMapping
.
A GET request will generate a payload containing its 'parameterMap' while a POST
request will be converted to a Message payload according to the registered
HttpMessageConverter
s.
Several are registered by default, but the list can be explicitly set via
setMessageConverters(List)
.
To customize the mapping of request headers to the MessageHeaders, provide a
reference to a org.springframework.integration.mapping.HeaderMapper<HttpHeaders>
implementation
to the BaseHttpInboundEndpoint.setHeaderMapper(org.springframework.integration.mapping.HeaderMapper)
method.
The behavior is "request/reply" by default. Pass false
to the constructor
to force send-only as opposed to sendAndReceive. Send-only means that as soon as
the Message is created and passed to the
request channel
,
a response will be generated. Subclasses determine how that response is generated
(e.g. simple status response or rendering a View).
In a request-reply scenario, the reply Message's payload will be extracted prior
to generating a response by default.
To have the entire serialized Message available for the response, switch the
extractReplyPayload
value to false
.
IntegrationManagement.ManagementOverrides
activeCount, JAXB_PRESENT, NON_READABLE_BODY_HTTP_METHODS, ROME_TOOLS_PRESENT
messagingTemplate
lifecycleCondition, lifecycleLock
EXPRESSION_PARSER, logger
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
DEFAULT_PHASE
Constructor and Description |
---|
HttpRequestHandlingEndpointSupport()
Construct a gateway that will wait for the
replyTimeout for a reply; if the timeout is exceeded a '500 Internal Server Error'
status code is returned. |
HttpRequestHandlingEndpointSupport(boolean expectReply)
Construct a gateway.
|
Modifier and Type | Method and Description |
---|---|
protected Message<?> |
doHandleRequest(HttpServletRequest servletRequest,
RequestEntity<?> httpEntity)
Handles the HTTP request by generating a Message and sending it to the request channel.
|
protected Object |
extractRequestBody(ServletServerHttpRequest request) |
protected List<HttpMessageConverter<?>> |
getMessageConverters() |
protected void |
onInit()
Locates the
MultipartResolver bean based on the default name defined by the
DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME constant if available. |
protected ServletServerHttpRequest |
prepareRequest(HttpServletRequest servletRequest)
Prepares an instance of
ServletServerHttpRequest from the raw
HttpServletRequest . |
protected RequestEntity<Object> |
prepareRequestEntity(ServletServerHttpRequest request) |
void |
setMergeWithDefaultConverters(boolean mergeWithDefaultConverters)
Flag which determines if the default converters should be available after
custom converters.
|
void |
setMessageConverters(List<HttpMessageConverter<?>> messageConverters)
Set the message body converters to use.
|
void |
setMultipartResolver(MultipartResolver multipartResolver)
Specify the
MultipartResolver to use when checking requests. |
protected void |
setStatusCodeIfNeeded(ServerHttpResponse response,
HttpEntity<?> httpEntity) |
protected Object |
setupResponseAndConvertReply(ServletServerHttpResponse response,
Message<?> replyMessage)
Converts the reply message to the appropriate HTTP reply object and
sets up the
ServletServerHttpResponse . |
afterShutdown, beforeShutdown, createEvaluationContext, evaluateHttpStatus, getComponentType, getCrossOrigin, getExtractReplyPayload, getHeaderExpressions, getHeaderMapper, getIntegrationPatternType, getPayloadExpression, getRequestMapping, getRequestPayloadType, getStatusCodeExpression, getValidator, isExpectReply, isReadable, resolveHttpStatusFromHeaders, setCrossOrigin, setExtractReplyPayload, setHeaderExpressions, setHeaderMapper, setPayloadExpression, setRequestMapping, setRequestPayloadType, setRequestPayloadTypeClass, setStatusCodeExpression, setStatusCodeExpressionString, setValidator, validate
buildErrorMessage, buildSendTimer, destroy, doStart, doStop, getErrorChannel, getErrorMessageAttributes, getManagedName, getManagedType, getOverrides, getReplyChannel, getRequestChannel, isLoggingEnabled, receive, receive, receiveMessage, receiveMessage, registerMetricsCaptor, registerReplyMessageCorrelatorIfNecessary, send, sendAndReceive, sendAndReceiveMessage, sendAndReceiveMessageReactive, sendTimer, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setErrorOnTimeout, setLoggingEnabled, setManagedName, setManagedType, setReplyChannel, setReplyChannelName, setReplyMapper, setReplyTimeout, setRequestChannel, setRequestChannelName, setRequestMapper, setRequestTimeout, setShouldTrack
doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getThisAs
getBeanName, getComponentName
public HttpRequestHandlingEndpointSupport()
replyTimeout
for a reply; if the timeout is exceeded a '500 Internal Server Error'
status code is returned. This can be modified using the
statusCodeExpression
.public HttpRequestHandlingEndpointSupport(boolean expectReply)
replyTimeout
for a reply; if the timeout is exceeded
a '500 Internal Server Error' status code is returned. This can be modified using
the statusCodeExpression
.
If 'false', a 200 OK status will be returned; this can also be modified using
statusCodeExpression
.expectReply
- true if a reply is expected from the downstream flow.MessagingGatewaySupport.setReplyTimeout(long)
,
BaseHttpInboundEndpoint.setStatusCodeExpression(org.springframework.expression.Expression)
public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters)
messageConverters
- The message converters.protected List<HttpMessageConverter<?>> getMessageConverters()
public void setMergeWithDefaultConverters(boolean mergeWithDefaultConverters)
mergeWithDefaultConverters
- true to merge, false to replace.public void setMultipartResolver(MultipartResolver multipartResolver)
MultipartResolver
to use when checking requests. If no resolver is provided, the
"multipartResolver" bean in the context will be used as a fallback. If that is not available either, this
endpoint will not support multipart requests.multipartResolver
- The multipart resolver.protected void onInit()
MultipartResolver
bean based on the default name defined by the
DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME
constant if available.
Sets up default converters if no converters set, or setMergeWithDefaultConverters(boolean)
was called with true after the converters were set.onInit
in class BaseHttpInboundEndpoint
protected final Message<?> doHandleRequest(HttpServletRequest servletRequest, RequestEntity<?> httpEntity)
servletRequest
- The servlet request.httpEntity
- the request entity to use.protected final Object setupResponseAndConvertReply(ServletServerHttpResponse response, Message<?> replyMessage)
ServletServerHttpResponse
.response
- The ServletServerHttpResponse.replyMessage
- The reply message.extractReplyPayload
) otherwise the message.protected void setStatusCodeIfNeeded(ServerHttpResponse response, HttpEntity<?> httpEntity)
protected ServletServerHttpRequest prepareRequest(HttpServletRequest servletRequest)
ServletServerHttpRequest
from the raw
HttpServletRequest
. Also converts the request into a multipart request to
make multiparts available if necessary. If no multipart resolver is set,
simply returns the existing request.servletRequest
- current HTTP requestMultipartResolver.resolveMultipart(javax.servlet.http.HttpServletRequest)
protected RequestEntity<Object> prepareRequestEntity(ServletServerHttpRequest request) throws IOException
IOException
protected Object extractRequestBody(ServletServerHttpRequest request) throws IOException
IOException