Search in sources :

Example 1 with Container

use of org.directwebremoting.Container in project ma-core-public by infiniteautomation.

the class ContainerUtil method createDefaultContainer.

/**
 * Create a {@link DefaultContainer}, allowing users to upgrade to a child
 * of DefaultContainer using an {@link ServletConfig} init parameter of
 * <code>org.directwebremoting.Container</code>. Note that while the
 * parameter name is the classname of {@link Container}, currently the only
 * this can only be used to create children that inherit from
 * {@link DefaultContainer}. This restriction may be relaxed in the future.
 * Unlike {@link #setupDefaultContainer(DefaultContainer, ServletConfig)},
 * this method does not call any setup methods.
 * @param servletConfig The source of init parameters
 * @return An unsetup implementaion of DefaultContainer
 * @throws ServletException If the specified class could not be found
 * @see ServletConfig#getInitParameter(String)
 */
public static DefaultContainer createDefaultContainer(ServletConfig servletConfig) throws ServletException {
    try {
        String typeName = servletConfig.getInitParameter(Container.class.getName());
        if (typeName == null) {
            return new DefaultContainer();
        }
        log.debug("Using alternate Container implementation: " + typeName);
        Class type = LocalUtil.classForName(typeName);
        return (DefaultContainer) type.newInstance();
    } catch (Exception ex) {
        throw new ServletException(ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) Container(org.directwebremoting.Container) ServletException(javax.servlet.ServletException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with Container

use of org.directwebremoting.Container in project ma-core-public by infiniteautomation.

the class DwrConvertTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    ServletContext servletContext = pageContext.getServletContext();
    Container container = (Container) servletContext.getAttribute("DwrContainer");
    if (container == null)
        throw new JspException("Can't find 'DwrContainer' in servlet context");
    ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
    final ScriptBuffer scriptBuffer = new ScriptBuffer();
    scriptBuffer.appendScript("return ");
    scriptBuffer.appendData(obj);
    WebContextBuilder webContextBuilder = (WebContextBuilder) servletContext.getAttribute(WebContextBuilder.class.getName());
    try {
        webContextBuilder.set((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse(), null, servletContext, container);
        JspWriter out = pageContext.getOut();
        out.write("function() {");
        out.write(ScriptBufferUtil.createOutput(scriptBuffer, converterManager));
        out.write(";}()");
    } catch (IOException e) {
        throw new JspException("Error writing tag content", e);
    } catch (MarshallException e) {
        throw new JspException("Error marshalling object data", e);
    } finally {
        webContextBuilder.unset();
    }
    return EVAL_PAGE;
}
Also used : JspException(javax.servlet.jsp.JspException) Container(org.directwebremoting.Container) ConverterManager(org.directwebremoting.extend.ConverterManager) MarshallException(org.directwebremoting.extend.MarshallException) ServletContext(javax.servlet.ServletContext) WebContextBuilder(org.directwebremoting.WebContextFactory.WebContextBuilder) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) ScriptBuffer(org.directwebremoting.ScriptBuffer)

Example 3 with Container

use of org.directwebremoting.Container in project jaffa-framework by jaffa-projects.

the class FinderMetaDataHelper method getServiceClass.

/**
 * Looks up dwr.xml for the input serviceName and returns the corresponding class.
 * The servletContext is needed to get a handle on the DWR context.
 */
private static Class getServiceClass(String serviceName, ServletContext servletContext) {
    // Obtain the ServletContext for the 'dwr' servlet. Error out if not found
    String dwrPath = servletContext.getContextPath() + "/dwr";
    ServletContext dwrServletContext = servletContext.getContext(dwrPath);
    if (dwrServletContext == null) {
        String m = "Unable to obtain ServletContext for the '" + dwrPath + "' servlet. The ServiceClass cannot be determined for: " + serviceName;
        log.error(m);
        throw new IllegalArgumentException(m);
    }
    // Check the ServletContext for a List of Containers
    List<Container> containers = (List<Container>) dwrServletContext.getAttribute(ContainerUtil.ATTRIBUTE_CONTAINER_LIST);
    if (containers == null) {
        String m = "Unable to load the dwr.xml configuration from the '" + dwrPath + "' servlet. The ServiceClass cannot be determined for: " + serviceName;
        log.error(m);
        throw new IllegalArgumentException(m);
    }
    // Iterate through the Containers, looking for a 'Creator' for the input service
    Class serviceClass = null;
    for (Container container : containers) {
        CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
        Creator creator = creatorManager.getCreator(serviceName);
        if (creator != null) {
            serviceClass = creator.getType();
            if (log.isDebugEnabled())
                log.debug("The ServiceClass for '" + serviceName + "' is " + serviceClass);
            break;
        }
    }
    // Error out if the service class cannot be determined
    if (serviceClass == null) {
        String m = "ServiceClass not be found for '" + serviceName + "' in dwr.xml";
        log.error(m);
        throw new IllegalArgumentException(m);
    }
    return serviceClass;
}
Also used : Container(org.directwebremoting.Container) ServletContext(javax.servlet.ServletContext) ArrayList(java.util.ArrayList) List(java.util.List) Creator(org.directwebremoting.extend.Creator) CreatorManager(org.directwebremoting.extend.CreatorManager)

Example 4 with Container

use of org.directwebremoting.Container in project ma-core-public by infiniteautomation.

the class DwrWebContextFilter method doFilter.

/* (non-Javadoc)
     * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
     */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    ServletContext servletContext = filterConfig.getServletContext();
    Container container = (Container) servletContext.getAttribute(Container.class.getName());
    if (container == null) {
        log.error("DwrWebContextFilter can not find ServletContext attribute for the DWR Container. Is DwrServlet configured in this web-application?");
    }
    ServletConfig servletConfig = (ServletConfig) servletContext.getAttribute(ServletConfig.class.getName());
    if (servletConfig == null) {
        log.error("DwrWebContextFilter can not find ServletContext attribute for the ServletConfig.");
    }
    WebContextBuilder webContextBuilder = (WebContextBuilder) servletContext.getAttribute(WebContextBuilder.class.getName());
    if (webContextBuilder == null) {
        log.error("DwrWebContextFilter can not find ServletContext attribute for the WebContextBuilder. WebContext will not be available.");
    } else {
        try {
            webContextBuilder.set((HttpServletRequest) request, (HttpServletResponse) response, servletConfig, servletContext, container);
            // It is totally legitimate for a servlet to be unavailable
            // (e.g. Spring DwrController)
            HttpServlet servlet = (HttpServlet) servletContext.getAttribute(HttpServlet.class.getName());
            if (servlet != null) {
                ServletLoggingOutput.setExecutionContext(servlet);
            }
            chain.doFilter(request, response);
        } finally {
            webContextBuilder.unset();
            ServletLoggingOutput.unsetExecutionContext();
        }
    }
}
Also used : Container(org.directwebremoting.Container) HttpServlet(javax.servlet.http.HttpServlet) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) WebContextBuilder(org.directwebremoting.WebContextFactory.WebContextBuilder)

Example 5 with Container

use of org.directwebremoting.Container in project ma-core-public by infiniteautomation.

the class ContainerUtil method shutdownServerLoadMonitorsInContainerList.

/**
 * Internal use only.
 * <p>If we detect that the server is being shutdown then we want to kill
 * any reverse ajax threads.
 * @param containers The list of containers to look for ServerLoadMonitors in
 * @param title What causes this (for debug purposes)
 */
public static void shutdownServerLoadMonitorsInContainerList(List containers, String title) {
    if (containers == null || containers.size() == 0) {
        log.debug("No containers to shutdown for: " + title);
        return;
    }
    log.debug("Shutting down containers for: " + title);
    for (Iterator it = containers.iterator(); it.hasNext(); ) {
        Container container = (Container) it.next();
        ServerLoadMonitor monitor = (ServerLoadMonitor) container.getBean(ServerLoadMonitor.class.getName());
        monitor.shutdown();
    }
}
Also used : Container(org.directwebremoting.Container) ServerLoadMonitor(org.directwebremoting.extend.ServerLoadMonitor) Iterator(java.util.Iterator)

Aggregations

Container (org.directwebremoting.Container)5 ServletContext (javax.servlet.ServletContext)3 IOException (java.io.IOException)2 WebContextBuilder (org.directwebremoting.WebContextFactory.WebContextBuilder)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ServletConfig (javax.servlet.ServletConfig)1 ServletException (javax.servlet.ServletException)1 HttpServlet (javax.servlet.http.HttpServlet)1 JspException (javax.servlet.jsp.JspException)1 JspWriter (javax.servlet.jsp.JspWriter)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 ScriptBuffer (org.directwebremoting.ScriptBuffer)1 ConverterManager (org.directwebremoting.extend.ConverterManager)1 Creator (org.directwebremoting.extend.Creator)1 CreatorManager (org.directwebremoting.extend.CreatorManager)1 MarshallException (org.directwebremoting.extend.MarshallException)1 ServerLoadMonitor (org.directwebremoting.extend.ServerLoadMonitor)1 SAXException (org.xml.sax.SAXException)1