use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayTransport method commonHighwayMock.
private void commonHighwayMock(Invocation invocation) {
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Endpoint lEndpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
Mockito.when(ep.getPort()).thenReturn(80);
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class OperationInstancesDiscoveryFilter method groupByVersion.
protected Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> groupByVersion(Invocation invocation, Map<String, MicroserviceInstance> instances) {
OperationMeta latestOperationMeta = invocation.getOperationMeta();
MicroserviceMeta latestMicroserviceMeta = latestOperationMeta.getSchemaMeta().getMicroserviceMeta();
AppManager appManager = RegistryUtils.getServiceRegistry().getAppManager();
MicroserviceVersions MicroserviceVersions = appManager.getOrCreateMicroserviceVersions(latestMicroserviceMeta.getAppId(), latestMicroserviceMeta.getName());
Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap = new IdentityHashMap<>();
for (MicroserviceInstance instance : instances.values()) {
MicroserviceVersionMeta versionMeta = MicroserviceVersions.getVersion(instance.getServiceId());
Map<String, MicroserviceInstance> versionInstances = versionMap.computeIfAbsent(versionMeta, vm -> {
return new HashMap<>();
});
versionInstances.put(instance.getInstanceId(), instance);
}
return versionMap;
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class MockUtil method mockAbstractServiceProvider.
public void mockAbstractServiceProvider() {
new MockUp<AbstractProducerProvider>() {
@SuppressWarnings("unchecked")
@Mock
protected <T> T findProviderSchema(OperationMeta operationMeta) {
PojoProducerMeta lPojoSchemaMeta = Mockito.mock(PojoProducerMeta.class);
Mockito.when(lPojoSchemaMeta.getInstance()).thenReturn(lPojoSchemaMeta);
return (T) lPojoSchemaMeta;
}
};
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class VertxHttpMethod method getMethod.
private HttpMethod getMethod(Invocation invocation) {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
String method = swaggerRestOperation.getHttpMethod();
return HttpMethod.valueOf(method);
}
use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.
the class VertxHttpMethod method doMethod.
public void doMethod(HttpClientWithContext httpClientWithContext, Invocation invocation, AsyncResponse asyncResp) throws Exception {
OperationMeta operationMeta = invocation.getOperationMeta();
RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
String path = this.createRequestPath(invocation, swaggerRestOperation);
IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
HttpClientRequest clientRequest = this.createRequest(httpClientWithContext.getHttpClient(), invocation, ipPort, path, asyncResp);
clientRequest.putHeader(org.apache.servicecomb.core.Const.TARGET_MICROSERVICE, invocation.getMicroserviceName());
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(clientRequest, httpClientWithContext.context().owner(), asyncResp);
invocation.getHandlerContext().put(RestConst.INVOCATION_HANDLER_REQUESTCLIENT, restClientRequest);
Buffer requestBodyBuffer = restClientRequest.getBodyBuffer();
HttpServletRequestEx requestEx = new VertxClientRequestToHttpServletRequest(clientRequest, requestBodyBuffer);
for (HttpClientFilter filter : httpClientFilters) {
filter.beforeSendRequest(invocation, requestEx);
}
clientRequest.exceptionHandler(e -> {
LOGGER.error(e.toString());
asyncResp.fail(invocation.getInvocationType(), e);
});
// 从业务线程转移到网络线程中去发送
httpClientWithContext.runOnContext(httpClient -> {
this.setCseContext(invocation, clientRequest);
clientRequest.setTimeout(AbstractTransport.getRequestTimeoutProperty().get());
try {
restClientRequest.end();
} catch (Throwable e) {
LOGGER.error("send http request failed,", e);
asyncResp.fail(invocation.getInvocationType(), e);
}
});
}
Aggregations