Search in sources :

Example 1 with AllTaskListsModel

use of org.glassfish.jersey.examples.oauth2.googleclient.model.AllTaskListsModel in project jersey by jersey.

the class TaskResource method getTasksResponse.

/**
     * Queries task data from google.
     *
     * @param client Client configured for authentication with access token.
     * @return Google task data response or redirect to google authorize page response.
     */
private Response getTasksResponse(final Client client) {
    client.register(JacksonFeature.class);
    client.register(new LoggingFeature(Logger.getLogger("example.client.tasks"), LoggingFeature.Verbosity.PAYLOAD_ANY));
    final WebTarget baseTarget = client.target(GOOGLE_TASKS_BASE_URI);
    final Response response = baseTarget.path("users/@me/lists").request().get();
    final List<TaskListModel> listOfTaskLists;
    switch(response.getStatus()) {
        case //Response.Status.UNAUTHORIZED
        401:
            SimpleOAuthService.setAccessToken(null);
            return googleAuthRedirect();
        case //Response.Status.OK
        200:
            listOfTaskLists = processTaskLists(baseTarget, response.readEntity(TaskRootBean.class));
            break;
        default:
            listOfTaskLists = null;
    }
    final AllTaskListsModel tasks = new AllTaskListsModel(listOfTaskLists);
    return Response.ok(tasks).build();
}
Also used : Response(javax.ws.rs.core.Response) LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) AllTaskListsModel(org.glassfish.jersey.examples.oauth2.googleclient.model.AllTaskListsModel) WebTarget(javax.ws.rs.client.WebTarget) TaskListModel(org.glassfish.jersey.examples.oauth2.googleclient.model.TaskListModel)

Aggregations

WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 AllTaskListsModel (org.glassfish.jersey.examples.oauth2.googleclient.model.AllTaskListsModel)1 TaskListModel (org.glassfish.jersey.examples.oauth2.googleclient.model.TaskListModel)1 LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)1