Search in sources :

Example 86 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.

the class JettyHttpComponent method createServletForConnector.

protected CamelServlet createServletForConnector(Server server, Connector connector, List<Handler> handlers, JettyHttpEndpoint endpoint) throws Exception {
    ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    if (Server.getVersion().startsWith("8")) {
        context.getClass().getMethod("setConnectorNames", new Class[] { String[].class }).invoke(context, new Object[] { new String[] { connector.getName() } });
    }
    addJettyHandlers(server, handlers);
    CamelServlet camelServlet = new CamelContinuationServlet();
    ServletHolder holder = new ServletHolder();
    holder.setServlet(camelServlet);
    holder.setAsyncSupported(true);
    holder.setInitParameter(CamelServlet.ASYNC_PARAM, Boolean.toString(endpoint.isAsync()));
    context.addServlet(holder, "/*");
    // use rest enabled resolver in case we use rest
    camelServlet.setServletResolveConsumerStrategy(new HttpRestServletResolveConsumerStrategy());
    return camelServlet;
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpRestServletResolveConsumerStrategy(org.apache.camel.http.common.HttpRestServletResolveConsumerStrategy) CamelServlet(org.apache.camel.http.common.CamelServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 87 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.

the class JettyHttpComponent method enableMultipartFilter.

private void enableMultipartFilter(HttpCommonEndpoint endpoint, Server server, String connectorKey) throws Exception {
    ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
    CamelContext camelContext = this.getCamelContext();
    FilterHolder filterHolder = new FilterHolder();
    filterHolder.setInitParameter("deleteFiles", "true");
    if (ObjectHelper.isNotEmpty(camelContext.getProperty(TMP_DIR))) {
        File file = new File(camelContext.getProperty(TMP_DIR));
        if (!file.isDirectory()) {
            throw new RuntimeCamelException("The temp file directory of camel-jetty is not exists, please recheck it with directory name :" + camelContext.getProperties().get(TMP_DIR));
        }
        context.setAttribute("javax.servlet.context.tempdir", file);
    }
    // if a filter ref was provided, use it.
    Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter();
    if (filter == null) {
        // if no filter ref was provided, use the default filter
        filter = new MultiPartFilter();
    }
    filterHolder.setFilter(new CamelFilterWrapper(filter));
    String pathSpec = endpoint.getPath();
    if (pathSpec == null || "".equals(pathSpec)) {
        pathSpec = "/";
    }
    if (endpoint.isMatchOnUriPrefix()) {
        pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
    }
    addFilter(context, filterHolder, pathSpec);
    LOG.debug("using multipart filter implementation " + filter.getClass().getName() + " for path " + pathSpec);
}
Also used : CamelContext(org.apache.camel.CamelContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) MultiPartFilter(org.eclipse.jetty.servlets.MultiPartFilter) Filter(javax.servlet.Filter) MultiPartFilter(org.eclipse.jetty.servlets.MultiPartFilter) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) RuntimeCamelException(org.apache.camel.RuntimeCamelException) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File)

Example 88 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.

the class JettyHttpComponent method setFilters.

private void setFilters(JettyHttpEndpoint endpoint, Server server, String connectorKey) {
    ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
    List<Filter> filters = endpoint.getFilters();
    for (Filter filter : filters) {
        FilterHolder filterHolder = new FilterHolder();
        if (endpoint.getFilterInitParameters() != null) {
            filterHolder.setInitParameters(endpoint.getFilterInitParameters());
        }
        filterHolder.setFilter(new CamelFilterWrapper(filter));
        String pathSpec = endpoint.getPath();
        if (pathSpec == null || "".equals(pathSpec)) {
            pathSpec = "/";
        }
        if (endpoint.isMatchOnUriPrefix()) {
            pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
        }
        addFilter(context, filterHolder, pathSpec);
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Filter(javax.servlet.Filter) MultiPartFilter(org.eclipse.jetty.servlets.MultiPartFilter) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 89 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.

the class WebsocketCamelRouterTestSupport method setUp.

@Before
public void setUp() throws Exception {
    server = new Server(PORT);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    servletHolder = new ServletHolder(new CamelWebSocketServlet());
    servletHolder.setName("CamelWsServlet");
    context.addServlet(servletHolder, "/*");
    server.start();
    if (startCamelContext) {
        super.setUp();
    }
}
Also used : Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Before(org.junit.Before)

Example 90 with ServletContextHandler

use of org.eclipse.jetty.servlet.ServletContextHandler in project camel by apache.

the class WsProducerTestBase method startTestServer.

public void startTestServer() throws Exception {
    // start a simple websocket echo service
    server = new Server(PORT);
    Connector connector = getConnector();
    server.addConnector(connector);
    ServletContextHandler ctx = new ServletContextHandler();
    ctx.setContextPath("/");
    ctx.addServlet(TestServletFactory.class.getName(), "/*");
    server.setHandler(ctx);
    server.start();
    assertTrue(server.isStarted());
}
Also used : Connector(org.eclipse.jetty.server.Connector) Server(org.eclipse.jetty.server.Server) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Aggregations

ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)390 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)253 Server (org.eclipse.jetty.server.Server)217 ServerConnector (org.eclipse.jetty.server.ServerConnector)98 Test (org.junit.Test)70 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)56 IOException (java.io.IOException)42 HttpServletRequest (javax.servlet.http.HttpServletRequest)39 HttpClient (org.eclipse.jetty.client.HttpClient)39 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)39 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)37 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)37 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)32 Connector (org.eclipse.jetty.server.Connector)29 Request (org.eclipse.jetty.client.api.Request)27 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)24 ServletContainer (org.glassfish.jersey.servlet.ServletContainer)24 ServletException (javax.servlet.ServletException)22 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)22 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)22