繁体   English   中英

在清漆后面使用restlet时出错(反向代理)

[英]Error by using restlet behind varnish (Reverse proxy)

我正在使用restlet服务器为我的移动应用程序提供一个RESTful提供程序。 使清漆工作与清漆有什么关系吗?

确实,无需使用清漆并使我的应用程序直接与我的其余服务器联系,则一切正常。

这是restlet服务器返回的异常:

May 14, 2012 7:48:10 PM org.restlet.resource.UniformResource doCatch
WARNING: Exception or error caught in resource
java.lang.NullPointerException
        at fr.evoxmusic.ebackupserver.rest.IsGoogleRegistered.isGoogleRegistered(IsGoogleRegistered.java:30)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.restlet.resource.ServerResource.doHandle(ServerResource.java:449)
        at org.restlet.resource.ServerResource.post(ServerResource.java:1114)
        at org.restlet.resource.ServerResource.doHandle(ServerResource.java:533)
        at org.restlet.resource.ServerResource.doNegotiatedHandle(ServerResource.java:590)
        at org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:302)
        at org.restlet.resource.ServerResource.handle(ServerResource.java:849)

注意:我正在使用Reslet客户端。 这里我的代码联系服务器。

public class RestletClient extends ClientResource {
    private static final String TAG = "RestletClient";
    private static final String UserAgent = "eBackupSMS";

    public static JSONObject SendHttpPost(String URL, JSONObject entity) {
        JSONObject result = new JSONObject();
        JsonRepresentation jr = new JsonRepresentation(entity);

        Client client = new Client(new Context(), Protocol.HTTP);
        client.getContext().getParameters().add("useForwardedForHeader", "true");
        ClientResource cr = new ClientResource(URL);
        cr.setNext(client);

        List<Preference<Encoding>> preflist = cr.getClientInfo().getAcceptedEncodings();
        preflist.add(new Preference<Encoding>(Encoding.GZIP));
        preflist.add(new Preference<Encoding>(Encoding.DEFLATE));

        cr.getClientInfo().setAgent(UserAgent);

        // Others params.
        cr.setRetryDelay(10000);
        cr.setRetryAttempts(3);
        cr.setRetryOnError(true);

        try {

            cr.post(jr);
            jr = new JsonRepresentation(cr.getResponseEntity());
            cr.release();

            result = jr.getJsonObject();
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }

        return result;
    }

}

这里是发生错误的isGoogleRegistered资源。

public class IsGoogleRegistered extends ServerResource {

    /**
     * Method used to verify if the token provided by the client is valid for
     * the google server.
     * 
     * @param entity as json representation
     * @return a jsonobject containing the response
     * @throws Exception
     * 
     * @example : {"google":{"registrationid":"client token id"}}
     */
    @Post("json")
    public JsonRepresentation isGoogleRegistered(JsonRepresentation entity) throws Exception {
        JSONObject wrapper = new JSONObject();
        JSONObject content = new JSONObject();

        wrapper = entity.getJsonObject().getJSONObject("google");

        try {
            if (C2DMMessage.isGoogleRegistered(JBackupServer.c2dmToken, wrapper.getString("registrationid")))
                content.put("isgoogleregistered", true);
            else
                content.put("isgoogleregistered", false);
        } catch (IOException e) {
            content.put("error", "connection to google servers not available");
        }

        wrapper = new JSONObject();
        wrapper.put("result", content);

        JsonRepresentation jr = new JsonRepresentation(wrapper);
        return jr;
    }

}

第30行:

wrapper = entity.getJsonObject().getJSONObject("google");

谢谢。

通过使用socat,我看到清漆似乎无法正确地将分块的HTTP请求转发到后端。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM