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"));
}
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);
}
}
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);
}
}
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());
}
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);
}
}
Aggregations