Example usage for java.net SocketException SocketException

List of usage examples for java.net SocketException SocketException

Introduction

In this page you can find the example usage for java.net SocketException SocketException.

Prototype

public SocketException(String msg) 

Source Link

Document

Constructs a new SocketException with the specified detail message.

Usage

From source file:org.jsslutils.extra.apachetomcat5.JSSLutilsJSSESocketFactory.java

public Socket acceptSocket(ServerSocket socket) throws IOException {
    SSLSocket asock = null;/*from  w  w  w  .j av  a 2  s.c o m*/
    try {
        asock = (SSLSocket) socket.accept();
        configureClientAuth(asock);
    } catch (SSLException e) {
        throw new SocketException("SSL handshake error" + e.toString());
    }
    return asock;
}

From source file:jnode.vm.NetAPIImpl.java

/**
 * Return a network device by its address
 * /* www.j a va  2 s. c  o  m*/
 * @param addr
 *            The address of the interface to return
 * @exception SocketException
 *                If an error occurs
 * @exception NullPointerException
 *                If the specified addess is null
 */
public VMNetDevice getByInetAddress(InetAddress addr) throws SocketException {
    log.info("getByInetAddress");
    for (Device dev : DeviceUtils.getDevicesByAPI(NetDeviceAPI.class)) {
        try {
            final NetDeviceAPI api = dev.getAPI(NetDeviceAPI.class);
            final ProtocolAddressInfo info = api.getProtocolAddressInfo(EthernetConstants.ETH_P_IP);
            log.info("Checking Device (" + dev.toString() + ") Address : (" + addr.toString() + ") Present : ("
                    + info.contains(addr) + ")");
            if (info.contains(addr)) {
                return new NetDeviceImpl(dev);
            }
        } catch (ApiNotFoundException ex) {
            // Ignore
        }
    }
    throw new SocketException("no network interface is bound to such an IP address");
}

From source file:org.jnode.net.ipv4.icmp.ICMPProtocol.java

/**
 * Gets the SocketImplFactory of this protocol.
 * /*from  w  w  w . ja  va  2s.c o m*/
 * @throws SocketException If this protocol is not Socket based.
 */
public SocketImplFactory getSocketImplFactory() throws SocketException {
    throw new SocketException("ICMP is packet based");
}

From source file:org.apache.tomcat.util.net.jsse.JSSE14Support.java

/**
 * JSSE in JDK 1.4 has an issue/feature that requires us to do a
 * read() to get the client-cert.  As suggested by Andreas
 * Sterbenz//from w  w w . j a va  2  s .c  o m
 */
private void synchronousHandshake(SSLSocket socket) throws IOException {
    InputStream in = socket.getInputStream();
    int oldTimeout = socket.getSoTimeout();
    socket.setSoTimeout(1000);
    byte[] b = new byte[0];
    listener.reset();
    socket.startHandshake();
    int maxTries = 60; // 60 * 1000 = example 1 minute time out
    for (int i = 0; i < maxTries; i++) {
        if (logger.isTraceEnabled())
            logger.trace("Reading for try #" + i);
        try {
            int x = in.read(b);
        } catch (SSLException sslex) {
            logger.info("SSL Error getting client Certs", sslex);
            throw sslex;
        } catch (IOException e) {
            // ignore - presumably the timeout
        }
        if (listener.completed) {
            break;
        }
    }
    socket.setSoTimeout(oldTimeout);
    if (listener.completed == false) {
        throw new SocketException("SSL Cert handshake timeout");
    }
}

From source file:org.jnode.net.ipv4.udp.UDPProtocol.java

/**
 * Gets the SocketImplFactory of this protocol.
 * //from  w w w  .  j a  va2 s  .co  m
 * @throws SocketException If this protocol is not Socket based.
 */
public SocketImplFactory getSocketImplFactory() throws SocketException {
    throw new SocketException("UDP is packet based");
}

From source file:org.jnode.net.ipv4.icmp.ICMPProtocol.java

/**
 * Gets the DatagramSocketImplFactory of this protocol.
 * //  ww  w .  ja  v  a  2 s. c o  m
 * @throws SocketException If this protocol is not DatagramSocket based.
 */
public DatagramSocketImplFactory getDatagramSocketImplFactory() throws SocketException {
    throw new SocketException("Not implemented yet");
}

From source file:org.apache.tomcat.util.net.jsse.JSSESocketFactory.java

public Socket acceptSocket(ServerSocket socket) throws IOException {
    SSLSocket asock = null;//from   ww w. j  a va  2s. c o  m
    try {
        asock = (SSLSocket) socket.accept();
        asock.setNeedClientAuth(clientAuth);
    } catch (SSLException e) {
        throw new SocketException("SSL handshake error" + e.toString());
    }
    return asock;
}

From source file:org.alfresco.repo.webdav.GetMethodTest.java

@Test
public void readContentDoesNotLogSocketExceptions() throws IOException, WebDAVServerException {
    SocketException sockEx = new SocketException("Client aborted connection");
    ContentIOException contentEx = new ContentIOException("Wrapping the socket exception.", sockEx);

    // Reader.getContent() will throw a ContentIOException when a client aborts.
    doThrow(contentEx).when(reader).getContent(any(OutputStream.class));

    try {//from   w  w w  .  j av a 2 s  . c  o m
        getMethod.readContent(fileInfo, reader);
        fail("Exception should have been thrown.");
    } catch (WebDAVServerException e) {
        verify(logger, never()).error(anyString(), same(contentEx));
        // Error will only be seen when debugging.
        verify(logger).debug(anyString(), same(contentEx));
        assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getHttpStatusCode());
        assertNull(e.getCause()); // Avoids logging stacking trace
    }
}

From source file:Networking.Networking.java

/**
 * Constructs a new {@see #Networking} object. Sets {@see #state} to 
 * {@see Networking.NetworkState#NOT_CONNECTED}, initializes {@see #udpInData}
 * as array of 512 bytes. Sets {@see #playerPortUDP} to value defined in 
 * {@see edu.cvut.vorobvla.bap.BapPorts#PLAYER_PORT} and initializes
 * {@see udpSocket} with this value as constructor parameter (a port to
 * bind with this socket). If initialization fails 
 * ({@code SocketException} occurs) increments {@see #playerPortUDP} and
 * attempts to initialize {@see udpSocket} with parameter {@see #playerPortUDP}.
 * Proceeds like this until initialization succeeds or until {@see #playerPortUDP}
 * reaches {@see edu.cvut.vorobvla.bap.BapPorts#PLAYER_PORT}{@code + }
 * {@see edu.cvut.vorobvla.bap.BapPorts#PLAYER_PORT_RANGE}{@code - 1}.
 * Initializes {@see networkListener} as an anonymous {@code Thread} child
 * with overridden {@code run()} method. 
 * <p> The {@code run()} method//w w w.  j av a2s.  c  o  m
 * the greatest part of the network protocol (waits for
 * {@see edu.cvut.vorobvla.bap.BapMessages#MSG_CALL_FOR_PLAYERS}, processes it
 * and calls {@see establishConnectionWithModerator} and {@see recvOpts}).
 * <p>Constructor of {@see #Networking} proceeds with setting {@see #gameListener}
 * to {@code null}, {@see #broadcastLatestTimestamp} to {@code 0} and
 * initializing {@see #parser}.
 * 
 * @throws SocketException if all attempts to initialize {@see udpSocket}
 * were unsuccessful.
 */
private Networking() throws SocketException {
    state = NetworkState.NOT_CONNECTED;
    this.playerPortUDP = BapPorts.PLAYER_PORT;
    //    identity = Player.getInstance().getName();
    udpInData = new byte[512];
    while (udpSocket == null) {//may be bug
        try {
            udpSocket = new DatagramSocket(playerPortUDP);
        } catch (SocketException ex) {
            if (playerPortUDP < BapPorts.PLAYER_PORT + BapPorts.PLAYER_PORT_RANGE) {
                Logger.getLogger(Networking.class.getName()).log(Level.INFO,
                        "bad UDP port " + playerPortUDP + ". trying another...",
                        "bad UDP port " + playerPortUDP + ". trying another...");
                playerPortUDP++;

            } else {
                throw new SocketException("no suttable UDP port");
                //Logger.getLogger(Networking.class.getName()).log(Level.SEVERE, null, "no suttable UDP port");
                //break;
            }
        }
    }
    networkListener = new Thread() {

        @Override
        public void run() {
            try {
                //    System.out.println("Start listening to UDP broadcast on"
                //  + udpSocket.getLocalSocketAddress().toString());
                DatagramPacket initMsgFromModerator = recvUDP();
                String msg = new String(initMsgFromModerator.getData());
                if (!msg.split(":")[0].matches(BapMessages.MSG_CALL_FOR_PLAYERS)) {
                    System.err.println("wrong message. got '" + msg + "' while '"
                            + BapMessages.MSG_CALL_FOR_PLAYERS + "' expexted");
                    return;
                }
                System.out.println("RECEVED: " + msg);
                //get the moderator's IP from the pachage and the port that is listen by it from the message                 

                establishConnectionWithModerator(initMsgFromModerator.getAddress(),
                        Integer.parseInt(msg.split(BapMessages.FIELD_DELIM)[1].replaceAll("\\D", "")));
                recvOpts();
            } catch (IOException ex) {
                Logger.getLogger(Networking.class.getName()).log(Level.SEVERE, null, ex);
                System.err.println("exception while establishing connection");
            }
        }
    };

    gameListener = null;
    parser = new JSONParser();
    broadcastLatestTimestamp = 0;
    //    establishConnectionWithModerator();
}

From source file:org.jnode.net.ipv4.tcp.TCPOutChannel.java

/**
 * Send a TCP segment containing the given data.
 * This method blocks until there is enough space in the output buffer
 * to hold the data./*from  w  w w  . j av  a 2s .c  o  m*/
 *
 * @param ipHdr
 * @param hdr
 * @param data
 * @param offset
 * @param length Must be smaller or equal to mss.
 */
public synchronized void send(IPv4Header ipHdr, TCPHeader hdr, byte[] data, int offset, int length)
        throws SocketException {
    if (DEBUG) {
        log.debug("outChannel.send(ipHdr,hdr,data," + offset + ", " + length + ")");
    }
    // Check for maximum datalength
    if (length > mss) {
        throw new IllegalArgumentException("dataLength must be <= mss");
    }
    // Wait until there is space in the output buffer
    while ((length > dataBuffer.getFreeSize()) && !controlBlock.isReset()) {
        try {
            wait();
        } catch (InterruptedException ex) {
            // Ignore
        }
    }
    if (controlBlock.isReset()) {
        throw new SocketException("Connection reset");
    }
    // Add to databuffer
    final int bufOfs = dataBuffer.add(data, offset, length);
    // Update tcp header
    hdr.setDataLength(length);
    // Do the actual send
    sendHelper(ipHdr, hdr, bufOfs);
}