本文整理汇总了Java中javax.servlet.annotation.WebInitParam类的典型用法代码示例。如果您正苦于以下问题:Java WebInitParam类的具体用法?Java WebInitParam怎么用?Java WebInitParam使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebInitParam类属于javax.servlet.annotation包,在下文中一共展示了WebInitParam类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toMappedFilter
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
public MappedFilter toMappedFilter(Filter filter, int order) {
WebFilter wfAnnotation = filter.getClass().getAnnotation(WebFilter.class);
if (wfAnnotation == null) {
throw new IllegalArgumentException(
"Filter contains no @WebFilter annotation and can not be mapped directly. Wrap it in a MappedFilter instead.");
}
String name = wfAnnotation.filterName() != null && wfAnnotation.filterName().length() > 0
? wfAnnotation.filterName() : null;
Set<String> urlPatterns = new HashSet<>(asList(wfAnnotation.urlPatterns()));
Map<String, String> initParams = new HashMap<>();
WebInitParam[] paramsArray = wfAnnotation.initParams();
if (paramsArray != null) {
asList(paramsArray).forEach(p -> initParams.put(p.name(), p.value()));
}
return new MappedFilter(filter, urlPatterns, name, initParams, order);
}
示例2: toMappedServlet
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
public MappedServlet toMappedServlet(Servlet servlet) {
WebServlet wsAnnotation = servlet.getClass().getAnnotation(WebServlet.class);
if (wsAnnotation == null) {
throw new IllegalArgumentException(
"Servlet contains no @WebServlet annotation and can not be mapped directly. Wrap it in a MappedServlet instead.");
}
String name = wsAnnotation.name() != null && wsAnnotation.name().length() > 0 ? wsAnnotation.name() : null;
Set<String> urlPatterns = new HashSet<>(asList(wsAnnotation.urlPatterns()));
Map<String, String> initParams = new HashMap<>();
WebInitParam[] paramsArray = wsAnnotation.initParams();
if (paramsArray != null) {
asList(paramsArray).forEach(p -> initParams.put(p.name(), p.value()));
}
return new MappedServlet(servlet, urlPatterns, name, initParams);
}
示例3: configure
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
private void configure(final ServletEnvironment environment, final HttpServlet servlet,
final Class<? extends HttpServlet> type, final String name, final WebServlet annotation) {
final ServletRegistration.Dynamic mapping = environment.addServlet(name, servlet);
final Set<String> clash = mapping
.addMapping(annotation.urlPatterns().length > 0 ? annotation.urlPatterns() : annotation.value());
if (clash != null && !clash.isEmpty()) {
final String msg = String.format(
"Servlet registration %s clash with already installed servlets on paths: %s",
type.getSimpleName(), Joiner.on(',').join(clash));
if (option(DenyServletRegistrationWithClash)) {
throw new IllegalStateException(msg);
} else {
logger.warn(msg);
}
}
if (annotation.initParams().length > 0) {
for (WebInitParam param : annotation.initParams()) {
mapping.setInitParameter(param.name(), param.value());
}
}
mapping.setAsyncSupported(annotation.asyncSupported());
}
示例4: configure
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
private void configure(final ServletEnvironment environment, final Filter filter,
final String name, final WebFilter annotation) {
final FilterRegistration.Dynamic mapping = environment.addFilter(name, filter);
final EnumSet<DispatcherType> dispatcherTypes = EnumSet.copyOf(Arrays.asList(annotation.dispatcherTypes()));
if (annotation.servletNames().length > 0) {
mapping.addMappingForServletNames(dispatcherTypes, false, annotation.servletNames());
} else {
final String[] urlPatterns = annotation.urlPatterns().length > 0
? annotation.urlPatterns() : annotation.value();
mapping.addMappingForUrlPatterns(dispatcherTypes, false, urlPatterns);
}
if (annotation.initParams().length > 0) {
for (WebInitParam param : annotation.initParams()) {
mapping.setInitParameter(param.name(), param.value());
}
}
mapping.setAsyncSupported(annotation.asyncSupported());
}
示例5: testConversion
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
@Test
public void testConversion() {
Class<? extends HttpServlet> servletClass = DefaultServlet.class;
String name = "name";
String[] value = new String[]{"a"};
String[] urlPatterns = new String[]{"/b"};
int loadOnStartup = 2;
WebInitParam[] initParams = new WebInitParam[]{new WebParam("name","value")};
boolean asyncSupported = true;
ServletDescriptor servletDescriptor = new ServletDescriptor(name, value, urlPatterns, loadOnStartup,
initParams, asyncSupported, servletClass);
ServletInfo servletInfo = mapper.apply(servletDescriptor);
assertThat(servletInfo.getName()).isEqualTo(name);
assertThat(servletInfo.getServletClass()).isEqualTo(servletClass);
assertThat(servletInfo.getMappings()).isEqualTo(asList(urlPatterns));
assertThat(servletInfo.getLoadOnStartup()).isEqualTo(loadOnStartup);
assertThat(servletInfo.isAsyncSupported()).isEqualTo(asyncSupported);
assertThat(servletInfo.getInitParams()).isEqualTo(singletonMap("name","value"));
}
示例6: readAnnotatedInitParams
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
private Map<String, String> readAnnotatedInitParams() {
Map<String, String> initParams = new HashMap<>();
if (isAnnotated()) {
WebFilter regAnnotation = filter.getClass().getAnnotation(WebFilter.class);
for (WebInitParam param : regAnnotation.initParams()) {
initParams.put(param.name(), param.value());
}
}
return initParams;
}
示例7: init
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
@PostConstruct
public void init() {
logger.info("Starting undertow w/ resteasy support.");
WebServlet resteasyServlet = new WebServletLiteral("RestEasy",new String[]{"/"},
new WebInitParam[]{},true,1);
Map<String,Object> servletContextParams = new HashMap<>();
servletContextParams.put(ResteasyDeployment.class.getName(), createDeployment());
undertowComponent = new UndertowComponent(httpListenPort,httpListenAddress,contextRoot,deploymentName)
.addServlet(resteasyServlet,HttpServlet30Dispatcher.class)
.setWebSocketEndpoint(CourseServer.class)
.addListener(RequestScopedServletRequestListener.class)
.start(servletContextParams);
logger.info("Container up and running on port "+httpListenPort);
}
示例8: WebServletLiteral
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
public WebServletLiteral(String name, String[] urlPatterns, WebInitParam[] params, boolean asyncSupported, int loadOnStartup) {
this.name = name;
this.urlPatterns = urlPatterns;
this.params = params;
this.asyncSupported = asyncSupported;
this.loadOnStartup = loadOnStartup;
}
示例9: startUndertow
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
public void startUndertow(@Observes ApplicationStartupEvent applicationStartupEvent) {
WebServlet resteasyServlet = new WebServletLiteral("RestEasy",new String[]{"/"},
new WebInitParam[]{},true,1);
Map<String,Object> servletContextParams = new HashMap<>();
servletContextParams.put(ResteasyDeployment.class.getName(), createDeployment());
undertowComponent = new UndertowComponent(undertowBindPort,undertowBindAddress,contextRoot,deploymentName)
.addServlet(resteasyServlet,HttpServlet30Dispatcher.class)
.addListener(RequestScopedServletRequestListener.class)
.start(servletContextParams);
}
示例10: cxfServlet
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
@Produces
@Dependent
public ServletDescriptor cxfServlet(RestServerConfiguration restServerConfiguration) {
String servletMapping = restServerConfiguration.getRestServletMapping();
List<WebInitParam> params = new ArrayList<>();
if(enableSseTransport) {
params.add(new WebParam(CXFNonSpringJaxrsServlet.TRANSPORT_ID, SseHttpTransportFactory.TRANSPORT_ID));
}
WebInitParam[] initParams = params.toArray(new WebInitParam[params.size()]);
return new ServletDescriptor("CXF",null, new String[]{servletMapping},1, initParams,true,CXFCdiServlet.class);
}
示例11: resteasyServlet
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
@Produces
public ServletDescriptor resteasyServlet() {
String path = restServerConfiguration.getRestServerUri();
if( !(applicationInstance.isUnsatisfied() || applicationInstance.isAmbiguous())) {
ApplicationPath appPath = ClassUtils.getAnnotation(applicationInstance.get().getClass(), ApplicationPath.class);
if(appPath != null) {
path = appPath.value();
}
}
String pattern = path.endsWith("/") ? path + "*" : path + "/*";
WebInitParam param = new WebParam("resteasy.servlet.mapping.prefix", path);
return new ServletDescriptor("ResteasyServlet",new String[]{pattern}, new String[]{pattern},
1,new WebInitParam[]{param},true,HttpServlet30Dispatcher.class);
}
示例12: shouldCreateServletHolderWithParams
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
@Test
public void shouldCreateServletHolderWithParams() {
when(servletHandler.newServletHolder(Source.EMBEDDED)).thenReturn(new ServletHolder(Source.EMBEDDED));
ServletDescriptor servletDescriptor = new ServletDescriptor("name", new String[]{"uri"}, new String[]{"uri"},
1,new WebInitParam[]{new WebParam("key","value")},true, DefaultServlet.class);
ServletHolder holder = mapper.apply(servletDescriptor);
assertThat(holder.getInitParameters()).isEqualTo(singletonMap("key","value"));
}
示例13: apply
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
@Override
public ServletInfo apply(ServletDescriptor servletDescriptor) {
ServletInfo servletInfo = Servlets.servlet(servletDescriptor.name(), servletDescriptor.servletClass())
.setAsyncSupported(servletDescriptor.asyncSupported())
.setLoadOnStartup(servletDescriptor.loadOnStartup())
.addMappings(servletDescriptor.urlPatterns());
if(servletDescriptor.initParams() != null) {
for(WebInitParam param : servletDescriptor.initParams()) {
servletInfo.addInitParam(param.name(), param.value());
}
}
return servletInfo;
}
示例14: FilterDescriptor
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
public FilterDescriptor(String name, String[] value, String[] urlPatterns, DispatcherType[] dispatcherTypes,
WebInitParam[] initParams, boolean asyncSupported, String[] servletNames, Class<? extends Filter> clazz) {
this.name = name;
this.value = value;
this.urlPatterns = urlPatterns;
this.dispatcherTypes = dispatcherTypes;
this.initParams = initParams;
this.asyncSupported = asyncSupported;
this.servletNames = servletNames;
this.clazz = clazz;
}
示例15: ServletDescriptor
import javax.servlet.annotation.WebInitParam; //导入依赖的package包/类
public ServletDescriptor(String name, String[] value, String[] urlPatterns, int loadOnStartup, WebInitParam[] initParams,
boolean asyncSupported, Class<? extends HttpServlet> servletClass) {
this.name = name;
this.value = value;
this.urlPatterns = urlPatterns;
this.loadOnStartup = loadOnStartup;
this.initParams = initParams;
this.asyncSupported = asyncSupported;
this.servletClass = servletClass;
}