Search in sources :

Example 36 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.

the class TestPostHTTP method setup.

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);
}
Also used : ServletHandler(org.eclipse.jetty.servlet.ServletHandler)

Example 37 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.

the class TestHttpClient method setup.

@BeforeClass
public static void setup() throws Exception {
    // Create embedded Jetty server
    // Use less threads to mitigate Gateway Timeout (504) with proxy test
    // Minimum thread pool size = (acceptors=2 + selectors=8 + request=1), defaults to max=200
    final QueuedThreadPool threadPool = new QueuedThreadPool(50);
    server = new Server(threadPool);
    final ContextHandlerCollection handlerCollection = new ContextHandlerCollection();
    final ServletContextHandler contextHandler = new ServletContextHandler();
    contextHandler.setContextPath("/nifi-api");
    final ServletContextHandler wrongPathContextHandler = new ServletContextHandler();
    wrongPathContextHandler.setContextPath("/wrong/nifi-api");
    handlerCollection.setHandlers(new Handler[] { contextHandler, wrongPathContextHandler });
    server.setHandler(handlerCollection);
    final ServletHandler servletHandler = new ServletHandler();
    contextHandler.insertHandler(servletHandler);
    final ServletHandler wrongPathServletHandler = new ServletHandler();
    wrongPathContextHandler.insertHandler(wrongPathServletHandler);
    final SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath("src/test/resources/certs/localhost-ks.jks");
    sslContextFactory.setKeyStorePassword("localtest");
    sslContextFactory.setKeyStoreType("JKS");
    httpConnector = new ServerConnector(server);
    final HttpConfiguration https = new HttpConfiguration();
    https.addCustomizer(new SecureRequestCustomizer());
    sslConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(https));
    server.setConnectors(new Connector[] { httpConnector, sslConnector });
    wrongPathServletHandler.addServletWithMapping(WrongSiteInfoServlet.class, "/site-to-site");
    servletHandler.addServletWithMapping(SiteInfoServlet.class, "/site-to-site");
    servletHandler.addServletWithMapping(PeersServlet.class, "/site-to-site/peers");
    servletHandler.addServletWithMapping(PortTransactionsAccessDeniedServlet.class, "/data-transfer/input-ports/input-access-denied-id/transactions");
    servletHandler.addServletWithMapping(PortTransactionsServlet.class, "/data-transfer/input-ports/input-running-id/transactions");
    servletHandler.addServletWithMapping(InputPortTransactionServlet.class, "/data-transfer/input-ports/input-running-id/transactions/transaction-id");
    servletHandler.addServletWithMapping(FlowFilesServlet.class, "/data-transfer/input-ports/input-running-id/transactions/transaction-id/flow-files");
    servletHandler.addServletWithMapping(PortTransactionsServlet.class, "/data-transfer/input-ports/input-timeout-id/transactions");
    servletHandler.addServletWithMapping(InputPortTransactionServlet.class, "/data-transfer/input-ports/input-timeout-id/transactions/transaction-id");
    servletHandler.addServletWithMapping(FlowFilesTimeoutServlet.class, "/data-transfer/input-ports/input-timeout-id/transactions/transaction-id/flow-files");
    servletHandler.addServletWithMapping(PortTransactionsServlet.class, "/data-transfer/input-ports/input-timeout-data-ex-id/transactions");
    servletHandler.addServletWithMapping(InputPortTransactionServlet.class, "/data-transfer/input-ports/input-timeout-data-ex-id/transactions/transaction-id");
    servletHandler.addServletWithMapping(FlowFilesTimeoutAfterDataExchangeServlet.class, "/data-transfer/input-ports/input-timeout-data-ex-id/transactions/transaction-id/flow-files");
    servletHandler.addServletWithMapping(PortTransactionsServlet.class, "/data-transfer/output-ports/output-running-id/transactions");
    servletHandler.addServletWithMapping(OutputPortTransactionServlet.class, "/data-transfer/output-ports/output-running-id/transactions/transaction-id");
    servletHandler.addServletWithMapping(FlowFilesServlet.class, "/data-transfer/output-ports/output-running-id/transactions/transaction-id/flow-files");
    servletHandler.addServletWithMapping(PortTransactionsServlet.class, "/data-transfer/output-ports/output-timeout-id/transactions");
    servletHandler.addServletWithMapping(OutputPortTransactionServlet.class, "/data-transfer/output-ports/output-timeout-id/transactions/transaction-id");
    servletHandler.addServletWithMapping(FlowFilesTimeoutServlet.class, "/data-transfer/output-ports/output-timeout-id/transactions/transaction-id/flow-files");
    servletHandler.addServletWithMapping(PortTransactionsServlet.class, "/data-transfer/output-ports/output-timeout-data-ex-id/transactions");
    servletHandler.addServletWithMapping(OutputPortTransactionServlet.class, "/data-transfer/output-ports/output-timeout-data-ex-id/transactions/transaction-id");
    servletHandler.addServletWithMapping(FlowFilesTimeoutAfterDataExchangeServlet.class, "/data-transfer/output-ports/output-timeout-data-ex-id/transactions/transaction-id/flow-files");
    server.start();
    logger.info("Starting server on port {} for HTTP, and {} for HTTPS", httpConnector.getLocalPort(), sslConnector.getLocalPort());
    startProxyServer();
    startProxyServerWithAuth();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) Server(org.eclipse.jetty.server.Server) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) BeforeClass(org.junit.BeforeClass)

Example 38 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project nifi by apache.

the class AtlasAPIV2ServerEmulator method createServer.

private void createServer() throws Exception {
    server = new Server();
    final ContextHandlerCollection handlerCollection = new ContextHandlerCollection();
    final ServletContextHandler staticContext = new ServletContextHandler();
    staticContext.setContextPath("/");
    final ServletContextHandler atlasApiV2Context = new ServletContextHandler();
    atlasApiV2Context.setContextPath("/api/atlas/v2/");
    handlerCollection.setHandlers(new Handler[] { staticContext, atlasApiV2Context });
    server.setHandler(handlerCollection);
    final ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(Resource.newClassPathResource("public", false, false));
    staticContext.setHandler(resourceHandler);
    final ServletHandler servletHandler = new ServletHandler();
    atlasApiV2Context.insertHandler(servletHandler);
    httpConnector = new ServerConnector(server);
    httpConnector.setPort(21000);
    server.setConnectors(new Connector[] { httpConnector });
    servletHandler.addServletWithMapping(TypeDefsServlet.class, "/types/typedefs/");
    servletHandler.addServletWithMapping(EntityBulkServlet.class, "/entity/bulk/");
    servletHandler.addServletWithMapping(EntityGuidServlet.class, "/entity/guid/*");
    servletHandler.addServletWithMapping(SearchByUniqueAttributeServlet.class, "/entity/uniqueAttribute/type/*");
    servletHandler.addServletWithMapping(SearchBasicServlet.class, "/search/basic/");
    servletHandler.addServletWithMapping(LineageServlet.class, "/debug/lineage/");
    notificationServerEmulator = new AtlasNotificationServerEmulator();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 39 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project core by weld.

the class EclipseWeldServletHandler method findWAC.

protected static WebAppContext findWAC(ServletContext context) {
    if (context instanceof ContextHandler.Context) {
        ContextHandler.Context sContext = (ContextHandler.Context) context;
        ContextHandler contextHandler = sContext.getContextHandler();
        Handler handler = contextHandler.getHandler();
        if (handler instanceof ServletHandler) {
            ServletHandler servletHandler = (ServletHandler) handler;
            Server server = servletHandler.getServer();
            Handler serverHandler = server.getHandler();
            if (serverHandler instanceof HandlerCollection) {
                HandlerCollection hc = (HandlerCollection) serverHandler;
                for (Handler h : hc.getHandlers()) {
                    if (h instanceof WebAppContext) {
                        WebAppContext wac = (WebAppContext) h;
                        if (wac.getServletHandler() == servletHandler) {
                            return wac;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletContext(javax.servlet.ServletContext) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Example 40 with ServletHandler

use of org.eclipse.jetty.servlet.ServletHandler in project oozie by apache.

the class ServletMapper method mapOozieServlets.

/**
 * Maps Oozie servlets to path specs. Make sure it is in sync with FilterMapper when making changes.
 */
void mapOozieServlets() {
    mapServlet(VersionServlet.class, "/versions");
    mapServlet(V0AdminServlet.class, "/v0/admin/*");
    mapServlet(V1AdminServlet.class, "/v1/admin/*");
    mapServlet(V2AdminServlet.class, "/v2/admin/*");
    mapServlet(CallbackServlet.class, "/callback/*");
    ServletHandler servletHandler = servletContextHandler.getServletHandler();
    String v0JobsServletName = V0JobsServlet.class.getSimpleName();
    servletHandler.addServlet(new ServletHolder(v0JobsServletName, new V0JobsServlet()));
    ServletMapping jobServletMappingV0 = new ServletMapping();
    jobServletMappingV0.setPathSpec("/v0/jobs");
    jobServletMappingV0.setServletName(v0JobsServletName);
    String v1JobsServletName = V1JobsServlet.class.getSimpleName();
    servletHandler.addServlet(new ServletHolder(v1JobsServletName, new V1JobsServlet()));
    ServletMapping jobServletMappingV1 = new ServletMapping();
    jobServletMappingV1.setPathSpec("/v1/jobs");
    jobServletMappingV1.setServletName(v1JobsServletName);
    // v1 and v2 version for the jobs API are same.
    ServletMapping jobServletMappingV2 = new ServletMapping();
    jobServletMappingV2.setPathSpec("/v2/jobs");
    jobServletMappingV2.setServletName(v1JobsServletName);
    servletHandler.addServletMapping(jobServletMappingV0);
    servletHandler.addServletMapping(jobServletMappingV1);
    servletHandler.addServletMapping(jobServletMappingV2);
    mapServlet(V0JobServlet.class, "/v0/job/*");
    mapServlet(V1JobServlet.class, "/v1/job/*");
    mapServlet(V2JobServlet.class, "/v2/job/*");
    mapServlet(SLAServlet.class, "/v1/sla/*");
    mapServlet(V2SLAServlet.class, "/v2/sla/*");
    mapServlet(V2ValidateServlet.class, "/v2/validate/*");
    mapServlet(ErrorServlet.class, "/error/*");
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) V0JobsServlet(org.apache.oozie.servlet.V0JobsServlet) V1JobsServlet(org.apache.oozie.servlet.V1JobsServlet)

Aggregations

ServletHandler (org.eclipse.jetty.servlet.ServletHandler)54 Server (org.eclipse.jetty.server.Server)23 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)22 ServerConnector (org.eclipse.jetty.server.ServerConnector)11 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)10 Test (org.junit.Test)10 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)8 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)5 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InetSocketAddress (java.net.InetSocketAddress)3 HttpServlet (javax.servlet.http.HttpServlet)3 ServletMapping (org.eclipse.jetty.servlet.ServletMapping)3 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2