Search in sources :

Example 1 with ServletTransport

use of com.predic8.membrane.servlet.embedded.ServletTransport in project service-proxy by membrane.

the class MembraneServletContextListener method contextInitialized.

public void contextInitialized(ServletContextEvent sce) {
    try {
        log.info(Constants.PRODUCT_NAME + " starting...");
        log.debug("loading proxies configuration from: " + getProxiesXmlLocation(sce));
        appCtx = new BaseLocationXmlWebApplicationContext();
        Router router = RouterUtil.initializeRoutersFromSpringWebContext(appCtx, sce.getServletContext(), getProxiesXmlLocation(sce));
        if (router != null)
            throw new RuntimeException("A <router> with a <servletTransport> cannot be used with MembraneServletContextListener. Use MembraneServlet instead.");
        log.info(Constants.PRODUCT_NAME + " running.");
    } catch (Exception ex) {
        log.error("Router not started!", ex);
        throw new RuntimeException("Router not started!", ex);
    }
}
Also used : Router(com.predic8.membrane.core.Router) BaseLocationXmlWebApplicationContext(com.predic8.membrane.servlet.config.spring.BaseLocationXmlWebApplicationContext)

Example 2 with ServletTransport

use of com.predic8.membrane.servlet.embedded.ServletTransport in project service-proxy by membrane.

the class RouterUtil method initializeRoutersFromSpringWebContext.

public static Router initializeRoutersFromSpringWebContext(XmlWebApplicationContext appCtx, final ServletContext ctx, String configLocation) {
    appCtx.setServletContext(ctx);
    appCtx.setConfigLocation(configLocation);
    appCtx.refresh();
    Collection<Router> routers = appCtx.getBeansOfType(Router.class).values();
    Router theOne = null;
    for (Router r : routers) {
        r.getResolverMap().addSchemaResolver(new FileSchemaWebAppResolver(ctx));
        if (r.getTransport() instanceof ServletTransport) {
            if (theOne != null)
                throw new RuntimeException("Only one <router> may have a <servletTransport> defined.");
            theOne = r;
        }
    }
    appCtx.start();
    return theOne;
}
Also used : Router(com.predic8.membrane.core.Router) ServletTransport(com.predic8.membrane.servlet.embedded.ServletTransport)

Example 3 with ServletTransport

use of com.predic8.membrane.servlet.embedded.ServletTransport in project service-proxy by membrane.

the class MembraneServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    try {
        appCtx = new BaseLocationXmlWebApplicationContext();
        log.debug("loading beans configuration from: " + getProxiesXmlLocation(config));
        router = RouterUtil.initializeRoutersFromSpringWebContext(appCtx, config.getServletContext(), getProxiesXmlLocation(config));
        if (router == null)
            throw new RuntimeException("No <router> with a <servletTransport> was found. To use <router> with <transport>, use MembraneServletContextListener instead of MembraneServlet.");
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) BaseLocationXmlWebApplicationContext(com.predic8.membrane.servlet.config.spring.BaseLocationXmlWebApplicationContext) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

Router (com.predic8.membrane.core.Router)2 BaseLocationXmlWebApplicationContext (com.predic8.membrane.servlet.config.spring.BaseLocationXmlWebApplicationContext)2 ServletTransport (com.predic8.membrane.servlet.embedded.ServletTransport)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1