简体   繁体   中英

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?

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?

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

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.

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): 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM