本文整理汇总了Java中javax.ws.rs.container.ContainerRequestContext.getProperty方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequestContext.getProperty方法的具体用法?Java ContainerRequestContext.getProperty怎么用?Java ContainerRequestContext.getProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.container.ContainerRequestContext
的用法示例。
在下文中一共展示了ContainerRequestContext.getProperty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
String origin = requestContext.getHeaderString(ORIGIN);
if (origin == null || requestContext.getMethod().equalsIgnoreCase("OPTIONS")
|| requestContext.getProperty("cors.failure") != null) {
// don't do anything if origin is null, its an OPTIONS request, or cors.failure is set
return;
}
responseContext.getHeaders().putSingle(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
if (allowCredentials)
responseContext.getHeaders().putSingle(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
if (exposedHeaders != null) {
responseContext.getHeaders().putSingle(ACCESS_CONTROL_EXPOSE_HEADERS, exposedHeaders);
}
}
示例2: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) {
if (requestContext instanceof ContainerRequest) {
final Principal principal = (Principal) requestContext.getProperty("Principal");
if (principal == null) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
return;
}
final PermissionRequired annotation = resourceInfo.getResourceMethod().getDeclaredAnnotation(PermissionRequired.class);
try (AlpineQueryManager qm = new AlpineQueryManager()) {
if (principal instanceof LdapUser) {
final LdapUser user = qm.getLdapUser(((LdapUser) principal).getUsername());
final String[] permissions = annotation.value();
for (String permission: permissions) {
// todo check if user has one of these required permissions
}
}
}
}
}
示例3: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
if (!shouldFilter(requestContext, resourceInfo)) {
// do nothing if the filter doesn't apply
return;
}
try {
Span span = (Span) requestContext.getProperty(SERVER_SPAN_CONTEXT_KEY);
if (span != null) {
span.setTag(Tags.HTTP_STATUS.getKey(), responseContext.getStatus());
span.finish();
}
} catch (Exception e) {
LOGGER.error("Server Response Filter failed", e);
}
}
示例4: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(
ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws
IOException {
MDC.remove(mdcName);
String correlationId = (String) requestContext.getProperty(mdcName);
if (correlationId == null) { // Can happen if there are oauth issues.
correlationId = UUID.randomUUID().toString();
}
responseContext.getHeaders().add(headerName, correlationId);
}
示例5: 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;
}
示例6: remove
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public Object remove(final String name) {
final ContainerRequestContext containerRequest = containerRequestHolder.get();
final Object scopedObject = containerRequest.getProperty(name);
if (scopedObject != null) {
containerRequest.removeProperty(name);
getDestructionCallbacks(containerRequest).remove(name);
return scopedObject;
} else {
return null;
}
}
示例7: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@SuppressWarnings("nls")
@Override
public void filter(ContainerRequestContext context) throws IOException
{
ResourceMethodInvoker invoker = (ResourceMethodInvoker) context.getProperty(ResourceMethodInvoker.class
.getName());
Class<?> clazz = invoker.getResourceClass();
Institutional.Type instType = Institutional.Type.INSTITUTIONAL;
Institutional instanno = clazz.getAnnotation(Institutional.class);
if( instanno != null )
{
instType = instanno.value();
}
boolean hasInst = CurrentInstitution.get() != null;
if( instType != Institutional.Type.BOTH && (hasInst != (instType == Institutional.Type.INSTITUTIONAL)) )
{
throw new NotFoundException();
}
// Class or calling method system restricted?
SecureOnCallSystem system = clazz.getAnnotation(SecureOnCallSystem.class);
if( system == null )
{
system = invoker.getMethod().getAnnotation(SecureOnCallSystem.class);
}
if( system != null && !CurrentUser.getUserState().isSystem() )
{
throw new AccessDeniedException("You do not have the privileges to access this endpoint");
}
}
示例8: 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);
}
}
示例9: getDestructionCallbacks
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static Map<String, Runnable> getDestructionCallbacks(@NotNull final ContainerRequestContext containerRequest) {
return (Map<String, Runnable>) containerRequest.getProperty(DESTRUCTION_CALLBACK_PROPERTY);
}