代码之家  ›  专栏  ›  技术社区  ›  quarks

处理Restful或JAX-RS web服务的重定向响应

  •  2
  • quarks  · 技术社区  · 12 年前

    来自GWT的一个典型的restful调用(使用RestyGWT)如下所示:

    LoginService.Util.getService().login("FACEBOOK", new MethodCallback<Void>() {
        @Override
        public void onSuccess(Method method, Void response) {
    
        }
    
        @Override
        public void onFailure(Method method, Throwable exception) {
    
        }
    });
    

    尽管呼叫可能会响应Success 重新使用 不处理响应。服务器端重定向如下所示:

    return Response.seeOther(new URI(url)).build(); 
    

    处理请求重定向的正确方法是什么 RequestBuilder RestyGWT ?

    2 回复  |  直到 9 年前
        1
  •  1
  •   Thilina Sampath Alexander    9 年前

    查看本教程, RequestBuilder ,试试这个,

    // Send request to server and catch any errors.
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    
    try {
        Request request = builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable exception) {
                displayError("Couldn't retrieve JSON");
            }
    
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    updateTable(JsonUtils.safeEval(response.getText()));
                } else {
                    displayError("Couldn't retrieve JSON (" + response.getStatusText() + ")");
                }
            }
        });
    } catch (RequestException e) {
        displayError("Couldn't retrieve JSON");
    }
    
        2
  •  1
  •   Thilina Sampath Alexander    9 年前

    试试这个,

    response.sendRedirect("http://10.62.229.57:8080/birt/");
    

    我用于 重定向响应 在Jax的web服务中。