Restlet获取HTTP状态代码204而不是200

时间:2016-06-22 18:32:24

标签: java google-app-engine restlet

对于第一个请求,我收到了JSON响应。从下一个请求开始,即使ServerResource成功返回表示,我也开始获取此日志和HTTP状态代码204

ALTER PROCEDURE [dbo].[Test_String] (@ProductID VARCHAR(25))
AS
BEGIN

    DECLARE @ID VARCHAR (25)
    SET @ID = (
                      SELECT
                        LEFT(@ProductID, LEN(@ProductID) - LEN(REPLACE(@ProductID, '.', '')) - 1)
                     );

    SELECT @ID;
END;

布线路线的应用类

org.restlet.engine.adapter.ServerAdapter commit
WARNING: A response with an unavailable and potentially non empty entity was returned. Ignoring the entity for resource http://localhost:8888/xyz?abc=def

处理并返回JSON表示的服务器资源

@Override
public Restlet createInboundRoot() {
    router = new Router(getContext());
    CorsService corsService = new CorsService();         
    corsService.setAllowedOrigins( new HashSet<String>(Arrays.asList("http://example.com")));
    corsService.setAllowedCredentials(true);
    getServices().add(corsService);
    router.attach("/xyz", XYZ.class);
}

1 个答案:

答案 0 :(得分:0)

在发布响应后,表示状态available设置为false。因此,对ServerResource的后续调用会返回表示形式,但在handle()方法中,它会设置为204,因为getResponseEntity().isAvailable()会返回false

来自ServerResource

@Override
public Representation handle() {
       ...
        } finally {
            if (Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.equals(getStatus())) {
                updateAllowedMethods();
            } else if (Status.SUCCESS_OK.equals(getStatus())
                    && (getResponseEntity() == null || !getResponseEntity()
                            .isAvailable())) {
                getLogger()
                        .fine("A response with a 200 (Ok) status should have an entity. "
                                + "Changing the status to 204 (No content).");
                setStatus(Status.SUCCESS_NO_CONTENT);
            }
        }
    }
    return result;
}

<强>解

每次返回一个新表示,或者在返回表示之前将setAvailable设置为true

相关问题