Search in sources :

Example 46 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class TestRestServerVerticle method testRestServerVerticleWithRouter.

@Test
public void testRestServerVerticleWithRouter(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject jsonObject, @Mocked Future<Void> startFuture) throws Exception {
    URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080");
    new Expectations() {

        {
            transport.parseAddress("http://127.0.0.1:8080");
            result = endpointObject;
        }
    };
    Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080");
    new Expectations() {

        {
            context.config();
            result = jsonObject;
            jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
            result = endpiont;
        }
    };
    RestServerVerticle server = new RestServerVerticle();
    // process stuff done by Expectations
    server.init(vertx, context);
    server.start(startFuture);
}
Also used : Expectations(mockit.Expectations) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 47 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class TestRestServerVerticle method testRestServerVerticleWithRouterSSL.

@Test
public void testRestServerVerticleWithRouterSSL(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject jsonObject, @Mocked Future<Void> startFuture) throws Exception {
    URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080?sslEnabled=true");
    new Expectations() {

        {
            transport.parseAddress("http://127.0.0.1:8080?sslEnabled=true");
            result = endpointObject;
        }
    };
    Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080?sslEnabled=true");
    new Expectations() {

        {
            context.config();
            result = jsonObject;
            jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
            result = endpiont;
        }
    };
    RestServerVerticle server = new RestServerVerticle();
    // process stuff done by Expectations
    server.init(vertx, context);
    server.start(startFuture);
}
Also used : Expectations(mockit.Expectations) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 48 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayVerticle method testHighwayVehicle.

@Test
public void testHighwayVehicle(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject json) {
    HighwayServerVerticle highwayVehicle = new HighwayServerVerticle();
    URIEndpointObject endpointObject = new URIEndpointObject("highway://127.0.0.1:9090");
    new Expectations() {

        {
            transport.parseAddress(anyString);
            result = endpointObject;
        }
    };
    Endpoint endpoint = new Endpoint(transport, "highway://127.0.0.1:9090");
    new Expectations() {

        {
            context.config();
            result = json;
            json.getValue(anyString);
            result = endpoint;
        }
    };
    highwayVehicle.init(vertx, context);
    @SuppressWarnings("unchecked") Promise<Void> startPromise = Mockito.mock(Promise.class);
    highwayVehicle.startListen(startPromise);
    MockUtil.getInstance().mockHighwayConfig();
    try {
        highwayVehicle.startListen(startPromise);
        Assertions.assertTrue(true);
    } catch (Exception e) {
        Assertions.fail();
    }
}
Also used : Expectations(mockit.Expectations) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 49 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class RestClientInvocation method createRequestPath.

protected String createRequestPath(RestOperationMeta swaggerRestOperation) throws Exception {
    URIEndpointObject address = (URIEndpointObject) invocation.getEndpoint().getAddress();
    String urlPrefix = address.getFirst(DefinitionConst.URL_PREFIX);
    String path = (String) invocation.getHandlerContext().get(RestConst.REST_CLIENT_REQUEST_PATH);
    if (path == null) {
        path = swaggerRestOperation.getPathBuilder().createRequestPath(invocation.getSwaggerArguments());
    }
    if (StringUtils.isEmpty(urlPrefix) || path.startsWith(urlPrefix)) {
        return path;
    }
    return urlPrefix + path;
}
Also used : URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 50 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

the class RestTransportClient method findHttpClientPool.

protected HttpClientWithContext findHttpClientPool(Invocation invocation) {
    URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
    HttpClientWithContext httpClientWithContext;
    if (endpoint.isHttp2Enabled()) {
        httpClientWithContext = HttpClients.getClient(Http2TransportHttpClientOptionsSPI.CLIENT_NAME, invocation.isSync());
    } else {
        httpClientWithContext = HttpClients.getClient(HttpTransportHttpClientOptionsSPI.CLIENT_NAME, invocation.isSync());
    }
    return httpClientWithContext;
}
Also used : HttpClientWithContext(org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)82 Endpoint (org.apache.servicecomb.core.Endpoint)32 Test (org.junit.Test)31 Expectations (mockit.Expectations)26 Invocation (org.apache.servicecomb.core.Invocation)14 RequestOptions (io.vertx.core.http.RequestOptions)10 HttpClientWithContext (org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext)10 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)9 HttpMethod (io.vertx.core.http.HttpMethod)8 Handler (io.vertx.core.Handler)6 RoutingContext (io.vertx.ext.web.RoutingContext)6 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)6 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)5 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)5 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)5 Context (io.vertx.core.Context)4 HttpClient (io.vertx.core.http.HttpClient)4 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)4 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)3 DynamicPropertyFactory (com.netflix.config.DynamicPropertyFactory)3