Search in sources :

Example 36 with Invocation

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);
    });
}
Also used : ProduceProcessor(io.servicecomb.common.rest.codec.produce.ProduceProcessor) Invocation(io.servicecomb.core.Invocation)

Example 37 with Invocation

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());
}
Also used : ProducerHttpRequestArgMapper(io.servicecomb.provider.rest.common.ProducerHttpRequestArgMapper) HttpServletRequest(javax.servlet.http.HttpServletRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) Test(org.junit.Test)

Example 38 with Invocation

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());
}
Also used : ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) Response(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation)

Example 39 with Invocation

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);
}
Also used : Invocation(io.servicecomb.core.Invocation) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 40 with Invocation

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));
}
Also used : Response(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation) InvocationException(io.servicecomb.core.exception.InvocationException) HystrixCommandProperties(com.netflix.hystrix.HystrixCommandProperties) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Aggregations

Invocation (io.servicecomb.core.Invocation)70 Test (org.junit.Test)55 OperationMeta (io.servicecomb.core.definition.OperationMeta)29 Response (io.servicecomb.core.Response)20 AsyncResponse (io.servicecomb.core.AsyncResponse)19 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)10 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)9 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)9 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)9 MockUp (mockit.MockUp)9 InvocationException (io.servicecomb.core.exception.InvocationException)8 Endpoint (io.servicecomb.core.Endpoint)7 IpPort (io.servicecomb.foundation.common.net.IpPort)6 HttpClientRequest (io.vertx.core.http.HttpClientRequest)6 HttpClientResponse (io.vertx.core.http.HttpClientResponse)6 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)5 Buffer (io.vertx.core.buffer.Buffer)5 HttpClient (io.vertx.core.http.HttpClient)4 ArrayList (java.util.ArrayList)4 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)3