Success! Looks like we've fixed this one. According to our records the fix was applied for EXTGWT-1964 in a recent build.
  1. #1
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    70
    Vote Rating
    6
    mtraynham is on a distinguished road

      0  

    Default GXT 3 RC HttpProxy: Add "PUT" to load method.

    GXT 3 RC HttpProxy: Add "PUT" to load method.


    Within the class HttpProxy, the load method checks for a "Post" call. It should also be looking for "Put".

    Code:
     @Override
      public void load(final C loadConfig, final Callback<String, Throwable> callback) {
        try {
          String data = null;
          if (builder.getHTTPMethod().equals("POST")) {
            data = generateUrl(loadConfig);
          } else {
            StringBuilder url = new StringBuilder(initUrl);
            url.append(url.indexOf("?") == -1 ? "?" : "&");
            String params = generateUrl(loadConfig);
            url.append(params);
            setUrl(builder, url.toString());
          }
    
          builder.sendRequest(data, new RequestCallback() {
    
            @Override
            public void onError(Request request, Throwable exception) {
              callback.onFailure(exception);
            }
    
            @Override
            public void onResponseReceived(Request request, Response response) {
              if (response.getStatusCode() != Response.SC_OK) {
                callback.onFailure(new RuntimeException("HttpProxy: Invalid status code " + response.getStatusCode()));
                return;
              }
              callback.onSuccess(response.getText());
    
            }
          });
        } catch (Exception e) {
          callback.onFailure(e);
        }
      }

  2. #2
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    70
    Vote Rating
    6
    mtraynham is on a distinguished road

      0  

    Default


    Could do something like this...
    Code:
    if (builder.getHTTPMethod().equals(RequestBuilder.POST.toString()) || 
                        builder.getHTTPMethod().equals(RequestBuilder.PUT.toString())) {

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Good point - what would you say to !method.equals("GET") so that all supported verbs except GET have a body? Or, better still, to add a method like shouldUseBody to allow subclasses to override this?

  4. #4
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    70
    Vote Rating
    6
    mtraynham is on a distinguished road

      0  

    Default


    Hey that would be great! I do believe the HTTPMethod "Head" doesn't allow for body either. Not entirely sure what your getting at with the shouldUseBody part, but possibly disabling it altogether? Maybe:

    Code:
    protected boolean shouldUseBody() {
            return true;
        }
    
        @Override
        public void load(final C loadConfig, final Callback<String, Throwable> callback) {
            try {
                String data = null;
                if (shouldUseBody() && !builder.getHTTPMethod().equals(RequestBuilder.GET.toString()) && 
                        !builder.getHTTPMethod().equals(RequestBuilder.HEAD.toString())) {
                    data = generateUrl(loadConfig);
                } else {
                    StringBuilder url = new StringBuilder(initUrl);
                    url.append(url.indexOf("?") == -1 ? "?" : "&");
                    String params = generateUrl(loadConfig);
                    url.append(params);
                    setUrl(builder, url.toString());
                }
    
                builder.sendRequest(data, new RequestCallback() {
                    public void onError(Request request, Throwable exception) {
                        callback.onFailure(exception);
                    }
    
                    public void onResponseReceived(Request request, Response response) {
                        if (response.getStatusCode() != Response.SC_OK) {
                            callback.onFailure(new RuntimeException("HttpProxy: Invalid status code " + response.getStatusCode()));
                            return;
                        }
                        callback.onSuccess(response.getText());
                    }
                });
            } catch (Exception e) {
                callback.onFailure(e);
            }
        }

  5. #5
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    I was going for this instead, so the logic can be controlled completely from a subclass:
    Code:
    protected boolean shouldUseBody() {
        return builder.getHTTPMethod().equals(RequestBuilder.POST.toString()) || 
            builder.getHTTPMethod().equals(RequestBuilder.PUT.toString());
    }
    @Override
    public void load(final C loadConfig, final Callback<String, Throwable> callback) {
        try {
            String data = null;
            if (shouldUseBody()) {
                data = generateUrl(loadConfig);
            } else {
    //...

  6. #6
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    70
    Vote Rating
    6
    mtraynham is on a distinguished road

      0  

    Default


    Ahh I see. I'm perfectly fine with that. Thanks Colin.

  7. #7
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    70
    Vote Rating
    6
    mtraynham is on a distinguished road

      0  

    Default


    By the way Colin, I just encountered a really weird FireFox bug with HttpProxy. It only happens if the URL I am requesting is on the same context path and the application has been deployed. Works fine in gwt hosted mode.

    Within the load method:
    Code:
    ....
          builder.sendRequest(data, new RequestCallback() {
    
            @Override
            public void onError(Request request, Throwable exception) {
              callback.onFailure(exception);
            }
    
            @Override
            public void onResponseReceived(Request request, Response response) {
              if (response.getStatusCode() != Response.SC_OK) {
                callback.onFailure(new RuntimeException("HttpProxy: Invalid status code " + response.getStatusCode()));
                return;
              }
              callback.onSuccess(response.getText());
    
            }
          });
    ....
    The service I am calling returns a 200, yet has no text and throws a pretty nasty FireFox error.

    The line:
    Code:
    callback.onSuccess(response.getText());
    is the issue.

    The FireFox error:
    (NS_ERROR_CANNOT_CONVERT_DATA): Component returned failure code: 0x80460001 (NS_ERROR_CANNOT_CONVERT_DATA)
    QueryInterface: function QueryInterface() {
    [native code]
    }
    result: 2152071169
    filename: http://localhost:8080/webapp/Webapp/...7FF.cache.html
    lineNumber: 5707
    columnNumber: 0
    inner: null
    data: null
    initialize: function initialize() {
    [native code]
    }

  8. #8
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    This may be a browser specific issue based on the content-type sent from the server - what are you setting for that header? Have you tried using something else like a plain XHR to read this same server data? My suspicion is that the response text cannot be read in firefox without this header set correctly.

  9. #9
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    70
    Vote Rating
    6
    mtraynham is on a distinguished road

      0  

    Default


    That is a good point, I'll try messing with content-type or accept headers.

  10. #10
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,732
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    The discussed change has been made to HttpProxy in SVN, and it will be available in the next release.

Thread Participants: 2