Search in sources :

Example 1 with StreamHandler

use of java.util.logging.StreamHandler in project jersey by jersey.

the class ResourceBundleTest method testBadResource.

@Test
public void testBadResource() throws Exception {
    final ResourceConfig resourceConfig = new ResourceConfig(BadResource.class);
    ByteArrayOutputStream logOutput = new ByteArrayOutputStream();
    Handler logHandler = new StreamHandler(logOutput, new SimpleFormatter());
    GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
    // TODO: there should be a better way to get the log output!
    final Enumeration<String> loggerNames = LogManager.getLogManager().getLoggerNames();
    while (loggerNames.hasMoreElements()) {
        String name = loggerNames.nextElement();
        if (name.startsWith("org.glassfish")) {
            LogManager.getLogManager().getLogger(Errors.class.getName()).addHandler(logHandler);
        }
    }
    GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, false);
    logOutput.flush();
    final String logOutputAsString = logOutput.toString();
    Assert.assertFalse(logOutputAsString.contains("[failed to localize]"));
    Assert.assertTrue(logOutputAsString.contains("BadResource"));
}
Also used : StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) StreamHandler(java.util.logging.StreamHandler) Handler(java.util.logging.Handler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with StreamHandler

use of java.util.logging.StreamHandler in project android_frameworks_base by ParanoidAndroid.

the class CookiesTest method testCookiesAreNotLogged.

/**
     * Test that we don't log potentially sensitive cookie values.
     * http://b/3095990
     */
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
    // enqueue an HTTP response with a cookie that will be rejected
    server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
    server.play();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = Logger.getLogger("org.apache.http");
    StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
        HttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet(server.getUrl("/").toURI()));
        handler.close();
        String log = out.toString("UTF-8");
        assertTrue(log, log.contains("password"));
        assertTrue(log, log.contains("fake.domain"));
        assertFalse(log, log.contains("secret"));
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 3 with StreamHandler

use of java.util.logging.StreamHandler in project android_frameworks_base by ResurrectionRemix.

the class CookiesTest method testCookiesAreNotLogged.

/**
     * Test that we don't log potentially sensitive cookie values.
     * http://b/3095990
     */
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
    // enqueue an HTTP response with a cookie that will be rejected
    server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
    server.play();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = Logger.getLogger("org.apache.http");
    StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
        HttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet(server.getUrl("/").toURI()));
        handler.close();
        String log = out.toString("UTF-8");
        assertTrue(log, log.contains("password"));
        assertTrue(log, log.contains("fake.domain"));
        assertFalse(log, log.contains("secret"));
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 4 with StreamHandler

use of java.util.logging.StreamHandler in project geode by apache.

the class GemcachedDevelopmentJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
    PORT = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    this.server = new GemFireMemcachedServer("", PORT, getProtocol());
    server.start();
    logger.addHandler(new StreamHandler());
}
Also used : StreamHandler(java.util.logging.StreamHandler) Before(org.junit.Before)

Example 5 with StreamHandler

use of java.util.logging.StreamHandler in project platform_frameworks_base by android.

the class CookiesTest method testCookiesAreNotLogged.

/**
     * Test that we don't log potentially sensitive cookie values.
     * http://b/3095990
     */
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
    // enqueue an HTTP response with a cookie that will be rejected
    server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
    server.play();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Logger logger = Logger.getLogger("org.apache.http");
    StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
    logger.addHandler(handler);
    try {
        HttpClient client = new DefaultHttpClient();
        client.execute(new HttpGet(server.getUrl("/").toURI()));
        handler.close();
        String log = out.toString("UTF-8");
        assertTrue(log, log.contains("password"));
        assertTrue(log, log.contains("fake.domain"));
        assertFalse(log, log.contains("secret"));
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : MockResponse(com.google.mockwebserver.MockResponse) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Aggregations

StreamHandler (java.util.logging.StreamHandler)51 ByteArrayOutputStream (java.io.ByteArrayOutputStream)28 LogRecord (java.util.logging.LogRecord)17 SimpleFormatter (java.util.logging.SimpleFormatter)16 Logger (java.util.logging.Logger)12 Properties (java.util.Properties)7 MockResponse (com.google.mockwebserver.MockResponse)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 Formatter (java.util.logging.Formatter)3 Handler (java.util.logging.Handler)3 Test (org.junit.Test)3 CommandHandler (org.apache.ignite.internal.commandline.CommandHandler)2 Before (org.junit.Before)2 Command (com.google.copybara.shell.Command)1 CommandOutputWithStatus (com.google.copybara.util.CommandOutputWithStatus)1 CommandRunner (com.google.copybara.util.CommandRunner)1 HighTemporalResolutionFormatter (com.ms.silverking.log.HighTemporalResolutionFormatter)1 XMLEncoder (java.beans.XMLEncoder)1