开发者

apache wink jettison

Using Jettison provider.

 public Set getClasses() {
  Set s = new HashSet();
  s.add(DatabaseResource.class);
  return s;
  }
  public Set<Object> getSingletons() {
  Set s = new HashSet();
  JettisonJAXBProvider jaxbProvider = new JettisonJAXBProvider();
  jaxbProvider.setUseAsReader(true);
  jaxbProvider.setUseAsWriter(true);
  return s;
  }

Server Code:

 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public Book post(Book inMessage) {
  System.out.println("entered post method");
      Book outMessage = new Book();
      outMessage.setAuthur("Shiva:"+inMessage.getAuthur());
      outMessage.setBookId("500");
      outMessage.setBookName("SHIVA THE GREAT");

      return outMessage;

 }

Client Code:

Resource resource = client.resource("http://localhost:8080/CoeeServer/rest/book");

  Book book = new Book();
        book.setAuthur("author--Shiva.");
        book.setBookId("500");
        book.setBookName("Shiva the great");




        Book response1  = resource.contentType(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(Book.class,book);

Is this the right way to call? Can anyone has any suggestions.


I am getting the following error.

No javax.ws.rs.ext.MessageBodyWriter found 开发者_如何学Gofor type {0} and media type {1}. Verify that all entity providers are correctly registered.


I solved my problem . Problem was with jaxb annotations just replaced with @XmlRootElement. This may help other so posting my my solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜