大家好,有人可以帮助我如何使用JAXB向Spring MVC Controller发送发帖请求,我尝试了以下代码,但出现此错误:
org.jboss.resteasy.spi.InternalServerErrorException: Bad arguments passed to public java.lang.Object com.hraccess.jaxrs.resteasy.service.ServiceInfoRubis.ValidateInteresEnParties(java.lang.String,com.hraccess.jaxrs.resteasy.model.EntryZYX5) ( java.lang.String 7pjgQK5yhjQAvAe3Xpk07LktJxZR8yOXwLeNdPQtn60bNNWQBV2yjX07rOBkPbj8, org.jboss.resteasy.spi.BadRequestException org.jboss.resteasy.spi.BadRequestException: Could not find message body reader for type: class com.hraccess.jaxrs.resteasy.model.EntryZYX5 of content type: application/x-www-form-urlencoded )
在这部分中,我将请求发送到我的MVC控制器:
System.setProperty("javax.xml.bind.context.factory","org.eclipse.persistence.jaxb.JAXBContextFactory");
JAXBContext jaxbContext = null;
Reponse listInterPart = new Reponse();
try {
String host = env.getProperty("standard.webservices.url.services");
// String soccleMatcle_host = soccleMatcle.substring(0, 10);
String url = host + "/ServiceInfoRubis/validate_int_parties/" + vsid;
logger.info("Appel du webservice spécifique, url : " + url);
//String ss = new String("");
jaxbContext = JAXBContext.newInstance(EntryZYX5.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
java.io.StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(data, sw);
StringEntity params = new StringEntity(sw.toString());
Map<String, String> mapHeader = new HashMap<String, String>();
mapHeader.put("Accept-Language", "fr-FR");
mapHeader.put("Accept", "application/json; charset=UTF-8");
HttpResponse response = httpSerivce.post(mapHeader, url, params);
StringBuffer result = new StringBuffer();
if (response != null) {
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String line = "";
while ((line = rd.readLine()) != null) {
result.append(line);
}
}
这是我的控制器:
@POST
@Path("/validate_int_parties/{vsid}")
@Produces({"application/json; charset=UTF-8", "application/xml; charset=UTF-8"})
@RequestWrapper
public Object ValidateInteresEnParties(@PathParam("vsid") String vsid , @RequestBody EntryZYX5 data) {
IntersPart ii = new IntersPart();
ii.setFlag07("1");
/
return null;
}