use of org.directwebremoting.WebContextFactory.WebContextBuilder in project ma-core-public by infiniteautomation.
the class StartupUtil method outOfContainerDestroy.
/**
* Clean up the current thread when {@link #outOfContainerInit()} has been
* called.
* @param container The container created by {@link #outOfContainerInit()}.
*/
public void outOfContainerDestroy(Container container) {
ServletLoggingOutput.unsetExecutionContext();
WebContextBuilder webContextBuilder = (WebContextBuilder) container.getBean(WebContextBuilder.class.getName());
if (webContextBuilder != null) {
webContextBuilder.unset();
}
}
use of org.directwebremoting.WebContextFactory.WebContextBuilder 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;
}
use of org.directwebremoting.WebContextFactory.WebContextBuilder in project ma-core-public by infiniteautomation.
the class StartupUtil method outOfContainerInit.
/**
* A way to setup DWR outside of any Containers.
* This method can also serve as a template for in container code wanting
* to get DWR setup. Callers of this method should clean up after themselves
* by calling {@link #outOfContainerDestroy(Container)}
* @return A new initialized container.
* @throws ServletException If the setup fails.
*/
public Container outOfContainerInit() throws ServletException {
try {
ServletConfig servletConfig = new FakeServletConfig("test", new FakeServletContext());
ServletContext servletContext = servletConfig.getServletContext();
StartupUtil.setupLogging(servletConfig, null);
StartupUtil.logStartup(servletConfig);
DefaultContainer container = ContainerUtil.createDefaultContainer(servletConfig);
ContainerUtil.setupDefaultContainer(container, servletConfig);
WebContextBuilder webContextBuilder = StartupUtil.initWebContext(servletConfig, servletContext, container);
StartupUtil.initServerContext(servletConfig, servletContext, container);
ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder, null);
ContainerUtil.configureContainerFully(container, servletConfig);
ContainerUtil.publishContainer(container, servletConfig);
return container;
} catch (ServletException ex) {
throw ex;
} catch (Exception ex) {
throw new ServletException(ex);
}
}
use of org.directwebremoting.WebContextFactory.WebContextBuilder in project ma-core-public by infiniteautomation.
the class StartupUtil method initWebContext.
/**
* Get the {@link WebContextFactory.WebContextBuilder} out of the
* {@link Container}, configure it (call WebContextBuilder#set()) and use it
* to configure the {@link WebContextFactory}.
* @param servletConfig The servlet configuration
* @param servletContext The servlet context
* @param servlet The servlet that we are running under
* @param container The container to save in the ServletContext
* @return a new WebContextBuilder
*/
public static WebContextBuilder initWebContext(ServletConfig servletConfig, ServletContext servletContext, Container container) {
WebContextBuilder webContextBuilder = (WebContextBuilder) container.getBean(WebContextBuilder.class.getName());
WebContextFactory.setWebContextBuilder(webContextBuilder);
webContextBuilder.set(null, null, servletConfig, servletContext, container);
return webContextBuilder;
}
use of org.directwebremoting.WebContextFactory.WebContextBuilder 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();
}
}
}
Aggregations