Search in sources :

Example 1 with ServletMapping

use of org.apache.myfaces.spi.ServletMapping in project tomee by apache.

the class TomEEWebConfigProvider method getFacesServletMappings.

@Override
public List<ServletMapping> getFacesServletMappings(final ExternalContext externalContext) {
    final List<ServletMapping> facesServletMappings = super.getFacesServletMappings(externalContext);
    try {
        // getContext() is a runtime object where getServletRegistrations() is forbidden so unwrap
        final ServletContext sc = ServletContext.class.cast(Reflections.get(externalContext.getContext(), "sc"));
        if (sc != null && sc.getServletRegistrations() != null) {
            for (final Map.Entry<String, ? extends ServletRegistration> reg : sc.getServletRegistrations().entrySet()) {
                final ServletRegistration value = reg.getValue();
                if ("javax.faces.webapp.FacesServlet".equals(value.getClassName())) {
                    for (final String mapping : value.getMappings()) {
                        final Class<?> clazz = sc.getClassLoader().loadClass(value.getClassName());
                        final org.apache.myfaces.shared_impl.webapp.webxml.ServletMapping mappingImpl = new org.apache.myfaces.shared_impl.webapp.webxml.ServletMapping(value.getName(), clazz, mapping);
                        facesServletMappings.add(new ServletMappingImpl(mappingImpl));
                    }
                }
            }
        } else {
            facesServletMappings.addAll(super.getFacesServletMappings(externalContext));
        }
    } catch (final Exception e) {
        // don't fail cause our cast failed
        facesServletMappings.clear();
        facesServletMappings.addAll(super.getFacesServletMappings(externalContext));
    }
    return facesServletMappings;
}
Also used : ServletMapping(org.apache.myfaces.spi.ServletMapping) ServletMappingImpl(org.apache.myfaces.spi.impl.ServletMappingImpl) ServletRegistration(javax.servlet.ServletRegistration) ServletContext(javax.servlet.ServletContext) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1 ServletRegistration (javax.servlet.ServletRegistration)1 ServletMapping (org.apache.myfaces.spi.ServletMapping)1 ServletMappingImpl (org.apache.myfaces.spi.impl.ServletMappingImpl)1