Сервер возвращает 406 HTTP-код при XML, но отлично работает в случае JSON. Ниже приведены фрагменты кода и прикрепленные журналы, а также:Spring + BlazeDS + REST XML-ответ
Библиотеки:
BlazeDS 4.0, Spring 3.2, JBoss 7.1.1Final, Maven 3,0
REST MVC контроллер:
@Controller
@RequestMapping("/contacts")
public class ContactsController {
@RequestMapping(method = RequestMethod.GET,produces= {"application/xml","application/json"})
@ResponseStatus(value=HttpStatus.OK)
public @ResponseBody List<Contact> find(@RequestParam(required = false) String searchStr) {
Конфигурация Весна:
@Configuration
@EnableWebMvc
public class Config extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(
ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_XML)
.mediaType("xml", MediaType.APPLICATION_XML)
.mediaType("json", MediaType.APPLICATION_JSON);
}
}
конфигурации Spring
<context:component-scan base-package="com.heksa.services"
use-default-filters="false">
<context:include-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
</context:component-scan>
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="defaultContentType" value="application/xml" />
<property name="mediaTypes">
<map>
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
</map>
</property>
</bean>
<bean id="xmlViewer"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.heksa.bean.Contact</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
<mvc:annotation-driven
content-negotiation-manager="contentNegotiationManager" />
<mvc:default-servlet-handler />
<!-- Flex-specific Configuration -->
<flex:message-broker mapping-order="1">
<flex:mapping pattern="/messagebroker/*" />
<flex:message-service
default-channels="my-streaming-amf,my-longpolling-amf,my-polling-amf" />
<flex:secured />
</flex:message-broker>
JBoss Журналы:
14:13:06,228 INFO [org.springframework.oxm.jaxb.Jaxb2Marshaller] (MSC service thread 1-8) Creating JAXBContext with classes to be bound [class com.heksa.bean.Contact]
14:13:06,241 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-8) Mapped "{[/contacts],methods=[GET],params=[],headers=[],consumes=[],produces=[application/xml || application/json],custom=[]}" onto public java.util.List<com.heksa.bean.Contact> com.heksa.services.ContactsController.find(java.lang.String)
14:13:06,241 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-8) Mapped "{[/contacts/{id}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void com.heksa.services.ContactsController.delete(int)
14:13:06,242 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-8) Mapped "{[/contacts],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public com.heksa.bean.Contact com.heksa.services.ContactsController.create(com.heksa.bean.Contact)
14:13:06,296 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (MSC service thread 1-8) Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'
Каков заголовок принимающего клиента в запросе? – Pedantic
Заголовки настроены правильно. Спасибо, что оставили комментарий. Теперь это исправлено. – Phani