Reputation: 784
I configure the RESTFul API in JPOS from jpos-rest.pdf.
The problem is I couldn't receive data from the client, but I can send data to the client.
In Echo.java
class by below code I can send data:
package org.jpos.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Map;
@Path("/echo")
public class Echo {
@GET
@Produces({MediaType.APPLICATION_JSON})
public Response echoGet() {
Map<String, Object> resp = new HashMap<>();
resp.put("success", "true");
resp.put("Name", "Hamid");
resp.put("Family", "Mohammadi");
Response.ResponseBuilder rb = Response.ok(resp, MediaType.APPLICATION_JSON).status(Response.Status.OK);
return rb.build();
}
}
How can I receive data from the client? There is no request parameter to find what is the request and its data;
Upvotes: 1
Views: 1101
Reputation: 784
Thanks to @Sabir Khan I changed the code to:
@Path("/echo")
public class Echo {
@PUT
@Produces({MediaType.APPLICATION_JSON})
@Consumes(MediaType.TEXT_PLAIN)
@Path("/{name}/{family}")
public Response echoGet(
@PathParam("name") String name,
@PathParam("family") String family,
String Desc
) {
Map<String, Object> resp = new HashMap<>();
resp.put("success", "true");
resp.put("Name", name);
resp.put("Family", family);
resp.put("Desc", Desc);
Response.ResponseBuilder rb = Response.ok(resp,
MediaType.APPLICATION_JSON).status(Response.Status.OK);
return rb.build();
}
}
and send data to RESTFul API like this:
Upvotes: 1