This is driving me nuts. I have a simple spring app with just a servlet context file configured like this:
<context:component-scan base-package="au.com.mypackage.service" />
<context:annotation-config />
<mvc:annotation-driven />
And a simple controller:
@Controller
public class MyController {
@RequestMapping(value = "/data/{id}", method=RequestMethod.GET)
@ResponseBody public Bean getData(@PathVariable String id) {
Bean bean = new Bean();
bean.setSomething(开发者_运维百科"hello");
bean.setSomethingElse(5);
return bean;
}
Which makes use of message converters to do it's work. I then submit this request from SoapUI:
GET http://localhost:8080/spring/data/123 HTTP/1.1
Accept-Encoding: gzip,deflate
Accept: application/json
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost:8080
And it appears to work ok. BUT, when I look in the tomcat logs I see that the controller is called twice. This is ok for JSON. But when I switch to requesting XML it goes horribly wrong. The second request (which should not happen anyway) triggers as massive error in XStream because of socket closures, etc.
The root of the problem is the calling of the controller twice. Does anyone know why this would be happening?
Solved it. The problem seems to be SoapUI. I switched to WizTools RESTClient and the double calls stopped. I don't know why SoapUI was doing this, although I got the impression the second call was always for XML regardless of what the first call was for.
精彩评论