Class HttpRequestHandlingEndpointSupport
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Phased
,SmartLifecycle
,ExpressionCapable
,OrderlyShutdownCapable
,IntegrationPattern
,NamedComponent
,IntegrationInboundManagement
,IntegrationManagement
,ManageableLifecycle
,ManageableSmartLifecycle
,TrackableComponent
- Direct Known Subclasses:
HttpRequestHandlingController
,HttpRequestHandlingMessagingGateway
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
.
- Since:
- 2.0
- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, Biju Kunjummen
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.http.inbound.BaseHttpInboundEndpoint
activeCount, JAXB_PRESENT, NON_READABLE_BODY_HTTP_METHODS, ROME_TOOLS_PRESENT
Fields inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
messagingTemplate
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLock
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
-
Constructor Summary
Constructors Constructor Description HttpRequestHandlingEndpointSupport()
Construct a gateway that will wait for thereplyTimeout
for a reply; if the timeout is exceeded a '500 Internal Server Error' status code is returned.HttpRequestHandlingEndpointSupport(boolean expectReply)
Construct a gateway. -
Method Summary
Modifier and Type Method Description protected Message<?>
doHandleRequest(javax.servlet.http.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 theMultipartResolver
bean based on the default name defined by theDispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME
constant if available.protected ServletServerHttpRequest
prepareRequest(javax.servlet.http.HttpServletRequest servletRequest)
Prepares an instance ofServletServerHttpRequest
from the rawHttpServletRequest
.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 theMultipartResolver
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 theServletServerHttpResponse
.Methods inherited from class org.springframework.integration.http.inbound.BaseHttpInboundEndpoint
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
Methods inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
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
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
HttpRequestHandlingEndpointSupport
public HttpRequestHandlingEndpointSupport()Construct a gateway that will wait for thereplyTimeout
for a reply; if the timeout is exceeded a '500 Internal Server Error' status code is returned. This can be modified using thestatusCodeExpression
. -
HttpRequestHandlingEndpointSupport
public HttpRequestHandlingEndpointSupport(boolean expectReply)Construct a gateway. If 'expectReply' is true it will wait for thereplyTimeout
for a reply; if the timeout is exceeded a '500 Internal Server Error' status code is returned. This can be modified using thestatusCodeExpression
. If 'false', a 200 OK status will be returned; this can also be modified usingstatusCodeExpression
.- Parameters:
expectReply
- true if a reply is expected from the downstream flow.- See Also:
MessagingGatewaySupport.setReplyTimeout(long)
,BaseHttpInboundEndpoint.setStatusCodeExpression(org.springframework.expression.Expression)
-
-
Method Details
-
setMessageConverters
Set the message body converters to use. These converters are used to convert from and to HTTP requests and responses.- Parameters:
messageConverters
- The message converters.
-
getMessageConverters
-
setMergeWithDefaultConverters
public void setMergeWithDefaultConverters(boolean mergeWithDefaultConverters)Flag which determines if the default converters should be available after custom converters.- Parameters:
mergeWithDefaultConverters
- true to merge, false to replace.
-
setMultipartResolver
Specify theMultipartResolver
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.- Parameters:
multipartResolver
- The multipart resolver.
-
onInit
protected void onInit()Locates theMultipartResolver
bean based on the default name defined by theDispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME
constant if available. Sets up default converters if no converters set, orsetMergeWithDefaultConverters(boolean)
was called with true after the converters were set.- Overrides:
onInit
in classBaseHttpInboundEndpoint
-
doHandleRequest
protected final Message<?> doHandleRequest(javax.servlet.http.HttpServletRequest servletRequest, RequestEntity<?> httpEntity)Handles the HTTP request by generating a Message and sending it to the request channel. If this gateway's 'expectReply' property is true, it will also generate a response from the reply Message once received.- Parameters:
servletRequest
- The servlet request.httpEntity
- the request entity to use.- Returns:
- The response Message.
-
setupResponseAndConvertReply
protected final Object setupResponseAndConvertReply(ServletServerHttpResponse response, Message<?> replyMessage)Converts the reply message to the appropriate HTTP reply object and sets up theServletServerHttpResponse
.- Parameters:
response
- The ServletServerHttpResponse.replyMessage
- The reply message.- Returns:
- The message payload (if
extractReplyPayload
) otherwise the message.
-
setStatusCodeIfNeeded
-
prepareRequest
protected ServletServerHttpRequest prepareRequest(javax.servlet.http.HttpServletRequest servletRequest)Prepares an instance ofServletServerHttpRequest
from the rawHttpServletRequest
. 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.- Parameters:
servletRequest
- current HTTP request- Returns:
- the processed request (multipart wrapper if necessary)
- See Also:
MultipartResolver.resolveMultipart(javax.servlet.http.HttpServletRequest)
-
prepareRequestEntity
protected RequestEntity<Object> prepareRequestEntity(ServletServerHttpRequest request) throws IOException- Throws:
IOException
-
extractRequestBody
- Throws:
IOException
-