2013-07-26 3 views
0

서버 스텁

@GET 
    @Path("/user/{id}") 
    @Produces(MediaType.APPLICATION_JSON) 
    public User getUser(@PathParam("id") String id){ 
     User user = myService.getUserById(id); 
     if (user!= null){ 
      return user; 
     } 
     return null; 
    } 

을 ========================== ==== 클라이언트아파치 윙크 서버 스텁는 null, 나머지 클라이언트 던져 예외

User response = WinkRestClient.resource(path).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).get(User.class); 

던져 예외 스텁 :

서버 스텁는 null는, 클라이언트가이 예외를 슬로우
Exception in thread "main" java.lang.RuntimeException: A javax.ws.rs.ext.MessageBodyReader implementation was not found for class com.test.entity.User type and application/octet-stream media type. Verify that all entity providers are correctly registered. Add a custom javax.ws.rs.ext.MessageBodyReader provider to handle the type and media type if a JAX-RS entity provider does not currently exist. 
    at org.apache.wink.client.internal.handlers.ClientResponseImpl.readEntity(ClientResponseImpl.java:122) 
    at org.apache.wink.client.internal.handlers.ClientResponseImpl.getEntity(ClientResponseImpl.java:65) 
    at org.apache.wink.client.internal.handlers.ClientResponseImpl.getEntity(ClientResponseImpl.java:52) 
    at org.apache.wink.client.internal.ResourceImpl.invoke(ResourceImpl.java:196) 
    at org.apache.wink.client.internal.ResourceImpl.get(ResourceImpl.java:303) 
    at com.wolianw.sale.bl.ClResourceTest.main(ClResourceTest.java:14) 

클라이언트가 예외를 발생시키지 않도록 할 수있는 대답은 다음과 같습니다. [User = null]

답변

0

오류와 정확히 일치해야합니다. MediaType.APPLICATION_OCTET_STREAM에 대한 MessageBodyReader를 만듭니다.

응답에 페이로드가 없으며 null을 반환하는 경우 클라이언트는 요청에 설정 한 헤더를 허용하는 것과 상관없이 MediaType.APPLICATION_OCTET_STREAM에 등록 된 공급자를 찾고 있으며 응답의 실제 헤더는 무엇입니까? .

이 동작이 마음에 들지 않으면 Jersey 클라이언트를 사용할 수 있습니다.