Java Code Examples for java.net.InetSocketAddress#createUnresolved()

The following examples show how to use java.net.InetSocketAddress#createUnresolved() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NiFiProperties.java    From nifi with Apache License 2.0 6 votes vote down vote up
public InetSocketAddress getClusterLoadBalanceAddress() {
    try {
        String address = getProperty(LOAD_BALANCE_ADDRESS);
        if (StringUtils.isBlank(address)) {
            address = getProperty(CLUSTER_NODE_ADDRESS);
        }
        if (StringUtils.isBlank(address)) {
            address = "localhost";
        }

        final int port = getIntegerProperty(LOAD_BALANCE_PORT, DEFAULT_LOAD_BALANCE_PORT);
        return InetSocketAddress.createUnresolved(address, port);
    } catch (final Exception e) {
        throw new RuntimeException("Invalid load balance address/port due to: " + e, e);
    }
}
 
Example 2
Source File: ProxyDetectorImplTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  proxySelectorSupplier = new Supplier<ProxySelector>() {
    @Override
    public ProxySelector get() {
      return proxySelector;
    }
  };
  proxyDetector = new ProxyDetectorImpl(proxySelectorSupplier, authenticator, null);
  int proxyPort = 1234;
  unresolvedProxy = InetSocketAddress.createUnresolved("10.0.0.1", proxyPort);
  proxyParmeters = new ProxyParameters(
      new InetSocketAddress(InetAddress.getByName(unresolvedProxy.getHostName()), proxyPort),
      NO_USER,
      NO_PW);
}
 
Example 3
Source File: WebsocketClientTransportTest.java    From rsocket-java with Apache License 2.0 5 votes vote down vote up
@DisplayName("connects to server")
@Test
void connect() {
  InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 0);

  WebsocketServerTransport serverTransport = WebsocketServerTransport.create(address);

  serverTransport
      .start(duplexConnection -> Mono.empty())
      .flatMap(context -> WebsocketClientTransport.create(context.address()).connect())
      .as(StepVerifier::create)
      .expectNextCount(1)
      .verifyComplete();
}
 
Example 4
Source File: AddressUtilsTest.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceNumericIPAddressWithResolvedInstance() {
	InetSocketAddress socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 8080);
	InetSocketAddress replacedAddress = AddressUtils.replaceUnresolvedNumericIp(socketAddress);
	assertThat(replacedAddress).isNotSameAs(socketAddress);
	assertThat(socketAddress.isUnresolved()).isTrue();
	assertThat(replacedAddress.isUnresolved()).isFalse();
	assertThat(replacedAddress.getAddress().getHostAddress()).isEqualTo("127.0.0.1");
	assertThat(replacedAddress.getPort()).isEqualTo(8080);
	assertThat(replacedAddress.getHostString()).isEqualTo("127.0.0.1");
}
 
Example 5
Source File: AbstractClient.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public InetSocketAddress getLocalAddress() {
    Channel channel = getChannel();
    if (channel == null)
        return InetSocketAddress.createUnresolved(NetUtils.getLocalHost(), 0);
    return channel.getLocalAddress();
}
 
Example 6
Source File: SocksSSLConnectionSocketFactory.java    From TelegramBots with MIT License 5 votes vote down vote up
@Override
public Socket connectSocket(
        int connectTimeout,
        Socket socket,
        HttpHost host,
        InetSocketAddress remoteAddress,
        InetSocketAddress localAddress,
        HttpContext context) throws IOException {
    String hostName = host.getHostName();
    int port = remoteAddress.getPort();
    InetSocketAddress unresolvedRemote = InetSocketAddress.createUnresolved(hostName, port);
    return super.connectSocket(connectTimeout, socket, host, unresolvedRemote, localAddress, context);
}
 
Example 7
Source File: HttpHeadersTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void ipv6Host() {
	InetSocketAddress host = InetSocketAddress.createUnresolved("[::1]", 0);
	headers.setHost(host);
	assertEquals("Invalid Host header", host, headers.getHost());
	assertEquals("Invalid Host header", "[::1]", headers.getFirst("Host"));
}
 
Example 8
Source File: OkHttpClientTransportTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void proxy_immediateServerClose() throws Exception {
  ServerSocket serverSocket = new ServerSocket(0);
  InetSocketAddress targetAddress = InetSocketAddress.createUnresolved("theservice", 80);
  clientTransport = new OkHttpClientTransport(
      targetAddress,
      "authority",
      "userAgent",
      EAG_ATTRS,
      executor,
      socketFactory,
      sslSocketFactory,
      hostnameVerifier,
      ConnectionSpec.CLEARTEXT,
      DEFAULT_MAX_MESSAGE_SIZE,
      INITIAL_WINDOW_SIZE,
      HttpConnectProxiedSocketAddress.newBuilder()
          .setTargetAddress(targetAddress)
          .setProxyAddress(serverSocket.getLocalSocketAddress()).build(),
      tooManyPingsRunnable,
      DEFAULT_MAX_INBOUND_METADATA_SIZE,
      transportTracer,
      false);
  clientTransport.start(transportListener);

  Socket sock = serverSocket.accept();
  serverSocket.close();
  sock.close();

  ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
  verify(transportListener, timeout(TIME_OUT_MS)).transportShutdown(captor.capture());
  Status error = captor.getValue();
  assertTrue("Status didn't contain proxy: " + captor.getValue(),
      error.getDescription().contains("proxy"));
  assertEquals("Not UNAVAILABLE: " + captor.getValue(),
      Status.UNAVAILABLE.getCode(), error.getCode());
  verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
}
 
Example 9
Source File: ProxyDetectorImplTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void unresolvedProxyAddressBecomesResolved() throws Exception {
  InetSocketAddress unresolvedProxy = InetSocketAddress.createUnresolved("10.0.0.100", 1234);
  assertTrue(unresolvedProxy.isUnresolved());
  Proxy proxy1 = new java.net.Proxy(java.net.Proxy.Type.HTTP, unresolvedProxy);
  when(proxySelector.select(any(URI.class))).thenReturn(ImmutableList.of(proxy1));
  HttpConnectProxiedSocketAddress proxy =
      (HttpConnectProxiedSocketAddress) proxyDetector.proxyFor(destination);
  assertFalse(((InetSocketAddress) proxy.getProxyAddress()).isUnresolved());
}
 
Example 10
Source File: EmbeddedBrokerPerClassAdminImpl.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public InetSocketAddress getBrokerAddress(final PortType portType)
{
    Integer port = _ports.get(portType.name());
    if (port == null)
    {
        throw new IllegalStateException(String.format("Could not find port with name '%s' on the Broker", portType.name()));
    }
    return InetSocketAddress.createUnresolved("localhost", port);
}
 
Example 11
Source File: PTContainer.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
public void read(final Object object, final Input in) throws KryoException
{
  PhysicalPlan plan = (PhysicalPlan)object;

  int containerId = in.readInt();

  for (PTContainer c : plan.getContainers()) {
    if (c.getId() == containerId) {
      int stateOrd = in.readInt();
      c.state = PTContainer.State.values()[stateOrd];
      c.containerId = in.readString();
      c.resourceRequestPriority = in.readInt();
      c.requiredMemoryMB = in.readInt();
      c.allocatedMemoryMB = in.readInt();
      c.requiredVCores = in.readInt();
      c.allocatedVCores = in.readInt();
      String bufferServerHost = in.readString();
      if (bufferServerHost != null) {
        c.bufferServerAddress = InetSocketAddress.createUnresolved(bufferServerHost, in.readInt());
      }
      c.host = in.readString();
      c.nodeHttpAddress = in.readString();
      int tokenLength = in.readInt();
      if (tokenLength != -1) {
        c.bufferServerToken = in.readBytes(tokenLength);
      } else {
        c.bufferServerToken = null;
      }
      break;
    }
  }
}
 
Example 12
Source File: OkHttpClientTransportTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void proxy_immediateServerClose() throws Exception {
  ServerSocket serverSocket = new ServerSocket(0);
  clientTransport = new OkHttpClientTransport(
      InetSocketAddress.createUnresolved("theservice", 80),
      "authority",
      "userAgent",
      executor,
      sslSocketFactory,
      hostnameVerifier,
      ConnectionSpec.CLEARTEXT,
      DEFAULT_MAX_MESSAGE_SIZE,
      INITIAL_WINDOW_SIZE,
      new ProxyParameters(
          (InetSocketAddress) serverSocket.getLocalSocketAddress(), NO_USER, NO_PW),
      tooManyPingsRunnable,
      DEFAULT_MAX_INBOUND_METADATA_SIZE,
      transportTracer);
  clientTransport.start(transportListener);

  Socket sock = serverSocket.accept();
  serverSocket.close();
  sock.close();

  ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
  verify(transportListener, timeout(TIME_OUT_MS)).transportShutdown(captor.capture());
  Status error = captor.getValue();
  assertTrue("Status didn't contain proxy: " + captor.getValue(),
      error.getDescription().contains("proxy"));
  assertEquals("Not UNAVAILABLE: " + captor.getValue(),
      Status.UNAVAILABLE.getCode(), error.getCode());
  verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
}
 
Example 13
Source File: LazyConnectExchangeClient.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public InetSocketAddress getLocalAddress() {
    if (client == null){
        return InetSocketAddress.createUnresolved(NetUtils.getLocalHost(), 0);
    } else {
        return client.getLocalAddress();
    }
}
 
Example 14
Source File: SyslogBaseTestClass.java    From datacollector with Apache License 2.0 4 votes vote down vote up
protected InetSocketAddress getDummyReceiver() {
  return InetSocketAddress.createUnresolved("receiver", 7007);
}
 
Example 15
Source File: AbstractClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public InetSocketAddress getLocalAddress() {
    Channel channel = getChannel();
    if (channel == null)
        return InetSocketAddress.createUnresolved(NetUtils.getLocalHost(), 0);
    return channel.getLocalAddress();
}
 
Example 16
Source File: AbstractClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public InetSocketAddress getLocalAddress() {
    Channel channel = getChannel();
    if (channel == null)
        return InetSocketAddress.createUnresolved(NetUtils.getLocalHost(), 0);
    return channel.getLocalAddress();
}
 
Example 17
Source File: BlockingConnectionTest.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@Override
public InetSocketAddress address() {
	return InetSocketAddress.createUnresolved("localhost", 4321);
}
 
Example 18
Source File: OkHttpClientTransportTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void proxy_200() throws Exception {
  ServerSocket serverSocket = new ServerSocket(0);
  InetSocketAddress targetAddress = InetSocketAddress.createUnresolved("theservice", 80);
  clientTransport = new OkHttpClientTransport(
      targetAddress,
      "authority",
      "userAgent",
      EAG_ATTRS,
      executor,
      socketFactory,
      sslSocketFactory,
      hostnameVerifier,
      ConnectionSpec.CLEARTEXT,
      DEFAULT_MAX_MESSAGE_SIZE,
      INITIAL_WINDOW_SIZE,
      HttpConnectProxiedSocketAddress.newBuilder()
          .setTargetAddress(targetAddress)
          .setProxyAddress(serverSocket.getLocalSocketAddress()).build(),
      tooManyPingsRunnable,
      DEFAULT_MAX_INBOUND_METADATA_SIZE,
      transportTracer,
      false);
  clientTransport.start(transportListener);

  Socket sock = serverSocket.accept();
  serverSocket.close();

  BufferedReader reader = new BufferedReader(new InputStreamReader(sock.getInputStream(), UTF_8));
  assertEquals("CONNECT theservice:80 HTTP/1.1", reader.readLine());
  assertEquals("Host: theservice:80", reader.readLine());
  while (!"".equals(reader.readLine())) {}

  sock.getOutputStream().write("HTTP/1.1 200 OK\r\nServer: test\r\n\r\n".getBytes(UTF_8));
  sock.getOutputStream().flush();

  assertEquals("PRI * HTTP/2.0", reader.readLine());
  assertEquals("", reader.readLine());
  assertEquals("SM", reader.readLine());
  assertEquals("", reader.readLine());

  // Empty SETTINGS
  sock.getOutputStream().write(new byte[] {0, 0, 0, 0, 0x4, 0});
  // GOAWAY
  sock.getOutputStream().write(new byte[] {
      0, 0, 0, 8, 0x7, 0,
      0, 0, 0, 0, // last stream id
      0, 0, 0, 0, // error code
  });
  sock.getOutputStream().flush();

  verify(transportListener, timeout(TIME_OUT_MS)).transportShutdown(isA(Status.class));
  while (sock.getInputStream().read() != -1) {}
  verify(transportListener, timeout(TIME_OUT_MS)).transportTerminated();
  sock.close();
}
 
Example 19
Source File: HttpURLConnection.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public HttpURLConnection(URL u, String host, int port) {
    this(u, new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(host, port)));
}
 
Example 20
Source File: ClientRegistryImplTest.java    From SI with BSD 2-Clause "Simplified" License 3 votes vote down vote up
private void givenASimpleClient(Long lifetime) {

        Client.Builder builder = new Client.Builder(registrationId, ep, address, port,
                InetSocketAddress.createUnresolved("localhost", 5683));

        client = builder.lifeTimeInSec(lifetime).smsNumber(sms).bindingMode(binding).objectLinks(objectLinks).build();
    }