使用varlet背后的反向错误(反向代理)

时间:2012-05-14 18:04:13

标签: java android json restlet varnish

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

确实,不使用清漆并让我的应用程序直接联系我的休息服务器一切正常。

这是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");

感谢。

1 个答案:

答案 0 :(得分:0)

通过使用socat我看到varnish似乎没有正确地将chunked http请求转发到后端..