Class HttpRequestHandlingEndpointSupport

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
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.OrderlyShutdownCapable, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationInboundManagement, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.ManageableSmartLifecycle, org.springframework.integration.support.management.TrackableComponent
Direct Known Subclasses:
HttpRequestHandlingController, HttpRequestHandlingMessagingGateway

public abstract class HttpRequestHandlingEndpointSupport
extends BaseHttpInboundEndpoint
Base class for HTTP request handling endpoints.

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 HttpMessageConverters. 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
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.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

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors 
    Constructor 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.
  • Method Summary

    Modifier and Type Method Description
    protected org.springframework.messaging.Message<?> doHandleRequest​(javax.servlet.http.HttpServletRequest servletRequest, org.springframework.http.RequestEntity<?> httpEntity)
    Handles the HTTP request by generating a Message and sending it to the request channel.
    protected java.lang.Object extractRequestBody​(org.springframework.http.server.ServletServerHttpRequest request)  
    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.
    protected org.springframework.http.server.ServletServerHttpRequest prepareRequest​(javax.servlet.http.HttpServletRequest servletRequest)
    Prepares an instance of ServletServerHttpRequest from the raw HttpServletRequest.
    protected org.springframework.http.RequestEntity<java.lang.Object> prepareRequestEntity​(org.springframework.http.server.ServletServerHttpRequest request)  
    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, org.springframework.http.HttpEntity<?> httpEntity)  
    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.

    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

  • Method Details

    • setMessageConverters

      public void setMessageConverters​(java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> messageConverters)
      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

      protected java.util.List<org.springframework.http.converter.HttpMessageConverter<?>> 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

      public void setMultipartResolver​(org.springframework.web.multipart.MultipartResolver multipartResolver)
      Specify the 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.
      Parameters:
      multipartResolver - The multipart resolver.
    • onInit

      protected void onInit()
      Locates the 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.
      Overrides:
      onInit in class BaseHttpInboundEndpoint
    • doHandleRequest

      protected final org.springframework.messaging.Message<?> doHandleRequest​(javax.servlet.http.HttpServletRequest servletRequest, org.springframework.http.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 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.
      Parameters:
      response - The ServletServerHttpResponse.
      replyMessage - The reply message.
      Returns:
      The message payload (if extractReplyPayload) otherwise the message.
    • setStatusCodeIfNeeded

      protected void setStatusCodeIfNeeded​(org.springframework.http.server.ServerHttpResponse response, org.springframework.http.HttpEntity<?> httpEntity)
    • prepareRequest

      protected org.springframework.http.server.ServletServerHttpRequest prepareRequest​(javax.servlet.http.HttpServletRequest servletRequest)
      Prepares an instance of 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.
      Parameters:
      servletRequest - current HTTP request
      Returns:
      the processed request (multipart wrapper if necessary)
      See Also:
      MultipartResolver.resolveMultipart(javax.servlet.http.HttpServletRequest)
    • prepareRequestEntity

      protected org.springframework.http.RequestEntity<java.lang.Object> prepareRequestEntity​(org.springframework.http.server.ServletServerHttpRequest request) throws java.io.IOException
      Throws:
      java.io.IOException
    • extractRequestBody

      protected java.lang.Object extractRequestBody​(org.springframework.http.server.ServletServerHttpRequest request) throws java.io.IOException
      Throws:
      java.io.IOException