1

我正在使用 restyGwt 向 jersey 发送请求,我已经在客户端使用请求对象(request.cancel)关闭了请求,但我发现服务器正在处理我的请求,即使我在客户端关闭,它也不会被通知到连接停止的服务器。

我想在客户端取消请求后立即告诉服务器停止处理该请求

这是我的客户休息 gwt 代码

@POST
@Produces("application/json")
@Consumes("application/json")
@Path("servicepoint/getAllServicepointAndCount")
public Request findAllServicepointandCount(@QueryParam("startIndex") Integer     startIndex,
        @QueryParam("maxSize") Integer maxSize,
        MethodCallback<ServicepointResponse> methodCallback);

这是我向服务器发出请求的 gwt 类

ServicepointRestyService service = GWT
            .create(ServicepointRestyService.class);
    ((RestServiceProxy) service).setResource(resource);

    final Request method=service.findAllServicepointandCount( index,     length,
            new MethodCallback<ServicepointResponse>() {

                @Override
                public void onFailure(Method method, Throwable exception) {
                    Window.alert(exception.getMessage());

                }

                @Override
                public void onSuccess(Method method,
                        ServicepointResponse response) {
                    Window.alert("response.getMassege");
                }
            });
    Timer t=new Timer() {

        @Override
        public void run() {
            Window.alert("cancelled");
            method.cancel();// cancel connection


        }
    };
    t.schedule(2000);
}

球衣 impl

@POST
@Produces("application/json")
@Consumes("application/json")
@Path("/getAllServicepointAndCount")
public ServicepointResponse findAllServicepointandCount(
        @QueryParam("startIndex") Integer startIndex,
        @QueryParam("maxSize") Integer maxSize) {
    logger.finer("Entering startIndex" + startIndex + "" + maxSize);
    ServicepointResponse data = new ServicepointResponse();
    List<ServicepointPojo> spPojos = new ArrayList<>();

    try {
        while(true){
            System.out.println(new Date().getTime());
            Thread.sleep(1000);
        }catch (Exception e) {
        e.printStackTrace();

    }

即使我在 2 秒后停止了我的请求,服务器仍然打印它从未停止过的日期和时间,我已经编写了这段代码来检查这个功能

4

0 回答 0