本文整理了Java中javax.servlet.ServletRequest.getAttribute()
方法的一些代码示例,展示了ServletRequest.getAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServletRequest.getAttribute()
方法的具体详情如下:
包路径:javax.servlet.ServletRequest
类名称:ServletRequest
方法名:getAttribute
[英]Returns the value of the named attribute as an Object
, or null
if no attribute of the given name exists.
Attributes can be set two ways. The servlet container may set attributes to make available custom information about a request. For example, for requests made using HTTPS, the attribute javax.servlet.request.X509Certificate
can be used to retrieve information on the certificate of the client. Attributes can also be set programatically using ServletRequest#setAttribute. This allows information to be embedded into a request before a RequestDispatcher call.
Attribute names should follow the same conventions as package names. This specification reserves names matching java.*
, javax.*
, and sun.*
.
[中]以Object
或null
的形式返回命名属性的值(如果不存在给定名称的属性)。
属性可以通过两种方式设置。servlet容器可以设置属性,以提供有关请求的自定义信息。例如,对于使用HTTPS发出的请求,属性javax.servlet.request.X509Certificate
可用于检索有关客户端证书的信息。还可以使用ServletRequest#setAttribute通过编程设置属性。这允许在RequestDispatcher调用之前将信息嵌入到请求中。
属性名称应遵循与包名称相同的约定。此规范保留与java.*
、javax.*
和sun.*
匹配的名称。
代码示例来源:origin: spring-projects/spring-framework
/**
* Expose the specified request attribute if not already present.
* @param request current servlet request
* @param name the name of the attribute
* @param value the suggested value of the attribute
*/
private static void exposeRequestAttributeIfNotPresent(ServletRequest request, String name, Object value) {
if (request.getAttribute(name) == null) {
request.setAttribute(name, value);
}
}
代码示例来源:origin: org.springframework/spring-web
/**
* Expose the specified request attribute if not already present.
* @param request current servlet request
* @param name the name of the attribute
* @param value the suggested value of the attribute
*/
private static void exposeRequestAttributeIfNotPresent(ServletRequest request, String name, Object value) {
if (request.getAttribute(name) == null) {
request.setAttribute(name, value);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Obtain the {@link WebAsyncManager} for the current request, or if not
* found, create and associate it with the request.
*/
public static WebAsyncManager getAsyncManager(ServletRequest servletRequest) {
WebAsyncManager asyncManager = null;
Object asyncManagerAttr = servletRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE);
if (asyncManagerAttr instanceof WebAsyncManager) {
asyncManager = (WebAsyncManager) asyncManagerAttr;
}
if (asyncManager == null) {
asyncManager = new WebAsyncManager();
servletRequest.setAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, asyncManager);
}
return asyncManager;
}
代码示例来源:origin: org.springframework/spring-web
/**
* Obtain the {@link WebAsyncManager} for the current request, or if not
* found, create and associate it with the request.
*/
public static WebAsyncManager getAsyncManager(ServletRequest servletRequest) {
WebAsyncManager asyncManager = null;
Object asyncManagerAttr = servletRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE);
if (asyncManagerAttr instanceof WebAsyncManager) {
asyncManager = (WebAsyncManager) asyncManagerAttr;
}
if (asyncManager == null) {
asyncManager = new WebAsyncManager();
servletRequest.setAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, asyncManager);
}
return asyncManager;
}
代码示例来源:origin: jersey/jersey
@Override
public void forward(final ServletRequest request, final ServletResponse response) throws ServletException, IOException {
final Object oldIt = request.getAttribute(MODEL_ATTRIBUTE_NAME);
final Object oldResolvingClass = request.getAttribute(RESOLVING_CLASS_ATTRIBUTE_NAME);
request.setAttribute(RESOLVING_CLASS_ATTRIBUTE_NAME, viewable.getResolvingClass());
request.setAttribute(OLD_MODEL_ATTRIBUTE_NAME, viewable.getModel());
request.setAttribute(MODEL_ATTRIBUTE_NAME, viewable.getModel());
request.setAttribute(BASE_PATH_ATTRIBUTE_NAME, basePath);
request.setAttribute(REQUEST_ATTRIBUTE_NAME, request);
request.setAttribute(RESPONSE_ATTRIBUTE_NAME, response);
dispatcher.forward(request, response);
request.setAttribute(RESOLVING_CLASS_ATTRIBUTE_NAME, oldResolvingClass);
request.setAttribute(MODEL_ATTRIBUTE_NAME, oldIt);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Get a crumb value based on user specific information in the request.
* @param request
*/
public String getCrumb(ServletRequest request) {
String crumb = null;
if (request != null) {
crumb = (String) request.getAttribute(CRUMB_ATTRIBUTE);
}
if (crumb == null) {
crumb = issueCrumb(request, getDescriptor().getCrumbSalt());
if (request != null) {
if ((crumb != null) && crumb.length()>0) {
request.setAttribute(CRUMB_ATTRIBUTE, crumb);
} else {
request.removeAttribute(CRUMB_ATTRIBUTE);
}
}
}
return crumb;
}
代码示例来源:origin: spring-projects/spring-framework
boolean hasAlreadyFilteredAttribute = request.getAttribute(alreadyFilteredAttributeName) != null;
request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
try {
doFilterInternal(httpRequest, httpResponse, filterChain);
代码示例来源:origin: apache/incubator-druid
if (request.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT) != null) {
filterChain.doFilter(request, response);
return;
request.setAttribute(
AuthConfig.DRUID_AUTHENTICATION_RESULT,
new AuthenticationResult(clientPrincipal, authorizerName, name, null)
代码示例来源:origin: spring-projects/spring-session
HttpServletResponse httpRespOnse= (HttpServletResponse) response;
boolean hasAlreadyFilteredAttribute = request
.getAttribute(this.alreadyFilteredAttributeName) != null;
request.setAttribute(this.alreadyFilteredAttributeName, Boolean.TRUE);
try {
doFilterInternal(httpRequest, httpResponse, filterChain);
代码示例来源:origin: geoserver/geoserver
(AuthenticationCachingFilter) GeoServerCompositeFilter.this,
(HttpServletRequest) request);
if (cacheKey != null) request.setAttribute(CACHE_KEY_ATTRIBUTE, cacheKey);
Authentication postAuthentication =
SecurityContextHolder.getContext().getAuthentication();
String cacheKey = (String) request.getAttribute(CACHE_KEY_ATTRIBUTE);
if (postAuthentication != null && cacheKey != null) {
Integer idleSecs = (Integer) request.getAttribute(CACHE_KEY_IDLE_SECS);
Integer liveSecs = (Integer) request.getAttribute(CACHE_KEY_LIVE_SECS);
request.setAttribute(CACHE_KEY_ATTRIBUTE, null);
request.setAttribute(CACHE_KEY_IDLE_SECS, null);
request.setAttribute(CACHE_KEY_LIVE_SECS, null);
代码示例来源:origin: org.springframework/spring-web
boolean hasAlreadyFilteredAttribute = request.getAttribute(alreadyFilteredAttributeName) != null;
request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
try {
doFilterInternal(httpRequest, httpResponse, filterChain);
代码示例来源:origin: cloudfoundry/uaa
}catch (Exception x) {
logger.error("Uncaught Exception:", x);
if (req.getAttribute("javax.servlet.error.exception") == null) {
req.setAttribute("javax.servlet.error.exception", x);
代码示例来源:origin: apache/shiro
throws ServletException, IOException {
String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName();
if ( request.getAttribute(alreadyFilteredAttributeName) != null ) {
log.trace("Filter '{}' already executed. Proceeding without invoking this filter.", getName());
filterChain.doFilter(request, response);
request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
代码示例来源:origin: openzipkin/brave
TraceContext cOntext= (TraceContext) request.getAttribute(TraceContext.class.getName());
if (context != null) {
request.setAttribute(SpanCustomizer.class.getName(), span.customizer());
request.setAttribute(TraceContext.class.getName(), span.context());
代码示例来源:origin: nutzam/nutz
Integer mark = (Integer) req.getAttribute(markKey);
if (mark != null) {
req.setAttribute(markKey, mark+1);
} else {
req.setAttribute(markKey, 0);
req.removeAttribute(markKey);
} else {
req.setAttribute(markKey, mark - 1);
代码示例来源:origin: haraldk/TwelveMonkeys
/**
* If request is filtered, returns true, otherwise marks request as filtered
* and returns false.
* A return value of false, indicates that the filter has not yet run.
* A return value of true, indicates that the filter has run for this
* request, and processing should not continue.
*
* Note that the method will mark the request as filtered on first
* invocation.
*
* @see #ATTRIB_RUN_ONCE_EXT
* @see #ATTRIB_RUN_ONCE_VALUE
*
* @param pRequest the servlet request
* @return {@code true} if the request is already filtered, otherwise
* {@code false}.
*/
private boolean isRunOnce(final ServletRequest pRequest) {
// If request already filtered, return true (skip)
if (pRequest.getAttribute(attribRunOnce) == ATTRIB_RUN_ONCE_VALUE) {
return true;
}
// Set attribute and return false (continue)
pRequest.setAttribute(attribRunOnce, ATTRIB_RUN_ONCE_VALUE);
return false;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-web
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
throws IOException, ServletException {
if (request.getAttribute(ALREADY_FILTERED_ATTRIBUTE) != null) {
chain.doFilter(request, response);
} else {
request.setAttribute(ALREADY_FILTERED_ATTRIBUTE, Boolean.TRUE);
try {
this.initializer.setLoggerContext();
chain.doFilter(request, response);
} finally {
this.initializer.clearLoggerContext();
}
}
}
代码示例来源:origin: awslabs/aws-serverless-java-container
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
Object apiGwCOntext= servletRequest.getAttribute(RequestReader.API_GATEWAY_CONTEXT_PROPERTY);
if (apiGwCOntext== null) {
log.warn("API Gateway context is null");
filterChain.doFilter(servletRequest, servletResponse);
}
if (!AwsProxyRequestContext.class.isAssignableFrom(apiGwContext.getClass())) {
log.warn("API Gateway context object is not of valid type");
filterChain.doFilter(servletRequest, servletResponse);
}
AwsProxyRequestContext ctx = (AwsProxyRequestContext)apiGwContext;
if (ctx.getIdentity() == null) {
log.warn("Identity context is null");
filterChain.doFilter(servletRequest, servletResponse);
}
String cognitoIdentityId = ctx.getIdentity().getCognitoIdentityId();
if (cognitoIdentityId == null || "".equals(cognitoIdentityId.trim())) {
log.warn("Cognito identity id in request is null");
}
servletRequest.setAttribute(COGNITO_IDENTITY_ATTRIBUTE, cognitoIdentityId);
filterChain.doFilter(servletRequest, servletResponse);
}
代码示例来源:origin: awslabs/aws-serverless-java-container
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
Object apiGwCOntext= servletRequest.getAttribute(RequestReader.API_GATEWAY_CONTEXT_PROPERTY);
if (apiGwCOntext== null) {
log.warn("API Gateway context is null");
filterChain.doFilter(servletRequest, servletResponse);
}
if (!AwsProxyRequestContext.class.isAssignableFrom(apiGwContext.getClass())) {
log.warn("API Gateway context object is not of valid type");
filterChain.doFilter(servletRequest, servletResponse);
}
AwsProxyRequestContext ctx = (AwsProxyRequestContext)apiGwContext;
if (ctx.getIdentity() == null) {
log.warn("Identity context is null");
filterChain.doFilter(servletRequest, servletResponse);
}
String cognitoIdentityId = ctx.getIdentity().getCognitoIdentityId();
if (cognitoIdentityId == null || "".equals(cognitoIdentityId.trim())) {
log.warn("Cognito identity id in request is null");
}
servletRequest.setAttribute(COGNITO_IDENTITY_ATTRIBUTE, cognitoIdentityId);
filterChain.doFilter(servletRequest, servletResponse);
}
代码示例来源:origin: awslabs/aws-serverless-java-container
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
Object apiGwCOntext= servletRequest.getAttribute(RequestReader.API_GATEWAY_CONTEXT_PROPERTY);
if (apiGwCOntext== null) {
log.warn("API Gateway context is null");
filterChain.doFilter(servletRequest, servletResponse);
}
if (!AwsProxyRequestContext.class.isAssignableFrom(apiGwContext.getClass())) {
log.warn("API Gateway context object is not of valid type");
filterChain.doFilter(servletRequest, servletResponse);
}
AwsProxyRequestContext ctx = (AwsProxyRequestContext)apiGwContext;
if (ctx.getIdentity() == null) {
log.warn("Identity context is null");
filterChain.doFilter(servletRequest, servletResponse);
}
String cognitoIdentityId = ctx.getIdentity().getCognitoIdentityId();
if (cognitoIdentityId == null || "".equals(cognitoIdentityId.trim())) {
log.warn("Cognito identity id in request is null");
}
servletRequest.setAttribute(COGNITO_IDENTITY_ATTRIBUTE, cognitoIdentityId);
filterChain.doFilter(servletRequest, servletResponse);
}