Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2002-2014 the original author or authors.
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package org.springframework.integration.http.inbound;
Inbound HTTP endpoint that implements Spring's org.springframework.web.servlet.mvc.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 extractReplyPayload (true by default, meaning just the payload). The corresponding key in the map is determined by the replyKey property (with a default of "reply").

Mark Fisher
Gary Russell
 	private static final String DEFAULT_ERROR_CODE = "spring.integration.http.handler.error";
 	private static final String DEFAULT_REPLY_KEY = "reply";
 	private static final String DEFAULT_ERRORS_KEY = "errors";
 	private volatile Expression viewExpression;
 	private volatile String replyKey = ;
 	private volatile String errorsKey = ;
 	private volatile String errorCode = ;
 	public HttpRequestHandlingController(boolean expectReply) {

Specify the view name.

viewName The view name.
 	public void setViewName(String viewName) {
 		Assert.isTrue(StringUtils.hasText(viewName), "View name must contain text");
 		this. = new LiteralExpression(viewName);

Specify the key to be used when adding the reply Message or payload to the core map (will be payload only unless the value of HttpRequestHandlingEndpointSupport.setExtractReplyPayload(boolean) is false). The default key is "reply".

replyKey The reply key.
 	public void setReplyKey(String replyKey) {
		this. = (replyKey != null) ? replyKey : ;

The key used to expose org.springframework.validation.Errors in the core, in the case that message handling fails. Defaults to "errors".

errorsKey The key value to set.
	public void setErrorsKey(String errorsKey) {
		this. = errorsKey;

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 a org.springframework.context.MessageSource. The default value is spring.integration.http.handler.error. Three arguments are provided: the exception, its message and its stack trace as a String.

errorCode The error code to set.
	public void setErrorCode(String errorCode) {
		this. = errorCode;

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,

viewExpression The view expression.
	public void setViewExpression(Expression viewExpression) {
		this. = viewExpression;
	protected void onInit() throws Exception {

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.
	public final ModelAndView handleRequest(HttpServletRequest servletRequestHttpServletResponse servletResponse)
			throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		try {
			Message<?> replyMessage = super.doHandleRequest(servletRequestservletResponse);
			if (replyMessage != null) {
				ServletServerHttpResponse response = new ServletServerHttpResponse(servletResponse);
				Object reply = setupResponseAndConvertReply(responsereplyMessage);
			if (this. != null) {
				Object view;
				if (replyMessage != null) {
					view = this..getValue(this.replyMessage);
				else {
				if (view instanceof View) {
				else if (view instanceof String) {
				else {
					throw new IllegalStateException("view expression must resolve to a View or String");
		catch (Exception e) {
			MapBindingResult errors = new MapBindingResult(new HashMap<StringObject>(), "dummy");
			PrintWriter stackTrace = new PrintWriter(new StringWriter());
			errors.reject(new Object[] { ee.getMessage(), stackTrace.toString() },
					"A Spring Integration handler raised an exception while handling an HTTP request.  The exception is of type "
e.getClass() + " and it has a message: (" + e.getMessage() + ")");
		return modelAndView;
New to GrepCode? Check out our FAQ X