Response entity is HttpUrlConnector and not what i set it to

1,102 views
Skip to first unread message

michael...@gmail.com

unread,
Oct 29, 2015, 11:53:38 AM10/29/15
to dropwizard-user
team,

here is my rest server code:


@POST
    @Path("/example3")
    @Consumes("application/json")
    @Produces({"application/json"})
    public Response example3(Example example) throws JsonProcessingException {
        try{
            example.setFoo("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
          System.out.println(example);
          ObjectMapper mapper = new ObjectMapper();
          mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        }catch(Exception e){
           
        }
      return  Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON).entity("FOOBAR").build();
    }


client code:

@Test
    public void postJerseyTest7() throws JsonParseException,
            JsonMappingException, IOException {
        ClientConfig config = new ClientConfig();

        Client client = ClientBuilder.newClient(config);

        WebTarget target = client.target("http://localhost:8080/hello-world");

        Example example = new Example(7, "foo");

        Response response = target
                .path("example3")
                .request()
                .accept(MediaType.APPLICATION_JSON)
                .post(Entity.entity(example, MediaType.APPLICATION_JSON),
                        Response.class);

        System.out.println("Response: " + response);
        System.out.println("entity: " + response.getEntity());


    }

yields:

Response: InboundJaxrsResponse{context=ClientResponse{method=POST, uri=http://localhost:8080/hello-world/example3, status=400, reason=Bad Request}}
entity: org.glassfish.jersey.client.internal.HttpUrlConnector$2@43a2dab4


why is my entity not FOOBAR?


many thanks,

mp

Michael Kidd

unread,
Nov 11, 2015, 6:51:05 AM11/11/15
to dropwizard-user
try response.readEntity(String.class);
Reply all
Reply to author
Forward
0 new messages