我试图做一个RESTful Web服务来实现所有四个CRUD操作。我被困在“创建”中,因为我无法获取发布的数据。这是我写的方法。就像一个信息,我使用JAX-RS + JAXB XML的Jersey RI来序列化对象。REST风格的Java Web服务中POST方法的问题
这就是:
@POST
@Consumes("application/xml")
public Response createStudent(InputStream is) {
Student st = this.readStudent(is);
st.setUserId(idCounter.incrementAndGet());
studentDB.put(st.getUserId(), st);
System.out.println("Created student " + st.getUserId());
return Response.created(URI.create("/student/"+ st.getUserId())).build();
}
而且readStudent方法如下:
protected Student readStudent(InputStream is){
JAXBContext ctx;
Student st = null;
try {
String xml = is.toString();
System.out.println(xml);
ctx = JAXBContext.newInstance(Student.class);
st = (Student) ctx.createUnmarshaller().unmarshal(new StringReader(xml));
return st;
} catch (JAXBException e){
e.printStackTrace();
}
finally { return st; }
}
有人可以给我一些有关此轻?我用尽了每一个想法,使这个作品,没有任何工作!
在此先感谢。
嗯,尝试并在尝试卷曲URI时收到此消息: 找不到类型的消息正文阅读器:内容类型为com.esconn.domain.Student的类:application/xml – 2010-11-04 23:42:36