use of org.glassfish.jersey.server.model.AnnotatedMethod in project jersey by jersey.
the class InjectLinkFieldDescriptor method getLinkTemplate.
/**
* TODO javadoc.
*/
public static String getLinkTemplate(ResourceMappingContext rmc, InjectLink link) {
String template = null;
if (!link.resource().equals(Class.class)) {
ResourceMappingContext.Mapping map = rmc.getMapping(link.resource());
if (map != null) {
template = map.getTemplate().getTemplate().toString();
} else {
// extract template from specified class' @Path annotation
Path path = link.resource().getAnnotation(Path.class);
template = path == null ? "" : path.value();
}
// extract template from specified class' @Path annotation
if (link.method().length() > 0) {
// append value of method's @Path annotation
MethodList methods = new MethodList(link.resource());
methods = methods.withMetaAnnotation(HttpMethod.class);
Iterator<AnnotatedMethod> iterator = methods.iterator();
while (iterator.hasNext()) {
AnnotatedMethod method = iterator.next();
if (!method.getMethod().getName().equals(link.method())) {
continue;
}
StringBuilder builder = new StringBuilder();
builder.append(template);
Path methodPath = method.getAnnotation(Path.class);
if (methodPath != null) {
String methodTemplate = methodPath.value();
if (!(template.endsWith("/") || methodTemplate.startsWith("/"))) {
builder.append("/");
}
builder.append(methodTemplate);
}
CharSequence querySubString = extractQueryParams(method);
if (querySubString.length() > 0) {
builder.append("{?");
builder.append(querySubString);
builder.append("}");
}
template = builder.toString();
break;
}
}
} else {
template = link.value();
}
return template;
}
use of org.glassfish.jersey.server.model.AnnotatedMethod in project jersey by jersey.
the class InjectLinkFieldDescriptor method extractQueryParams.
private static CharSequence extractQueryParams(AnnotatedMethod method) throws SecurityException {
// append query parameters
StringBuilder querySubString = new StringBuilder();
int parameterIndex = 0;
for (Annotation[] paramAnns : method.getParameterAnnotations()) {
for (Annotation ann : paramAnns) {
if (ann.annotationType() == QueryParam.class) {
querySubString.append(((QueryParam) ann).value());
querySubString.append(',');
}
if (ann.annotationType() == BeanParam.class) {
Class<?> beanParamType = method.getParameterTypes()[parameterIndex];
Field[] fields = beanParamType.getFields();
for (Field field : fields) {
QueryParam queryParam = field.getAnnotation(QueryParam.class);
if (queryParam != null) {
querySubString.append(queryParam.value());
querySubString.append(',');
}
}
Method[] beanMethods = beanParamType.getMethods();
for (Method beanMethod : beanMethods) {
QueryParam queryParam = beanMethod.getAnnotation(QueryParam.class);
if (queryParam != null) {
querySubString.append(queryParam.value());
querySubString.append(',');
}
}
}
}
parameterIndex++;
}
CharSequence result = "";
if (querySubString.length() > 0) {
result = querySubString.subSequence(0, querySubString.length() - 1);
}
return result;
}
use of org.glassfish.jersey.server.model.AnnotatedMethod in project jersey by jersey.
the class RolesAllowedDynamicFeature method configure.
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
final AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
// DenyAll on the method take precedence over RolesAllowed and PermitAll
if (am.isAnnotationPresent(DenyAll.class)) {
configuration.register(new RolesAllowedRequestFilter());
return;
}
// RolesAllowed on the method takes precedence over PermitAll
RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(new RolesAllowedRequestFilter(ra.value()));
return;
}
// PermitAll takes precedence over RolesAllowed on the class
if (am.isAnnotationPresent(PermitAll.class)) {
// Do nothing.
return;
}
// DenyAll can't be attached to classes
// RolesAllowed on the class takes precedence over PermitAll
ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(new RolesAllowedRequestFilter(ra.value()));
}
}
use of org.glassfish.jersey.server.model.AnnotatedMethod in project ratelimitj by mokies.
the class RateLimited429EnforcerFeature method configure.
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext context) {
final AnnotatedMethod method = new AnnotatedMethod(resourceInfo.getResourceMethod());
final RateLimited rateLimited = method.getAnnotation(RateLimited.class);
if (null != rateLimited) {
context.register(RateLimit429EnforcerFilter.class);
}
}
use of org.glassfish.jersey.server.model.AnnotatedMethod in project coastal-hazards by USGS-CIDA.
the class DynamicRolesLoginRedirectFeature method configure.
@Override
public void configure(final ResourceInfo resourceInfo, final FeatureContext configuration) {
AnnotatedMethod am = new AnnotatedMethod(resourceInfo.getResourceMethod());
// DenyAll on the method take precedence over RolesAllowed and PermitAll
if (am.isAnnotationPresent(DenyAll.class)) {
configuration.register(new RolesAllowedPastLoginFilter());
return;
}
// RolesAllowed on the method takes precedence over PermitAll
RolesAllowed ra = am.getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(new RolesAllowedPastLoginFilter(ra.value()));
return;
}
// PermitAll takes precedence over RolesAllowed on the class
if (am.isAnnotationPresent(PermitAll.class)) {
// Do nothing.
return;
}
// DenyAll can't be attached to classes
// RolesAllowed on the class takes precedence over PermitAll
ra = resourceInfo.getResourceClass().getAnnotation(RolesAllowed.class);
if (ra != null) {
configuration.register(new RolesAllowedPastLoginFilter(ra.value()));
}
}
Aggregations