本文整理了Java中javax.servlet.ServletContext.getServletRegistration()
方法的一些代码示例,展示了ServletContext.getServletRegistration()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServletContext.getServletRegistration()
方法的具体详情如下:
包路径:javax.servlet.ServletContext
类名称:ServletContext
方法名:getServletRegistration
[英]Obtain the details of the named servlet.
[中]获取命名servlet的详细信息。
代码示例来源:origin: igniterealtime/Openfire
@Override
public ServletRegistration getServletRegistration( String s )
{
return proxy.getServletRegistration( s );
}
代码示例来源:origin: Atmosphere/atmosphere
try {
if (config.getServletConfig() != null) {
ServletRegistration s = config.getServletContext().getServletRegistration(config.getServletConfig().getServletName());
s = config.getServletContext().getServletRegistration(VoidServletConfig.ATMOSPHERE_SERVLET);
代码示例来源:origin: stackoverflow.com
public class MyInitializer implements ServletContainerInitializer {
public void onStartup(Set<Class<?>> c, ServletContext ctx) {
ctx.getServletRegistration("default").addMapping("*.html");
ctx.getServletRegistration("default").addMapping("/index.html");
}
}
代码示例来源:origin: spring-projects/spring-framework
private String getServletPath(ServletConfig config) {
String name = config.getServletName();
ServletRegistration registration = config.getServletContext().getServletRegistration(name);
if (registration == null) {
throw new IllegalStateException("ServletRegistration not found for Servlet '" + name + "'");
}
Collection<String> mappings = registration.getMappings();
if (mappings.size() == 1) {
String mapping = mappings.iterator().next();
if (mapping.equals("/")) {
return "";
}
if (mapping.endsWith("/*")) {
String path = mapping.substring(0, mapping.length() - 2);
if (!path.isEmpty() && logger.isDebugEnabled()) {
logger.debug("Found servlet mapping prefix '" + path + "' for '" + name + "'");
}
return path;
}
}
throw new IllegalArgumentException("Expected a single Servlet mapping: " +
"either the default Servlet mapping (i.e. '/'), " +
"or a path based mapping (e.g. '/*', '/foo/*'). " +
"Actual mappings: " + mappings + " for Servlet '" + name + "'");
}
代码示例来源:origin: org.springframework/spring-web
private String getServletPath(ServletConfig config) {
String name = config.getServletName();
ServletRegistration registration = config.getServletContext().getServletRegistration(name);
if (registration == null) {
throw new IllegalStateException("ServletRegistration not found for Servlet '" + name + "'");
}
Collection<String> mappings = registration.getMappings();
if (mappings.size() == 1) {
String mapping = mappings.iterator().next();
if (mapping.equals("/")) {
return "";
}
if (mapping.endsWith("/*")) {
String path = mapping.substring(0, mapping.length() - 2);
if (!path.isEmpty() && logger.isDebugEnabled()) {
logger.debug("Found servlet mapping prefix '" + path + "' for '" + name + "'");
}
return path;
}
}
throw new IllegalArgumentException("Expected a single Servlet mapping: " +
"either the default Servlet mapping (i.e. '/'), " +
"or a path based mapping (e.g. '/*', '/foo/*'). " +
"Actual mappings: " + mappings + " for Servlet '" + name + "'");
}
代码示例来源:origin: Atmosphere/atmosphere
public AtmosphereFrameworkInitializer configureFramework(ServletConfig sc, boolean init, boolean useNative, Class<? extends AtmosphereFramework> frameworkClass) throws ServletException {
if (framework == null) {
if (sc.getServletContext().getMajorVersion() > 2) {
try {
framework = (AtmosphereFramework) sc.getServletContext()
.getAttribute(sc.getServletContext().getServletRegistration(sc.getServletName()).getName());
} catch (Exception ex) {
// Equinox throw an exception (NPE)
// WebLogic Crap => https://github.com/Atmosphere/atmosphere/issues/1569
if (UnsupportedOperationException.class.isAssignableFrom(ex.getClass())) {
logger.warn("WebLogic 12c unable to retrieve Servlet. Please make sure your servlet-name is 'AtmosphereServlet' " +
"or set org.atmosphere.servlet to the current value");
String name = sc.getInitParameter(ApplicationConfig.SERVLET_NAME);
if (name == null) {
name = AtmosphereServlet.class.getSimpleName();
}
framework = (AtmosphereFramework) sc.getServletContext().getAttribute(name);
} else {
logger.trace("", ex);
}
}
}
if (framework == null) {
framework = newAtmosphereFramework(frameworkClass, isFilter, autoDetectHandlers);
}
}
framework.setUseNativeImplementation(useNative);
if (init) framework.init(sc);
return this;
}
代码示例来源:origin: jersey/jersey
private void onStartupImpl(final Set<Class<?>> classes, final ServletContext servletContext) throws ServletException {
// first see if there are any application classes in the web app
for (final Class<? extends Application> applicationClass : getApplicationClasses(classes)) {
final ServletRegistration servletRegistration = servletContext.getServletRegistration(applicationClass.getName());
if (servletRegistration != null) {
addServletWithExistingRegistration(servletContext, servletRegistration, applicationClass, classes);
} else {
// Servlet is not registered with app name or the app name is used to register a different servlet
// check if some servlet defines the app in init params
final List<Registration> srs = getInitParamDeclaredRegistrations(servletContext, applicationClass);
if (!srs.isEmpty()) {
// app handled by at least one servlet or filter
// fix the registrations if needed (i.e. add servlet class)
for (final Registration sr : srs) {
if (sr instanceof ServletRegistration) {
addServletWithExistingRegistration(servletContext, (ServletRegistration) sr,
applicationClass, classes);
}
}
} else {
// app not handled by any servlet/filter -> add it
addServletWithApplication(servletContext, applicationClass, classes);
}
}
}
// check for javax.ws.rs.core.Application registration
addServletWithDefaultConfiguration(servletContext, classes);
}
代码示例来源:origin: jersey/jersey
private void onStartupImpl(final Set<Class<?>> classes, final ServletContext servletContext) throws ServletException {
// first see if there are any application classes in the web app
for (final Class<? extends Application> applicationClass : getApplicationClasses(classes)) {
final ServletRegistration servletRegistration = servletContext.getServletRegistration(applicationClass.getName());
if (servletRegistration != null) {
addServletWithExistingRegistration(servletContext, servletRegistration, applicationClass, classes);
} else {
// Servlet is not registered with app name or the app name is used to register a different servlet
// check if some servlet defines the app in init params
final List<Registration> srs = getInitParamDeclaredRegistrations(servletContext, applicationClass);
if (!srs.isEmpty()) {
// app handled by at least one servlet or filter
// fix the registrations if needed (i.e. add servlet class)
for (final Registration sr : srs) {
if (sr instanceof ServletRegistration) {
addServletWithExistingRegistration(servletContext, (ServletRegistration) sr,
applicationClass, classes);
}
}
} else {
// app not handled by any servlet/filter -> add it
addServletWithApplication(servletContext, applicationClass, classes);
}
}
}
// check for javax.ws.rs.core.Application registration
addServletWithDefaultConfiguration(servletContext, classes);
}
代码示例来源:origin: jersey/jersey
/**
* 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));
}
}
}
}
代码示例来源:origin: jersey/jersey
/**
* 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));
}
}
}
}
代码示例来源:origin: apache/felix
@Override
public ServletRegistration getServletRegistration(String servletName)
{
return delegatee.getServletRegistration(servletName);
}
代码示例来源:origin: apache/felix
@Override
public ServletRegistration getServletRegistration(final String servletName)
{
return this.context.getServletRegistration(servletName);
}
代码示例来源:origin: org.igniterealtime.openfire/xmppserver
@Override
public ServletRegistration getServletRegistration( String s )
{
return proxy.getServletRegistration( s );
}
代码示例来源:origin: org.apache.felix/org.apache.felix.http.base
@Override
public ServletRegistration getServletRegistration(final String servletName)
{
return this.context.getServletRegistration(servletName);
}
代码示例来源:origin: org.jboss.seam/jboss-seam
public ServletRegistration getServletRegistration(String servletName)
{
return delegate.getServletRegistration(servletName);
}
代码示例来源:origin: org.crazyyak.dev/yak-dev-jersey-spring
/**
* Includes jspf as servlet
* @param servletContext the servlet context for this app
* @param appContext the application context for this app
*/
protected void addJspfServlet(ServletContext servletContext, WebApplicationContext appContext) {
servletContext.getServletRegistration("jsp").addMapping("*.jspf");
}
代码示例来源:origin: GluuFederation/oxAuth
public void onServletContextActivation(@Observes ServletContext context ) {
this.contextPath = context.getContextPath();
this.facesMapping = "";
String[] mappings = context.getServletRegistration("Faces Servlet").getMappings().toArray(new String[0]);
if (mappings.length == 0) {
return;
}
this.facesMapping = mappings[0].replaceAll("\\*", "");
}
代码示例来源:origin: org.joinfaces/jsf-spring-boot-autoconfigure
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
ServletRegistration servletRegistration = servletContext.getServletRegistration(FACES_SERVLET_NAME);
if (servletRegistration instanceof ServletRegistration.Dynamic) {
((ServletRegistration.Dynamic) servletRegistration).setMultipartConfig(this.multipartConfigElement);
}
}
}
代码示例来源:origin: org.kasource.websocket/ka-websocket-core
/**
* Returns the first URL mapped for this servlet.
*
* @return URL mapped for the servlet.
**/
public String getMaping() {
ServletRegistration reg = servletConfig.getServletContext().getServletRegistration(
servletConfig.getServletName());
return reg.getMappings().iterator().next();
}
代码示例来源:origin: apache/cxf
private String getServletMapping(final ServletContext ctx, final String name) throws ServletException {
ServletRegistration sr = ctx.getServletRegistration(name);
if (sr != null) {
return sr.getMappings().iterator().next();
}
final String error = "Servlet with a name " + name + " is not available";
throw new ServletException(error);
}
内容来源于网络,如有侵权,请联系作者删除!