0

I have the following POST endpoint that uses jax-rs framework:

    @POST
    @NoCache
    @Path("/{client}/email/template/type/{type}")
    public void sendEmail(
    @PathParam("client") String client,
    @PathParam("type") String communicationTemplateType) {
        emailService.sendEmail(client, communicationTemplateType);
    }

Whenever I am hitting this endpoint I am getting the following error with an error code of 415:

JBWEB000135: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

What is the issue with my endpoint?

java12399900
  • 1,485
  • 7
  • 26
  • 56
  • Are there any other annotations on the Resource (i.e. at the class level)? What headers does your POST request send? – tgdavies Jan 08 '21 at 10:38
  • 2
    1. Tip: Always use `@Consumes` and `@Produces` annotations. 2. Are you trying to send an entity in the body? If so, you have to have a parameter to support the entity. 3. Make sure to use correct Content-Type headers... All three of these things should be handled. – Paul Samsotha Jan 08 '21 at 14:57
  • Also can show how you are sending the request? – Paul Samsotha Jan 08 '21 at 17:48
  • 2
    Have you fixed all the points I've mentioned in my previous comment? There's no point in adding bounty and not updating your post with requests from comments. No one was able to answer your question then and they won't be able to answer it just because you add a bounty. Just wasting your internet points. For better help, please read my previous comments and update your post. – Paul Samsotha Jan 21 '21 at 18:19

4 Answers4

4

As reported inside https://docs.oracle.com/cd/E19798-01/821-1841/6nmq2cp22/index.html:

If a resource is unable to consume the MIME type of a client request, the JAX-RS runtime sends back an HTTP 415 (“Unsupported Media Type”) error.

Did you try to add a @Consumes notation to specify the accepted media type?

user2862981
  • 274
  • 1
  • 8
0

You pass all the params in your URL. Try to switch to GET instead of POST.

Michael Gantman
  • 7,315
  • 2
  • 19
  • 36
0

While POST endpoints with empty bodies are not uncommon, the following response gives me some pause:

JBWEB000135: The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.

Can you please verify the client and ensure it is not sending any data in its request body. Also verify if any Content-Type Header is sent by your client.

If you are not sure if client is silently adding any body/header, you can use Postman to simulate this. Or a simple curl will suffice.

jms
  • 747
  • 6
  • 19
0

Debug the connection request and check the MIME type headers. If your client POSTs a request and states a MIME type you don't support then you need to change the request or adapt your server REST service to support that MIME type.

For example, if you use a browser as a client to perform the REST POST call, you can click F12 (fire fox/chrome) before running the POST call, then do the operation and you will see all REST calls performed.

Click on the call you are interested in, and check the headers. If you are missing some content type you can add the annotation for it on your service.

For example: I first opened F12 then I used this site to run a POST call: https://reqbin.com/

Then in the F12 window (firefox in my case): enter image description here

thedrs
  • 1,412
  • 12
  • 29