KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've created a rest api using Jersey/Jackson and it works well. I want to adjust my POST methods to receive a string token in addition to the POJO they are receiving as JSON. I've adjusted one of my methods like so: @POST @Path("/user") @Consumes(MediaType.APPLICATION_JSON) public Response createObject(User o, String token) { System.out.println("token: " + token); String password = Tools.encryptPassword(o.getPassword()); o.setPassword(password); String response = DAL.upsert(o); return Response.status(201).entity(response).build(); } I want to call that method, but for whatever reason token prints to null no matter what I try. Here is the client code I've written to send the post request: public String update() { try { com.sun.jersey.api.client.Client daclient = com.sun.jersey.api.client.Client .create(); WebResource webResource = daclient .resource("http://localhost:8080/PhizzleAPI/rest/post/user"); User c = new User(id, client, permission, reseller, type, username, password, name, email, active, createddate, lastmodifieddate, token, tokentimestamp); JSONObject j = new JSONObject(c); ObjectMapper mapper = new ObjectMapper(); String request = mapper.writeValueAsString(c) + "&{''token'':,''" + "dog" + "''}"; System.out.println("request:" + request); ClientResponse response = webResource.type("application/json") .post(ClientResponse.class, request); if (response.getStatus() != 201) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } System.out.println("Output from Server .... \n"); String output = response.getEntity(String.class); setId(UUID.fromString(output)); System.out.println("output:" + output);
Tags (comma-separated)
Save Edits
Cancel