public abstract class HttpRequestHandlingEndpointSupport extends MessagingGatewaySupport implements OrderlyShutdownCapable
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 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 extractReplyPayload
value to
false
.
logger
Constructor and Description |
---|
HttpRequestHandlingEndpointSupport() |
HttpRequestHandlingEndpointSupport(boolean expectReply) |
Modifier and Type | Method and Description |
---|---|
int |
afterShutdown()
Called after normal shutdown of schedulers, executors etc,
and after the shutdown delay has elapsed, but before any
forced shutdown of any remaining active scheduler/executor
threads.Can optionally return the number of active messages
still in process.
|
int |
beforeShutdown()
Called before shutdown begins.
|
protected StandardEvaluationContext |
createEvaluationContext() |
protected Message<?> |
doHandleRequest(HttpServletRequest servletRequest,
HttpServletResponse servletResponse)
Handles the HTTP request by generating a Message and sending it to the request channel.
|
protected void |
doStart()
Lifecycle
|
String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
protected List<HttpMessageConverter<?>> |
getMessageConverters() |
RequestMapping |
getRequestMapping() |
protected boolean |
isExpectReply() |
protected boolean |
isShuttingDown() |
protected void |
onInit()
Locates the
MultipartResolver bean based on the default name defined by the
DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME constant if available. |
void |
setExtractReplyPayload(boolean extractReplyPayload)
Specify whether only the reply Message's payload should be passed in the response.
|
void |
setHeaderExpressions(Map<String,Expression> headerExpressions)
Specifies a Map of SpEL expressions to evaluate in order to generate the Message headers.
|
void |
setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper)
Set the
HeaderMapper to use when mapping between HTTP headers and MessageHeaders. |
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. |
void |
setPath(String path)
Deprecated.
since 3.0 in favor of requestMapping
|
void |
setPayloadExpression(Expression payloadExpression)
Specifies a SpEL expression to evaluate in order to generate the Message payload.
|
void |
setRequestMapping(RequestMapping requestMapping)
Set the
RequestMapping which allows you to specify a flexible RESTFul-mapping for this endpoint. |
void |
setRequestPayloadType(Class<?> requestPayloadType)
Specify the type of payload to be generated when the inbound HTTP request content is read by the
HttpMessageConverter s. |
void |
setSupportedMethods(HttpMethod... supportedMethods)
Deprecated.
since 3.0 in favor to requestMapping
|
protected Object |
setupResponseAndConvertReply(ServletServerHttpResponse response,
Message<?> replyMessage)
Converts the reply message to the appropriate HTTP reply object and
sets up the
ServletServerHttpResponse . |
doStop, receive, send, sendAndReceive, sendAndReceiveMessage, setErrorChannel, setReplyChannel, setReplyMapper, setReplyTimeout, setRequestChannel, setRequestMapper, setRequestTimeout, setShouldTrack
getPhase, isAutoStartup, isRunning, setAutoStartup, setPhase, setTaskScheduler, start, stop, stop
afterPropertiesSet, getApplicationContextId, getBeanFactory, getComponentName, getConversionService, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setComponentName, setConversionService, setMessageBuilderFactory, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getComponentName
public HttpRequestHandlingEndpointSupport()
public HttpRequestHandlingEndpointSupport(boolean expectReply)
protected boolean isExpectReply()
@Deprecated public void setPath(String path)
path
- The path.public void setPayloadExpression(Expression payloadExpression)
#pathVariables
#requestParams
#requestAttributes
#requestHeaders
#matrixVariables
#cookies
payloadExpression
- The payload expression.public void setHeaderExpressions(Map<String,Expression> headerExpressions)
#pathVariables
#requestParams
#requestAttributes
#requestHeaders
#matrixVariables
#cookies
headerExpressions
- The header expressions.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 setHeaderMapper(HeaderMapper<HttpHeaders> headerMapper)
HeaderMapper
to use when mapping between HTTP headers and MessageHeaders.headerMapper
- The header mapper.public void setRequestMapping(RequestMapping requestMapping)
RequestMapping
which allows you to specify a flexible RESTFul-mapping for this endpoint.requestMapping
- The request mapping.public final RequestMapping getRequestMapping()
@Deprecated public void setSupportedMethods(HttpMethod... supportedMethods)
supportedMethods
- The supported methods.public void setRequestPayloadType(Class<?> requestPayloadType)
HttpMessageConverter
s. By default this value is null which means at runtime any "text" Content-Type will
result in String while all others default to byte[].class
.requestPayloadType
- The payload type.public void setExtractReplyPayload(boolean extractReplyPayload)
extractReplyPayload
- true to extract the reply payload.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.public String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class MessagingGatewaySupport
protected void onInit() throws 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 MessagingGatewaySupport
Exception
- Any exception.protected final Message<?> doHandleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException
servletRequest
- The servlet request.servletResponse
- The servlet response.IOException
- Any IOException.protected final Object setupResponseAndConvertReply(ServletServerHttpResponse response, Message<?> replyMessage)
ServletServerHttpResponse
.response
- The ServletServerHttpResponse.replyMessage
- The reply message.extractReplyPayload
) otherwise the message.protected StandardEvaluationContext createEvaluationContext()
protected void doStart()
doStart
in class MessagingGatewaySupport
protected boolean isShuttingDown()
public int beforeShutdown()
OrderlyShutdownCapable
beforeShutdown
in interface OrderlyShutdownCapable
public int afterShutdown()
OrderlyShutdownCapable
afterShutdown
in interface OrderlyShutdownCapable