Java 从RESTful服务检索ArrayList到Jersey客户端
我有2个项目文件夹。一个用于restful服务,一个用于客户端。 基本上,我的客户机将调用该服务并从特定用户的数据库中获取所有注释。(这些注释随后将显示在表格中) 这是我(目前)遇到的错误: 我已经解决了Java 从RESTful服务检索ArrayList到Jersey客户端,java,web-services,rest,jersey,jersey-client,Java,Web Services,Rest,Jersey,Jersey Client,我有2个项目文件夹。一个用于restful服务,一个用于客户端。 基本上,我的客户机将调用该服务并从特定用户的数据库中获取所有注释。(这些注释随后将显示在表格中) 这是我(目前)遇到的错误: 我已经解决了 org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo SEVERE: MessageBodyWriter not found for
org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=text/html, type=class java.util.ArrayList, genericType=java.util.List<inventory.Note>.
然后在my clients servlet中切换到以下行:
ClientResponse resp = webR.accept(MediaType.APPLICATION_XML/*"text/html"*/).post(ClientResponse.class, form);
@Path("/getAll")
@POST
@Consumes({MediaType.APPLICATION_FORM_URLENCODED})
public Response login(@FormParam("username") String uname) throws ClassNotFoundException, SQLException{
.
.
List<Note> note_AL = new ArrayList<Note>();
.
.
(Insert stuf into the array list)
.
.
GenericEntity<List<Note>> generic_list_of_notes = new GenericEntity<List<Note>>(note_AL){};
return Response.ok(generic_list_of_notes).build();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Form form = new Form();
form.add("username", "mike");
Client client = Client.create();
WebResource webR = client.resource("http://localhost:8080/MyNote/api/notes/getAll");
ClientResponse resp = webR.accept("text/html").post(ClientResponse.class, form);
//This get printed out (so maybe I have an extra error?
if (resp.getStatus() != 200){
System.err.println("Unable to connect to the RESTFUL web service");
}
//I get the error here
ArrayList<Model.Note> output = (ArrayList<Model.Note>) resp.getEntity(new GenericType<List<Model.Note>>(){});
//Don't know if this is correct. Haven't reached this step because of the above error:
request.setAttribute("note-all", resp.getEntity(ArrayList.class));
}
public class Note {
private int id;
private String title;
private String text;
private String color;
private String date;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=text/html, type=class java.util.ArrayList, genericType=java.util.List<inventory.Note>.
@Produces({MediaType.APPLICATION_XML})
ClientResponse resp = webR.accept(MediaType.APPLICATION_XML/*"text/html"*/).post(ClientResponse.class, form);