use of com.alipay.sofa.runtime.api.client.param.ServiceParam 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.ServiceParam 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.ServiceParam 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.ServiceParam in project sofa-boot by sofastack.
the class ClientFactoryTest method testRemoveServiceOrRemoveReference.
/**
* test removeService and removeReference methods in ReferenceClientImpl and ServiceClientImpl
*/
@Test
public void testRemoveServiceOrRemoveReference() {
// without unique id
ServiceParam serviceParam = new ServiceParam();
serviceParam.setInstance(new PrivateServiceImpl());
serviceParam.setInterfaceType(PrivateService.class);
serviceClient.service(serviceParam);
// with unique id
serviceParam.setUniqueId("uniqueId");
serviceClient.service(serviceParam);
try {
Thread.sleep(2000);
} catch (Exception e) {
// ignore
}
// reference without unique id
ReferenceParam<PrivateService> referenceParam = new ReferenceParam<>();
referenceParam.setInterfaceType(PrivateService.class);
Assert.assertEquals(PrivateServiceImpl.class.getName(), referenceClient.reference(referenceParam).service());
// reference with unique id
referenceParam.setUniqueId("uniqueId");
Assert.assertEquals(PrivateServiceImpl.class.getName(), referenceClient.reference(referenceParam).service());
// remove Reference
referenceClient.removeReference(PrivateService.class);
referenceClient.removeReference(referenceParam);
// remove Service
try {
serviceClient.removeService(PrivateService.class, -1);
} catch (IllegalArgumentException ex) {
Assert.assertTrue(ex.getMessage().contains("Argument delay must be a positive integer or zero"));
}
serviceClient.removeService(PrivateService.class, "uniqueId", 0);
}
Aggregations