Skip to content

Instantly share code, notes, and snippets.

@os890
Last active January 1, 2016 10:48
Show Gist options
  • Save os890/8133398 to your computer and use it in GitHub Desktop.
Save os890/8133398 to your computer and use it in GitHub Desktop.
public class ViewConfigValidator implements ServletContextListener
{
@Override
public void contextInitialized(ServletContextEvent sce)
{
ViewConfigResolver viewConfigResolver =
BeanProvider.getContextualReference(ViewConfigResolver.class);
for (ConfigDescriptor configDescriptor :
viewConfigResolver.getConfigDescriptors())
{
try
{
if (!isInternal(configDescriptor.getConfigClass()) &&
sce.getServletContext()
.getResource(configDescriptor.getPath()) == null)
{
throw new IllegalStateException("path " +
configDescriptor.getPath() +
" doesn't exist, but it's mapped by " +
configDescriptor.getConfigClass().getName());
}
}
catch (MalformedURLException e)
{
throw ExceptionUtils.throwAsRuntimeException(e);
}
}
}
//needed with deltaspike 0.5
private boolean isInternal(Class configClass)
{
return ViewConfig.class.equals(configClass) ||
DefaultErrorView.class.equals(configClass) ||
ViewRef.class.equals(configClass) ||
ViewRef.Manual.class.equals(configClass);
}
@Override
public void contextDestroyed(ServletContextEvent sce)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment