use of com.alipay.sofa.runtime.api.client.param.BindingParam in project sofa-boot by alipay.
the class SofaBootRpcAllTest method testRestSwaggerAddService.
@Test
public void testRestSwaggerAddService() throws IOException {
List<BindingParam> bindingParams = new ArrayList<>();
bindingParams.add(new RestBindingParam());
ServiceParam serviceParam = new ServiceParam();
serviceParam.setInterfaceType(AddService.class);
serviceParam.setInstance((AddService) () -> "Hello");
serviceParam.setBindingParams(bindingParams);
ServiceClient serviceClient = clientFactory.getClient(ServiceClient.class);
serviceClient.service(serviceParam);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpUriRequest request = new HttpGet("http://localhost:8341/swagger/openapi");
HttpResponse response = httpClient.execute(request);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
Assert.assertTrue(EntityUtils.toString(response.getEntity()).contains("/webapi/add_service"));
}
use of com.alipay.sofa.runtime.api.client.param.BindingParam 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;
}
use of com.alipay.sofa.runtime.api.client.param.BindingParam in project sofa-boot by sofastack.
the class BoltSwaggerServiceApplicationListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {
List<BindingParam> bindingParams = new ArrayList<>();
bindingParams.add(new RestBindingParam());
ServiceParam serviceParam = new ServiceParam();
serviceParam.setInterfaceType(SwaggerRestService.class);
serviceParam.setInstance(new SwaggerRestServiceImpl());
serviceParam.setBindingParams(bindingParams);
ServiceClient serviceClient = clientFactory.getClient(ServiceClient.class);
serviceClient.service(serviceParam);
}
use of com.alipay.sofa.runtime.api.client.param.BindingParam in project sofa-boot by sofastack.
the class SwaggerServiceApplicationListener method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
List<BindingParam> bindingParams = new ArrayList<>();
bindingParams.add(new RestBindingParam());
ServiceParam serviceParam = new ServiceParam();
serviceParam.setInterfaceType(SwaggerService.class);
serviceParam.setInstance(new SwaggerServiceImpl());
serviceParam.setBindingParams(bindingParams);
ServiceClient serviceClient = clientFactory.getClient(ServiceClient.class);
serviceClient.service(serviceParam);
}
use of com.alipay.sofa.runtime.api.client.param.BindingParam 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;
}
Aggregations