| 
 controller代码如下:......
 @RequestMapping(value = "/verifyMessages",method = RequestMethod.POST)
 public String recieveMessages(@RequestBody InMessage inMessage)
 {
 System.out.println(inMessage.getCreateTime());
 System.out.println(inMessage.getMsgType());
 // System.out.println(text);
 return null;
 }
 .......
 InMessage 代码如下:
 @XStreamAlias("xml")
 public class InMessage {
 private String ToUserName; ......
 //定义了一些成员变量和set,get方法
 
 配置文件如下:
 .......
 <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
 p:messageConverters-ref="messageConverters"/>
 <util:list id="messageConverters"><!--<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
 <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
 <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
 <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
 -->
 <bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"
 p:marshaller-ref="xmlMarshaller"
 p:unmarshaller-ref="xmlMarshaller">
 </bean>
 </util:list>
 <!-- 声明Marshaller,使用XStream技术 -->
 <bean id="xmlMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"
 p:autodetectAnnotations="true">
 <property name="streamDriver">
 <bean class="com.thoughtworks.xstream.io.xml.StaxDriver"/>
 </property>
 <property name="annotatedClasses">
 <list>
 <value>models.entity.InMessage</value>
 </list>
 </property>
 </bean>
 ......
 curl测试语句如下:
 curl -H "Accept:application/xml" -H "Content-Type:application/xml" -d "<xml></xml>" http://localhost:8080/Weixin_CSS_IntelligentResponse/intelligentresponse/verifyMessages
 
 错误代码:HTTP Status 415
 错误原因: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
 
 xml解析jar包:xpp3_min-1.1.3.4.O.jar,xstream-1.4.5.jar
 public String recieveMessages(@RequestBody InMessage inMessage) 中的声明估计有问题, 服务器拒绝了这个请求,因为请求实体的格式不支持请求的请求的资源的方法。  |