本文整理汇总了Java中javax.ws.rs.container.ResourceInfo类的典型用法代码示例。如果您正苦于以下问题:Java ResourceInfo类的具体用法?Java ResourceInfo怎么用?Java ResourceInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceInfo类属于javax.ws.rs.container包,在下文中一共展示了ResourceInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testVersionFilter
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@SuppressWarnings("boxing")
private MultivaluedMap<String, String> testVersionFilter(String version) throws WebApplicationException, NoSuchMethodException {
ResourceInfo resourceInfo = mock(ResourceInfo.class);
ContainerRequestContext request = mock(ContainerRequestContext.class);
UriInfo uriInfo = mock(UriInfo.class);
when(request.getUriInfo()).thenReturn(uriInfo);
Method method = SinceClass.class.getMethod("dummy");
MultivaluedMap<String, String> prop = new MultivaluedHashMap<>();
prop.putSingle(CommonParams.PARAM_VERSION, version);
when(uriInfo.getPathParameters()).thenReturn(prop);
VersionFilter filter = spy(new VersionFilter());
when(filter.getResourceInfo()).thenReturn(resourceInfo);
when(resourceInfo.getResourceMethod()).thenReturn(method);
filter.filter(request);
return prop;
}
示例2: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
List<Annotation> authzSpecs = new ArrayList<>();
Annotation classAuthzSpec =
resourceInfo.getResourceClass().getAnnotation(AppkeyAnnotation.class);
Annotation methodAuthzSpec =
resourceInfo.getResourceMethod().getAnnotation(AppkeyAnnotation.class);
if (classAuthzSpec != null)
authzSpecs.add(classAuthzSpec);
if (methodAuthzSpec != null)
authzSpecs.add(methodAuthzSpec);
if (!authzSpecs.isEmpty()) {
context.register(AppkeyFilter.class);
}
}
示例3: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
List<Annotation> authzSpecs = new ArrayList<>();
Annotation classAuthzSpec =
resourceInfo.getResourceClass().getAnnotation(AuthAnnotation.class);
Annotation methodAuthzSpec =
resourceInfo.getResourceMethod().getAnnotation(AuthAnnotation.class);
if (classAuthzSpec != null)
authzSpecs.add(classAuthzSpec);
if (methodAuthzSpec != null)
authzSpecs.add(methodAuthzSpec);
if (!authzSpecs.isEmpty()) {
// 需要拦截的api
context.register(AuthorizationFilter.class);
}
}
示例4: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
CacheFor cc = resourceInfo.getResourceClass().getAnnotation(CacheFor.class);
CacheFor mcc = resourceInfo.getResourceMethod().getAnnotation(CacheFor.class);
if( mcc!=null ) {
cc = mcc;
}
if (cc!=null) {
if( cc.value() == 0 ) {
context.register(NoCacheFilter.class);
} else if( cc.value() > 0 ) {
context.register(new CacheFilter("max-age= " + cc.unit().toSeconds(cc.value())));
}
} else {
context.register(NoCacheFilter.class);
}
}
示例5: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
// 获取资源方法
Method resourceMethod = resourceInfo.getResourceMethod();
if (resourceMethod != null) {
// 获取FormatJson注解
ResponseFormat formatJson = resourceMethod.getAnnotation(ResponseFormat.class);
if (formatJson == null || formatJson.type().equals(FormatType.JSON)) {
context.register(DefaultWebFilter.class);
}
}
}
示例6: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
Class<?> resourceClass = resourceInfo.getResourceClass();
Method resourceMethod = resourceInfo.getResourceMethod();
if (isStaticContent(resourceClass, resourceMethod)) {
// class or method is annotated with MCRStaticContent
// -> do not register any filter
return;
}
String packageName = resourceClass.getPackage().getName();
if (getPackages().contains(packageName)) {
registerTransactionFilter(context);
registerSessionHookFilter(context);
registerAccessFilter(context, resourceClass, resourceMethod);
}
}
示例7: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext featureContext) {
AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
RequireBasicAuth requireBasicAuth = null;
if (am.isAnnotationPresent(RequireBasicAuth.class)) {
requireBasicAuth = am.getAnnotation(RequireBasicAuth.class);
}
else {
requireBasicAuth = resourceInfo.getResourceClass().getAnnotation(RequireBasicAuth.class);
}
if (requireBasicAuth != null) {
featureContext.register(new BasicAuthKarafSecurityRequestFilter(requireBasicAuth.limitToGroups(), requireBasicAuth.limitToRoles(), requireBasicAuth.karafRealm(), requireBasicAuth.requiresSecure(), requireBasicAuth.httpRealm()));
}
}
示例8: selectVariant
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
private static MediaType selectVariant(Request request, ResourceInfo resourceInfo) {
Produces produces = resourceInfo.getResourceMethod().getAnnotation(Produces.class);
if (produces == null) {
produces = getAnnotation(resourceInfo.getResourceClass(), Produces.class);
}
if (produces != null) {
List<Variant> variants = Arrays.stream(produces.value())
.map((String mt) -> Variant.mediaTypes(MediaType.valueOf(mt)).build().get(0))
.collect(Collectors.toList());
Variant variant = request.selectVariant(variants);
if (variant != null) {
return variant.getMediaType();
}
}
return null;
}
示例9: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
final Annotation[][] parameterAnnotations = am.getParameterAnnotations();
//@DenyAll shouldn't be attached to classes
final boolean annotationOnClass = (resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class) != null) ||
(resourceInfo.getResourceClass().getAnnotation(PermitAll.class) != null);
final boolean annotationOnMethod = am.isAnnotationPresent(RolesAllowed.class) || am.isAnnotationPresent(DenyAll.class) ||
am.isAnnotationPresent(PermitAll.class);
if (annotationOnClass || annotationOnMethod) {
context.register(filterClass);
} else {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation instanceof Auth) {
context.register(filterClass);
return;
}
}
}
}
}
示例10: processResponse
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void processResponse(ContainerRequestContext requestContext, ContainerResponseContext responseContext,
ResourceInfo resourceInfo) {
MediaType mediaType = responseContext.getMediaType();
if (mediaType != null && MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
Object responseData = responseContext.getEntity();
WrapperResponseEntity jsonResponse;
if (responseData instanceof WrapperResponseEntity) {
jsonResponse = (WrapperResponseEntity) responseData;
} else {
jsonResponse = new WrapperResponseEntity(ResponseCode.OK);
jsonResponse.setData(responseData);
}
responseContext.setStatus(ResponseCode.OK.getCode());
responseContext.setEntity(jsonResponse);
}
}
示例11: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
// 获取资源方法
Method resourceMethod = resourceInfo.getResourceMethod();
if (resourceMethod != null) {
// 获取FormatJson注解
ResponseFormat formatJson = resourceMethod.getAnnotation(ResponseFormat.class);
if(formatJson == null || formatJson.type().equals(FormatType.JSON)){
context.register(DefaultWebFilter.class);
}
}
}
示例12: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
// TODO why it is called twice for the same endpoint
if (!tracingDisabled(resourceInfo) && builder.allTraced) {
log(resourceInfo);
context.register(new ServerTracingFilter(
builder.tracer,
operationName(resourceInfo),
builder.spanDecorators,
builder.operationNameBuilder.build(resourceInfo.getResourceClass(), resourceInfo.getResourceMethod()),
builder.skipPattern != null ? Pattern.compile(builder.skipPattern) : null),
builder.priority);
if (builder.traceSerialization) {
context.register(new ServerTracingInterceptor(builder.tracer,
builder.serializationSpanDecorators), builder.serializationPriority);
}
}
}
示例13: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
Trace annotation = resourceInfo.getResourceMethod().getAnnotation(Trace.class);
String operationName = this.operationName;
if (annotation != null) {
if (!annotation.operationName().equals("")) {
operationName = annotation.operationName();
}
context.register(new ServerRequestTracingFilter(this.tracer, operationName,
this.tracedAttributes, this.tracedProperties, this.decorator));
context.register(new ServerResponseTracingFilter(this.tracer));
} else {
if (traceAll) {
context.register(new ServerRequestTracingFilter(this.tracer, operationName,
this.tracedAttributes, this.tracedProperties, this.decorator));
context.register(new ServerResponseTracingFilter(this.tracer));
}
}
}
示例14: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
// RolesAllowed on the method takes precedence over PermitAll
RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(AuthCheckFilter.INSTANCE);
return;
}
// PermitAll takes precedence over RolesAllowed on the class
// This avoids putting AuthCheckFilter in the request flow for all path's which
// are defined under PermitAll annotation. That is requests for "/", "/login", "/mainLogin" and "/spnegoLogin"
// path's doesn't go through AuthCheckFilter.
if (am.isAnnotationPresent(PermitAll.class)) {
// Do nothing.
return;
}
// RolesAllowed on the class takes precedence over PermitAll
ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(AuthCheckFilter.INSTANCE);
}
}
示例15: configure
import javax.ws.rs.container.ResourceInfo; //导入依赖的package包/类
@Override
public void configure(ResourceInfo resourceInfo, FeatureContext context) {
if (resourceInfo.getResourceClass().getName()
.startsWith(RootResource.class.getPackage().getName() + ".") == false) {
return;
}
Permissions permissions = resourceInfo.getResourceMethod().getAnnotation(Permissions.class);
if (permissions == null) {
permissions = resourceInfo.getResourceClass().getAnnotation(Permissions.class);
}
if (permissions == null) {
//TODO
Logger.getLogger(PermissionProvider.class.getName())
.warning(String.format("%s not annotated @Permissions",
resourceInfo.getResourceMethod().toGenericString()));
return;
}
context.register(new PermissionTester(permissions));
}