Search in sources :

Example 1 with CamelServlet

use of org.apache.camel.http.common.CamelServlet in project camel by apache.

the class CamelHttpTransportServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    // use rest enabled resolver in case we use rest
    this.setServletResolveConsumerStrategy(new HttpRestServletResolveConsumerStrategy());
    String ignore = config.getInitParameter("ignoreDuplicateServletName");
    Boolean bool = ObjectConverter.toBoolean(ignore);
    if (bool != null) {
        ignoreDuplicateServletName = bool;
    } else {
        // always log so people can see it easier
        String msg = "Invalid parameter value for init-parameter ignoreDuplicateServletName with value: " + ignore;
        LOG.error(msg);
        throw new ServletException(msg);
    }
    String name = config.getServletName();
    String contextPath = config.getServletContext().getContextPath();
    if (httpRegistry == null) {
        httpRegistry = DefaultHttpRegistry.getHttpRegistry(name);
        CamelServlet existing = httpRegistry.getCamelServlet(name);
        if (existing != null) {
            String msg = "Duplicate ServletName detected: " + name + ". Existing: " + existing + " This: " + this.toString() + ". Its advised to use unique ServletName per Camel application.";
            // always log so people can see it easier
            if (isIgnoreDuplicateServletName()) {
                LOG.warn(msg);
            } else {
                LOG.error(msg);
                throw new ServletException(msg);
            }
        }
        httpRegistry.register(this);
    }
    LOG.info("Initialized CamelHttpTransportServlet[name={}, contextPath={}]", getServletName(), contextPath);
}
Also used : ServletException(javax.servlet.ServletException) HttpRestServletResolveConsumerStrategy(org.apache.camel.http.common.HttpRestServletResolveConsumerStrategy) CamelServlet(org.apache.camel.http.common.CamelServlet)

Example 2 with CamelServlet

use of org.apache.camel.http.common.CamelServlet 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 3 with CamelServlet

use of org.apache.camel.http.common.CamelServlet in project ddf by codice.

the class HttpProxyCamelHttpTransportServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    String ignore = config.getInitParameter("ignoreDuplicateServletName");
    Boolean bool = ObjectConverter.toBoolean(ignore);
    if (bool != null) {
        ignoreDuplicateServletName = bool;
    } else {
        // always log so people can see it easier
        String msg = "Invalid parameter value for init-parameter ignoreDuplicateServletName with value: " + ignore;
        LOG.debug(msg);
        throw new ServletException(msg);
    }
    String name = config.getServletName();
    String contextPath = config.getServletContext().getContextPath();
    if (httpRegistry == null) {
        httpRegistry = DefaultHttpRegistry.getHttpRegistry(name);
        CamelServlet existing = httpRegistry.getCamelServlet(name);
        if (existing != null) {
            String msg = "Duplicate ServetName detected: " + name + ". Existing: " + existing + " This: " + this + ". Its advised to use unique ServletName per Camel application.";
            // always log so people can see it easier
            if (isIgnoreDuplicateServletName()) {
                LOG.debug(msg);
            } else {
                LOG.debug(msg);
                throw new ServletException(msg);
            }
        }
        httpRegistry.register(this);
    }
    LOG.debug("Initialized CamelHttpTransportServlet[name={}, contextPath={}]", getServletName(), contextPath);
}
Also used : ServletException(javax.servlet.ServletException) CamelServlet(org.apache.camel.http.common.CamelServlet)

Example 4 with CamelServlet

use of org.apache.camel.http.common.CamelServlet in project camel by apache.

the class DefaultHttpRegistry method register.

@SuppressWarnings("rawtypes")
public void register(CamelServlet provider, Map properties) {
    CamelServlet camelServlet = provider;
    camelServlet.setServletName((String) properties.get("servlet-name"));
    register(camelServlet);
}
Also used : CamelServlet(org.apache.camel.http.common.CamelServlet)

Aggregations

CamelServlet (org.apache.camel.http.common.CamelServlet)4 ServletException (javax.servlet.ServletException)2 HttpRestServletResolveConsumerStrategy (org.apache.camel.http.common.HttpRestServletResolveConsumerStrategy)2 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1