Search in sources :

Example 36 with URIEndpointObject

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

the class TestHighwayVerticle method testHighwayVerticle.

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

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

        {
            context.config();
            result = json;
            json.getValue(anyString);
            result = endpoint;
        }
    };
    highwayVerticle.init(vertx, context);
    @SuppressWarnings("unchecked") Promise<Void> startPromise = Mockito.mock(Promise.class);
    highwayVerticle.startListen(startPromise);
    MockUtil.getInstance().mockHighwayConfig();
    try {
        highwayVerticle.startListen(startPromise);
        assertTrue(true);
    } catch (Exception e) {
        Assert.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 37 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project 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 Promise<Void> startPromise) 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(startPromise);
}
Also used : Expectations(mockit.Expectations) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 38 with URIEndpointObject

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

the class TestVertxRestTransport method testSendException.

@Test
public void testSendException() {
    boolean validAssert;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
    Endpoint end = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(end);
    Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
    try {
        validAssert = true;
        instance.send(invocation, asyncResp);
    } catch (Exception e) {
        validAssert = false;
    }
    Assert.assertFalse(validAssert);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 39 with URIEndpointObject

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

the class RestClientTransportContextFactory method createRequestPath.

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

Example 40 with URIEndpointObject

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

the class RestClientTransportContextFactory method createHttpClientRequest.

protected Future<HttpClientRequest> createHttpClientRequest(Invocation invocation) {
    try {
        RestOperationMeta restOperationMeta = RestMetaUtils.getRestOperationMeta(invocation.getOperationMeta());
        HttpClientWithContext httpClientWithContext = findHttpClientPool(invocation);
        URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
        HttpMethod method = HttpMethod.valueOf(restOperationMeta.getHttpMethod());
        RequestOptions requestOptions = new RequestOptions().setHost(endpoint.getHostOrIp()).setPort(endpoint.getPort()).setSsl(endpoint.isSslEnabled()).setMethod(method).setURI(createRequestPath(invocation, restOperationMeta));
        return httpClientRequestFactory.create(invocation, httpClientWithContext.getHttpClient(), requestOptions);
    } catch (Throwable e) {
        throw new InvocationException(BAD_REQUEST, FAILED_TO_CREATE_REST_CLIENT_TRANSPORT_CONTEXT, e.getMessage(), e);
    }
}
Also used : RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) RequestOptions(io.vertx.core.http.RequestOptions) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) HttpClientWithContext(org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) HttpMethod(io.vertx.core.http.HttpMethod)

Aggregations

URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)79 Endpoint (org.apache.servicecomb.core.Endpoint)29 Test (org.junit.Test)28 Expectations (mockit.Expectations)23 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