title: In GWT, when is the AsyncCallback:onFailure method called in a json-p request using JsonpRequestBuilder
body: <p>I've been implementing a GWT application that calls a REST-service (which we're also developing). When the REST-service returns anything with a HTTP-status other than 200 I would expect the onFailure method of AsyncCallback to be called. However I can't get this to happen. </p>
  
  <p>To test it further I created a test GWT app and a test servlet. The part of the GWT app that calls the service looks like this:</p>
  
  <pre><code>JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
  jsonp.setCallbackParam("_jsonp");
  jsonp.setFailureCallbackParam("_jsonp_failure");
  
  jsonp.requestObject(url, new AsyncCallback&lt;JavaScriptObject&gt;()
  {
  
      @Override
      public void onFailure(Throwable caught)
      {
          Window.alert("Failure: " + caught.getMessage());
      }
  
      @Override
      public void onSuccess(JavaScriptObject result)
      {
          Window.alert("Success");
      }
  });
  </code></pre>
  
  <p>The servlet-code looks like this:</p>
  
  <pre><code>public class MyRestServlet extends HttpServlet
  {
      protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
      {
          String padding = httpServletRequest.getParameter("_jsonp_failure");
          httpServletResponse.setContentType("application/x+javascript");
          httpServletResponse.setStatus(500);
  
  
          PrintWriter out = httpServletResponse.getWriter();
          out.println(padding + "({\"some\":\"json\"});");
          out.close();
      }
  }
  </code></pre>
  
  <p>OnFailure eventually gets called when the request times out, but I would expect it to be called as soon as the http response arrives(if it's a failure). I guess there is something I haven't understood and I would really appreciate to get some help with this.</p>
  
  <p>Thanks</p>