Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting 400 bad request from same application on Weblogic on Red Hat
    primarykey
    data
    text
    <p>I've been developing an application that provides a REST service. I have some tested code that I run against it to see if it works okay.</p> <p>When running it against the application deployed on my local Weblogic development server, it works fine.</p> <p>However, when I deployed it on another Weblogic server on a Red Hat machine, I get 400 Bad Request errors.</p> <p>Here is the client code I'm using to test the service:</p> <pre><code> Client client = Client.create(); //WebResource webResource = client.resource("http://10.1.1.2:7001/NotificationFramework/rest/notifications/createNotification"); WebResource webResource = client.resource("http://rhvm:7003/NotificationFramework/rest/notifications/createNotification"); ClientResponse clientResponse = webResource.type("application/json").post(ClientResponse.class, testJsonObject.toString()); JSONObject response2 = new JSONObject(clientResponse.getEntity(String.class)); System.out.println(response2); </code></pre> <p>The commented line is the one on my local machine.</p> <p>Here is the response I'm getting:</p> <pre><code>An error occurred: Server returned HTTP response code: 400 for URL: http://rhvm:7003/NotificationFramework/rest/notifications/createNotification </code></pre> <p>And here is an excerpt of the code providing the REST service:</p> <pre><code>@Path("/notifications") public class RestServices { @POST @Path("/createNotification") @Consumes( {MediaType.APPLICATION_JSON} ) @Produces( {MediaType.APPLICATION_JSON} ) public static NotificationResponse createNotification(JAXBElement&lt;Notification&gt; n) { // do some stuff return notificationResponse; } </code></pre> <p>I've already tried putting an extra / on the end. And I've tested it with the RESTClient add-on for Firefox and I get the exact same behaviour.</p> <p>Any help would be greatly appreciated.</p> <p>Thanks in advance.</p> <p><strong>// Edit</strong></p> <p>I discovered that it's something to do with the JAXBElement.</p> <p>The following services works:</p> <pre><code>@POST @Path("testRest3") @Consumes( {MediaType.APPLICATION_JSON} ) @Produces({MediaType.APPLICATION_JSON}) public static NotificationResponse testRest3() { logger.info("yo3"); return new NotificationResponse(101, "yo"); } </code></pre> <p>but the following doesn't:</p> <pre><code>@POST @Path("testRest4") @Consumes( {MediaType.APPLICATION_JSON} ) @Produces({MediaType.APPLICATION_JSON}) public static NotificationResponse testRest4(JAXBElement&lt;Notification&gt; n) { logger.info("yo4"); return new NotificationResponse(101, "yo"); } </code></pre> <p>I checked the Notification class as recommended by pestrella and found that @XmlRootElement was missing. I added this but this still hasn't fixed the problem. I'm not sure if it should be @Xml.. but I'm new to this. Following the <a href="http://www.vogella.com/articles/REST/article.html" rel="nofollow">tutorial</a> from vogella.</p> <p>Here is my Notification class:</p> <pre><code>@XmlRootElement public class Notification { private int applicationId; private int notificationId; private int priority; private String message; private String detail; private String appUrl; // methods and stuff } </code></pre> <p>And here is the body as submitted with the RESTClient add-on for Firefox:</p> <pre><code>{"appUrl":"","message":"my message","notificationId":1110001,"detail":"my detail","priority":3,"applicationId":111} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COYour code looks fine. If you are absolutely sure that you have deployed the same code, and that your test code is the same, I would look in your Weblogic logs first to determine what is causing the `400` response. Look for exceptions. Depending on how you've put your Jersey REST components together you might find that your `MessageBodyReader` cannot deserialize the incoming `POST` body because it is malformed. Can you add your `Notification` class code to the question as well as the `POST` body you send via RESTClient?
      singulars
    2. COYour comment has gotten me much closer. I made some dummy services and zoned in on the problem. It is, as you suggested, something to do with the way it's trying to get the data from the Notification object (n). I looked at my Notification class and found that '@XmlRootElement was missing. I added it but it still hasn't solved the problem (though the fact that it's called '@XmlRootElement makes me think that that's not right either... but I couldn't find '@JsonRootElement... I'm new to all this). I've added the stuff you asked to see. Thanks for helping with this. I really appreciate it.
      singulars
    3. COOh, I checked the weblogic logs but not exceptions as far as I could see anyway.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload