Search in sources :

Example 6 with URIEndpointObject

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

the class Consumer method prepareEdge.

private URIEndpointObject prepareEdge() {
    Microservice microservice = RegistryUtils.getMicroservice();
    EndpointsCache endpointsCache = new EndpointsCache(microservice.getAppId(), "edge", "latest", "");
    Endpoint ep = endpointsCache.getLatestEndpoints().get(0);
    URIEndpointObject edgeAddress = (URIEndpointObject) ep.getAddress();
    edgePrefix = String.format("http://%s:%d/api/business", edgeAddress.getHostOrIp(), edgeAddress.getPort());
    return edgeAddress;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Endpoint(org.apache.servicecomb.core.Endpoint) EndpointsCache(org.apache.servicecomb.core.endpoint.EndpointsCache) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 7 with URIEndpointObject

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

the class TestHighwayTransport method commonHighwayMock.

private void commonHighwayMock(Invocation invocation) {
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
    Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
    Endpoint lEndpoint = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
    WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
    Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
    URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
    Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
    Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
    Mockito.when(ep.getPort()).thenReturn(80);
}
Also used : Endpoint(org.apache.servicecomb.core.Endpoint) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 8 with URIEndpointObject

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

the class TestTcpServer method testTcpServerSSL.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testTcpServerSSL(@Mocked Vertx vertx, @Mocked AsyncResultCallback<InetSocketAddress> callback, @Mocked NetServer netServer) {
    new Expectations() {

        {
            vertx.createNetServer((NetServerOptions) any);
            result = netServer;
            netServer.connectHandler((Handler) any);
            netServer.listen(anyInt, anyString, (Handler) any);
        }
    };
    URIEndpointObject endpointObject = new URIEndpointObject("highway://127.0.0.1:6663?sslEnabled=true");
    TcpServer server = new TcpServerForTest(endpointObject);
    // assert done in Expectations
    server.init(vertx, "", callback);
}
Also used : Expectations(mockit.Expectations) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 9 with URIEndpointObject

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

the class VertxHttpMethod method createRequestPath.

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

Example 10 with URIEndpointObject

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

the class VertxHttpMethod method createRequest.

HttpClientRequest createRequest(HttpClient client, Invocation invocation, IpPort ipPort, String path, AsyncResponse asyncResp) {
    URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
    RequestOptions requestOptions = new RequestOptions();
    requestOptions.setHost(ipPort.getHostOrIp()).setPort(ipPort.getPort()).setSsl(endpoint.isSslEnabled()).setURI(path);
    HttpMethod method = getMethod(invocation);
    LOGGER.debug("Sending request by rest, method={}, qualifiedName={}, path={}, endpoint={}.", method, invocation.getMicroserviceQualifiedName(), path, invocation.getEndpoint().getEndpoint());
    HttpClientRequest request = client.request(method, requestOptions, response -> {
        handleResponse(invocation, response, asyncResp);
    });
    return request;
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) 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)16 Endpoint (org.apache.servicecomb.core.Endpoint)8 Test (org.junit.Test)8 Expectations (mockit.Expectations)5 ArrayList (java.util.ArrayList)3 Invocation (org.apache.servicecomb.core.Invocation)3 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)3 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 HttpMethod (io.vertx.core.http.HttpMethod)2 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)2 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)2 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)2 DiscoveryContext (org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext)2 Server (com.netflix.loadbalancer.Server)1 Context (io.vertx.core.Context)1 HttpClient (io.vertx.core.http.HttpClient)1 RequestOptions (io.vertx.core.http.RequestOptions)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1