javax.ws.rs.BadRequestException: HTTP 400 Bad Request

Java.net JIRA | puce | 1 year ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    My analysis so far is as following: AbstractRootElementJaxbProvider throws subclasses of WebApplicationException instead of an IOException: https://jersey.java.net/project-info/2.22.1/jersey/project/jersey-media-jaxb/xref/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.html At least in the latest version this handled somewhat in JerseyInvocation, where WebApplicationException gets catched and wrapped by a ResponseProcessingException. https://github.com/jersey/jersey/blob/master/core-client/src/main/java/org/glassfish/jersey/client/JerseyInvocation.java#L858 This is wakwards since the nested exception provides a wrong HTTP status code (eg. "HTTP 400 Bad Request", where the request itself was succesful. In the end the nested WebApplicationException gets unwrapped again: https://github.com/jersey/jersey/blob/master/core-client/src/main/java/org/glassfish/jersey/client/JerseyInvocation.java#L690 So I think the best thing would be if the AbstractRootElementJaxbProvider class would throw IOException. The case of a thrown WebApplicationException should never arise when calling response.readEntity (translate method). So the catch clause should be removed and it should be made sure this case never arises (otherwise it would still be catched by the Exception catch statement). The unwrapping of the cause of the ProcessingException in the translate method also seems wrong in some cases (e.g. when there is no cause). Why not just set the ProcessingException itself as cause? The IllegalStateException is not handled specially while ProcessingException is. Seems inconsistent. And last but not least the WebApplicationException should not be unwrapped in the invoke method. Again, I think WebApplicationException should never be the cause of a ProcessingException anyway.

    Java.net JIRA | 1 year ago | puce
    javax.ws.rs.BadRequestException: HTTP 400 Bad Request

    Root Cause Analysis

    1. javax.ws.rs.BadRequestException

      HTTP 400 Bad Request

      at org.glassfish.jersey.jaxb.internal.AbstractRootElementJaxbProvider.readFrom()
    2. org.glassfish.jersey
      AbstractRootElementJaxbProvider.readFrom
      1. org.glassfish.jersey.jaxb.internal.AbstractRootElementJaxbProvider.readFrom(AbstractRootElementJaxbProvider.java:136)
      1 frame
    3. Jersey Core
      InboundMessageContext.readEntity
      1. org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:256)
      2. org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:235)
      3. org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)
      4. org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
      5. org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
      6. org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:808)
      6 frames
    4. jersey-core-client
      JerseyInvocation$2.call
      1. org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
      2. org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:803)
      3. org.glassfish.jersey.client.JerseyInvocation.access$700(JerseyInvocation.java:92)
      4. org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:700)
      4 frames
    5. Jersey Core
      RequestScope.runInScope
      1. org.glassfish.jersey.internal.Errors.process(Errors.java:315)
      2. org.glassfish.jersey.internal.Errors.process(Errors.java:297)
      3. org.glassfish.jersey.internal.Errors.process(Errors.java:228)
      4. org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
      4 frames
    6. jersey-core-client
      JerseyInvocation$Builder.get
      1. org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:696)
      2. org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:420)
      3. org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:316)
      3 frames