本文整理匯總了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;
}