Class HttpRequestHandlingController
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.gateway.MessagingGatewaySupport
org.springframework.integration.http.inbound.BaseHttpInboundEndpoint
org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport
org.springframework.integration.http.inbound.HttpRequestHandlingController
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Phased
,SmartLifecycle
,ComponentSourceAware
,ExpressionCapable
,OrderlyShutdownCapable
,IntegrationPattern
,NamedComponent
,IntegrationInboundManagement
,IntegrationManagement
,ManageableLifecycle
,ManageableSmartLifecycle
,TrackableComponent
,Controller
public class HttpRequestHandlingController
extends HttpRequestHandlingEndpointSupport
implements Controller
Inbound HTTP endpoint that implements Spring's
Controller
interface to be used with a DispatcherServlet front
controller.
The viewName
will be passed into the ModelAndView return value.
This endpoint will have request/reply behavior by default. That can be overridden by passing false
to
the constructor. In the request/reply case, the core map will be passed to the view, and it will contain either the
reply Message or payload depending on the value of BaseHttpInboundEndpoint.setExtractReplyPayload(boolean)
(true by default, meaning just the payload).
The corresponding key in the map is determined by the replyKey
property (with a default of "reply").
- Since:
- 2.0
- Author:
- Mark Fisher, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
MessagingGatewaySupport.ConvertingMessagingTemplate
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The View model key for the error code.static final String
The View model key for errors.static final String
The View model key for reply.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
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal ModelAndView
handleRequest
(HttpServletRequest servletRequest, HttpServletResponse servletResponse) Handles the HTTP request by generating a Message and sending it to the request channel.protected void
onInit()
Locates theMultipartResolver
bean based on the default name defined by theDispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME
constant if available.void
setErrorCode
(String errorCode) The error code to use to signal an error in the message handling.void
setErrorsKey
(String errorsKey) The key used to exposeErrors
in the core, in the case that message handling fails.void
setReplyKey
(String replyKey) Specify the key to be used when adding the reply Message or payload to the core map (will be payload only unless the value ofBaseHttpInboundEndpoint.setExtractReplyPayload(boolean)
isfalse
).void
setViewExpression
(Expression viewExpression) Specifies a SpEL expression to evaluate in order to generate the view name.void
setViewName
(String viewName) Specify the view name.Methods inherited from class org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport
doHandleRequest, extractRequestBody, getMessageConverters, prepareRequest, prepareRequestEntity, setMergeWithDefaultConverters, setMessageConverters, setMultipartResolver, setStatusCodeIfNeeded, setupResponseAndConvertReply
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, getErrorMessageStrategy, getManagedName, getManagedType, getOverrides, getReplyChannel, getRequestChannel, isLoggingEnabled, isObserved, receive, receive, receiveMessage, receiveMessage, registerMetricsCaptor, registerObservationRegistry, registerReplyMessageCorrelatorIfNecessary, send, sendAndReceive, sendAndReceiveMessage, sendAndReceiveMessageReactive, sendTimer, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setErrorOnTimeout, setLoggingEnabled, setManagedName, setManagedType, setObservationConvention, setReceiverObservationConvention, 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, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, 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
-
Field Details
-
DEFAULT_ERROR_CODE
The View model key for the error code.- See Also:
-
DEFAULT_REPLY_KEY
The View model key for reply.- See Also:
-
DEFAULT_ERRORS_KEY
The View model key for errors.- See Also:
-
-
Constructor Details
-
HttpRequestHandlingController
public HttpRequestHandlingController() -
HttpRequestHandlingController
public HttpRequestHandlingController(boolean expectReply)
-
-
Method Details
-
setViewName
Specify the view name.- Parameters:
viewName
- The view name.
-
setReplyKey
Specify the key to be used when adding the reply Message or payload to the core map (will be payload only unless the value ofBaseHttpInboundEndpoint.setExtractReplyPayload(boolean)
isfalse
). The default key is "reply".- Parameters:
replyKey
- The reply key.
-
setErrorsKey
The key used to exposeErrors
in the core, in the case that message handling fails. Defaults to "errors".- Parameters:
errorsKey
- The key value to set.
-
setErrorCode
The error code to use to signal an error in the message handling. In the case of an error this code will be provided in an object error to be optionally translated in the standard MVC way using aMessageSource
. The default value isspring.integration.http.handler.error
. Three arguments are provided: the exception, its message and its stack trace as a String.- Parameters:
errorCode
- The error code to set.
-
setViewExpression
Specifies a SpEL expression to evaluate in order to generate the view name. The EvaluationContext will be populated with the reply message as the root object,- Parameters:
viewExpression
- The view expression.
-
onInit
protected void onInit()Description copied from class:HttpRequestHandlingEndpointSupport
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, orHttpRequestHandlingEndpointSupport.setMergeWithDefaultConverters(boolean)
was called with true after the converters were set.- Overrides:
onInit
in classHttpRequestHandlingEndpointSupport
-
handleRequest
public final ModelAndView handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) 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.- Specified by:
handleRequest
in interfaceController
-