java12399900
java12399900

Reputation: 1671

POST with Jax-RS giving HTTP error code 415?

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?

Upvotes: 0

Views: 541

Answers (4)

thedrs
thedrs

Reputation: 1464

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

Upvotes: 0

jms
jms

Reputation: 777

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.

Upvotes: 0

Michael Gantman
Michael Gantman

Reputation: 7808

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

Upvotes: 0

user2862981
user2862981

Reputation: 294

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?

Upvotes: 4

Related Questions