Search in sources :

Example 6 with JvmBindingParam

use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by alipay.

the class ClientFactoryTest method testBindingInstanceIsNotAssignableFromInterfaceType.

@Test
public void testBindingInstanceIsNotAssignableFromInterfaceType() throws IOException {
    String logRootPath = StringUtils.hasText(System.getProperty("logging.path")) ? System.getProperty("logging.path") : "./logs";
    File sofaLog = new File(logRootPath + File.separator + "sofa-runtime" + File.separator + "sofa-default.log");
    FileUtils.write(sofaLog, "", System.getProperty("file.encoding"));
    SofaRuntimeProperties.setServiceInterfaceTypeCheck(true);
    JvmBindingParam jvmBindingParam = new JvmBindingParam();
    jvmBindingParam.setSerialize(true);
    ServiceParam serviceParam = new ServiceParam();
    serviceParam.setInstance(new Object());
    serviceParam.setInterfaceType(SampleService.class);
    serviceParam.addBindingParam(jvmBindingParam);
    serviceClient.service(serviceParam);
    String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
    Assert.assertTrue(content.contains("SOFA-BOOT-01-00104: Bean " + "[com.alipay.sofa.runtime.test.beans.facade.SampleService] " + "type is [class java.lang.Object] not isAssignableFrom " + "[interface com.alipay.sofa.runtime.test.beans.facade.SampleService] , please check it"));
}
Also used : File(java.io.File) ServiceParam(com.alipay.sofa.runtime.api.client.param.ServiceParam) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with JvmBindingParam

use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by alipay.

the class ServiceFactoryBean method doAfterPropertiesSet.

@Override
protected void doAfterPropertiesSet() {
    if (!apiType && hasSofaServiceAnnotation()) {
        throw new ServiceRuntimeException(ErrorCode.convert("01-00103", beanId, ref.getClass()));
    }
    Implementation implementation = new DefaultImplementation();
    implementation.setTarget(ref);
    service = buildService();
    // default add jvm binding and service jvm binding should set serialize as true
    if (bindings.size() == 0) {
        JvmBindingParam jvmBindingParam = new JvmBindingParam().setSerialize(true);
        bindings.add(new JvmBinding().setJvmBindingParam(jvmBindingParam));
    }
    for (Binding binding : bindings) {
        service.addBinding(binding);
    }
    ComponentInfo componentInfo = new ServiceComponent(implementation, service, bindingAdapterFactory, sofaRuntimeContext);
    componentInfo.setApplicationContext(applicationContext);
    sofaRuntimeContext.getComponentManager().register(componentInfo);
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 8 with JvmBindingParam

use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by alipay.

the class ReferenceClientImpl method getReferenceFromReferenceParam.

@SuppressWarnings("unchecked")
private <T> Reference getReferenceFromReferenceParam(ReferenceParam<T> referenceParam) {
    BindingParam bindingParam = referenceParam.getBindingParam();
    Reference reference = new ReferenceImpl(referenceParam.getUniqueId(), referenceParam.getInterfaceType(), InterfaceMode.api, referenceParam.isJvmFirst(), null);
    if (bindingParam == null) {
        // default add jvm binding and reference jvm binding should set serialize as false
        JvmBindingParam jvmBindingParam = new JvmBindingParam();
        jvmBindingParam.setSerialize(false);
        reference.addBinding(new JvmBinding().setJvmBindingParam(jvmBindingParam));
    } else {
        BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(bindingParam.getBindingType());
        if (bindingConverter == null) {
            throw new ServiceRuntimeException(ErrorCode.convert("01-00200", bindingParam.getBindingType()));
        }
        BindingConverterContext bindingConverterContext = new BindingConverterContext();
        bindingConverterContext.setInBinding(true);
        bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
        bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
        Binding binding = bindingConverter.convert(bindingParam, bindingConverterContext);
        reference.addBinding(binding);
    }
    return reference;
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) Reference(com.alipay.sofa.runtime.service.component.Reference) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) BindingParam(com.alipay.sofa.runtime.api.client.param.BindingParam) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) ReferenceImpl(com.alipay.sofa.runtime.service.component.impl.ReferenceImpl) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 9 with JvmBindingParam

use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by sofastack.

the class ReferenceClientImpl method getReferenceFromReferenceParam.

@SuppressWarnings("unchecked")
private <T> Reference getReferenceFromReferenceParam(ReferenceParam<T> referenceParam) {
    BindingParam bindingParam = referenceParam.getBindingParam();
    Reference reference = new ReferenceImpl(referenceParam.getUniqueId(), referenceParam.getInterfaceType(), InterfaceMode.api, referenceParam.isJvmFirst(), null);
    if (bindingParam == null) {
        // default add jvm binding and reference jvm binding should set serialize as false
        JvmBindingParam jvmBindingParam = new JvmBindingParam();
        jvmBindingParam.setSerialize(false);
        reference.addBinding(new JvmBinding().setJvmBindingParam(jvmBindingParam));
    } else {
        BindingConverter bindingConverter = bindingConverterFactory.getBindingConverter(bindingParam.getBindingType());
        if (bindingConverter == null) {
            throw new ServiceRuntimeException(ErrorCode.convert("01-00200", bindingParam.getBindingType()));
        }
        BindingConverterContext bindingConverterContext = new BindingConverterContext();
        bindingConverterContext.setInBinding(true);
        bindingConverterContext.setAppName(sofaRuntimeContext.getAppName());
        bindingConverterContext.setAppClassLoader(sofaRuntimeContext.getAppClassLoader());
        Binding binding = bindingConverter.convert(bindingParam, bindingConverterContext);
        reference.addBinding(binding);
    }
    return reference;
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) Reference(com.alipay.sofa.runtime.service.component.Reference) BindingConverter(com.alipay.sofa.runtime.spi.service.BindingConverter) BindingParam(com.alipay.sofa.runtime.api.client.param.BindingParam) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) ReferenceImpl(com.alipay.sofa.runtime.service.component.impl.ReferenceImpl) BindingConverterContext(com.alipay.sofa.runtime.spi.service.BindingConverterContext) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException)

Example 10 with JvmBindingParam

use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by sofastack.

the class ServiceFactoryBean method doAfterPropertiesSet.

@Override
protected void doAfterPropertiesSet() {
    if (!apiType && hasSofaServiceAnnotation()) {
        throw new ServiceRuntimeException(ErrorCode.convert("01-00103", beanId, ref.getClass()));
    }
    Implementation implementation = new DefaultImplementation();
    implementation.setTarget(ref);
    service = buildService();
    // default add jvm binding and service jvm binding should set serialize as true
    if (bindings.size() == 0) {
        JvmBindingParam jvmBindingParam = new JvmBindingParam().setSerialize(true);
        bindings.add(new JvmBinding().setJvmBindingParam(jvmBindingParam));
    }
    for (Binding binding : bindings) {
        service.addBinding(binding);
    }
    ComponentInfo componentInfo = new ServiceComponent(implementation, service, bindingAdapterFactory, sofaRuntimeContext);
    componentInfo.setApplicationContext(applicationContext);
    sofaRuntimeContext.getComponentManager().register(componentInfo);
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) DefaultImplementation(com.alipay.sofa.runtime.spi.component.DefaultImplementation) Implementation(com.alipay.sofa.runtime.spi.component.Implementation) ServiceRuntimeException(com.alipay.sofa.runtime.api.ServiceRuntimeException) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Aggregations

JvmBindingParam (com.alipay.sofa.runtime.service.binding.JvmBindingParam)10 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)6 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)4 ServiceParam (com.alipay.sofa.runtime.api.client.param.ServiceParam)4 Reference (com.alipay.sofa.runtime.service.component.Reference)4 Binding (com.alipay.sofa.runtime.spi.binding.Binding)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 BindingParam (com.alipay.sofa.runtime.api.client.param.BindingParam)2 ReferenceParam (com.alipay.sofa.runtime.api.client.param.ReferenceParam)2 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)2 ReferenceImpl (com.alipay.sofa.runtime.service.component.impl.ReferenceImpl)2 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)2 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)2 Implementation (com.alipay.sofa.runtime.spi.component.Implementation)2 BindingConverter (com.alipay.sofa.runtime.spi.service.BindingConverter)2 BindingConverterContext (com.alipay.sofa.runtime.spi.service.BindingConverterContext)2 SampleService (com.alipay.sofa.runtime.test.beans.facade.SampleService)2 DefaultSampleService (com.alipay.sofa.runtime.test.beans.service.DefaultSampleService)2 File (java.io.File)2