use of javax.servlet.ServletRegistration in project jetty.project by eclipse.
the class HolderTest method testInitParams.
@Test
public void testInitParams() throws Exception {
ServletHolder holder = new ServletHolder(Source.JAVAX_API);
ServletRegistration reg = holder.getRegistration();
try {
reg.setInitParameter(null, "foo");
fail("null name accepted");
} catch (IllegalArgumentException e) {
}
try {
reg.setInitParameter("foo", null);
fail("null value accepted");
} catch (IllegalArgumentException e) {
}
reg.setInitParameter("foo", "bar");
assertFalse(reg.setInitParameter("foo", "foo"));
Set<String> clash = reg.setInitParameters(Collections.singletonMap("foo", "bax"));
assertTrue("should be one clash", clash != null && clash.size() == 1);
try {
reg.setInitParameters(Collections.singletonMap((String) null, "bax"));
fail("null name in map accepted");
} catch (IllegalArgumentException e) {
}
try {
reg.setInitParameters(Collections.singletonMap("foo", (String) null));
fail("null value in map accepted");
} catch (IllegalArgumentException e) {
}
Set<String> clash2 = reg.setInitParameters(Collections.singletonMap("FOO", "bax"));
assertTrue("should be no clash", clash2.isEmpty());
assertEquals("setInitParameters should not replace existing non-clashing init parameters", 2, reg.getInitParameters().size());
}
use of javax.servlet.ServletRegistration in project jersey by jersey.
the class JerseyServletContainerInitializer method addServletWithDefaultConfiguration.
/**
* Enhance default servlet (named {@link Application}) configuration.
*/
private static void addServletWithDefaultConfiguration(final ServletContext context, final Set<Class<?>> classes) throws ServletException {
ServletRegistration registration = context.getServletRegistration(Application.class.getName());
if (registration != null) {
final Set<Class<?>> appClasses = getRootResourceAndProviderClasses(classes);
final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(ResourceConfig.class, appClasses).addProperties(getInitParams(registration)).addProperties(Utils.getContextParams(context));
if (registration.getClassName() != null) {
// class name present - complete servlet registration from container point of view
Utils.store(resourceConfig, context, registration.getName());
} else {
// no class name - no complete servlet registration from container point of view
final ServletContainer servlet = new ServletContainer(resourceConfig);
registration = context.addServlet(registration.getName(), servlet);
((ServletRegistration.Dynamic) registration).setLoadOnStartup(1);
if (registration.getMappings().isEmpty()) {
// Error
LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_NO_MAPPING(registration.getName()));
} else {
LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_CLASSES(registration.getName(), appClasses));
}
}
}
}
use of javax.servlet.ServletRegistration 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;
}
Aggregations