本文整理汇总了Java中org.eclipse.jetty.server.handler.RequestLogHandler.setRequestLog方法的典型用法代码示例。如果您正苦于以下问题:Java RequestLogHandler.setRequestLog方法的具体用法?Java RequestLogHandler.setRequestLog怎么用?Java RequestLogHandler.setRequestLog使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.handler.RequestLogHandler
的用法示例。
在下文中一共展示了RequestLogHandler.setRequestLog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
public void start() throws Exception {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
log.info("Server started at end point {}", getServiceUri());
}
示例2: start
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
public void start() throws PulsarServerException {
log.info("Starting web socket proxy at port {}", conf.getWebServicePort());
try {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
} catch (Exception e) {
throw new PulsarServerException(e);
}
}
示例3: start
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
public void start() throws PulsarServerException {
try {
RequestLogHandler requestLogHandler = new RequestLogHandler();
Slf4jRequestLog requestLog = new Slf4jRequestLog();
requestLog.setExtended(true);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
requestLog.setLogLatency(true);
requestLogHandler.setRequestLog(requestLog);
handlers.add(0, new ContextHandlerCollection());
handlers.add(requestLogHandler);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
server.start();
log.info("Web Service started at {}", pulsar.getWebServiceAddress());
} catch (Exception e) {
throw new PulsarServerException(e);
}
}
示例4: start
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
public void start() throws Exception {
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(port);
server.setConnectors(new Connector[]{connector});
RequestLogHandler requestLogHandler = new RequestLogHandler();
configureRequestLogImpl();
requestLogHandler.setRequestLog(requestLogImpl);
HandlerList handlers = new HandlerList();
handlers.addHandler(requestLogHandler);
handlers.addHandler(getRequestHandler());
server.setHandler(handlers);
server.start();
}
示例5: customizeServer
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
@Override
public void customizeServer(Server server) {
if(logFile != null) {
HandlerCollection rootHandler = (HandlerCollection) server.getHandler();
List<Handler> handlers = new ArrayList<Handler>();
handlers.addAll(Arrays.asList(rootHandler.getHandlers()));
RequestLogHandler requestLogHandler = new RequestLogHandler();
NCSARequestLog requestLog = new NCSARequestLog(logFile.getAbsolutePath());
requestLog.setRetainDays(0);
requestLog.setAppend(true);
requestLog.setExtended(extended);
requestLog.setLogTimeZone("GMT");
requestLogHandler.setRequestLog(requestLog);
handlers.add(requestLogHandler);
rootHandler.setHandlers(handlers.toArray(new Handler[handlers.size()]));
}
}
示例6: setRequestLogHandler
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
private static RequestLogHandler setRequestLogHandler() {
ConfigureAdaptor conf = ConfigureManager.getConfigure();
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename("./logs/http-request-yyyy_mm_dd.log");
requestLog.setFilenameDateFormat("yyyy_MM_dd");
requestLog.setRetainDays(conf.getLogKeepDays());
requestLog.setAppend(true);
requestLog.setExtended(true);
requestLog.setLogCookies(false);
requestLog.setLogTimeZone(TimeZone.getDefault().getID());
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
return requestLogHandler;
}
示例7: createHandlers
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
private static HandlerCollection createHandlers(
final GatewayConfig config,
final GatewayServices services,
final ContextHandlerCollection contexts) {
HandlerCollection handlers = new HandlerCollection();
RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(new AccessHandler());
TraceHandler traceHandler = new TraceHandler();
traceHandler.setHandler(contexts);
traceHandler.setTracedBodyFilter(System.getProperty("org.apache.knox.gateway.trace.body.status.filter"));
CorrelationHandler correlationHandler = new CorrelationHandler();
correlationHandler.setHandler(traceHandler);
DefaultTopologyHandler defaultTopoHandler = new DefaultTopologyHandler(config, services, contexts);
handlers.setHandlers(new Handler[]{correlationHandler, defaultTopoHandler, logHandler});
return handlers;
}
示例8: test_embeddedServer_withHandlerChain
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
@Test
public void test_embeddedServer_withHandlerChain() throws Exception {
AtomicLong logCount = new AtomicLong(0);
RequestLog requestLog = (request, response) -> logCount.incrementAndGet();
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
StatisticsHandler handlerChain = new StatisticsHandler();
handlerChain.setHandler(requestLogHandler);
Javalin app = Javalin.create()
.port(0)
.embeddedServer(new EmbeddedJettyFactory(() -> {
Server server = new Server();
server.setHandler(handlerChain);
return server;
}))
.get("/", ctx -> ctx.result("Hello World"))
.start();
String origin = "http://localhost:" + app.port();
int requests = 10;
for (int i = 0; i < requests; i++) {
assertThat(Unirest.get(origin + "/").asString().getBody(), is("Hello World"));
assertThat(Unirest.get(origin + "/not_there").asString().getStatus(), is(404));
}
assertThat(handlerChain.getDispatched(), is(requests * 2));
assertThat(handlerChain.getResponses2xx(), is(requests));
assertThat(handlerChain.getResponses4xx(), is(requests));
assertThat(logCount.get(), is((long) (requests * 2)));
app.stop();
}
示例9: getHandlerCollection
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
private HandlerCollection getHandlerCollection(
ServerConfig serverConfig,
ServletPathsConfig servletPathsConfig,
ServletHolder jdiscServlet,
ComponentRegistry<ServletHolder> servletHolders,
FilterHolder jDiscFilterInvokerFilter,
RequestLog requestLog) {
ServletContextHandler servletContextHandler = createServletContextHandler();
servletHolders.allComponentsById().forEach((id, servlet) -> {
String path = getServletPath(servletPathsConfig, id);
servletContextHandler.addServlet(servlet, path);
servletContextHandler.addFilter(jDiscFilterInvokerFilter, path, EnumSet.allOf(DispatcherType.class));
});
servletContextHandler.addServlet(jdiscServlet, "/*");
GzipHandler gzipHandler = newGzipHandler(serverConfig);
gzipHandler.setHandler(servletContextHandler);
StatisticsHandler statisticsHandler = newStatisticsHandler();
statisticsHandler.setHandler(gzipHandler);
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(new Handler[]{statisticsHandler, requestLogHandler});
return handlerCollection;
}
示例10: setupHandler
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
private HandlerCollection setupHandler() throws Exception {
final ResourceConfig resourceConfig = setupResourceConfig();
final ServletContainer servlet = new ServletContainer(resourceConfig);
final ServletHolder jerseyServlet = new ServletHolder(servlet);
// Initialize and register Jersey ServletContainer
jerseyServlet.setInitOrder(1);
// statically provide injector to jersey application.
final ServletContextHandler context =
new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.setContextPath("/");
GzipHandler gzip = new GzipHandler();
gzip.setIncludedMethods("POST");
gzip.setMinGzipSize(860);
gzip.setIncludedMimeTypes("application/json");
context.setGzipHandler(gzip);
context.addServlet(jerseyServlet, "/*");
context.addFilter(new FilterHolder(new ShutdownFilter(stopping, mapper)), "/*", null);
context.setErrorHandler(new JettyJSONErrorHandler(mapper));
final RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(new Slf4jRequestLog());
final RewriteHandler rewrite = new RewriteHandler();
makeRewriteRules(rewrite);
final HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[]{rewrite, context, requestLogHandler});
return handlers;
}
示例11: getRequestLogHandler
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
private Handler getRequestLogHandler(Handler handler) {
RequestLog requestLog = new Log4JAccessLog(configuration.getAccessLogConfigFilePath(),
() -> configuration.isAccessLogEnabled());
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
requestLogHandler.setHandler(handler);
return requestLogHandler;
}
示例12: wrapJettyHandler
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
/**
* Wraps the Jetty handler.
*
* @param server the Jetty server.
*/
private void wrapJettyHandler(Server server) {
LogbackAccessJettyRequestLog requestLog = new LogbackAccessJettyRequestLog(
logbackAccessProperties, environment, applicationEventPublisher);
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setHandler(server.getHandler());
requestLogHandler.setRequestLog(requestLog);
server.setHandler(requestLogHandler);
}
示例13: main
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Create a basic jetty server object that will listen on port 8080. Note that if you set this to port 0
// then a randomly available port will be assigned that you can either look in the logs for the port,
// or programmatically obtain it for use in test cases.
Server server = new Server(8080);
HandlerCollection handlers = new HandlerCollection();
server.setHandler(handlers);
ServletHandler servlet = new ServletHandler();
servlet.addServletWithMapping(HelloServlet.class, "/*");
handlers.addHandler(servlet);
handlers.addHandler(new DefaultHandler()); // must be after servlet it seems
// log using NCSA (common log format)
// http://en.wikipedia.org/wiki/Common_Log_Format
NCSARequestLog requestLog = new NCSARequestLog();
requestLog.setFilename("/tmp/yyyy_mm_dd.request.log");
requestLog.setFilenameDateFormat("yyyy_MM_dd");
requestLog.setRetainDays(90);
requestLog.setAppend(true);
requestLog.setExtended(true);
requestLog.setLogCookies(false);
requestLog.setLogTimeZone("GMT");
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
handlers.addHandler(requestLogHandler);
// Start things up! By using the server.join() the server thread will join with the current thread.
// See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
server.start();
server.join();
}
示例14: providesRequestLogHandler
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
@Provides
@Singleton
@Inject
protected RequestLogHandler providesRequestLogHandler(RequestLog requestLog) {
RequestLogHandler requestLogHandler = new RequestLogHandler();
requestLogHandler.setRequestLog(requestLog);
return requestLogHandler;
}
示例15: WebServer
import org.eclipse.jetty.server.handler.RequestLogHandler; //导入方法依赖的package包/类
public WebServer(@NotNull SharedContext context, @Nullable Server server, @NotNull WebServerConfig config, @NotNull EncryptionFactory tokenFactory) {
this.context = context;
this.server = server;
this.config = config;
this.tokenFactory = tokenFactory;
if (server != null) {
final ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath("/");
handler = contextHandler.getServletHandler();
//final ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
//securityHandler.addConstraintMapping(new );
//contextHandler.setSecurityHandler(securityHandler);
final RequestLogHandler logHandler = new RequestLogHandler();
logHandler.setRequestLog(new RequestLog() {
@Override
public void log(Request request, Response response) {
final User user = (User) request.getAttribute(User.class.getName());
final String userName = (user == null || user.isAnonymous()) ? "" : user.getUserName();
log.info("{}:{} - {} - \"{} {}\" {} {}", request.getRemoteHost(), request.getRemotePort(), userName, request.getMethod(), request.getHttpURI(), response.getStatus(), response.getReason());
}
});
final HandlerCollection handlers = new HandlerCollection();
handlers.addHandler(contextHandler);
handlers.addHandler(logHandler);
server.setHandler(handlers);
} else {
handler = null;
}
}