use of java.net.SocketAddress in project jackrabbit-oak by apache.
the class ClientFilterHandlerTest method disallowedClientsShouldNotBeServed.
@Test
public void disallowedClientsShouldNotBeServed() {
EmbeddedChannel channel = new EmbeddedChannel(new ClientFilterHandler(new ClientFilter() {
@Override
public boolean isAllowed(SocketAddress address) {
return false;
}
}));
channel.connect(new InetSocketAddress("127.0.0.2", 8080));
assertFalse(channel.isOpen());
}
use of java.net.SocketAddress in project geode by apache.
the class ServerHandShakeProcessor method readClientVersion.
private static Version readClientVersion(ServerConnection connection) throws IOException, VersionException {
Socket socket = connection.getSocket();
int timeout = connection.getHandShakeTimeout();
int soTimeout = -1;
try {
soTimeout = socket.getSoTimeout();
socket.setSoTimeout(timeout);
InputStream is = socket.getInputStream();
short clientVersionOrdinal = Version.readOrdinalFromInputStream(is);
if (clientVersionOrdinal == -1) {
throw new EOFException(LocalizedStrings.ServerHandShakeProcessor_HANDSHAKEREADER_EOF_REACHED_BEFORE_CLIENT_VERSION_COULD_BE_READ.toLocalizedString());
}
Version clientVersion = null;
try {
clientVersion = Version.fromOrdinal(clientVersionOrdinal, true);
} catch (UnsupportedVersionException uve) {
// Allows higher version of wan site to connect to server
if (connection.getCommunicationMode() == Acceptor.GATEWAY_TO_GATEWAY && !(clientVersionOrdinal == Version.NOT_SUPPORTED_ORDINAL)) {
return Acceptor.VERSION;
} else {
SocketAddress sa = socket.getRemoteSocketAddress();
String sInfo = "";
if (sa != null) {
sInfo = " Client: " + sa.toString() + ".";
}
throw new UnsupportedVersionException(uve.getMessage() + sInfo);
}
}
if (!clientVersion.compatibleWith(Acceptor.VERSION)) {
// we can throw this
throw new IncompatibleVersionException(clientVersion, Acceptor.VERSION);
// to restrict
}
// Backward Compatibilty Support to limited no of versions
return clientVersion;
} finally {
if (soTimeout != -1) {
try {
socket.setSoTimeout(soTimeout);
} catch (IOException ignore) {
}
}
}
}
use of java.net.SocketAddress in project beam by apache.
the class SocketAddressFactoryTest method testHostPortSocket.
@Test
public void testHostPortSocket() {
SocketAddress socketAddress = SocketAddressFactory.createFrom("localhost:123");
assertThat(socketAddress, instanceOf(InetSocketAddress.class));
assertEquals("localhost", ((InetSocketAddress) socketAddress).getHostString());
assertEquals(123, ((InetSocketAddress) socketAddress).getPort());
}
use of java.net.SocketAddress in project beam by apache.
the class SocketAddressFactoryTest method testDomainSocket.
@Test
public void testDomainSocket() throws Exception {
File tmpFile = tmpFolder.newFile();
SocketAddress socketAddress = SocketAddressFactory.createFrom("unix://" + tmpFile.getAbsolutePath());
assertThat(socketAddress, instanceOf(DomainSocketAddress.class));
assertEquals(tmpFile.getAbsolutePath(), ((DomainSocketAddress) socketAddress).path());
}
use of java.net.SocketAddress in project robovm by robovm.
the class DatagramChannelImpl method receive.
@Override
public SocketAddress receive(ByteBuffer target) throws IOException {
target.checkWritable();
checkOpen();
if (!isBound) {
return null;
}
SocketAddress retAddr = null;
try {
begin();
// receive real data packet, (not peek)
synchronized (readLock) {
boolean loop = isBlocking();
if (!target.isDirect()) {
retAddr = receiveImpl(target, loop);
} else {
retAddr = receiveDirectImpl(target, loop);
}
}
} catch (InterruptedIOException e) {
// this line used in Linux
return null;
} finally {
end(retAddr != null);
}
return retAddr;
}
Aggregations