Search in sources :

Example 1 with UnsupportedAddressTypeException

use of java.nio.channels.UnsupportedAddressTypeException in project netty by netty.

the class AbstractAddressResolver method resolveAll.

@Override
public final Future<List<T>> resolveAll(SocketAddress address) {
    if (!isSupported(checkNotNull(address, "address"))) {
        // Address type not supported by the resolver
        return executor().newFailedFuture(new UnsupportedAddressTypeException());
    }
    if (isResolved(address)) {
        // Resolved already; no need to perform a lookup
        @SuppressWarnings("unchecked") final T cast = (T) address;
        return executor.newSucceededFuture(Collections.singletonList(cast));
    }
    try {
        @SuppressWarnings("unchecked") final T cast = (T) address;
        final Promise<List<T>> promise = executor().newPromise();
        doResolveAll(cast, promise);
        return promise;
    } catch (Exception e) {
        return executor().newFailedFuture(e);
    }
}
Also used : UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) List(java.util.List) UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException)

Example 2 with UnsupportedAddressTypeException

use of java.nio.channels.UnsupportedAddressTypeException in project robovm by robovm.

the class SocketChannelTest method testCFII_UnsupportedType.

public void testCFII_UnsupportedType() throws Exception {
    class SubSocketAddress extends SocketAddress {

        private static final long serialVersionUID = 1L;

        //empty
        public SubSocketAddress() {
            super();
        }
    }
    statusNotConnected_NotPending();
    SocketAddress newTypeAddress = new SubSocketAddress();
    try {
        this.channel1.connect(newTypeAddress);
        fail("Should throw an UnsupportedAddressTypeException here.");
    } catch (UnsupportedAddressTypeException e) {
    // OK.
    }
}
Also used : UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 3 with UnsupportedAddressTypeException

use of java.nio.channels.UnsupportedAddressTypeException in project robovm by robovm.

the class OldSocketChannelTest method testOpenSocketAddress.

public void testOpenSocketAddress() throws IOException {
    this.channel1 = SocketChannel.open(localAddr1);
    assertTrue(this.channel1.isConnected());
    SocketAddress newTypeAddress = new SubSocketAddress();
    try {
        this.channel1 = SocketChannel.open(newTypeAddress);
        fail("Should throw UnexpectedAddressTypeException");
    } catch (UnsupportedAddressTypeException e) {
    // expected
    }
    SocketAddress unresolvedAddress = InetSocketAddress.createUnresolved("127.0.0.1", 8080);
    try {
        this.channel1 = SocketChannel.open(unresolvedAddress);
        fail("Should throw UnresolvedAddressException");
    } catch (UnresolvedAddressException e) {
    // expected
    }
    SocketChannel channel1IP = null;
    try {
        channel1IP = SocketChannel.open(null);
        fail("Should throw an IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // correct
    }
    assertNull(channel1IP);
}
Also used : UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 4 with UnsupportedAddressTypeException

use of java.nio.channels.UnsupportedAddressTypeException in project j2objc by google.

the class SocketChannelImpl method bind.

/** @hide Until ready for a public API change */
@Override
public final synchronized SocketChannel bind(SocketAddress local) throws IOException {
    if (!isOpen()) {
        throw new ClosedChannelException();
    }
    if (isBound) {
        throw new AlreadyBoundException();
    }
    if (local == null) {
        local = new InetSocketAddress(Inet4Address.ANY, 0);
    } else if (!(local instanceof InetSocketAddress)) {
        throw new UnsupportedAddressTypeException();
    }
    InetSocketAddress localAddress = (InetSocketAddress) local;
    NetworkBridge.bind(fd, localAddress.getAddress(), localAddress.getPort());
    onBind(true);
    return this;
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) AlreadyBoundException(java.nio.channels.AlreadyBoundException) InetSocketAddress(java.net.InetSocketAddress)

Example 5 with UnsupportedAddressTypeException

use of java.nio.channels.UnsupportedAddressTypeException in project jdk8u_jdk by JetBrains.

the class Connect method doTest.

void doTest() {
    SctpChannel channel = null;
    SctpServerChannel ssc = null;
    try {
        /* Create a server channel to connect to */
        ssc = SctpServerChannel.open().bind(null);
        Set<SocketAddress> addrs = ssc.getAllLocalAddresses();
        if (addrs.isEmpty())
            debug("addrs should not be empty");
        final SocketAddress peerAddress = (InetSocketAddress) addrs.iterator().next();
        channel = SctpChannel.open();
        /* TEST 0.5 Verify default values for new/unconnected channel */
        check(channel.getRemoteAddresses().isEmpty(), "non empty set for unconnected channel");
        check(channel.association() == null, "non-null association for unconnected channel");
        check(!channel.isConnectionPending(), "should not have a connection pending");
        /* TEST 1: non-blocking connect */
        channel.configureBlocking(false);
        if (channel.connect(peerAddress) != true) {
            debug("non-blocking connect did not immediately succeed");
            check(channel.isConnectionPending(), "should return true for isConnectionPending");
            try {
                channel.connect(peerAddress);
                fail("should have thrown ConnectionPendingException");
            } catch (ConnectionPendingException cpe) {
                pass();
            } catch (IOException ioe) {
                unexpected(ioe);
            }
            channel.configureBlocking(true);
            check(channel.finishConnect(), "finishConnect should have returned true");
        }
        ssc.accept();
        ssc.close();
        /* TEST 1.5 Verify after connect */
        check(!channel.getRemoteAddresses().isEmpty(), "empty set for connected channel");
        check(channel.association() != null, "null association for connected channel");
        check(!channel.isConnectionPending(), "pending connection for connected channel");
        /* TEST 2: Verify AlreadyConnectedException thrown */
        try {
            channel.connect(peerAddress);
            fail("should have thrown AlreadyConnectedException");
        } catch (AlreadyConnectedException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 2.5: Verify AlreadyConnectedException thrown */
        try {
            channel.connect(peerAddress, 5, 5);
            fail("should have thrown AlreadyConnectedException");
        } catch (AlreadyConnectedException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 3: UnresolvedAddressException */
        channel.close();
        channel = SctpChannel.open();
        InetSocketAddress unresolved = InetSocketAddress.createUnresolved("xxyyzzabc", 4567);
        try {
            channel.connect(unresolved);
            fail("should have thrown UnresolvedAddressException");
        } catch (UnresolvedAddressException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 4: UnsupportedAddressTypeException */
        SocketAddress unsupported = new UnsupportedSocketAddress();
        try {
            channel.connect(unsupported);
            fail("should have thrown UnsupportedAddressTypeException");
        } catch (UnsupportedAddressTypeException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 5: ClosedChannelException */
        channel.close();
        final SctpChannel closedChannel = channel;
        testCCE(new Callable<Void>() {

            public Void call() throws IOException {
                closedChannel.connect(peerAddress);
                return null;
            }
        });
        /* TEST 5.5 getRemoteAddresses */
        testCCE(new Callable<Void>() {

            public Void call() throws IOException {
                closedChannel.getRemoteAddresses();
                return null;
            }
        });
        testCCE(new Callable<Void>() {

            public Void call() throws IOException {
                closedChannel.association();
                return null;
            }
        });
        check(!channel.isConnectionPending(), "pending connection for closed channel");
        /* Run some more finishConnect tests */
        /* TEST 6: NoConnectionPendingException */
        channel = SctpChannel.open();
        try {
            channel.finishConnect();
            fail("should have thrown NoConnectionPendingException");
        } catch (NoConnectionPendingException unused) {
            pass();
        } catch (IOException ioe) {
            unexpected(ioe);
        }
        /* TEST 7: ClosedChannelException */
        channel.close();
        final SctpChannel cceChannel = channel;
        testCCE(new Callable<Void>() {

            public Void call() throws IOException {
                cceChannel.finishConnect();
                return null;
            }
        });
        /* TEST 8: IOException: Connection refused. Exercises handleSocketError.
             *         Assumption: no sctp socket listening on 3456 */
        SocketAddress addr = new InetSocketAddress("localhost", 3456);
        channel = SctpChannel.open();
        try {
            channel.connect(addr);
            fail("should have thrown ConnectException: Connection refused");
        } catch (IOException ioe) {
            pass();
        }
    } catch (IOException ioe) {
        unexpected(ioe);
    } finally {
        try {
            if (channel != null)
                channel.close();
        } catch (IOException unused) {
        }
        try {
            if (ssc != null)
                ssc.close();
        } catch (IOException unused) {
        }
    }
}
Also used : SctpChannel(com.sun.nio.sctp.SctpChannel) UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) NoConnectionPendingException(java.nio.channels.NoConnectionPendingException) AlreadyConnectedException(java.nio.channels.AlreadyConnectedException) InetSocketAddress(java.net.InetSocketAddress) NoConnectionPendingException(java.nio.channels.NoConnectionPendingException) ConnectionPendingException(java.nio.channels.ConnectionPendingException) SctpServerChannel(com.sun.nio.sctp.SctpServerChannel) IOException(java.io.IOException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

UnsupportedAddressTypeException (java.nio.channels.UnsupportedAddressTypeException)12 InetSocketAddress (java.net.InetSocketAddress)6 SocketAddress (java.net.SocketAddress)4 AlreadyBoundException (java.nio.channels.AlreadyBoundException)3 SctpChannel (com.sun.nio.sctp.SctpChannel)2 AlreadyConnectedException (java.nio.channels.AlreadyConnectedException)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)2 IllegalUnbindException (com.sun.nio.sctp.IllegalUnbindException)1 SctpServerChannel (com.sun.nio.sctp.SctpServerChannel)1 IOException (java.io.IOException)1 ConnectionPendingException (java.nio.channels.ConnectionPendingException)1 NoConnectionPendingException (java.nio.channels.NoConnectionPendingException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 List (java.util.List)1