use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class AbstractRestServer method runOnExecutor.
protected void runOnExecutor(RestServerRequestInternal restRequest, RestOperationMeta restOperation, HTTP_RESPONSE httpResponse) throws Exception {
String acceptType = restRequest.getHeaderParam("Accept");
ProduceProcessor produceProcessor = locateProduceProcessor(restRequest, httpResponse, restOperation, acceptType);
if (produceProcessor == null) {
// locateProduceProcessor内部已经应答了
return;
}
Object[] args = RestCodec.restToArgs(restRequest, restOperation);
Invocation invocation = InvocationFactory.forProvider(transport.getEndpoint(), restOperation.getOperationMeta(), args);
this.setContext(invocation, restRequest);
this.setHttpRequestContext(invocation, restRequest);
invocation.next(resp -> {
sendResponse(restRequest, httpResponse, produceProcessor, resp);
});
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestHttpRequestParamCreator method testCreateMockParam.
@Test
public void testCreateMockParam() throws Exception {
ProducerHttpRequestArgMapper lHttpRequestParamCreator = new ProducerHttpRequestArgMapper(0);
Invocation invocation = Mockito.mock(Invocation.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
RestOperationMeta swaggerOperation = Mockito.mock(RestOperationMeta.class);
Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerOperation);
HttpServletRequest lHttpServletRequest = (HttpServletRequest) lHttpRequestParamCreator.createContextArg(invocation);
Assert.assertNull(lHttpServletRequest.getMethod());
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class CseClientHttpRequest method invoke.
private CseClientHttpResponse invoke(RequestMeta requestMeta, Object[] args) {
Invocation invocation = InvocationFactory.forConsumer(requestMeta.getReferenceConfig(), requestMeta.getOperationMeta(), args);
invocation.getHandlerContext().put(RestConst.REST_CLIENT_REQUEST_PATH, this.uri.getPath() + "?" + this.uri.getQuery());
Response response = InvokerUtils.innerSyncInvoke(invocation);
if (response.isSuccessed()) {
return new CseClientHttpResponse(response);
}
throw ExceptionFactory.convertConsumerException((Throwable) response.getResult());
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestBizkeeperCommand method testGetCacheKeyWithContextInitializedProvider.
@Test
public void testGetCacheKeyWithContextInitializedProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation, HystrixObservableCommand.Setter.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation)).andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation)).andCommandPropertiesDefaults(setter));
HystrixRequestContext.initializeContext();
String cacheKey = bizkeeperCommand.getCacheKey();
Assert.assertNotNull(cacheKey);
}
use of io.servicecomb.core.Invocation in project java-chassis by ServiceComb.
the class TestBizkeeperCommand method testGetCacheKeyConsumer.
@Test
public void testGetCacheKeyConsumer() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation, HystrixObservableCommand.Setter.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation)).andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation)).andCommandPropertiesDefaults(setter));
String str = bizkeeperCommand.getCacheKey();
Assert.assertNull(str);
Response resp = Mockito.mock(Response.class);
Mockito.when(resp.isFailed()).thenReturn(false);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.isFailed()).thenReturn(true);
InvocationException excp = Mockito.mock(InvocationException.class);
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(400);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(490);
Assert.assertEquals(true, bizkeeperCommand.isFailedResponse(resp));
}
Aggregations