@TemplateName("get") @Http( method = Http.HttpMethod.GET, uri = "/book?id={bookId}" ) RibbonRequest<ByteBuf> get(@Var("bookId")String bookId);
/** * @author Bob McWhirter */ @ResourceGroup(name="pricing") public interface PricingService { @TemplateName("get") @Http( method = Http.HttpMethod.GET, uri = "/book/{id}" ) RibbonRequest<ByteBuf> get(@Var("id") String id); }
private void extractTemplateName() { TemplateName annotation = method.getAnnotation(TemplateName.class); if (null != annotation) { templateName = annotation.value(); } else { templateName = method.getName(); } }
throw new ProxyAnnotationException(format("Method %s misses @Http annotation", method.getName())); final HttpMethod httpMethod = annotation.method(); final String uriTemplate = annotation.uri(); final Map<String, List<String>> headers = annotation.headers().length == 0 ? null : new HashMap<String, List<String>>(); for (Header h : annotation.headers()) { if (!headers.containsKey(h.name())) { ArrayList<String> values = new ArrayList<String>(); values.add(h.value()); headers.put(h.name(), values); } else { headers.get(h.name()).add(h.value()); templateBuilder.withMethod(httpMethod.name());
@Override public void process(String groupName, GroupBuilder groupBuilder, RibbonResourceFactory resourceFactory, Class<?> interfaceClass) { ClientProperties properties = interfaceClass.getAnnotation(ClientProperties.class); if (properties != null) { IClientConfig config = resourceFactory.getClientConfigFactory().newConfig(); for (Property prop : properties.properties()) { String name = prop.name(); config.set(CommonClientConfigKey.valueOf(name), prop.value()); } ClientOptions options = ClientOptions.from(config); groupBuilder.withClientOptions(options); if (properties.exportToArchaius()) { exportPropertiesToArchaius(groupName, config, interfaceClass.getName()); } } }
@Override public void process(String templateName, Builder templateBuilder, Method method) { Hystrix annotation = method.getAnnotation(Hystrix.class); if (annotation == null) { return; } String cacheKey = annotation.cacheKey().trim(); if (!cacheKey.isEmpty()) { templateBuilder.withRequestCacheKey(cacheKey); } if (annotation.fallbackHandler().length == 1) { FallbackHandler<?> hystrixFallbackHandler = Utils.newInstance(annotation.fallbackHandler()[0]); templateBuilder.withFallbackProvider(hystrixFallbackHandler); } else if (annotation.fallbackHandler().length > 1) { throw new ProxyAnnotationException(format("more than one fallback handler defined for method %s", method.getName())); } if (annotation.validator().length == 1) { HttpResponseValidator hystrixResponseValidator = Utils.newInstance(annotation.validator()[0]); templateBuilder.withResponseValidator(hystrixResponseValidator); } else if (annotation.validator().length > 1) { throw new ProxyAnnotationException(format("more than one validator defined for method %s", method.getName())); } }
ClassTemplate(Class<T> clientInterface) { this.clientInterface = clientInterface; ResourceGroup annotation = clientInterface.getAnnotation(ResourceGroup.class); if (annotation != null) { String name = annotation.name().trim(); resourceGroupName = name.isEmpty() ? null : annotation.name(); if (annotation.resourceGroupClass().length == 0) { resourceGroupClass = null; } else if (annotation.resourceGroupClass().length == 1) { resourceGroupClass = annotation.resourceGroupClass()[0]; } else { throw new ProxyAnnotationException("only one resource group may be defined with @ResourceGroup annotation"); } verify(); } else { resourceGroupName = null; resourceGroupClass = null; } }
@Override public void process(String templateName, TemplateBuilder templateBuilder, Method method) { CacheProvider annotation = method.getAnnotation(CacheProvider.class); if (annotation != null) { CacheProviderFactory<?> factory = Utils.newInstance(annotation.provider()); templateBuilder.withCacheProvider(annotation.key(), factory.createCacheProvider()); } }
private void extractParamNamesWithIndexes() { List<String> nameList = new ArrayList<String>(); List<Integer> idxList = new ArrayList<Integer>(); Annotation[][] params = method.getParameterAnnotations(); for (int i = 0; i < params.length; i++) { for (Annotation a : params[i]) { if (a.annotationType().equals(Var.class)) { String name = ((Var) a).value(); nameList.add(name); idxList.add(i); } } } int size = nameList.size(); paramNames = new String[size]; valueIdxs = new int[size]; for (int i = 0; i < size; i++) { paramNames[i] = nameList.get(i); valueIdxs[i] = idxList.get(i); } }
private void extractContentTransformerClass() { ContentTransformerClass annotation = method.getAnnotation(ContentTransformerClass.class); if (contentArgPosition == -1) { if (annotation != null) { throw new ProxyAnnotationException(format("ContentTransformClass defined on method %s with no @Content parameter", method.getName())); } return; } if (annotation == null) { Class<?> contentType = method.getParameterTypes()[contentArgPosition]; if (Observable.class.isAssignableFrom(contentType) && ByteBuf.class.isAssignableFrom(genericContentType) || ByteBuf.class.isAssignableFrom(contentType) || byte[].class.isAssignableFrom(contentType) || String.class.isAssignableFrom(contentType)) { return; } throw new ProxyAnnotationException(format("ContentTransformerClass annotation missing for content type %s in method %s", contentType.getName(), methodName())); } contentTansformerClass = annotation.value(); }
@TemplateName("get") @Http( method = Http.HttpMethod.GET, uri = "/book/{id}" ) RibbonRequest<ByteBuf> get(@Var("id") String id); }
/** * @author Bob McWhirter */ @ResourceGroup(name = "store") public interface StoreService { @TemplateName("get") @Http( method = Http.HttpMethod.GET, uri = "/book?id={bookId}" ) RibbonRequest<ByteBuf> get(@Var("bookId")String bookId); }