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);
}
}
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;
}
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;
}
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();
}
}
}
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();
}
}
Aggregations