
|
If you were logged in you would be able to see more operations.
|
|
|
|
Environment:
|
Nightly Build of 2.5.2 - 2/16
|
|
|
The below test case (created after experiencing the problem in a full blown app) contains two methods - one annotated @RequestMapping, the second @RequestMapping( method=RequestMethod.POST) - this is causing requests for the first method to be incorrectly dispatched to the second method.
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
public class SpringAnnotationMethodHandlerAdapterParameterTest extends TestCase
{
public void testSingleMethod() throws Exception
{
executeTest( "/foo/handleBill?", new MultiMethodController() );
executeTest( "/foo/generateFromReconciliation", new MultiMethodController() );
}
private void executeTest( String url, Object handler ) throws Exception
{
AnnotationMethodHandlerAdapter amha = new AnnotationMethodHandlerAdapter();
MockHttpServletRequest request = new MockHttpServletRequest( "POST", url );
request.addParameter( "data", "foo" );
HttpServletResponse response = new MockHttpServletResponse();
amha.handle( request, response, handler );
}
@Controller
@RequestMapping( value = { "/foo/*", "/bar/*" }, method = RequestMethod.POST )
public static class MultiMethodController
{
@RequestMapping
public void handleBill( @RequestParam( "data" )
String data, PrintWriter out ) throws Exception
{
System.out.println( "handleBill" );
}
@RequestMapping( method = RequestMethod.POST )
public void generateFromReconciliation( @RequestParam( "data" )
String data ) throws Exception
{
System.out.println( "generateFromReconciliation" );
}
}
}
|
|
Description
|
The below test case (created after experiencing the problem in a full blown app) contains two methods - one annotated @RequestMapping, the second @RequestMapping( method=RequestMethod.POST) - this is causing requests for the first method to be incorrectly dispatched to the second method.
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
public class SpringAnnotationMethodHandlerAdapterParameterTest extends TestCase
{
public void testSingleMethod() throws Exception
{
executeTest( "/foo/handleBill?", new MultiMethodController() );
executeTest( "/foo/generateFromReconciliation", new MultiMethodController() );
}
private void executeTest( String url, Object handler ) throws Exception
{
AnnotationMethodHandlerAdapter amha = new AnnotationMethodHandlerAdapter();
MockHttpServletRequest request = new MockHttpServletRequest( "POST", url );
request.addParameter( "data", "foo" );
HttpServletResponse response = new MockHttpServletResponse();
amha.handle( request, response, handler );
}
@Controller
@RequestMapping( value = { "/foo/*", "/bar/*" }, method = RequestMethod.POST )
public static class MultiMethodController
{
@RequestMapping
public void handleBill( @RequestParam( "data" )
String data, PrintWriter out ) throws Exception
{
System.out.println( "handleBill" );
}
@RequestMapping( method = RequestMethod.POST )
public void generateFromReconciliation( @RequestParam( "data" )
String data ) throws Exception
{
System.out.println( "generateFromReconciliation" );
}
}
}
|
Show » |
|