1

我正在使用 restlet 服务器,我的移动应用程序有一个 RESTful 提供程序。与清漆有什么关系可以使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");

谢谢。

4

1 回答 1

0

通过使用 socat 我看到清漆似乎没有正确地将分块的 http 请求转发到后端。

于 2012-05-16T13:14:32.703 回答