dimanche 8 mars 2015

Spring WS: HttpMediaTypeNotAcceptableException: Could not find acceptable representation

I have the following Spring 4 WS controller:



@RestController
@RequestMapping("/ws/import")
@Scope("request")
public class ImportController {
private static final Logger log = LoggerFactory.getLogger(ImportController.class);
@Autowired private ContactsService contactsService;
@Autowired private User user;

@RequestMapping("/files")
@ResponseBody
public List<String> imports() {
return contactsService.getImportFiles();
}

@RequestMapping("/sample/{file}")
@ResponseBody
public Sample sample(@PathVariable("file") String file) {
log.debug("Sampling {}", file);
return new Sample(100);
}
}


All of my WS requests are working just fine, other than #sample. This is the only one that has both a path variable and a response body. For some reason it's throwing:



org.springframework.web.HttpMediaTypeNotAcceptableException:
Could not find acceptable representation


It's binding fine as I see the log message as expected. It's on the response that it's having issues.


Here's my .xml config:



<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<util:list value-type="java.lang.String">
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</util:list>
</property>
</bean>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>


It's driving me nuts!


1 commentaire: