如何查看嵌入式/代码启动的jetty服务器的完整日志?

时间:2015-06-03 17:09:10

标签: logging jetty embedded-jetty jetty-9

我有以下代码片段来启动jetty服务器:

    server = setupSecureServer(8089, 8447, true);

    WebAppContext serverContext = new WebAppContext();
    serverContext.setContextPath("/foo");
    serverContext.setWar("/server/webapps/bar.war");
    server.setHandler(serverContext);

    server.start();

问题是,虽然上面可以启动一个码头服务器,但是在点击它的服务时我看到了HTTP 503。

我的问题是,有没有办法查看jetty服务器的完整日志,以帮助解决问题?

目前有log4j日志,但它不包含503错误的详细信息。

log4j.xml是:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
                     xmlns:log4j='http://jakarta.apache.org/log4j/'>

   <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d [%t] %-5p - [%C{1}:%L] %m%n"/>
      </layout>
   </appender>
   <root>
      <level value="ALL"/>
      <appender-ref ref="consoleAppender"/>
   </root>

</log4j:configuration>

为了完整性,setupSecureServer()方法的详细信息:

    public static Server setupSecureServer(final int port, final int sslport, final boolean clientAuth) {
        final SslConnectionFactory sslConnectionFactory =
                sslConnectionFactory(sslContextFactory(clientAuth));
        final HttpConnectionFactory httpsConnectionFactory = httpsConnectionFactory(httpConfig(sslport));
        return sslConnectedServer(port, sslport, sslConnectionFactory, httpsConnectionFactory);
    }

    public static SslConnectionFactory sslConnectionFactory(final SslContextFactory contextFactory) {
        return new SslConnectionFactory(contextFactory, HttpVersion.HTTP_1_1.toString());
    }

    public static SslContextFactory sslContextFactory(final boolean clientAuth) {
        final String keyStoreFile = System.getProperty("javax.net.ssl.keyStore");
        final String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
        final String trustStoreFile = System.getProperty("javax.net.ssl.trustStore");
        final String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");

        final SslContextFactory contextFactory = new SslContextFactory();
        contextFactory.setKeyStoreType("JCEKS");
        contextFactory.setKeyStorePath(keyStoreFile);
        contextFactory.setKeyStorePassword(keyStorePassword);
        contextFactory.setNeedClientAuth(clientAuth);
        contextFactory.setTrustStorePath(trustStoreFile);
        contextFactory.setTrustStoreType("JCEKS");
        contextFactory.setTrustStorePassword(trustStorePassword);

        contextFactory.setTrustAll(true);

        return contextFactory;
    }

    public static HttpConnectionFactory httpsConnectionFactory(final HttpConfiguration config) {
        final HttpConfiguration sslConfiguration = new HttpConfiguration(config);
        sslConfiguration.addCustomizer(new SecureRequestCustomizer());
        return new HttpConnectionFactory(sslConfiguration);
    }

    public static HttpConfiguration httpConfig(final int sslport) {
        final HttpConfiguration config = new HttpConfiguration();
        config.setSecureScheme("https");
        config.setSecurePort(sslport);
        config.setOutputBufferSize(32786);
        config.setRequestHeaderSize(8192);
        config.setResponseHeaderSize(8192);
        return config;
    }

    public static Server sslConnectedServer(final int port, final int sslPort, final SslConnectionFactory sslConnectionFactory,
            final HttpConnectionFactory httpsConnectionFactory) {
        final Server server = new Server(port);
        final ServerConnector sslConnector = new ServerConnector(server, sslConnectionFactory, httpsConnectionFactory);
        sslConnector.setPort(sslPort);
        server.addConnector(sslConnector);
        return server;
    }

0 个答案:

没有答案