title: Getting 400 bad request from same application on Weblogic on Red Hat
body: <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>