本文整理汇总了Java中javax.ws.rs.container.ContainerRequestContext.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequestContext.setProperty方法的具体用法?Java ContainerRequestContext.setProperty怎么用?Java ContainerRequestContext.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.container.ContainerRequestContext
的用法示例。
在下文中一共展示了ContainerRequestContext.setProperty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext context) throws IOException {
if (!shouldFilter(context, resourceInfo)) {
// do nothing if the filter doesn't apply
return;
}
try {
Tracer.SpanBuilder builder = tracer.buildSpan(getOperationName(context, resourceInfo))
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER)
.withTag(Tags.HTTP_METHOD.getKey(), context.getMethod())
.withTag(Tags.HTTP_URL.getKey(), context.getUriInfo().getAbsolutePath().toString());
builder.asChildOf(tracer.extract(Format.Builtin.HTTP_HEADERS, new ContainerRequestContextTextMap(context)));
final Span span = builder.startManual();
context.setProperty(SERVER_SPAN_CONTEXT_KEY, span);
} catch (Exception e) {
LOGGER.error("Server Request Filter failed", e);
}
}
示例2: checkOrigin
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
protected void checkOrigin(ContainerRequestContext requestContext, String origin) {
if (!allowedOrigins.contains("*") && !allowedOrigins.contains(origin)) {
requestContext.setProperty("cors.failure", true);
throw new ForbiddenException("Origin not allowed: " + origin);
}
}
示例3: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(final ContainerRequestContext ctx) throws IOException {
final SecurityContext sec = ctx.getSecurityContext();
LOGGER.debug("Checking security context: {}", sec.getUserPrincipal());
if (isNull(sec.getUserPrincipal())) {
ctx.setProperty(SESSION_PROPERTY, new HttpSession());
} else if (adminUsers.contains(sec.getUserPrincipal().getName())) {
ctx.setProperty(SESSION_PROPERTY, new HttpSession(AdministratorAgent));
} else if (sec.getUserPrincipal().getName().isEmpty()) {
ctx.setProperty(SESSION_PROPERTY, new HttpSession());
} else {
ctx.setProperty(SESSION_PROPERTY, new HttpSession(agentService.asAgent(sec.getUserPrincipal().getName())));
}
}
示例4: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
String correlationId = requestContext.getHeaderString(headerName);
if (correlationId == null) {
correlationId = UUID.randomUUID().toString();
}
requestContext.setProperty(mdcName, correlationId);
MDC.put(mdcName, correlationId);
}
示例5: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
HttpContextHelper.put(grizzlyRequestProvider.get());
if (!whiteSheetVerifier(grizzlyRequestProvider.get())) {
throw new NulsRuntimeException(ErrorCode.REQUEST_DENIED);
}
requestContext.setProperty("start", System.currentTimeMillis());
}
示例6: get
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public Object get(final String name,
final ObjectFactory<?> objectFactory) {
final ContainerRequestContext containerRequest = containerRequestHolder.get();
Object scopedObject = containerRequest.getProperty(name);
if (scopedObject == null) {
scopedObject = objectFactory.getObject();
containerRequest.setProperty(name, scopedObject);
}
return scopedObject;
}
示例7: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext request) {
MDC.put(USERNAME, getUsername(servletRequest));
if (request.getProperty(START_TIME) == null) {
request.setProperty(START_TIME, System.currentTimeMillis());
} else {
log.warn("{} is already set -- possible configuration error", START_TIME);
}
}
示例8: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
String calledMethod = requestContext.getMethod();
requestContext.setProperty("calledMethod", calledMethod);
}
示例9: setRequestContext
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
public static void setRequestContext(final ContainerRequestContext containerRequest) {
containerRequestHolder.set(containerRequest);
containerRequest.setProperty(DESTRUCTION_CALLBACK_PROPERTY, new HashMap<String, Runnable>());
}
示例10: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext request) throws IOException {
if (serverLogger.fastTrackFilters.stream().anyMatch(it -> it.test(request))) {
return;
}
Class<?> handlingClass = resourceInfo.getResourceClass();
Method handlingMethod = resourceInfo.getResourceMethod();
LogParams logParams = serverLogger.LogParamsForCall(handlingClass, handlingMethod);
if (! logParams.enableLogging) {
return;
}
request.setProperty(PROPERTYNAME, System.nanoTime());
LogRequest.LogRequestBuilder logRequest = LogRequest.builder();
logRequest.uri(getUri(request));
UibBruker uibBruker = uibBrukerProvider.get();
if (uibBruker != null) {
List<String> bruker = Lists.newArrayList();
bruker.add(uibBruker.fornavn + " " + uibBruker.etternavn);
if (! Strings.isNullOrEmpty(uibBruker.adBrukernavn)) {
bruker.add(uibBruker.adBrukernavn);
}
if (! Strings.isNullOrEmpty(uibBruker.personid)) {
bruker.add(uibBruker.personid);
}
logRequest.user(Joiner.on(", ").join(bruker));
}
String headerString = request.getHeaderString(Constants.CLIENT_APPNAME_HEADER);
if (Strings.isNullOrEmpty(headerString)) {
logRequest.clientApplication(headerString);
}
if (logParams.logHeaders) {
Map<String, String> headers = FormatUtil.MultiMapAsStringMap(request.getHeaders());
logRequest.headers((ImmutableMap.copyOf(headers)));
}
if (logParams.logRequestPayload) {
logRequest.entity(extractRequestEntity(request));
}
serverLogger.handleRequest(logRequest.build(), logParams);
}