I have a web-service:
@Path("/")
@RequestScoped
public class RegistrationService implements Serializable {
@Inject
private DeviceService deviceService;
@PUT
@Path( "/register/{device}" )
@Consumes( MediaType.TEXT_PLAIN )
@Produces( MediaType.TEXT_PLAIN )
public String device(@PathParam("device") String device) {
this.deviceService.saveNewDevice(device);
return "Succesful!";
}
}
And I have a restlet:
public void sendRegistration() {
ClientResource resource = new ClientResource(REG_URL);
resource.addSegment(ctx.getString(R.string.config_segment_register));
... (?)
}
So the current URL will be something like http:// host:port/application/ws/register/pathParam
How can I do the PUT-call to the web-service? There are methods to add queryParams and I could do addSegment to append the ID to the path, but somehow I need to do the PUT then.
Due to unfortunately not getting to work (maybe because of too little knowledge about/understanding of the API and processing) the suggestion by @Caleryn, I made some similar solution to https://stackoverflow.com/a/735090/1343241
@Path("/")
@RequestScoped
public class RegistrationService implements Serializable {
@Inject
private DeviceService deviceService;
@PUT
@Path( "/register" )
@Consumes( MediaType.APPLICATION_FORM_URLENCODED )
@Produces( MediaType.TEXT_PLAIN )
public String device(@FormParam("regId") String regId) {
this.deviceService.saveNewDevice(regId);
return "Succesful!";
}
}
And in the restlet:
Form queryParams = resource.getReference().getQueryAsForm();
queryParams.set("regId", regId);
resource.put(queryParams);