@POST
@Path("/sessions")
@Consumes("application/json")
@Produces("application/json")
public Response createSession(JSONObject jsonObject){
if (jsonObject.get("subjectId").equals("amadmin")){
jsonObject.put("username", jsonObject.get("subjectId"));
jsonObject.put("password", jsonObject.get("authInfo"));
}
else{
jsonObject.put("username", jsonObject.get("subjectId"));
jsonObject.put("password", jsonObject.get("authInfo"));
jsonObject.put("uri", "realm=" + jsonObject.get("realm"));
}
String openAmUrl = String.format("http://%s%s/identity/json/authenticate",
openAmIp, openAmWarName);
URI uri = null;
try {
uri = new URI(openAmUrl);
}
catch (URISyntaxException e) {
LOGGER.error("Exception " + e);
}
return Response.seeOther(uri).build();
}
I’m trying to call a post call with JSON string like:
{"subjectId":"me", "authInfo":"password"}
and I’m always getting HTTP/1.1 415 Unsupported Media Type.
I understand that if my method is receiving JSONObject then the string in the post is getting converted to JSONObject automatically, but still getting the 415 error, although Im using headers as:
Content-Type : application/json
Accept : application/json
can you please help?
actually it was simple, here is the new code: