io.vertx.core.net.impl.SocketAddressImpl Java Examples

The following examples show how to use io.vertx.core.net.impl.SocketAddressImpl. 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: ForwardedParser.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
private SocketAddress parseFor(String forToParse, int defaultPort) {
  String host = forToParse;
  int port = defaultPort;
  int portSeparatorIdx = forToParse.lastIndexOf(':');
  if (portSeparatorIdx > forToParse.lastIndexOf(']')) {
    host = forToParse.substring(0, portSeparatorIdx);
    port = parsePort(forToParse.substring(portSeparatorIdx + 1), defaultPort);
  }

  return new SocketAddressImpl(port, host);
}
 
Example #2
Source File: VertxVaadinRequestUT.java    From vertx-vaadin with MIT License 5 votes vote down vote up
@Test
public void shouldDelegateGetRemoteAddress() {
    when(httpServerRequest.remoteAddress())
        .thenReturn(null)
        .thenReturn(new SocketAddressImpl(8080, "10.3.100.108"));
    assertThat(vaadinRequest.getRemoteAddr()).isNull();
    assertThat(vaadinRequest.getRemoteAddr()).isEqualTo("10.3.100.108");
}
 
Example #3
Source File: EqualityTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testSocketAddressEquality() {
  SocketAddress address1 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest"));
  SocketAddress address2 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest"));
  assertNotSame(address1, address2);
  assertEquals(address1, address2);
}
 
Example #4
Source File: ImplicitParametersExtractorTest.java    From prebid-server-java with Apache License 2.0 5 votes vote down vote up
@Test
public void ipFromShouldReturnRemoteAddress() {
    // given
    given(httpRequest.remoteAddress()).willReturn(new SocketAddressImpl(0, "193.168.244.1"));

    // when and then
    assertThat(extractor.ipFrom(httpRequest)).isEqualTo("193.168.244.1");
}
 
Example #5
Source File: EqualityTest.java    From vertx-rx with Apache License 2.0 5 votes vote down vote up
@Test
public void testSocketAddressEquality() {
  SocketAddress address1 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest"));
  SocketAddress address2 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest"));
  assertNotSame(address1, address2);
  assertEquals(address1, address2);
}
 
Example #6
Source File: VertxVaadinRequestUT.java    From vertx-vaadin with MIT License 5 votes vote down vote up
@Test
public void shouldDelegateGetRemoteAddress() {
    when(httpServerRequest.remoteAddress())
        .thenReturn(null)
        .thenReturn(new SocketAddressImpl(8080, "10.3.100.108"));
    assertThat(vaadinRequest.getRemoteAddr()).isNull();
    assertThat(vaadinRequest.getRemoteAddr()).isEqualTo("10.3.100.108");
}
 
Example #7
Source File: ForwardedParser.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private SocketAddress parseFor(String forToParse, int defaultPort) {
    String host = forToParse;
    int port = defaultPort;
    int portSeparatorIdx = forToParse.lastIndexOf(':');
    if (portSeparatorIdx > forToParse.lastIndexOf(']')) {
        host = forToParse.substring(0, portSeparatorIdx);
        port = parsePort(forToParse.substring(portSeparatorIdx + 1), defaultPort);
    }

    return new SocketAddressImpl(port, host);
}
 
Example #8
Source File: VertxNetServerMetrics.java    From vertx-micrometer-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public String connected(SocketAddress remoteAddress, String remoteName) {
  String remote = Labels.fromAddress(new SocketAddressImpl(remoteAddress.port(), remoteName));
  connections.get(local, remote).increment();
  return remote;
}
 
Example #9
Source File: EqualityTest.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
@Test
public void testSocketAddressSet() {
  SocketAddress address1 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest"));
  SocketAddress address2 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest"));
  assertEquals(1, Stream.of(address1, address2).collect(toSet()).size());
}
 
Example #10
Source File: ToStringTest.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
@Test
public void testSocketAddressToString() {
  io.vertx.core.net.SocketAddress socketAddress = new SocketAddressImpl(8888, "guest");
  SocketAddress rxSocketAddress = SocketAddress.newInstance(socketAddress);
  assertEquals(socketAddress.toString(), rxSocketAddress.toString());
}
 
Example #11
Source File: EqualityTest.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
@Test
public void testSocketAddressSet() {
  SocketAddress address1 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest"));
  SocketAddress address2 = SocketAddress.newInstance(new SocketAddressImpl(8888, "guest"));
  assertEquals(1, Stream.of(address1, address2).collect(toSet()).size());
}
 
Example #12
Source File: ToStringTest.java    From vertx-rx with Apache License 2.0 4 votes vote down vote up
@Test
public void testSocketAddressToString() {
  io.vertx.core.net.SocketAddress socketAddress = new SocketAddressImpl(8888, "guest");
  SocketAddress rxSocketAddress = SocketAddress.newInstance(socketAddress);
  assertEquals(socketAddress.toString(), rxSocketAddress.toString());
}
 
Example #13
Source File: VertxNetClientMetrics.java    From vertx-micrometer-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public String connected(SocketAddress remoteAddress, String remoteName) {
  String remote = Labels.fromAddress(new SocketAddressImpl(remoteAddress.port(), remoteName));
  connections.get(local, remote).increment();
  return remote;
}
 
Example #14
Source File: VertxDatagramSocketMetrics.java    From vertx-micrometer-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public void listening(String localName, SocketAddress localAddress) {
  this.localAddress = Labels.fromAddress(new SocketAddressImpl(localAddress.port(), localName));
}
 
Example #15
Source File: VertxVaadinRequestUT.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Test
public void shouldDelegateGetRemotePort() {
    when(httpServerRequest.remoteAddress()).thenReturn(null, new SocketAddressImpl(5555, "10.1.1.1"));
    assertThat(vaadinRequest.getRemotePort()).isEqualTo(-1);
    assertThat(vaadinRequest.getRemotePort()).isEqualTo(5555);
}
 
Example #16
Source File: VertxVaadinRequestUT.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Test
public void shouldDelegateGetRemoteHost() {
    when(httpServerRequest.remoteAddress()).thenReturn(null, new SocketAddressImpl(5555, "10.1.1.1"));
    assertThat(vaadinRequest.getRemoteAddr()).isNull();
    assertThat(vaadinRequest.getRemoteAddr()).isEqualTo("10.1.1.1");
}
 
Example #17
Source File: VertxVaadinRequestUT.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Test
public void shouldDelegateGetRemotePort() {
    when(httpServerRequest.remoteAddress()).thenReturn(null, new SocketAddressImpl(5555, "10.1.1.1"));
    assertThat(vaadinRequest.getRemotePort()).isEqualTo(-1);
    assertThat(vaadinRequest.getRemotePort()).isEqualTo(5555);
}
 
Example #18
Source File: VertxVaadinRequestUT.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Test
public void shouldDelegateGetRemoteHost() {
    when(httpServerRequest.remoteAddress()).thenReturn(null, new SocketAddressImpl(5555, "10.1.1.1"));
    assertThat(vaadinRequest.getRemoteAddr()).isNull();
    assertThat(vaadinRequest.getRemoteAddr()).isEqualTo("10.1.1.1");
}