本文整理了Java中io.undertow.servlet.api.Deployment
类的一些代码示例,展示了Deployment
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Deployment
类的具体详情如下:
包路径:io.undertow.servlet.api.Deployment
类名称:Deployment
[英]Runtime representation of a deployment.
[中]部署的运行时表示。
代码示例来源:origin: wildfly/wildfly
private Principal[] getGrantedRoles(Account account, Deployment deployment) {
if (account == null) {
return new Principal[] {};
}
Set<String> roles = new HashSet<>(account.getRoles());
Map<String, Set<String>> principalVersusRolesMap = deployment.getDeploymentInfo().getPrincipalVersusRolesMap();
roles.addAll(principalVersusRolesMap.getOrDefault(account.getPrincipal().getName(), Collections.emptySet()));
Principal[] principals = new Principal[roles.size()];
int index = 0;
for (String role : roles) {
principals[index++] = () -> role;
}
return principals;
}
}
代码示例来源:origin: org.springframework.boot/spring-boot
registerServletContainerInitializerToDriveServletContextInitializers(deployment,
initializers);
deployment.setClassLoader(getServletClassLoader());
deployment.setContextPath(getContextPath());
deployment.setDisplayName(getDisplayName());
deployment.setDeploymentName("spring-boot");
if (isRegisterDefaultServlet()) {
DeploymentManager manager = Servlets.newContainer().addDeployment(deployment);
manager.deploy();
SessionManager sessionManager = manager.getDeployment().getSessionManager();
Duration timeoutDuration = getSession().getTimeout();
int sessionTimeout = (isZeroOrLess(timeoutDuration) ? -1
代码示例来源:origin: spring-projects/spring-framework
@Override
public ServletContext getServletContext() {
return this.manager.getDeployment().getServletContext();
}
代码示例来源:origin: org.mobicents.servlet.sip.containers/sip-servlets-as10
final String path = exchange.getRelativePath();
if(isForbiddenPath(path)) {
exchange.setResponseCode(StatusCodes.NOT_FOUND);
return;
String upgradeString = exchange.getRequestHeaders().getFirst(Headers.UPGRADE);
boolean isUpgradeRequest = upgradeString != null && !upgradeString.startsWith(HTTP2_UPGRADE_PREFIX);
if (info.getType() == ServletPathMatch.Type.REDIRECT && !isUpgradeRequest) {
executor = convergedServletContext.getDeployment().getExecutor();
代码示例来源:origin: io.undertow/undertow-servlet
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final String path = exchange.getRelativePath();
if(isForbiddenPath(path)) {
exchange.setStatusCode(StatusCodes.NOT_FOUND);
return;
String upgradeString = exchange.getRequestHeaders().getFirst(Headers.UPGRADE);
boolean isUpgradeRequest = upgradeString != null && !upgradeString.startsWith(HTTP2_UPGRADE_PREFIX);
if (info.getType() == ServletPathMatch.Type.REDIRECT && !isUpgradeRequest) {
executor = servletContext.getDeployment().getExecutor();
代码示例来源:origin: apache/cxf
private ServletContext buildServletContext(String contextName)
throws ServletException {
ServletContainer servletContainer = new ServletContainerImpl();
DeploymentInfo deploymentInfo = new DeploymentInfo();
deploymentInfo.setClassLoader(Thread.currentThread().getContextClassLoader());
deploymentInfo.setDeploymentName("cxf-undertow");
deploymentInfo.setContextPath(contextName);
ServletInfo asyncServlet = new ServletInfo(ServletPathMatches.DEFAULT_SERVLET_NAME, CxfUndertowServlet.class);
deploymentInfo.addServlet(asyncServlet);
servletContainer.addDeployment(deploymentInfo);
DeploymentManager deploymentManager = servletContainer.getDeployment(deploymentInfo.getDeploymentName());
deploymentManager.deploy();
deploymentManager.start();
return deploymentManager.getDeployment().getServletContext();
}
代码示例来源:origin: io.undertow/undertow-servlet
onAsyncError(error);
if (!dispatched) {
if(!exchange.isResponseStarted()) {
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
exchange.getResponseHeaders().clear();
UndertowLogger.REQUEST_IO_LOGGER.ioException((IOException) error);
} else {
ExceptionHandler exceptionHandler = servletRequestContext.getDeployment().getDeploymentInfo().getExceptionHandler();
if(exceptionHandler == null) {
exceptionHandler = LoggingExceptionHandler.DEFAULT;
代码示例来源:origin: org.wildfly.security.elytron-web/undertow-server-servlet
@Override
protected SessionManager getSessionManager() {
ServletRequestContext servletRequestContext = httpServerExchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
return servletRequestContext.getDeployment().getSessionManager();
}
代码示例来源:origin: io.undertow/undertow-servlet
@Override
public void sendError(final int sc, final String msg) throws IOException {
if(insideInclude) {
//not 100% sure this is the correct action
return;
}
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (responseStarted()) {
if(src.getErrorCode() > 0) {
return; //error already set
}
throw UndertowServletMessages.MESSAGES.responseAlreadyCommited();
}
if(servletContext.getDeployment().getDeploymentInfo().isSendCustomReasonPhraseOnError()) {
exchange.setReasonPhrase(msg);
}
writer = null;
responseState = ResponseState.NONE;
exchange.setStatusCode(sc);
if(src.isRunningInsideHandler()) {
//all we do is set the error on the context, we handle it when the request is returned
treatAsCommitted = true;
src.setError(sc, msg);
} else {
//if the src is null there is no outer handler, as we are in an asnc request
doErrorDispatch(sc, msg);
}
}
代码示例来源:origin: io.undertow/undertow-servlet
@Override
public boolean resolve(final HttpServerExchange value) {
String location = this.location.readAttribute(value);
ServletRequestContext src = value.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if(src == null) {
return false;
}
ResourceManager manager = src.getDeployment().getDeploymentInfo().getResourceManager();
if(manager == null) {
return false;
}
try {
Resource resource = manager.getResource(location);
if(resource == null) {
return false;
}
return resource.isDirectory();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: io.undertow/undertow-servlet
public boolean displayStackTraces() {
ServletStackTraces mode = deployment.getDeploymentInfo().getServletStackTraces();
if (mode == ServletStackTraces.NONE) {
return false;
} else if (mode == ServletStackTraces.ALL) {
return true;
} else {
InetSocketAddress localAddress = getExchange().getSourceAddress();
if(localAddress == null) {
return false;
}
InetAddress address = localAddress.getAddress();
if(address == null) {
return false;
}
if(!address.isLoopbackAddress()) {
return false;
}
return !getExchange().getRequestHeaders().contains(Headers.X_FORWARDED_FOR);
}
}
代码示例来源:origin: org.wildfly.camel/wildfly-camel-subsystem-core
final ServletInfo servletInfo = Servlets.servlet(EndpointServlet.NAME, EndpointServlet.class).addMapping("/*")
.setAsyncSupported(true);
CamelLogger.LOGGER.debug("Deploying endpoint {}", endPointDeplyomentInfo.getDeploymentName());
Thread.currentThread().setContextClassLoader(endPointDeplyomentInfo.getClassLoader());
try {
final DeploymentManager manager = servletContainerServiceSupplier.getValue().getServletContainer()
deploymentConsumer.accept((DeploymentImpl) deployment);
manager.start();
hostSupplier.getValue().registerDeployment(deployment, deployment.getHandler());
ManagedServlet managedServlet = deployment.getServlets().getManagedServlet(EndpointServlet.NAME);
代码示例来源:origin: io.undertow/undertow-servlet
@Override
public void setLocale(final Locale loc) {
if (insideInclude || responseStarted()) {
return;
}
this.locale = loc;
exchange.getResponseHeaders().put(Headers.CONTENT_LANGUAGE, loc.getLanguage() + "-" + loc.getCountry());
if (!charsetSet && writer == null) {
final Map<String, String> localeCharsetMapping = servletContext.getDeployment().getDeploymentInfo().getLocaleCharsetMapping();
// Match full language_country_variant first, then language_country,
// then language only
String charset = localeCharsetMapping.get(locale.toString());
if (charset == null) {
charset = localeCharsetMapping.get(locale.getLanguage() + "_"
+ locale.getCountry());
if (charset == null) {
charset = localeCharsetMapping.get(locale.getLanguage());
}
}
if (charset != null) {
this.charset = charset;
if (contentType != null) {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, getContentType());
}
}
}
}
代码示例来源:origin: io.undertow/undertow-servlet
@Override
public boolean isUserInRole(final String role) {
if (role == null) {
return false;
}
//according to the servlet spec this aways returns false
if (role.equals("*")) {
return false;
}
SecurityContext sc = exchange.getSecurityContext();
Account account = sc.getAuthenticatedAccount();
if (account == null) {
return false;
}
ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (role.equals("**")) {
Set<String> roles = servletRequestContext.getDeployment().getDeploymentInfo().getSecurityRoles();
if (!roles.contains("**")) {
return true;
}
}
final ServletChain servlet = servletRequestContext.getCurrentServlet();
final Deployment deployment = servletContext.getDeployment();
final AuthorizationManager authorizationManager = deployment.getDeploymentInfo().getAuthorizationManager();
return authorizationManager.isUserInRole(role, account, servlet.getManagedServlet().getServletInfo(), this, deployment);
}
代码示例来源:origin: io.undertow/undertow-servlet
public void doErrorDispatch(int sc, String error) throws IOException {
writer = null;
responseState = ResponseState.NONE;
resetBuffer();
treatAsCommitted = false;
final String location = servletContext.getDeployment().getErrorPages().getErrorLocation(sc);
if (location != null) {
RequestDispatcherImpl requestDispatcher = new RequestDispatcherImpl(location, servletContext);
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
try {
requestDispatcher.error(servletRequestContext, servletRequestContext.getServletRequest(), servletRequestContext.getServletResponse(), exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).getCurrentServlet().getManagedServlet().getServletInfo().getName(), error);
} catch (ServletException e) {
throw new RuntimeException(e);
}
} else if (error != null) {
setContentType("text/html");
setCharacterEncoding("UTF-8");
if(servletContext.getDeployment().getDeploymentInfo().isEscapeErrorMessage()) {
getWriter().write("<html><head><title>Error</title></head><body>" + escapeHtml(error) + "</body></html>");
} else {
getWriter().write("<html><head><title>Error</title></head><body>" + error + "</body></html>");
}
getWriter().close();
}
responseDone();
}
代码示例来源:origin: io.undertow/undertow-servlet
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
final AuthorizationManager authorizationManager = servletRequestContext.getDeployment().getDeploymentInfo().getAuthorizationManager();
TransportGuaranteeType connectionGuarantee = servletRequestContext.getOriginalRequest().isSecure() ? TransportGuaranteeType.CONFIDENTIAL : TransportGuaranteeType.NONE;
TransportGuaranteeType transportGuarantee = authorizationManager.transportGuarantee(connectionGuarantee,
servletRequestContext.getTransportGuarenteeType(), servletRequestContext.getOriginalRequest());
servletRequestContext.setTransportGuarenteeType(transportGuarantee);
if (TransportGuaranteeType.REJECTED == transportGuarantee) {
HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse();
response.sendError(StatusCodes.FORBIDDEN);
return;
}
super.handleRequest(exchange);
}
代码示例来源:origin: io.undertow/undertow-servlet
@Override
public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (!servletContext.getDeployment().getDeploymentInfo().isAllowNonStandardWrappers()) {
if (servletRequestContext.getOriginalRequest() != servletRequest) {
if (!(servletRequest instanceof ServletRequestWrapper)) {
throw UndertowServletMessages.MESSAGES.requestWasNotOriginalOrWrapper(servletRequest);
}
}
if (servletRequestContext.getOriginalResponse() != servletResponse) {
if (!(servletResponse instanceof ServletResponseWrapper)) {
throw UndertowServletMessages.MESSAGES.responseWasNotOriginalOrWrapper(servletResponse);
}
}
}
if (!isAsyncSupported()) {
throw UndertowServletMessages.MESSAGES.startAsyncNotAllowed();
} else if (asyncStarted) {
throw UndertowServletMessages.MESSAGES.asyncAlreadyStarted();
}
asyncStarted = true;
servletRequestContext.setServletRequest(servletRequest);
servletRequestContext.setServletResponse(servletResponse);
return asyncContext = new AsyncContextImpl(exchange, servletRequest, servletResponse, servletRequestContext, true, asyncContext);
}
代码示例来源:origin: io.undertow/undertow-servlet
case AUTHENTICATED:
if (isCacheable(notification)) {
if(servletContext.getDeployment().getDeploymentInfo().isChangeSessionIdOnLogin()) {
if (httpSession != null) {
Session session = underlyingSession(httpSession);
!httpSession.isInvalid() &&
session.getAttribute(NO_ID_CHANGE_REQUIRED) == null) {
ServletRequestContext src = notification.getExchange().getAttachment(ServletRequestContext.ATTACHMENT_KEY);
src.getOriginalRequest().changeSessionId();
代码示例来源:origin: org.wildfly.security.elytron-web/undertow-server-servlet
private static HttpScope applicationScope(HttpServerExchange exchange) {
ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
final ServletContext servletContext = deployment.getServletContext();
return new HttpScope() {
@Override
代码示例来源:origin: io.undertow/undertow-servlet
@Override
public ServletRegistration.Dynamic addServlet(final String servletName, final Servlet servlet) {
ensureNotProgramaticListener();
ensureNotInitialized();
ensureServletNameNotNull(servletName);
if (deploymentInfo.getServlets().containsKey(servletName)) {
return null;
}
ServletInfo s = new ServletInfo(servletName, servlet.getClass(), new ImmediateInstanceFactory<>(servlet));
readServletAnnotations(s);
deploymentInfo.addServlet(s);
ServletHandler handler = deployment.getServlets().addServlet(s);
return new ServletRegistrationImpl(s, handler.getManagedServlet(), deployment);
}
内容来源于网络,如有侵权,请联系作者删除!