Hi I am trying to consume a REST endpoint using POST, but I am getting the error below. The endpoint gives proper response in POSTMAN, but I am getting error in Java. Please let me know where the mistake is.
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request: [{
"error":"unsupported_grant_type",
"error_description":"The given grant_type is not supported"
}]] with root cause
org.springframework.web.client.HttpClientErrorException$BadRequest: 400 Bad Request: [{
"error":"unsupported_grant_type",
"error_description":"The given grant_type is not supported"
}]
Below is code:
Controller:
public class MemberController {
private static final Logger log = LoggerFactory.getLogger(MemberController.class);
#Autowired
MemberService memberService;
#PostMapping(value = "/token", headers = "Accept=application/json")
public String getToken() {
log.info("Test getToken method");
return memberService.callTokenService();
}
Service Class:
public class MemberService {
private static final Logger log = LoggerFactory.getLogger(MemberService.class);
private RestTemplate restTemplate = new RestTemplate();
final String tokenURL = "-------";
public String callTokenService() {
log.info("Inside Service");
TokenInput input = new TokenInput();
String clientId = "l7xxef159fc30ee8479e9a7dab859c458a4d";
String clientSecret = "a63d0b4a01b844c0b7e7eb724ef13959";
String grantType = "client_credentials";
input.setCLIENT_ID(clientId);
input.setCLIENT_SECRET(clientSecret);
input.setGRANT_TYPE(grantType);
ResponseEntity<TokenProperties> response = restTemplate.postForEntity(tokenURL, input, TokenProperties.class);
HttpStatus status = response.getStatusCode();
log.info("Status: "+status);
log.info("Response: "+response.toString());
return response.toString();
}
}
POJO class:
#JsonIgnoreProperties(ignoreUnknown = true)
public class TokenProperties {
String access_token;
String token_type;
String expires_in;
String scope;
public String getAccess_token()
{
return access_token;
}
public void setAccess_token(String access_token)
{
this.access_token = access_token;
}
public String getToken_type()
{
return token_type;
}
public void setToken_type(String token_type)
{
this.token_type = token_type;
}
public String getExpires_in()
{
return expires_in;
}
public void setExpires_in(String expires_in)
{
this.expires_in = expires_in;
}
public String getScope()
{
return scope;
}
public void setScope(String scope)
{
this.scope = scope;
}
#Override
public String toString() {
return "{" + "access_token='" + access_token + '\'' + ", token_type=" + token_type + ", expires_in=" + expires_in + '\'' + "scope='" + scope + '}';
}
}
TokenInput POJO:
package com.memberservice_v2;
public class TokenInput {
String CLIENT_ID;
String CLIENT_SECRET;
String GRANT_TYPE;
public String getCLIENT_ID() {
return CLIENT_ID;
}
public void setCLIENT_ID(String cLIENT_ID) {
CLIENT_ID = cLIENT_ID;
}
public String getCLIENT_SECRET() {
return CLIENT_SECRET;
}
public void setCLIENT_SECRET(String cLIENT_SECRET) {
CLIENT_SECRET = cLIENT_SECRET;
}
public String getGRANT_TYPE() {
return GRANT_TYPE;
}
public void setGRANT_TYPE(String gRANT_TYPE) {
GRANT_TYPE = gRANT_TYPE;
}
}
Can anyone please help me out? Please let me know where the mistake is. Thanks in Advance!
Your request ResponseEntity<TokenProperties> response = restTemplate.postForEntity(tokenURL, null, TokenProperties.class); to token endpoint is incomplete. You're not passing the payload (token request) as far as I can see in the aforementioned code.
First, create the token request and set the appropriate attributes such as client id, grant type etc.
TokenRequest tokenRequest = new TokenRequest();
// set the attributes as per the token endpoint
ResponseEntity<TokenProperties> response = restTemplate.postForEntity(tokenURL, tokenRequest, TokenProperties.class);
Related
Got myself stuck in following problem: previously I had a single regexp to check MSISDN and it looked like this: (380)[0-9]{9}. It worked like a charm but change request came in and I had to split it into two parts - first to check if the string start with 380 and the second one to check if it contains only digits and contains 12 characters. For some reason it doesn't work and fails during test on totally valid MSISDN: 380671112233. I've tried googling thing like regexp which check strating characters ^ but all my experiments failed. Can anybody suggest what am I doing wrong ? Thanks in advance!
#Slf4j
#Validated
#RestController
#RequiredArgsConstructor
#RequestMapping(InfoController.INFO_ENDPOINT )
public class InfoController {
public static final String INFO_ENDPOINT = "/info";
private final InfoService service;
#GetMapping(value = "/{msisdn}")
#ResponseBody
public InfoResponse getInfo(
#Pattern.List({
#Pattern(regexp = "(380)", message = "MSISDN_INCORRECT"),
#Pattern(regexp = "[0-9]{12}", message = "MSISDN_OUT_OF_RANGE")
})
#PathVariable("msisdn") String msisdn,
#RequestParam("cid") String cid) {
log.info("[{}] get information for msisdn {}", cid, msisdn);
InfoResponse response = service.getInfo(msisdn, cid);
log.info("[{}] successful response for msisdn {} - {}", cid, msisdn, response);
return response;
}
}
My test setup
private static final String CID = "123-aaa-bbb-312";
public static final String MSISDN = "380671122333";
public static final String NAME = "PP AA";
public static final long ID = 476561L;
public static final int DISTANCE = 69;
#Autowired
private MockMvc mockMvc;
#MockBean
private InfoService service;
#Test
#DisplayName("Valid request. Expected: valid response")
public void testController1() throws Exception {
InfoResponse response = new InfoResponse(MSISDN, NAME, ID, DISTANCE);
when(service.getInfo(any(), any())).thenReturn(response);
String request = UriComponentsBuilder
.fromPath(InfoController.INFO_ENDPOINT)
.pathSegment(MSISDN)
.queryParam("cid", CID)
.build().toString();
mockMvc.perform(get(request))
.andDo(print())
.andExpect(content().json(
"{\"param1\":\"" + MSISDN + "\"" +
",\"param2\":\"" + NAME + "\"" +
",\"param3\":" + ID +
",\"param4\":" + DISTANCE + "}"
))
.andExpect(status().isOk());
}
I am working on a java server which is sending Firebase Cloud Messaging notification to devices using OAUTH 2.0 authentication.
According to guide (https://firebase.google.com/docs/cloud-messaging/auth-server?authuser=0) I have generated key from an account service with editor role, but I keep getting 403 SENDER_ID_MISMATCH error.
Any suggestion?
public class FcmManager {
private static final String DEVICE_NOTIFICATION_URL = "https://fcm.googleapis.com/v1/projects/myprojectid/messages:send";
private static final String JSON_STR_DEVICE_NOTIFICATION = "{\"message\":{\"token\" : " +"\"%s\"" + ",\"notification\" : " +
"{\"body\" : \"%s\",\"title\" : \"%s\"}}}";
public static boolean sendNotificationDevice(DeviceNotification deviceNotification, String msgTitle,
String msgBody) throws Exception{
String accessToken = getAccessToken();
System.out.println(msgBody);
String jsonStr = String.format(JSON_STR_DEVICE_NOTIFICATION, deviceNotification.getToken()
,msgBody,msgTitle);
System.out.println(jsonStr);
F.Promise<String> response = WS.url(DEVICE_NOTIFICATION_URL)
.setContentType("application/json").setHeader("Authorization","Bearer " +
accessToken).post(jsonStr).map(
new F.Function<WS.Response, String>() {
public String apply(WS.Response response) {
String result = response.getBody();
System.out.println(result);
return result;
}
}
);
return true;
}
private static String getAccessToken() throws IOException {
GoogleCredential googleCredential = GoogleCredential
.fromStream(new FileInputStream("mygeneratedkeyfromaccountservice.json"))
.createScoped(Arrays.asList("https://www.googleapis.com/auth/firebase.messaging"));
googleCredential.refreshToken();
return googleCredential.getAccessToken();
}
}
Java JAX-RS web service with Jersey / Jackson, a service method expects a User parameter (POJO) as JSON. The client app (Angular 6) sends a POST request containing the User parameter (serialized as JSON). The service method call fails with error message: "Unrecognized token 'jsonUser': was expecting ('true', 'false' or 'null')".
Here is the User class (POJO) - you can see I tried annotating all the properties with #JsonProperty, but it's unnecessary, as I'm not "renaming" them:
import java.io.Serializable;
import javax.ws.rs.FormParam;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
//import org.glassfish.jersey.media.multipart.FormDataParam;
/**
* JavaBean for passing the User properties between the UI app (Angular)
* and TearsWs. Implementation requires this to be serializable (JSON).
*/
#JsonIgnoreProperties({ "DELIM" })
public class User implements Serializable {
private String userName;
private String employeeId;
private String employeeName;
private String homeUnitCode;
private boolean certifier;
private HomeUnit[] tkHomeUnits;
private boolean supervisor;
private Employee[] whoISupervise;
private boolean hrStaff;
private boolean collector;
private final static String DELIM = ", ";
public User() {
}
// getters / setters
//#JsonProperty("userName")
public void setUserName(String ldapUid) {
this.userName = ldapUid;
}
public String getUserName() {
return this.userName;
}
//#JsonProperty("employeeId")
public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}
public String getEmployeeId() {
return this.employeeId;
}
//#JsonProperty("employeeName")
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
public String getEmployeeName() {
return this.employeeName;
}
//#JsonProperty("homeUnitCode")
public void setHomeUnitCode(String homeUnitCode) {
this.homeUnitCode = homeUnitCode;
}
public String getHomeUnitCode() {
return this.homeUnitCode;
}
//#JsonProperty("certifier")
public void setCertifier(boolean certifier) {
this.certifier = certifier;
}
public boolean getCertifier() {
return this.certifier;
}
//#JsonProperty("tkHomeUnits")
public void setTkHomeUnits(HomeUnit[] tkHomeUnitCodes) {
this.tkHomeUnits = tkHomeUnitCodes;
}
public HomeUnit[] getTkHomeUnits() {
return this.tkHomeUnits;
}
//#JsonProperty("supervisor")
public void setSupervisor(boolean supervisor) {
this.supervisor = supervisor;
}
public boolean isSupervisor() {
return this.supervisor;
}
//#JsonProperty("whoISupervise")
public void setWhoISupervise(Employee[] whoISupervise) {
this.whoISupervise = whoISupervise;
}
public Employee[] getWhoISupervise() {
return this.whoISupervise;
}
//#JsonProperty("hrStaff")
public void setHrStaff(boolean hrStaff) {
this.hrStaff = hrStaff;
}
public boolean isHrStaff() {
return this.hrStaff;
}
//#JsonProperty("collector")
public void setCollector(boolean collector) {
this.collector = collector;
}
public boolean isCollector() {
return this.collector;
}
//methods
public boolean hasTauthority() {
return this.certifier || this.collector;
}
public String toString() {
int tkHUs = (tkHomeUnits == null) ? 0 : tkHomeUnits.length;
return "[User: "
+ "userName=" + this.userName + DELIM
+ "employeeId=" + this.employeeId + DELIM
+ "employeeName=" + this.employeeName + DELIM
+ "homeUnitCode=" + this.homeUnitCode + DELIM
+ "certifier=" + this.certifier + DELIM
+ "hrStaff=" + this.hrStaff + DELIM
+ "collector=" + this.collector + DELIM
+ "I can certify " + tkHUs + " homeUnits" + "]";
}
}
Here is the (Java) service method, which should accept and process the POST request:
/**
* Web service method.
*/
#POST
#Path("getTkHomeUnitEmployees")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response getTkHomeUnitEmployees(User user, #HeaderParam("X-Request-Param") String homeUnitCode) throws Exception {
String exceptionMessage;
if (user == null) {
exceptionMessage = "getTkHomeUnitEmployees() received a null User.";
log.error(exceptionMessage);
Response response = Response
.status(500)
.entity(exceptionMessage)
.build();
return response;
}
if (homeUnitCode == null || homeUnitCode.equals("")) {
exceptionMessage = "getTkHomeUnitEmployees() received a null HomeUnitCode.";
log.error(exceptionMessage);
Response response = Response
.status(500)
.entity(exceptionMessage)
.build();
return response;
}
if (!user.hasTauthority()) {
exceptionMessage = "getTkHomeUnitEmployees() received a request from a non-timekeeper and non-collector.";
log.error(exceptionMessage);
Response response = Response
.status(500)
.entity(exceptionMessage)
.build();
return response;
}
try {
Employee[] tkHomeUnitEmployees = new SecurityDao().getTkHomeUnitEmployees(user.getEmployeeId(), homeUnitCode);
Response response = Response
.ok(tkHomeUnitEmployees)
.header("Access-Control-Allow-Origin", "*")
.build();
return response;
} catch (Exception ex) {
exceptionMessage = "getTkHomeUnitEmployees(): " + ex;
Response response = Response
.status(500)
.entity(exceptionMessage)
.build();
return response;
}
}
The User object (client side, Javascript) is converted to JSON and encapsulated as a parameter in HttpParams; the POST passes it in the body of the request.
Here is the (Angular) client method, which sends the POST request to the web service:
getTkHomeUnitEmployees(user: User, homeUnitCode: string): Observable<Employee[]> {
const headers = new HttpHeaders()
.set('Content-Type', 'application/json')
.set('X-Request-Param', homeUnitCode); // homeUnitCode parameter in HttpHeaders
const httpOptions = {
headers: headers
};
let jsonUser: string = JSON.stringify(user);
const httpParams = new HttpParams()
.set('jsonUser', jsonUser);
let postUrl = this.wsUrl + 'getTkHomeUnitEmployees';
//postUrl += '?homeUnitCode=' + homeUnitCode; // homeUnitCode parameter as QueryParam
let obsArrayEmployees: Observable<Employee[]> = this.httpClient.post<Employee[]>(postUrl, httpParams, httpOptions);
return obsArrayEmployees;
}
...here I'm debugging the client (# browser Dev Tools), with a break in the getTkHomeUnitEmployees() method:
...I've displayed the value of jsonUser in the Console:
...here is the error in the Response:
...and here is the Request Params.
So, it appears the Jackson JsonParser is attempting to read and parse the parameter sent in the request, but the parameter includes "jsonUser=" at the beginning as part of it's value (json to be parsed). This is clearly wrong...
The service method blows up before actually entering / processing code; I can't set a breakpoint within the service method to examine the value of the parameter. It behaves as a "parameter invalid, return to caller" response.
I thought to manually hack the "jsonUser=" out of it (# client side), but it's not there. At the client, "jsonUser=" is not part of the parameter value; I believe it's just the key=value syntax of an http parameter (parameter-name=parameter-value), perhaps it's being prepended when the parameter is encapsulated into the HttpParams object.
Obviously I'm doing something wrong, but I haven't been able to figure it out; I thought this was the correct way to do this, but apparently not. Hope someone can help soon, I've been stuck on this for a couple days already.
You don't need to covert the 'user' object to string to pass to backend. Try passing the user object as it is.
this.httpClient.post<Employee[]>(postUrl, user, httpOptions);
And also please check if parameters passed really match the rest service exposed.
I started to learn spring boot and I'm faced with problems. I have following code:
#RestController
public class UserController {
#RequestMapping("/")
public String getMessageInfo(Message message) {
return "Id is " + message.getId() + ", message is " + message.getMessage() + ", parameter good is " + message.isGood();
}
}
Class Message:
public class Message {
private String message;
private int id;
private boolean good;
public Message() {}
public Message(int id) {this.id = id;}
public Message(String message) {this.message = message;}
public Message(boolean good) {this.good = good;}
public Message(String message, boolean good, int id) {
this.message = message;
this.good = good;
this.id = id;
}
public String getMessage() {
return message;
}
public int getId() {
return id;
}
public boolean isGood() {
return good;
}
}
And when I try to do something like this:
RestTemplate request = new RestTemplate();
String info = request.getForObject("http://localhost:8080/?id=4", String.class);
value of id is ignored. Same problem appears when I send request with boolean good parameter (for example localhost:8080/?good=true). It is called the default constructor instead of Message(boolean)/Message(int). But when I do something like localhost:8080/?message=1234 it isn't ignored. Can you explain me what is the problem?
And one more question: can I send instance of class Message to getMessageInfo in different way than localhost:8080/?message=1234&good=true&id=145? If I have more than 3 parameters? For example if class Message has 100 parameters?
since you are trying to deal with a complex object accept your object from a post request.
#RequestMapping("/",method=RequestMethod.POST)
public String getMessageInfo(#RequestBody Message message) {
return message;
}
in the above code i'm setting method attribute to POST then it will be called when you are making a POST request, and i am using #RequestBody Message message inside the method parameter. which will convert and form an Message object from the incoming request, if you dont put #requestBody annotation then a Bean will be injected to the method by spring instead of forming a one from the request.
you can try this code to make the request
final String uri = "http://localhost:8080/";
Message message = new Message(1, "Adam",true);
RestTemplate restTemplate = new RestTemplate();
Message result = restTemplate.postForObject( uri, message, Message.class);
when making an request create an Message object setting each and every field in it, otherwise you will end up in having Bad request error.
I solved the problem, if add smth like this:
#ModelAttribute("message")
public Message getMessage(String message, boolean good, int id){
return new Message(message, good, id);
}
#RequestMapping("/")
public String getUserInfo(#ModelAttribute("message") Message message) {
return "Id is " + message.getId() + ", message is " + message.getMessage() + ", parameter good is " + message.isGood();
}
all parameters aren't ignored.
You can use like this,
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("id", 1);
params.add("good", true);
params.add("message", 1234);
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(params, requestHeaders);
RestTemplate restTemplate = new RestTemplate();
Message message= restTemplate.postForObject("http://localhost:8080/", requestEntity, Message.class);
I have netbean Rest Web service project with several method as follow:
#Path("restws")
public class RestWs {
#Context
private UriInfo context;
public RestWs() {
}
#GET
#Produces("application/json")
public String getJson() {
return ("{\"pesan\":\"hello\"}");
}
#PUT
#Produces("text/plain")
#Consumes("application/json")
public String putJson(String content) {
return("Content yang didapat : "+content);
}
#Path("/mahasiswaData/{id}")
#GET
#Produces("application/json")
public String getMahasiswaByID(#PathParam("id")String nim)
{
JSONObject jo = new JSONObject();
jo.put("id", nim);
jo.put("nama", "Budi");
return(jo.toJSONString());
}
#Path("/mahasiswaData/{id}")
#POST
#Consumes("text/plain")
#Produces("application/json")
public String postMahasiswaByID(#PathParam("id")String nim, String data)
{
JSONObject jo = new JSONObject();
jo.put("id", nim);
jo.put("nama", "Budi");
jo.put("message", data);
return(jo.toJSONString());
}
#Path("/mahasiswaQuery")
#GET
#Produces("application/json")
public String getMahasiswaQuery(#QueryParam("nim")String nim, #QueryParam("nama") String nama)
{
JSONObject jo = new JSONObject();
jo.put("nim", nim);
jo.put("nama", nama);
jo.put("method", "GET");
return(jo.toJSONString());
}
#Path("/mahasiswaQuery")
#POST
#Produces("application/json")
public String postMahasiswaQuery(#QueryParam("nim")String nim, #QueryParam("nama") String nama)
{
JSONObject jo = new JSONObject();
jo.put("nim", nim);
jo.put("nama", nama);
jo.put("method", "Post");
return(jo.toJSONString());
}
}
then i make new project and add rest web service client. Automatically netbeans made me a new Class:
public class NewJerseyClient {
private WebTarget webTarget;
private Client client;
private static final String BASE_URI = "http://localhost:8080/PTIRestServer/webresources";
public NewJerseyClient() {
client = javax.ws.rs.client.ClientBuilder.newClient();
webTarget = client.target(BASE_URI).path("restws");
}
public String putJson(Object requestEntity) throws ClientErrorException {
return webTarget.request(javax.ws.rs.core.MediaType.APPLICATION_JSON).put(javax.ws.rs.client.Entity.entity(requestEntity, javax.ws.rs.core.MediaType.APPLICATION_JSON), String.class);
}
public String getMahasiswaByID(String id) throws ClientErrorException {
WebTarget resource = webTarget;
resource = resource.path(java.text.MessageFormat.format("mahasiswaData/{0}", new Object[]{id}));
return resource.request(javax.ws.rs.core.MediaType.APPLICATION_JSON).get(String.class);
}
public String postMahasiswaQuery() throws ClientErrorException {
return webTarget.path("mahasiswaQuery").request().post(null, String.class);
}
public String getMahasiswaQuery(String nim, String nama) throws ClientErrorException {
WebTarget resource = webTarget;
if (nim != null) {
resource = resource.queryParam("nim", nim);
}
if (nama != null) {
resource = resource.queryParam("nama", nama);
}
resource = resource.path("mahasiswaQuery");
return resource.request(javax.ws.rs.core.MediaType.APPLICATION_JSON).get(String.class);
}
public String postMahasiswaByID(Object requestEntity, String id) throws ClientErrorException {
return webTarget.path(java.text.MessageFormat.format("mahasiswaData/{0}", new Object[]{id})).request(javax.ws.rs.core.MediaType.TEXT_PLAIN).post(javax.ws.rs.client.Entity.entity(requestEntity, javax.ws.rs.core.MediaType.TEXT_PLAIN), String.class);
}
public String getJson() throws ClientErrorException {
WebTarget resource = webTarget;
return resource.request(javax.ws.rs.core.MediaType.APPLICATION_JSON).get(String.class);
}
public void close() {
client.close();
}
}
i can access all the get Method easily by using something like:
public static void main(String[] args) {
System.out.println(new NewJerseyClient().getMahasiswaQuery("23", "John"));
}
but when i try to access post/put method using this code:
public static void main(String[] args) {
NewJerseyClient c = new NewJerseyClient();
System.out.println(c.putJson("{\"name\":\"john\"}"));
System.out.println(c.postMahasiswaQuery());
System.out.println(c.postMahasiswaByID("plain text", "1"));
}
all of the method call give me an exception:
Exception in thread "main" javax.ws.rs.NotAcceptableException: HTTP 406 Not Acceptable
at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:898)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:749)
at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:88)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:650)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:421)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:646)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:402)
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:305)
at client.NewJerseyClient.postMahasiswaByID(NewJerseyClient.java:68)
at client.NewJerseyClient.main(NewJerseyClient.java:84)
can anyone help me? how to access method put/post? or anyone has a sample code how to access those method?
thanks
Your Rest service code looks good. however the client code generations in Netbeans has an issue i have filed a bug in netbeans.
To make your client code success. Please change the putJson request content type from javax.ws.rs.core.MediaType.APPLICATION_JSON to javax.ws.rs.core.MediaType.TEXT_PLAIN
public String putJson(Object requestEntity) throws ClientErrorException {
return webTarget.request(javax.ws.rs.core.MediaType.TEXT_PLAIN)
.put(javax.ws.rs.client.Entity.entity(requestEntity, javax.ws.rs.core.MediaType.APPLICATION_JSON), String.class);
}
Similarly for postMahasiswaByID method change the request content-type javax.ws.rs.core.MediaType.TEXT_PLAIN to javax.ws.rs.core.MediaType.APPLICATION_JSON
public String postMahasiswaByID(Object requestEntity, String id) throws ClientErrorException {
return webTarget.path(java.text.MessageFormat.format("mahasiswaData/{0}", new Object[]{id}))
.request(javax.ws.rs.core.MediaType.APPLICATION_JSON)
.post(javax.ws.rs.client.Entity.entity(requestEntity, javax.ws.rs.core.MediaType.TEXT_PLAIN), String.class);
}
Please let me know if it works.
Thanks
vidhya