本文整理了Java中org.eclipse.jetty.servlet.ServletHandler.addServletWithMapping()
方法的一些代码示例,展示了ServletHandler.addServletWithMapping()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServletHandler.addServletWithMapping()
方法的具体详情如下:
包路径:org.eclipse.jetty.servlet.ServletHandler
类名称:ServletHandler
方法名:addServletWithMapping
[英]Convenience method to add a servlet.
[中]添加servlet的便捷方法。
代码示例来源:origin: apache/avro
/** Constructs a server to run with the given ConnectionFactory on the given address/port. */
public HttpServer(ResponderServlet servlet, ConnectionFactory connectionFactory, String bindAddress, int port) throws IOException {
this.server = new org.eclipse.jetty.server.Server();
HttpConfiguration httpConfig = new HttpConfiguration();
HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
ServerConnector connector = new ServerConnector(this.server, connectionFactory, httpFactory);
if (bindAddress != null) {
connector.setHost(bindAddress);
}
connector.setPort(port);
server.addConnector(connector);
ServletHandler handler = new ServletHandler();
server.setHandler(handler);
handler.addServletWithMapping(new ServletHolder(servlet), "/*");
}
代码示例来源:origin: apache/avro
/**
* Constructs a server to run with the given connector.
*
* @deprecated - use the Constructors that take a ConnectionFactory
*/
@Deprecated
public HttpServer(ResponderServlet servlet, Connector connector) throws IOException {
this.server = connector.getServer();
if (server.getConnectors().length == 0 || Arrays.asList(server.getConnectors()).contains(connector)) {
server.addConnector(connector);
}
ServletHandler handler = new ServletHandler();
server.setHandler(handler);
handler.addServletWithMapping(new ServletHolder(servlet), "/*");
}
/**
代码示例来源:origin: apache/avro
public StatsServer(StatsPlugin plugin, int port) throws Exception {
this.httpServer = new Server(port);
this.plugin = plugin;
ServletHandler handler = new ServletHandler();
httpServer.setHandler(handler);
handler.addServletWithMapping(new ServletHolder(new StaticServlet()), "/");
handler.addServletWithMapping(new ServletHolder(new StatsServlet(plugin)), "/");
httpServer.start();
}
代码示例来源:origin: google/data-transfer-project
public void registerServlet(String path, Servlet servletContainer) {
ServletHolder servletHolder = new ServletHolder(Source.EMBEDDED);
servletHolder.setName("Data Transfer Project");
servletHolder.setServlet(servletContainer);
servletHolder.setInitOrder(1);
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
handler.setContextPath("/");
handlers.add(handler);
handler.getServletHandler().addServletWithMapping(servletHolder, path);
}
代码示例来源:origin: apache/incubator-druid
private static Server makeTestDeleteServer(int port, final CountDownLatch latch)
{
Server server = new Server(port);
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(new ServletHolder(new HttpServlet()
{
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp)
{
latch.countDown();
resp.setStatus(200);
}
}), "/default/*");
server.setHandler(handler);
return server;
}
代码示例来源:origin: apache/avro
/** Constructs a server to run on the named port on the specified address. */
public HttpServer(ResponderServlet servlet, String bindAddress, int port) throws IOException {
this.server = new org.eclipse.jetty.server.Server();
ServerConnector connector = new ServerConnector(this.server);
connector.setAcceptQueueSize(128);
connector.setIdleTimeout(10000);
if (bindAddress != null) {
connector.setHost(bindAddress);
}
connector.setPort(port);
server.addConnector(connector);
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(new ServletHolder(servlet), "/*");
ServletContextHandler sch = new ServletContextHandler();
sch.setServletHandler(handler);
server.setHandler(sch);
}
代码示例来源:origin: apache/incubator-druid
handler.addServletWithMapping(new ServletHolder(new HttpServlet()
代码示例来源:origin: line/armeria
private static Server startHttp2() throws Exception {
final Server server = new Server();
// Common HTTP configuration.
final HttpConfiguration config = new HttpConfiguration();
// HTTP/1.1 support.
final HttpConnectionFactory http1 = new HttpConnectionFactory(config);
// HTTP/2 cleartext support.
final HTTP2CServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(config);
// Add the connector.
final ServerConnector connector = new ServerConnector(server, http1, http2c);
connector.setPort(0);
server.addConnector(connector);
// Add the servlet.
final ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(newServletHolder(thriftServlet), TSERVLET_PATH);
server.setHandler(handler);
// Start the server.
server.start();
return server;
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@BeforeClass
public void setUpGlobal() throws Exception {
httpServer = new Server();
ServerConnector connector1 = addHttpConnector(httpServer);
httpServer.setHandler(new EchoHandler());
httpServer.start();
httpPort = connector1.getLocalPort();
proxy = new Server();
ServerConnector connector2 = addHttpConnector(proxy);
ServletHandler servletHandler = new ServletHandler();
ServletHolder servletHolder = servletHandler.addServletWithMapping(BasicAuthProxyServlet.class, "/*");
servletHolder.setInitParameter("maxThreads", "20");
proxy.setHandler(servletHandler);
proxy.start();
proxyPort = connector2.getLocalPort();
LOGGER.info("Local HTTP Server (" + httpPort + "), Proxy (" + proxyPort + ") started successfully");
}
代码示例来源:origin: org.springframework.boot/spring-boot
/**
* Add Jetty's {@code DefaultServlet} to the given {@link WebAppContext}.
* @param context the jetty {@link WebAppContext}
*/
protected final void addDefaultServlet(WebAppContext context) {
Assert.notNull(context, "Context must not be null");
ServletHolder holder = new ServletHolder();
holder.setName("default");
holder.setClassName("org.eclipse.jetty.servlet.DefaultServlet");
holder.setInitParameter("dirAllowed", "false");
holder.setInitOrder(1);
context.getServletHandler().addServletWithMapping(holder, "/");
context.getServletHandler().getServletMapping("/").setDefault(true);
}
代码示例来源:origin: apache/incubator-dubbo
ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
servletHolder.setInitOrder(2);
代码示例来源:origin: apache/incubator-dubbo
ServletHolder servletHolder = servletHandler.addServletWithMapping(DispatcherServlet.class, "/*");
servletHolder.setInitOrder(2);
代码示例来源:origin: line/armeria
private static Server startHttp1() throws Exception {
final Server server = new Server(0);
final ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(newServletHolder(thriftServlet), TSERVLET_PATH);
handler.addServletWithMapping(newServletHolder(rootServlet), "/");
handler.addFilterWithMapping(new FilterHolder(new ConnectionCloseFilter()), "/*",
EnumSet.of(DispatcherType.REQUEST));
server.setHandler(handler);
for (Connector c : server.getConnectors()) {
for (ConnectionFactory f : c.getConnectionFactories()) {
for (String p : f.getProtocols()) {
if (p.startsWith("h2c")) {
fail("Attempted to create a Jetty server without HTTP/2 support, but failed: " +
f.getProtocols());
}
}
}
}
server.start();
return server;
}
代码示例来源:origin: apache/nifi
private void setup(final Map<String, String> sslProperties) throws Exception {
// set up web service
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(CaptureServlet.class, "/*");
// create the service
server = new TestServer(sslProperties);
server.addHandler(handler);
server.startServer();
servlet = (CaptureServlet) handler.getServlets()[0].getServlet();
runner = TestRunners.newTestRunner(PostHTTP.class);
}
代码示例来源:origin: apache/nifi
@Test
public final void testSecure_oneWaySsl() throws Exception {
// set up web service
final ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(HelloWorldServlet.class, "/*");
// create the service, disabling the need for client auth
final Map<String, String> serverSslProperties = getKeystoreProperties();
serverSslProperties.put(TestServer.NEED_CLIENT_AUTH, Boolean.toString(false));
final TestServer server = new TestServer(serverSslProperties);
server.addHandler(handler);
try {
server.startServer();
final String destination = server.getSecureUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
// Use context service with only a truststore
useSSLContextService(getTruststoreProperties());
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
controller.setProperty(GetHTTP.URL, destination);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.run();
controller.assertAllFlowFilesTransferred(GetHTTP.REL_SUCCESS, 1);
final MockFlowFile mff = controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0);
mff.assertContentEquals("Hello, World!");
} finally {
server.shutdownServer();
}
}
代码示例来源:origin: apache/nifi
@Test
public final void testSecure_twoWaySsl() throws Exception {
// set up web service
final ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(HelloWorldServlet.class, "/*");
// create the service, providing both truststore and keystore properties, requiring client auth (default)
final Map<String, String> twoWaySslProperties = getKeystoreProperties();
twoWaySslProperties.putAll(getTruststoreProperties());
final TestServer server = new TestServer(twoWaySslProperties);
server.addHandler(handler);
try {
server.startServer();
final String destination = server.getSecureUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
// Use context service with a keystore and a truststore
useSSLContextService(twoWaySslProperties);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "10 secs");
controller.setProperty(GetHTTP.URL, destination);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.run();
controller.assertAllFlowFilesTransferred(GetHTTP.REL_SUCCESS, 1);
final MockFlowFile mff = controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0);
mff.assertContentEquals("Hello, World!");
} finally {
server.shutdownServer();
}
}
代码示例来源:origin: apache/nifi
@Test
public final void testExpressionLanguage() throws Exception {
// set up web service
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(UserAgentTestingServlet.class, "/*");
// create the service
TestServer server = new TestServer();
server.addHandler(handler);
try {
server.startServer();
String destination = server.getUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
controller.setProperty(GetHTTP.URL, destination+"/test_${literal(1)}.pdf");
controller.setProperty(GetHTTP.FILENAME, "test_${now():format('yyyy/MM/dd_HH:mm:ss')}");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.setProperty(GetHTTP.USER_AGENT, "testUserAgent");
controller.run();
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
MockFlowFile response = controller.getFlowFilesForRelationship(GetHTTP.REL_SUCCESS).get(0);
response.assertAttributeEquals("gethttp.remote.source","localhost");
String fileName = response.getAttribute(CoreAttributes.FILENAME.key());
assertTrue(fileName.matches("test_\\d\\d\\d\\d/\\d\\d/\\d\\d_\\d\\d:\\d\\d:\\d\\d"));
// shutdown web service
} finally {
server.shutdownServer();
}
}
代码示例来源:origin: apache/nifi
@Test
public final void testDynamicHeaders() throws Exception {
// set up web service
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(UserAgentTestingServlet.class, "/*");
// create the service
TestServer server = new TestServer();
server.addHandler(handler);
try {
server.startServer();
String destination = server.getUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
controller.setProperty(GetHTTP.URL, destination);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.setProperty(GetHTTP.USER_AGENT, "testUserAgent");
controller.setProperty("Static-Header", "StaticHeaderValue");
controller.setProperty("EL-Header", "${now()}");
controller.run();
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
// shutdown web service
} finally {
server.shutdownServer();
}
}
代码示例来源:origin: apache/nifi
@Test
public final void testUserAgent() throws Exception {
// set up web service
ServletHandler handler = new ServletHandler();
handler.addServletWithMapping(UserAgentTestingServlet.class, "/*");
// create the service
TestServer server = new TestServer();
server.addHandler(handler);
try {
server.startServer();
String destination = server.getUrl();
// set up NiFi mock controller
controller = TestRunners.newTestRunner(GetHTTP.class);
controller.setProperty(GetHTTP.CONNECTION_TIMEOUT, "5 secs");
controller.setProperty(GetHTTP.URL, destination);
controller.setProperty(GetHTTP.FILENAME, "testFile");
controller.setProperty(GetHTTP.ACCEPT_CONTENT_TYPE, "application/json");
controller.run();
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 0);
controller.setProperty(GetHTTP.USER_AGENT, "testUserAgent");
controller.run();
controller.assertTransferCount(GetHTTP.REL_SUCCESS, 1);
// shutdown web service
} finally {
server.shutdownServer();
}
}
代码示例来源:origin: apache/nifi
handler.addServletWithMapping(HttpErrorServlet.class, "/*");
内容来源于网络,如有侵权,请联系作者删除!