0

What is the MediaType we can use in @Produces annotation if we are expecting the server to return a JWT response?

for application json we can use,

 @Produces({MediaType.APPLICATION_JSON})

But what if we want it to be application/jwt ?

If we use it as below server will return an error saying
"No message body writer has been found for response class ...."

 @Produces({"application/jwt"})
Raveen Athapaththu
  • 190
  • 1
  • 1
  • 13
  • What is the type returned by the message? –  Aug 30 '19 at 13:52
  • @LutzHorn Server is sending a JWT. It's actually a JSON response signed and converted into a jwt. – Raveen Athapaththu Aug 31 '19 at 19:14
  • A JWT is a string like `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c`. Is such a string the response your method returns? –  Aug 31 '19 at 19:20
  • @LutzHorn yes!. Exactly something like that. I hope that is fine? because this is not anything related to authentication or sort of. It's a simple converted response. – Raveen Athapaththu Sep 01 '19 at 07:02

1 Answers1

0

I would try something like this:

@GET
@Produces("application/jwt")
public Response authenticate(...) {
    String jwt = ...;

    return Response.ok(jwt).build();
}

This should work.