Question

I want to setup Janrain authentication to my Play! project which is hosted on GAE and uses GAE module. But I get the following error while I try to login:

RuntimeException occured : Cannot parse JSON (check logs)

And Play highlighs the following line as error:

JsonElement rpxJson = rpxRequest.get().getJson();

Here is method that I use for token callback:

public static void tokenCallback(String token) {
    Properties p = Play.configuration;
    // Try the driver
    String rpxApi = p.getProperty("login.rpx.apiKey");


    WSRequest rpxRequest = WS.url("http://rpxnow.com/api/v2/auth_info");
    // get RPX
    rpxRequest.setParameter("token", token);
    rpxRequest.setParameter("apiKey", rpxApi);

    JsonElement rpxJson = rpxRequest.get().getJson();
    JsonElement profile = rpxJson.getAsJsonObject().get("profile");
    String identifier = profile.getAsJsonObject().getAsJsonPrimitive("identifier").getAsString();

    welcome(identifier);

}

And here is the error that I get from terminal:

Internal Server Error (500) for request POST /login/tokencallback

Execution exception (In /app/controllers/Login.java around line 27)
RuntimeException occured : Cannot parse JSON (check logs)

play.exceptions.JavaExecutionException: Cannot parse JSON (check logs)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
    at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: Cannot parse JSON (check logs)
    at play.libs.WS$HttpResponse.getJson(WS.java:668)
    at controllers.Login.tokenCallback(Login.java:27)
    at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:557)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:508)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:484)
    at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:479)
    at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
    ... 1 more
Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected EOF at line 2 column 1
    at com.google.gson.JsonParser.parse(JsonParser.java:65)
    at com.google.gson.JsonParser.parse(JsonParser.java:45)
    at play.libs.WS$HttpResponse.getJson(WS.java:665)
    ... 7 more
Caused by: com.google.gson.stream.MalformedJsonException: Expected EOF at line 2 column 1
    at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1310)
    at com.google.gson.stream.JsonReader.peek(JsonReader.java:390)
    at com.google.gson.JsonParser.parse(JsonParser.java:60)
    ... 9 more

What can I do? Please, help me to solve this problem.

Thanks in advance.

Was it helpful?

Solution

OK, Here is my first suggestion. Try using the HTTPS connection for the URL. I ran into some problems with the HTTP connection. Here is how I do the Janrain connection:

        WSRequest rpxRequest = WS.url("https://rpxnow.com/api/v2/auth_info");
        // get RPX
        rpxRequest.setParameter("token", token);
        rpxRequest.setParameter("apiKey", rpxApi);

        HttpResponse res = null;
        try {
            res = rpxRequest.post();
        } catch (JavaExecutionException ex) {
            Log.error("unknown error ", ex);
            Validation.addError("", "Unknown Error: please try again");
            Validation.keep();
            Secure.login();
        } catch (Exception ex) {
            Log.error("Most likely SSL error", ex);
            Validation.addError("", "SSL Error: please try again");
            Validation.keep();
            Secure.login();
        }
        if (res.getStatus() != 200) {
            Log.error("status 200 error");
            Validation.addError("", "Status 200 error: please try again");
            Validation.keep();
            Secure.login();
        }
        JsonElement rpxJson = res.getJson();
        JsonElement profile = rpxJson.getAsJsonObject().get("profile");
        JsonObject profileJson = profile.getAsJsonObject();

OTHER TIPS

Having called the URL http://rpxnow.com/api/v2/auth_info , it immediately redirects to https://rpxnow.com/api/v2/auth_info (http s ). I suspect you don't get the JSON answer, but a http redirect code in your call to the web service.

Two possibilites:

1) Change the web service call to https://rpxnow.com/api/v2/auth_info , this probably solves your problem, failing that;

2) Change the line JsonElement rpxJson = rpxRequest.get().getJson(); into something like

HttpResponse httpResponse = rpxRequest.get();
Logger.log ( httpResponse.getString() ); 
if ( httpResponse.success() ) {
    JsonElement rpxJson = httpResponse.getJson();
} else {
    // fail gracefully
}

and report back on the contents of the answer which gets logged in the second line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top