use of javax.servlet.ServletRegistration in project jersey by jersey.
the class JerseyServletContainerInitializer method addServletWithExistingRegistration.
/**
* Enhance existing servlet configuration.
*/
private static void addServletWithExistingRegistration(final ServletContext context, ServletRegistration registration, final Class<? extends Application> clazz, final Set<Class<?>> classes) throws ServletException {
// create a new servlet container for a given app.
final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(clazz, classes).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);
final ServletRegistration.Dynamic dynamicRegistration = context.addServlet(clazz.getName(), servlet);
dynamicRegistration.setAsyncSupported(true);
dynamicRegistration.setLoadOnStartup(1);
registration = dynamicRegistration;
}
if (registration.getMappings().isEmpty()) {
final ApplicationPath ap = clazz.getAnnotation(ApplicationPath.class);
if (ap != null) {
final String mapping = createMappingPath(ap);
if (!mappingExists(context, mapping)) {
registration.addMapping(mapping);
LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_MAPPING(clazz.getName(), mapping));
} else {
LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_MAPPING_CONFLICT(clazz.getName(), mapping));
}
} else {
// Error
LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_NO_MAPPING_OR_ANNOTATION(clazz.getName(), ApplicationPath.class.getSimpleName()));
}
} else {
LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_APPLICATION(clazz.getName()));
}
}
use of javax.servlet.ServletRegistration in project spring-boot by spring-projects.
the class JerseyAutoConfiguration method setServletContext.
@Override
public void setServletContext(ServletContext servletContext) {
String servletRegistrationName = getServletRegistrationName();
ServletRegistration registration = servletContext.getServletRegistration(servletRegistrationName);
if (registration != null) {
if (logger.isInfoEnabled()) {
logger.info("Configuring existing registration for Jersey servlet '" + servletRegistrationName + "'");
}
registration.setInitParameters(this.jersey.getInit());
registration.setInitParameter(CommonProperties.METAINF_SERVICES_LOOKUP_DISABLE, Boolean.TRUE.toString());
}
}
use of javax.servlet.ServletRegistration in project Axe by DongyuCai.
the class DispatcherServlet method init.
@Override
public void init(ServletConfig servletConfig) throws ServletException {
//获取 ServletContext 对象(用于注册servlet)
ServletContext servletContext = servletConfig.getServletContext();
//初始化框架相关 helper 类
try {
HelperLoader.init(servletContext);
//注册处理JSP的Servlet
String appJspPath = ConfigHelper.getAppJspPath();
if (StringUtil.isNotEmpty(appJspPath)) {
appJspPath = appJspPath.endsWith("/") ? appJspPath : appJspPath + "/";
ServletRegistration jspServlet = servletContext.getServletRegistration("jsp");
jspServlet.addMapping(appJspPath + "*");
}
//注册处理静态资源的默认Servlet
String appAssetPath = ConfigHelper.getAppAssetPath();
if (StringUtil.isNotEmpty(appAssetPath)) {
appAssetPath = appAssetPath.endsWith("/") ? appAssetPath : appAssetPath + "/";
ServletRegistration defaultServlet = servletContext.getServletRegistration("default");
defaultServlet.addMapping(appAssetPath + "*");
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
use of javax.servlet.ServletRegistration in project wildfly by wildfly.
the class DefaultReplacingServletContextListener method contextInitialized.
public void contextInitialized(ServletContextEvent sce) {
ServletRegistration registration = sce.getServletContext().addServlet("ReplacementServlet", new ReplacementServlet());
registration.addMapping("/");
}
use of javax.servlet.ServletRegistration in project dropwizard by dropwizard.
the class AdminEnvironmentTest method addsATaskServlet.
@Test
public void addsATaskServlet() throws Exception {
final Task task = new Task("thing") {
@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
}
};
env.addTask(task);
handler.setServer(new Server());
handler.start();
final ServletRegistration registration = handler.getServletHandler().getServletContext().getServletRegistration("tasks");
assertThat(registration.getMappings()).containsOnly("/tasks/*");
}
Aggregations