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 HeaderMapper<HttpHeaders>
implementation
to the BaseHttpInboundEndpoint.setHeaderMapper(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
BaseHttpInboundEndpoint.extractReplyPayload
value to false
.
IntegrationManagement.ManagementOverrides
activeCount, expectReply, jaxb2Present, nonReadableBodyHttpMethods, romeToolsPresent
messagingTemplate
lifecycleCondition, lifecycleLock
EXPRESSION_PARSER, logger
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
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 org.springframework.messaging.Message<?> |
doHandleRequest(javax.servlet.http.HttpServletRequest servletRequest,
javax.servlet.http.HttpServletResponse servletResponse)
Handles the HTTP request by generating a Message and sending it to the request channel.
|
protected java.util.List<org.springframework.http.converter.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. |
void |
setMergeWithDefaultConverters(boolean mergeWithDefaultConverters)
Flag which determines if the default converters should be available after
custom converters.
|
void |
setMessageConverters(java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
Set the message body converters to use.
|
void |
setMultipartResolver(org.springframework.web.multipart.MultipartResolver multipartResolver)
Specify the
MultipartResolver to use when checking requests. |
protected void |
setStatusCodeIfNeeded(org.springframework.http.server.ServerHttpResponse response) |
protected java.lang.Object |
setupResponseAndConvertReply(org.springframework.http.server.ServletServerHttpResponse response,
org.springframework.messaging.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, getPayloadExpression, getRequestMapping, getRequestPayloadType, getStatusCodeExpression, isExpectReply, isReadable, resolveHttpStatusFromHeaders, setCrossOrigin, setExtractReplyPayload, setHeaderExpressions, setHeaderMapper, setPayloadExpression, setRequestMapping, setRequestPayloadType, setRequestPayloadTypeClass, setStatusCodeExpression, setStatusCodeExpressionString
buildErrorMessage, doStart, doStop, getErrorChannel, getErrorMessageAttributes, getManagedName, getManagedType, getMessageCount, getMessageCountLong, getOverrides, getReplyChannel, getRequestChannel, isCountsEnabled, isLoggingEnabled, receive, receive, receiveMessage, receiveMessage, registerReplyMessageCorrelatorIfNecessary, reset, send, sendAndReceive, sendAndReceiveMessage, sendAndReceiveMessageReactive, setCountsEnabled, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setLoggingEnabled, setManagedName, setManagedType, setReplyChannel, setReplyChannelName, setReplyMapper, setReplyTimeout, setRequestChannel, setRequestChannelName, setRequestMapper, setRequestTimeout, setShouldTrack
destroy, doStop, getPhase, getRole, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, setTaskScheduler, start, stop, stop
afterPropertiesSet, extractTypeIfPossible, getApplicationContext, getApplicationContextId, getBeanFactory, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getComponentName
setCounter
registerMetricsCaptor
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(Expression)
public void setMessageConverters(java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
messageConverters
- The message converters.protected java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> getMessageConverters()
public void setMergeWithDefaultConverters(boolean mergeWithDefaultConverters)
mergeWithDefaultConverters
- true to merge, false to replace.public void setMultipartResolver(org.springframework.web.multipart.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() throws java.lang.Exception
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
java.lang.Exception
- Any exception.protected final org.springframework.messaging.Message<?> doHandleRequest(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse) throws java.io.IOException
servletRequest
- The servlet request.servletResponse
- The servlet response.java.io.IOException
- Any IOException.protected final java.lang.Object setupResponseAndConvertReply(org.springframework.http.server.ServletServerHttpResponse response, org.springframework.messaging.Message<?> replyMessage)
ServletServerHttpResponse
.response
- The ServletServerHttpResponse.replyMessage
- The reply message.BaseHttpInboundEndpoint.extractReplyPayload
) otherwise the message.protected void setStatusCodeIfNeeded(org.springframework.http.server.ServerHttpResponse response)