Search in sources :

Example 76 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project 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 Promise<Void> startPromise) 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(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 77 with URIEndpointObject

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

the class TestRestServerVerticle method testRestServerVerticleWithHttp2.

@Test
public void testRestServerVerticleWithHttp2(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject jsonObject, @Mocked Promise<Void> startPromise) {
    URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080?protocol=http2");
    new Expectations() {

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

        {
            context.config();
            result = jsonObject;
            jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
            result = endpiont;
        }
    };
    RestServerVerticle server = new RestServerVerticle();
    boolean status = false;
    try {
        server.init(vertx, context);
        server.start(startPromise);
    } catch (Exception e) {
        status = true;
    }
    Assertions.assertFalse(status);
}
Also used : Expectations(mockit.Expectations) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 78 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project 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 79 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project 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 80 with URIEndpointObject

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

the class RestClientInvocation method createRequest.

Future<HttpClientRequest> createRequest(IpPort ipPort, String path) {
    URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
    HttpMethod method = getMethod();
    RequestOptions requestOptions = new RequestOptions();
    requestOptions.setHost(ipPort.getHostOrIp()).setPort(ipPort.getPort()).setSsl(endpoint.isSslEnabled()).setMethod(method).setURI(path);
    invocation.getTraceIdLogger().debug(LOGGER, "Sending request by rest, method={}, qualifiedName={}, path={}, endpoint={}.", method, invocation.getMicroserviceQualifiedName(), path, invocation.getEndpoint().getEndpoint());
    return httpClientWithContext.getHttpClient().request(requestOptions);
}
Also used : RequestOptions(io.vertx.core.http.RequestOptions) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) HttpMethod(io.vertx.core.http.HttpMethod)

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