private static WebTarget addPathFromAnnotation(final AnnotatedElement ae, WebTarget target) { final Path p = ae.getAnnotation(Path.class); if (p != null) { target = target.path(p.value()); } return target; }
public static Map<Method, RestfulClientInvoker> proxy(final Class<?> iface, WebTarget base, final ProxyConfig config) { if (iface.isAnnotationPresent(Path.class)) { Path path = iface.getAnnotation(Path.class); if (!path.value().equals("") && !path.value().equals("/")) { base = base.path(path.value()); } } HashMap<Method, RestfulClientInvoker> methodMap = new HashMap<Method, RestfulClientInvoker>(); for (Method method : iface.getMethods()) { RestfulClientInvoker invoker = createClientInvoker(iface, method, (ResteasyWebTarget) base, config); methodMap.put(method, invoker); } return methodMap; }
public static String getPath(javax.ws.rs.Path classLevelPath, javax.ws.rs.Path methodLevelPath, String parentPath, boolean isSubresource) { if (classLevelPath == null && methodLevelPath == null && StringUtils.isEmpty(parentPath)) { return null; } StringBuilder b = new StringBuilder(); appendPathComponent(parentPath, b); if (classLevelPath != null && !isSubresource) { appendPathComponent(classLevelPath.value(), b); } if (methodLevelPath != null) { appendPathComponent(methodLevelPath.value(), b); } return b.length() == 0 ? "/" : b.toString(); }
private <T> Set<Resource> prefixResources(String prefix, Set<Class<? extends T>> resources) { final String pathPrefix = prefix.endsWith("/") ? prefix.substring(0, prefix.length() - 1) : prefix; return resources .stream() .map(resource -> { final javax.ws.rs.Path pathAnnotation = Resource.getPath(resource); final String resourcePathSuffix = Strings.nullToEmpty(pathAnnotation.value()); final String resourcePath = resourcePathSuffix.startsWith("/") ? pathPrefix + resourcePathSuffix : pathPrefix + "/" + resourcePathSuffix; return Resource .builder(resource) .path(resourcePath) .build(); }) .collect(Collectors.toSet()); }
private void appendPath(final Path path) { if (path == null) { throw new IllegalArgumentException(LocalizationMessages.PARAM_NULL("path")); } appendPath(path.value()); }
private void appendPath(final Path path) { if (path == null) { throw new IllegalArgumentException(LocalizationMessages.PARAM_NULL("path")); } appendPath(path.value()); }
public synchronized Map<String, Object> generateOverview() { if (!overviewResult.isEmpty()) { return overviewResult; } final List<Map<String, Object>> apis = Lists.newArrayList(); for (Class<?> clazz : getAnnotatedClasses()) { Api info = clazz.getAnnotation(Api.class); Path path = clazz.getAnnotation(Path.class); if (info == null || path == null) { LOG.debug("Skipping REST resource with no Api or Path annotation: <{}>", clazz.getCanonicalName()); continue; } final String prefixedPath = prefixedPath(clazz, path.value()); final Map<String, Object> apiDescription = Maps.newHashMap(); apiDescription.put("name", prefixedPath.startsWith(pluginPathPrefix) ? "Plugins/" + info.value() : info.value()); apiDescription.put("path", prefixedPath); apiDescription.put("description", info.description()); apis.add(apiDescription); } Collections.sort(apis, (o1, o2) -> ComparisonChain.start().compare(o1.get("name").toString(), o2.get("name").toString()).result()); Map<String, String> info = Maps.newHashMap(); info.put("title", "Graylog REST API"); overviewResult.put("apiVersion", ServerVersion.VERSION.toString()); overviewResult.put("swaggerVersion", EMULATED_SWAGGER_VERSION); overviewResult.put("apis", apis); return overviewResult; }
@Test public void testDerivedAnnotation() { final Path annotation = ReflectionUtils.getAnnotation(Child.class, javax.ws.rs.Path.class); Assert.assertNotNull(annotation); Assert.assertEquals(annotation.value(), "parentInterfacePath"); }
public ReactiveSeq<Tuple2<String,String>> extractResources() { return resources.stream().peek(resource -> logMissingPath(resource)) .filter(resource-> resource.getClass().getAnnotation(Path.class)!=null) .map(resource -> Tuple.tuple(resource.getClass().getName(), resource.getClass().getAnnotation(Path.class).value())); }
private void removeRegistration(ResourceMethodRegistry rm, String path, Method method) { try { if (rm.isWiderMatching()) { RootNode rootNode = get(rm, "rootNode"); rootNode.removeBinding(path, method); } else { String methodpath = method.getAnnotation(Path.class).value(); String classExpression = path.replace(methodpath, ""); if (classExpression.endsWith("/")) { classExpression.substring(0, classExpression.length() - 1); } RootClassNode root = get(rm, "root"); root.removeBinding(classExpression, path, method); } } catch (Exception e) { LOGGER.error("Could not remove method registration from path {}, {}", e, path, method); } }
final String basepath = ((Path) clazz.getAnnotation(Path.class)).value().substring(1); //Ignore the first "/" final List<Class<? extends ResourceFilter>> baseResourceFilters = clazz.getAnnotation(ResourceFilters.class) == null ? Collections.emptyList() :
resourceBuilder = Resource.builder(rPathAnnotation.value()); } else { resourceBuilder = Resource.builder();
resourceBuilder = Resource.builder(rPathAnnotation.value()); } else { resourceBuilder = Resource.builder();
private void addSubResourceLocators( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final boolean extended) { for (AnnotatedMethod am : methodList.withoutMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { final String path = am.getAnnotation(Path.class).value(); Resource.Builder builder = resourceBuilder; if (path != null && !path.isEmpty() && !"/".equals(path)) { builder = resourceBuilder.addChildResource(path); } builder.addMethod() .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); } } }
private void addSubResourceLocators( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final boolean extended) { for (AnnotatedMethod am : methodList.withoutMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { final String path = am.getAnnotation(Path.class).value(); Resource.Builder builder = resourceBuilder; if (path != null && !path.isEmpty() && !"/".equals(path)) { builder = resourceBuilder.addChildResource(path); } builder.addMethod() .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); } } }
private static void workOutSubResourceLocatorsList( AbstractResource resource, MethodList methodList, boolean isEncoded) { for (AnnotatedMethod m : methodList.hasNotMetaAnnotation(HttpMethod.class). hasAnnotation(Path.class)) { final Path mPathAnnotation = m.getAnnotation(Path.class); final AbstractSubResourceLocator subResourceLocator = new AbstractSubResourceLocator( resource, m.getMethod(), new PathValue( mPathAnnotation.value()), m.getAnnotations()); processParameters( subResourceLocator.getResource().getResourceClass(), subResourceLocator.getMethod().getDeclaringClass(), subResourceLocator, m, isEncoded); resource.getSubResourceLocators().add(subResourceLocator); } }
private void addSubResourceMethods( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final List<MediaType> defaultConsumedTypes, final List<MediaType> defaultProducedTypes, final Collection<Class<? extends Annotation>> defaultNameBindings, final boolean extended ) { for (AnnotatedMethod am : methodList.withMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { Resource.Builder childResourceBuilder = resourceBuilder.addChildResource(am.getAnnotation(Path.class).value()); ResourceMethod.Builder methodBuilder = childResourceBuilder.addMethod(am.getMetaMethodAnnotations(HttpMethod.class).get(0).value()) .consumes(resolveConsumedTypes(am, defaultConsumedTypes)) .produces(resolveProducedTypes(am, defaultProducedTypes)) .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .nameBindings(defaultNameBindings) .nameBindings(am.getAnnotations()) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); introspectAsyncFeatures(am, methodBuilder); } }
private void addSubResourceMethods( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final List<MediaType> defaultConsumedTypes, final List<MediaType> defaultProducedTypes, final Collection<Class<? extends Annotation>> defaultNameBindings, final boolean extended ) { for (AnnotatedMethod am : methodList.withMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { Resource.Builder childResourceBuilder = resourceBuilder.addChildResource(am.getAnnotation(Path.class).value()); ResourceMethod.Builder methodBuilder = childResourceBuilder.addMethod(am.getMetaMethodAnnotations(HttpMethod.class).get(0).value()) .consumes(resolveConsumedTypes(am, defaultConsumedTypes)) .produces(resolveProducedTypes(am, defaultProducedTypes)) .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .nameBindings(defaultNameBindings) .nameBindings(am.getAnnotations()) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); introspectAsyncFeatures(am, methodBuilder); } }