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