use of com.alipay.sofa.runtime.api.annotation.SofaServiceBinding in project sofa-boot by sofastack.
the class ServiceBeanFactoryPostProcessor method getSofaServiceBinding.
private List<Binding> getSofaServiceBinding(SofaService sofaServiceAnnotation, SofaServiceBinding[] sofaServiceBindings) {
List<Binding> bindings = new ArrayList<>();
for (SofaServiceBinding sofaServiceBinding : sofaServiceBindings) {
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaServiceBinding.bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaServiceBinding.bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(false);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaServiceAnnotation, sofaServiceBinding, bindingConverterContext);
bindings.add(binding);
}
return bindings;
}
use of com.alipay.sofa.runtime.api.annotation.SofaServiceBinding in project sofa-boot by sofastack.
the class AnnotationPlaceHolderTest method testServiceAnnotationPlaceHolder.
@Test
@SuppressWarnings("unchecked")
public void testServiceAnnotationPlaceHolder() {
PlaceHolderBinder binder = new PlaceHolderBinder() {
@Override
public String bind(String origin) {
return environment.resolvePlaceholders(origin);
}
};
SofaService sofaService = AnnotationSampleService.class.getAnnotation(SofaService.class);
PlaceHolderAnnotationInvocationHandler.AnnotationWrapperBuilder<SofaService> builder = PlaceHolderAnnotationInvocationHandler.AnnotationWrapperBuilder.wrap(sofaService).withBinder(binder);
SofaService delegate = builder.build();
Assert.assertEquals(sofaService.hashCode(), delegate.hashCode());
Assert.assertEquals(sofaService.toString(), delegate.toString());
Assert.assertEquals(SampleService.class, sofaService.interfaceType());
Assert.assertEquals(SampleService.class, delegate.interfaceType());
Assert.assertEquals("${annotation.sample.service.uniqueId}", sofaService.uniqueId());
Assert.assertEquals("annotation-sample-service-uniqueId", delegate.uniqueId());
Assert.assertEquals(1, sofaService.bindings().length);
Assert.assertEquals(1, delegate.bindings().length);
SofaServiceBinding binding = sofaService.bindings()[0];
String[] filters = binding.filters();
SofaServiceBinding delegateBinding = delegate.bindings()[0];
String[] delegateFilters = delegateBinding.filters();
Assert.assertEquals("${annotation.sample.service.bindingType}", binding.bindingType());
Assert.assertEquals("bolt", delegateBinding.bindingType());
Assert.assertEquals(300, binding.timeout());
Assert.assertEquals(300, delegateBinding.timeout());
Assert.assertEquals(2, filters.length);
Assert.assertEquals(2, delegateFilters.length);
Assert.assertEquals("${annotation.sample.service.filter-1}", filters[0]);
Assert.assertEquals("service-filter-1", delegateFilters[0]);
Assert.assertEquals("filter-2", filters[1]);
Assert.assertEquals("filter-2", delegateFilters[1]);
Assert.assertTrue(delegate instanceof WrapperAnnotation);
Assert.assertTrue(delegateBinding instanceof WrapperAnnotation);
}
use of com.alipay.sofa.runtime.api.annotation.SofaServiceBinding in project sofa-boot by alipay.
the class AnnotationPlaceHolderTest method testServiceAnnotationPlaceHolder.
@Test
@SuppressWarnings("unchecked")
public void testServiceAnnotationPlaceHolder() {
PlaceHolderBinder binder = new PlaceHolderBinder() {
@Override
public String bind(String origin) {
return environment.resolvePlaceholders(origin);
}
};
SofaService sofaService = AnnotationSampleService.class.getAnnotation(SofaService.class);
PlaceHolderAnnotationInvocationHandler.AnnotationWrapperBuilder<SofaService> builder = PlaceHolderAnnotationInvocationHandler.AnnotationWrapperBuilder.wrap(sofaService).withBinder(binder);
SofaService delegate = builder.build();
Assert.assertEquals(sofaService.hashCode(), delegate.hashCode());
Assert.assertEquals(sofaService.toString(), delegate.toString());
Assert.assertEquals(SampleService.class, sofaService.interfaceType());
Assert.assertEquals(SampleService.class, delegate.interfaceType());
Assert.assertEquals("${annotation.sample.service.uniqueId}", sofaService.uniqueId());
Assert.assertEquals("annotation-sample-service-uniqueId", delegate.uniqueId());
Assert.assertEquals(1, sofaService.bindings().length);
Assert.assertEquals(1, delegate.bindings().length);
SofaServiceBinding binding = sofaService.bindings()[0];
String[] filters = binding.filters();
SofaServiceBinding delegateBinding = delegate.bindings()[0];
String[] delegateFilters = delegateBinding.filters();
Assert.assertEquals("${annotation.sample.service.bindingType}", binding.bindingType());
Assert.assertEquals("bolt", delegateBinding.bindingType());
Assert.assertEquals(300, binding.timeout());
Assert.assertEquals(300, delegateBinding.timeout());
Assert.assertEquals(2, filters.length);
Assert.assertEquals(2, delegateFilters.length);
Assert.assertEquals("${annotation.sample.service.filter-1}", filters[0]);
Assert.assertEquals("service-filter-1", delegateFilters[0]);
Assert.assertEquals("filter-2", filters[1]);
Assert.assertEquals("filter-2", delegateFilters[1]);
Assert.assertTrue(delegate instanceof WrapperAnnotation);
Assert.assertTrue(delegateBinding instanceof WrapperAnnotation);
}
use of com.alipay.sofa.runtime.api.annotation.SofaServiceBinding in project sofa-boot by alipay.
the class ServiceBeanFactoryPostProcessor method getSofaServiceBinding.
private List<Binding> getSofaServiceBinding(SofaService sofaServiceAnnotation, SofaServiceBinding[] sofaServiceBindings) {
List<Binding> bindings = new ArrayList<>();
for (SofaServiceBinding sofaServiceBinding : sofaServiceBindings) {
BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(new BindingType(sofaServiceBinding.bindingType()));
if (bindingConverter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00200", sofaServiceBinding.bindingType()));
}
BindingConverterContext bindingConverterContext = new BindingConverterContext();
bindingConverterContext.setInBinding(false);
bindingConverterContext.setApplicationContext(applicationContext);
bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
Binding binding = bindingConverter.convert(sofaServiceAnnotation, sofaServiceBinding, bindingConverterContext);
bindings.add(binding);
}
return bindings;
}
Aggregations