Search in sources :

Example 11 with IpPort

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

the class IpPortManager method getNextAvailableAddress.

public IpPort getNextAvailableAddress(IpPort failedIpPort) {
    int currentIndex = currentAvailableIndex.get();
    IpPort current = getAvailableAddress(currentIndex);
    if (current.equals(failedIpPort)) {
        currentAvailableIndex.compareAndSet(currentIndex, currentIndex + 1);
        current = getAvailableAddress();
    }
    LOGGER.info("Change service center address from {} to {}", failedIpPort.toString(), current.toString());
    return current;
}
Also used : IpPort(org.apache.servicecomb.foundation.common.net.IpPort) CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint)

Example 12 with IpPort

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

the class ServiceRegistryConfig method getIpPort.

public ArrayList<IpPort> getIpPort() {
    DynamicStringProperty property = DynamicPropertyFactory.getInstance().getStringProperty("cse.service.registry.address", "https://127.0.0.1:30100");
    List<String> uriList = Arrays.asList(property.get().split(","));
    ArrayList<IpPort> ipPortList = new ArrayList<>();
    uriList.forEach(anUriList -> {
        try {
            URI uri = new URI(anUriList);
            StringBuilder sb = new StringBuilder(uri.getHost());
            sb.append(':').append(uri.getPort() < 0 ? PROTOCOL_HTTP_PORT : uri.getPort());
            this.ssl = uri.getScheme().startsWith("https");
            ipPortList.add(NetUtils.parseIpPort(sb.toString()));
        } catch (Exception e) {
            LOGGER.error("cse.service.registry.address invalid : {}", anUriList, e);
        }
    });
    return ipPortList;
}
Also used : DynamicStringProperty(com.netflix.config.DynamicStringProperty) ArrayList(java.util.ArrayList) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) URI(java.net.URI)

Example 13 with IpPort

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

the class MockForRestServerVerticle method mockRestServerVerticle.

public void mockRestServerVerticle() {
    final HttpServer server = Mockito.mock(HttpServer.class);
    new MockUp<RestServerVerticle>() {

        @Mock
        private void startListen(HttpServer server, IpPort ipPort, Future<Void> startFuture) {
        }

        @Mock
        private HttpServer createHttpServer(boolean isHttp_2) {
            return server;
        }
    };
}
Also used : HttpServer(io.vertx.core.http.HttpServer) Future(io.vertx.core.Future) MockUp(mockit.MockUp) IpPort(org.apache.servicecomb.foundation.common.net.IpPort)

Example 14 with IpPort

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

the class RestUtilsTest method defaultHeadersContainServiceRegistryAndAuthentication.

@Test
public void defaultHeadersContainServiceRegistryAndAuthentication() throws Exception {
    MultiMap headers = RestUtils.getDefaultHeaders();
    headers.addAll(RestUtils.getSignAuthHeaders(RestUtils.createSignRequest(HttpMethod.GET.toString(), new IpPort("127.0.0.1", 443), new RequestParam().addQueryParam("testParam", "test"), "test", new HashMap<>())));
    assertThat(headers.get("Content-Type"), is("application/json"));
    assertThat(headers.get("User-Agent"), is("cse-serviceregistry-client/1.0.0"));
    assertThat(headers.get("x-domain-name"), is("default"));
    assertThat(headers.get("X-Service-AK"), is("blah..."));
}
Also used : MultiMap(io.vertx.core.MultiMap) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) Test(org.junit.Test)

Example 15 with IpPort

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

the class TestClientHttp method testRequestContext.

@Test
public void testRequestContext() {
    RequestContext oContext = new RequestContext();
    oContext.setUri("//test");
    oContext.setMethod(io.vertx.core.http.HttpMethod.POST);
    oContext.setIpPort(new IpPort("145.0.0.1", 8080));
    oContext.setParams(null);
    Assert.assertEquals("//test", oContext.getUri());
    Assert.assertEquals(io.vertx.core.http.HttpMethod.POST, oContext.getMethod());
    Assert.assertEquals(8080, oContext.getIpPort().getPort());
    Assert.assertEquals(null, oContext.getParams());
    RestResponse oResponse = new RestResponse(null, null);
    oResponse.setRequestContext(oContext);
    Assert.assertEquals(oContext, oResponse.getRequestContext());
    Assert.assertEquals(null, oResponse.getResponse());
}
Also used : IpPort(org.apache.servicecomb.foundation.common.net.IpPort) Test(org.junit.Test)

Aggregations

IpPort (org.apache.servicecomb.foundation.common.net.IpPort)69 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)36 CountDownLatch (java.util.concurrent.CountDownLatch)35 IOException (java.io.IOException)19 ExecutionException (java.util.concurrent.ExecutionException)19 Holder (javax.xml.ws.Holder)15 Test (org.junit.Test)14 HttpClientResponse (io.vertx.core.http.HttpClientResponse)12 ArrayList (java.util.ArrayList)10 Handler (io.vertx.core.Handler)6 URI (java.net.URI)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Expectations (mockit.Expectations)6 MockUp (mockit.MockUp)6 Future (io.vertx.core.Future)5 HttpClientRequest (io.vertx.core.http.HttpClientRequest)5 HttpMethod (io.vertx.core.http.HttpMethod)5 SignRequest (org.apache.servicecomb.foundation.auth.SignRequest)4 HttpClientWithContext (org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext)4