Bad Request from Jersey server endpoint

juju Source

I've been looking at a problem which happens when I submit a request;

Authorization: Bearer blahblahblahstuff
Accept: application/json
Content-Type: application/json; charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.8.0_60
Connection: keep-alive
Content-Length: 395 

with a syntactically correct Gson json body. It's exactly the same length, and well formed. I used wireshark to capture the exact response and the numbers add up. ie, I don't think there's bloat on the end of the request body. Please tell me if wireshark wouldn't be able to pick this up. Considering this, I don't think the fix here would be applicable to this issue.

I've been testing it locally running payara, and the production server is also payara (exact same version). Locally, the request is fine, works as expected, using exactly the same params live, the endpoint isn't reached, as we handle our own api error codes, and this one is given in html, not json, and can be seen below;

Payara Server #badassfish - Error report

HTTP Status 400 - Bad Request

type: Status report

message: Bad Request

description: The request sent by the client was syntactically incorrect.

Payara Server #badassfish

We are using the HttpUrlConnection library execute the post;

        URL url = new URL(uri);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        if (this.clientip != null && !this.clientip.isEmpty())
            connection.addRequestProperty("X-Forwarded-For", this.clientip);
        if (this.vauthtoken != null && !this.vauthtoken.isEmpty())
            connection.addRequestProperty("Authorization", "Bearer " + this.vauthtoken);
        connection.setRequestProperty("Accept", "application/json");
        connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");

        if(this.body != null)
            try (OutputStream os = connection.getOutputStream()) {

        if(connection.getResponseCode() == HttpURLConnection.HTTP_OK)
            response = this.getJsonBody(connection.getInputStream());
            response = this.getJsonBody(connection.getErrorStream());

And our endpoint looks like;

public class SomeClass extends SomeThingelse {

    final static Logger LOGGER = Logger.getLogger(SomeClass.class.getName());

    @Secured(roles = {Role.SOMEROLE}, crud = Crud.CREATE)
    public Response someMethodRelating(@Context SecurityContext securityContext, @Valid SomeValidatedClass svClass)

Have I missed something? Or is this more of a server issue? Any help would be greatly appreciated thank you.



answered 6 months ago Nyamiou The Galeanthrope #1

Either you are not using the correct method (using GET instead of POST), or the body you are sending is not JSON or does not validate the rules that are in SomeValidatedClass.

comments powered by Disqus