com.netflix.ribbon.proxy.processor.AnnotationProcessorsProvider Java Examples

The following examples show how to use com.netflix.ribbon.proxy.processor.AnnotationProcessorsProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxMovieProxyExampleTest.java    From ribbon with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBindCustomClientConfigFactory() {
    ConfigurationManager.getConfigInstance().setProperty(MovieService.class.getSimpleName() + ".MyConfig.listOfServers", "localhost:" + port);

    Injector injector = Guice.createInjector(
            new AbstractModule() {
                @Override
                protected void configure() {
                    bind(RibbonResourceFactory.class).to(DefaultResourceFactory.class).in(Scopes.SINGLETON);
                    bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
                    bind(AnnotationProcessorsProvider.class).to(DefaultAnnotationProcessorsProvider.class).in(Scopes.SINGLETON);
                    bind(ClientConfigFactory.class).to(MyClientConfigFactory.class).in(Scopes.SINGLETON);
                }
            },
            new AbstractModule() {
                @Override
                protected void configure() {
                    bind(MovieService.class).toProvider(new RibbonResourceProvider<MovieService>(MovieService.class)).asEagerSingleton();
                }
            }
    );

    RxMovieProxyExample example = injector.getInstance(RxMovieProxyExample.class);
    assertTrue(example.runExample());
}
 
Example #2
Source File: MethodTemplateExecutor.java    From ribbon with Apache License 2.0 5 votes vote down vote up
MethodTemplateExecutor(HttpResourceGroup httpResourceGroup, MethodTemplate methodTemplate, AnnotationProcessorsProvider annotations) {
    this.httpResourceGroup = httpResourceGroup;
    this.methodTemplate = methodTemplate;
    httpRequestTemplateBuilder = createHttpRequestTemplateBuilder();
    for (AnnotationProcessor processor: annotations.getProcessors()) {
        processor.process(methodTemplate.getTemplateName(), httpRequestTemplateBuilder, methodTemplate.getMethod());
    }
}
 
Example #3
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T newInstance(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory,
                                ClientConfigFactory configFactory, RibbonTransportFactory transportFactory, AnnotationProcessorsProvider processors) {
    if (!clientInterface.isInterface()) {
        throw new IllegalArgumentException(clientInterface.getName() + " is a class not interface");
    }
    return (T) Proxy.newProxyInstance(
            Thread.currentThread().getContextClassLoader(),
            new Class[]{clientInterface, ProxyLifeCycle.class},
            new RibbonDynamicProxy<T>(clientInterface, resourceGroupFactory, configFactory, transportFactory, processors)
    );
}
 
Example #4
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 5 votes vote down vote up
public RibbonDynamicProxy(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory, ClientConfigFactory configFactory,
                          RibbonTransportFactory transportFactory, AnnotationProcessorsProvider processors) {
    registerAnnotationProcessors(processors);
    ClassTemplate<T> classTemplate = ClassTemplate.from(clientInterface);
    HttpResourceGroup httpResourceGroup = new ProxyHttpResourceGroupFactory<T>(classTemplate, resourceGroupFactory, processors).createResourceGroup();
    templateExecutorMap = MethodTemplateExecutor.from(httpResourceGroup, clientInterface, processors);
    lifeCycle = new ProxyLifecycleImpl(httpResourceGroup);
}
 
Example #5
Source File: RibbonDynamicProxyTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetupWithResourceGroupNameInAnnotation() throws Exception {
    mockStatic(ProxyHttpResourceGroupFactory.class);
    expectNew(ProxyHttpResourceGroupFactory.class, new Class[]{ClassTemplate.class, 
        RibbonResourceFactory.class, AnnotationProcessorsProvider.class
        }, anyObject(), anyObject(), anyObject()).andReturn(httpResourceGroupFactoryMock);

    replayAll();

    RibbonDynamicProxy.newInstance(SampleMovieServiceWithResourceGroupNameAnnotation.class);
}
 
Example #6
Source File: RibbonDynamicProxyTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
private void initializeSampleMovieServiceMocks() {
    MethodTemplateExecutor tgMock = createMock(MethodTemplateExecutor.class);
    expect(tgMock.executeFromTemplate(anyObject(Object[].class))).andReturn(ribbonRequestMock);

    Map<Method, MethodTemplateExecutor> tgMap = new HashMap<Method, MethodTemplateExecutor>();
    tgMap.put(methodByName(SampleMovieService.class, "findMovieById"), tgMock);

    mockStatic(MethodTemplateExecutor.class);
    expect(MethodTemplateExecutor.from(httpResourceGroupMock, SampleMovieService.class, AnnotationProcessorsProvider.DEFAULT)).andReturn(tgMap);
}
 
Example #7
Source File: MethodTemplateExecutor.java    From ribbon with Apache License 2.0 5 votes vote down vote up
public static Map<Method, MethodTemplateExecutor> from(HttpResourceGroup httpResourceGroup, Class<?> clientInterface, AnnotationProcessorsProvider annotations) {
    MethodTemplate[] methodTemplates = MethodTemplate.from(clientInterface);
    Map<Method, MethodTemplateExecutor> tgm = new HashMap<Method, MethodTemplateExecutor>();
    for (MethodTemplate mt : methodTemplates) {
        tgm.put(mt.getMethod(), new MethodTemplateExecutor(httpResourceGroup, mt, annotations));
    }
    return tgm;
}
 
Example #8
Source File: MethodTemplateExecutorTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromFactory() throws Exception {
    expect(httpResourceGroupMock.newTemplateBuilder(anyObject(String.class))).andReturn(httpRequestTemplateBuilderMock).anyTimes();
    expect(httpRequestTemplateBuilderMock.withMethod(anyObject(String.class))).andReturn(httpRequestTemplateBuilderMock).anyTimes();
    expect(httpRequestTemplateBuilderMock.withUriTemplate(anyObject(String.class))).andReturn(httpRequestTemplateBuilderMock).anyTimes();
    replayAll();

    Map<Method, MethodTemplateExecutor> executorMap = MethodTemplateExecutor.from(httpResourceGroupMock, ShortMovieService.class, AnnotationProcessorsProvider.DEFAULT);

    assertEquals(ShortMovieService.class.getMethods().length, executorMap.size());
}
 
Example #9
Source File: RibbonModule.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    bind(ClientConfigFactory.class).toInstance(ClientConfigFactory.DEFAULT);
    bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON);
    bind(AnnotationProcessorsProvider.class).to(DefaultAnnotationProcessorsProvider.class).in(Scopes.SINGLETON);
    bind(RibbonResourceFactory.class).to(DefaultResourceFactory.class).in(Scopes.SINGLETON);
}
 
Example #10
Source File: ServiceLoaderTest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceLoader() {
    AnnotationProcessorsProvider annotations = AnnotationProcessorsProvider.DEFAULT;
    List<AnnotationProcessor> processors = annotations.getProcessors();
    boolean hasEVCacheProcessor = false;
    for (AnnotationProcessor processor: processors) {
        Class<?> clazz = processor.getClass();
        if (clazz.equals(EVCacheAnnotationProcessor.class)) {
            hasEVCacheProcessor = true;
            break;
        }
    }
    assertTrue(hasEVCacheProcessor);
}
 
Example #11
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 4 votes vote down vote up
static void registerAnnotationProcessors(AnnotationProcessorsProvider processors) {
    processors.register(new HttpAnnotationProcessor());
    processors.register(new HystrixAnnotationProcessor());
    processors.register(new CacheProviderAnnotationProcessor());
    processors.register(new ClientPropertiesProcessor());
}
 
Example #12
Source File: MethodTemplateExecutorTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
private MethodTemplateExecutor createExecutor(Class<?> clientInterface, String methodName) {
    MethodTemplate methodTemplate = new MethodTemplate(methodByName(clientInterface, methodName));
    return new MethodTemplateExecutor(httpResourceGroupMock, methodTemplate, AnnotationProcessorsProvider.DEFAULT);
}
 
Example #13
Source File: MethodTemplateExecutorTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() {
    RibbonDynamicProxy.registerAnnotationProcessors(AnnotationProcessorsProvider.DEFAULT);
}
 
Example #14
Source File: EvCacheAnnotationTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() {
    RibbonDynamicProxy.registerAnnotationProcessors(AnnotationProcessorsProvider.DEFAULT);
}
 
Example #15
Source File: EvCacheAnnotationTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
private MethodTemplateExecutor createExecutor(Class<?> clientInterface, String methodName) {
    MethodTemplate methodTemplate = new MethodTemplate(methodByName(clientInterface, methodName));
    return new MethodTemplateExecutor(httpResourceGroupMock, methodTemplate, AnnotationProcessorsProvider.DEFAULT);
}
 
Example #16
Source File: HttpResourceGroupFactoryTest.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Test
public void testResourceGroupAnnotationMissing() throws Exception {
    ClassTemplate<SampleMovieService> classTemplate = new ClassTemplate<SampleMovieService>(SampleMovieService.class);
    new ProxyHttpResourceGroupFactory<SampleMovieService>(classTemplate, new DefaultResourceFactory(ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT, AnnotationProcessorsProvider.DEFAULT),
            AnnotationProcessorsProvider.DEFAULT).createResourceGroup();
}
 
Example #17
Source File: RibbonResourceFactory.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public RibbonResourceFactory(ClientConfigFactory configFactory, RibbonTransportFactory transportFactory, AnnotationProcessorsProvider processors) {
    this.clientConfigFactory = configFactory;
    this.transportFactory = transportFactory;
    this.annotationProcessors = processors;
}
 
Example #18
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public static <T> T newInstance(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory,
                                ClientConfigFactory configFactory, RibbonTransportFactory transportFactory) {
    return newInstance(clientInterface, resourceGroupFactory, configFactory, transportFactory, AnnotationProcessorsProvider.DEFAULT);
}
 
Example #19
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public static <T> T newInstance(Class<T> clientInterface) {
    return newInstance(clientInterface, new DefaultResourceFactory(ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT, AnnotationProcessorsProvider.DEFAULT),
            ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT, AnnotationProcessorsProvider.DEFAULT);
}
 
Example #20
Source File: SecuredRibbonResourceFactory.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public SecuredRibbonResourceFactory(final int maxChunkSize) {
    this(ClientConfigFactory.DEFAULT,
         new SecuredTransportFactory(maxChunkSize),
         AnnotationProcessorsProvider.DEFAULT);
}
 
Example #21
Source File: RibbonDynamicProxy.java    From ribbon with Apache License 2.0 4 votes vote down vote up
RibbonDynamicProxy(Class<T> clientInterface, HttpResourceGroup httpResourceGroup) {
    AnnotationProcessorsProvider processors = AnnotationProcessorsProvider.DEFAULT;
    registerAnnotationProcessors(processors);
    lifeCycle = new ProxyLifecycleImpl(httpResourceGroup);
    templateExecutorMap = MethodTemplateExecutor.from(httpResourceGroup, clientInterface, processors);
}
 
Example #22
Source File: ProxyHttpResourceGroupFactory.java    From ribbon with Apache License 2.0 4 votes vote down vote up
ProxyHttpResourceGroupFactory(ClassTemplate<T> classTemplate, RibbonResourceFactory httpResourceGroupFactory,
                              AnnotationProcessorsProvider processors) {
    this.classTemplate = classTemplate;
    this.httpResourceGroupFactory = httpResourceGroupFactory;
    this.processors = processors;
}
 
Example #23
Source File: ProxyHttpResourceGroupFactory.java    From ribbon with Apache License 2.0 4 votes vote down vote up
ProxyHttpResourceGroupFactory(ClassTemplate<T> classTemplate) {
    this(classTemplate, new DefaultResourceFactory(ClientConfigFactory.DEFAULT, RibbonTransportFactory.DEFAULT, AnnotationProcessorsProvider.DEFAULT),
            AnnotationProcessorsProvider.DEFAULT);
}
 
Example #24
Source File: DefaultResourceFactory.java    From ribbon with Apache License 2.0 4 votes vote down vote up
public DefaultResourceFactory(ClientConfigFactory clientConfigFactory, RibbonTransportFactory transportFactory) {
    super(clientConfigFactory, transportFactory, AnnotationProcessorsProvider.DEFAULT);
}
 
Example #25
Source File: DefaultResourceFactory.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Inject
public DefaultResourceFactory(ClientConfigFactory clientConfigFactory, RibbonTransportFactory transportFactory,
                              AnnotationProcessorsProvider annotationProcessorsProvider) {
    super(clientConfigFactory, transportFactory, annotationProcessorsProvider);
}
 
Example #26
Source File: SecuredRibbonResourceFactory.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public SecuredRibbonResourceFactory(final ClientConfigFactory configFactory, final RibbonTransportFactory transportFactory, final AnnotationProcessorsProvider processors) {
    super(configFactory, transportFactory, processors);
}
 
Example #27
Source File: SecuredRibbonResourceFactory.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
public SecuredRibbonResourceFactory(final int maxChunkSize) {
    this(ClientConfigFactory.DEFAULT,
        new SecuredTransportFactory(maxChunkSize),
        AnnotationProcessorsProvider.DEFAULT);
}
 
Example #28
Source File: SecuredRibbonResourceFactory.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public SecuredRibbonResourceFactory(final ClientConfigFactory configFactory, final RibbonTransportFactory transportFactory, final AnnotationProcessorsProvider processors) {
    super(configFactory, transportFactory, processors);
}