Search in sources :

Example 21 with LoggingFeature

use of org.glassfish.jersey.logging.LoggingFeature 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)

Example 22 with LoggingFeature

use of org.glassfish.jersey.logging.LoggingFeature in project jersey by jersey.

the class Server method start.

/**
     * Start SSL-secured HTTP test server.
     *
     * @throws IOException in case there is an error while reading server key store or trust store.
     * @return an instance of the started SSL-secured HTTP test server.
     */
public static Server start(String keystore) throws IOException {
    final InputStream trustStore = Server.class.getResourceAsStream(SERVER_TRUST_STORE);
    final InputStream keyStore = Server.class.getResourceAsStream(keystore);
    // Grizzly ssl configuration
    SSLContextConfigurator sslContext = new SSLContextConfigurator();
    // set up security context
    // contains server key pair
    sslContext.setKeyStoreBytes(ByteStreams.toByteArray(keyStore));
    sslContext.setKeyStorePass("asdfgh");
    // contains client certificate
    sslContext.setTrustStoreBytes(ByteStreams.toByteArray(trustStore));
    sslContext.setTrustStorePass("asdfgh");
    ResourceConfig rc = new ResourceConfig();
    rc.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));
    rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);
    final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
    // start Grizzly embedded server //
    LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
    grizzlyServer.start();
    return new Server(grizzlyServer);
}
Also used : HttpServer(org.glassfish.grizzly.http.server.HttpServer) InputStream(java.io.InputStream) LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) SSLEngineConfigurator(org.glassfish.grizzly.ssl.SSLEngineConfigurator) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) SSLContextConfigurator(org.glassfish.grizzly.ssl.SSLContextConfigurator)

Example 23 with LoggingFeature

use of org.glassfish.jersey.logging.LoggingFeature in project jersey by jersey.

the class ResponseReadAndBufferEntityTest method configure.

@Override
protected Application configure() {
    enable(TestProperties.DUMP_ENTITY);
    enable(TestProperties.LOG_TRAFFIC);
    return new ResourceConfig(Resource.class).registerInstances(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));
}
Also used : LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 24 with LoggingFeature

use of org.glassfish.jersey.logging.LoggingFeature in project jersey by jersey.

the class AsyncJaxrsApplication method getSingletons.

@Override
public Set<Object> getSingletons() {
    final HashSet<Object> instances = new HashSet<Object>();
    instances.add(new LoggingFeature(Logger.getLogger(AsyncJaxrsApplication.class.getName()), LoggingFeature.Verbosity.PAYLOAD_ANY));
    return instances;
}
Also used : LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) HashSet(java.util.HashSet)

Example 25 with LoggingFeature

use of org.glassfish.jersey.logging.LoggingFeature in project jersey by jersey.

the class AsyncTest method configureClient.

@Override
protected void configureClient(ClientConfig config) {
    // TODO: fails with true on request - should be fixed by resolving JERSEY-2273
    config.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.HEADERS_ONLY));
    config.connectorProvider(new JettyConnectorProvider());
}
Also used : LoggingFeature(org.glassfish.jersey.logging.LoggingFeature)

Aggregations

LoggingFeature (org.glassfish.jersey.logging.LoggingFeature)45 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)33 Response (javax.ws.rs.core.Response)6 Client (javax.ws.rs.client.Client)4 WebTarget (javax.ws.rs.client.WebTarget)4 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)4 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)4 Resource (org.glassfish.jersey.server.model.Resource)4 ClientConfig (org.glassfish.jersey.client.ClientConfig)2 MultiPartFeature (org.glassfish.jersey.media.multipart.MultiPartFeature)2 Test (org.junit.Test)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 UserPrincipal (com.sun.security.auth.UserPrincipal)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Principal (java.security.Principal)1 HashSet (java.util.HashSet)1 ExecutorService (java.util.concurrent.ExecutorService)1 Logger (java.util.logging.Logger)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1