Search in sources :

Example 21 with ConnectException

use of java.net.ConnectException in project XobotOS by xamarin.

the class SocketChannelImpl method connect.

@Override
public boolean connect(SocketAddress socketAddress) throws IOException {
    // status must be open and unconnected
    checkUnconnected();
    // check the address
    InetSocketAddress inetSocketAddress = validateAddress(socketAddress);
    InetAddress normalAddr = inetSocketAddress.getAddress();
    int port = inetSocketAddress.getPort();
    // When connecting, map ANY address to localhost
    if (normalAddr.isAnyLocalAddress()) {
        normalAddr = InetAddress.getLocalHost();
    }
    boolean finished = false;
    try {
        if (isBlocking()) {
            begin();
        }
        finished = IoBridge.connect(fd, normalAddr, port);
        isBound = finished;
    } catch (IOException e) {
        if (e instanceof ConnectException && !isBlocking()) {
            status = SOCKET_STATUS_PENDING;
        } else {
            if (isOpen()) {
                close();
                finished = true;
            }
            throw e;
        }
    } finally {
        if (isBlocking()) {
            end(finished);
        }
    }
    initLocalAddressAndPort();
    connectAddress = inetSocketAddress;
    if (socket != null) {
        socket.socketImpl().initRemoteAddressAndPort(connectAddress.getAddress(), connectAddress.getPort());
    }
    synchronized (this) {
        if (isBlocking()) {
            status = (finished ? SOCKET_STATUS_CONNECTED : SOCKET_STATUS_UNCONNECTED);
        } else {
            status = SOCKET_STATUS_PENDING;
        }
    }
    return finished;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) InetAddress(java.net.InetAddress) ConnectException(java.net.ConnectException)

Example 22 with ConnectException

use of java.net.ConnectException in project XobotOS by xamarin.

the class SocketChannelImpl method finishConnect.

@Override
public boolean finishConnect() throws IOException {
    synchronized (this) {
        if (!isOpen()) {
            throw new ClosedChannelException();
        }
        if (status == SOCKET_STATUS_CONNECTED) {
            return true;
        }
        if (status != SOCKET_STATUS_PENDING) {
            throw new NoConnectionPendingException();
        }
    }
    boolean finished = false;
    try {
        begin();
        InetAddress inetAddress = connectAddress.getAddress();
        int port = connectAddress.getPort();
        // Return immediately.
        finished = IoBridge.isConnected(fd, inetAddress, port, 0, 0);
        isBound = finished;
    } catch (ConnectException e) {
        if (isOpen()) {
            close();
            finished = true;
        }
        throw e;
    } finally {
        end(finished);
    }
    synchronized (this) {
        status = (finished ? SOCKET_STATUS_CONNECTED : status);
        isBound = finished;
    }
    return finished;
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) NoConnectionPendingException(java.nio.channels.NoConnectionPendingException) InetAddress(java.net.InetAddress) ConnectException(java.net.ConnectException)

Example 23 with ConnectException

use of java.net.ConnectException in project XobotOS by xamarin.

the class DatagramChannelImpl method connect.

/**
     * @see java.nio.channels.DatagramChannel#connect(java.net.SocketAddress)
     */
@Override
public synchronized DatagramChannel connect(SocketAddress address) throws IOException {
    // must open
    checkOpen();
    // status must be un-connected.
    if (connected) {
        throw new IllegalStateException();
    }
    // check the address
    InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address);
    try {
        begin();
        IoBridge.connect(fd, inetSocketAddress.getAddress(), inetSocketAddress.getPort());
    } catch (ConnectException e) {
    // ConnectException means connect fail, not exception
    } finally {
        end(true);
    }
    // set the connected address.
    connectAddress = inetSocketAddress;
    connected = true;
    isBound = true;
    return this;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectException(java.net.ConnectException)

Example 24 with ConnectException

use of java.net.ConnectException in project OpenAM by OpenRock.

the class PasswordValidator method isAgentAdminLoginValid.

/*
     * validate Agent Administrator's name and password.
     */
private ValidationResult isAgentAdminLoginValid(String passfileName, Map props, IStateAccess state) throws InstallException {
    ValidationResultStatus validRes = ValidationResultStatus.STATUS_FAILED;
    LocalizedMessage returnMessage = null;
    String agentUserName = null;
    String serverURL = null;
    String restAuthURL = null;
    String agentUserNameKey = (String) props.get(STR_AGENT_PROFILE_LOOKUP_KEY);
    if (agentUserNameKey != null) {
        agentUserName = (String) state.get(agentUserNameKey);
    }
    Map tokens = state.getData();
    if (tokens.containsKey("AM_SERVER_URL")) {
        serverURL = (String) tokens.get("AM_SERVER_URL");
    }
    String agentUserPasswd = readDataFromFile(passfileName);
    try {
        restAuthURL = serverURL + "/identity/authenticate";
        String encodingType = "UTF-8";
        String encodedPostData = "username=" + URLEncoder.encode(agentUserName, encodingType) + "&password=" + URLEncoder.encode(agentUserPasswd, encodingType) + "&uri=" + URLEncoder.encode("realm=/&module=Application", encodingType);
        RESTUtils.RESTResponse response = RESTUtils.callServiceURL(restAuthURL, encodedPostData);
        // Read response code
        int responseCode = response.getResponseCode();
        if (responseCode == HTTP_RESPONSE_OK) {
            validRes = ValidationResultStatus.STATUS_SUCCESS;
            setCreateAgentProfile(state, "true");
        } else if (responseCode == HTTP_RESPONSE_AUTHENTICATION_FAILED) {
            String responseStr = response.toString();
            if (responseStr.indexOf(STR_IDENTITY_INVALID_PASSWORD) > 0) {
                // wrong password
                returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_AGENT_PASSWORD, new Object[] { agentUserName });
            } else if (responseStr.indexOf(STR_IDENTITY_INVALID_CREDENTIALS) > 0) {
                // user does not exist.
                returnMessage = LocalizedMessage.get(LOC_VA_ERR_IN_VAL_AGENT_PROFILE_NOT_PRESENT, new Object[] { agentUserName });
            } else {
                Debug.log("PasswordValidator.isAgentAdminLoginValid() - " + "Error from OpenSSO:" + response.toString());
                returnMessage = LocalizedMessage.get(LOC_VA_ERR_IN_VAL_OTHER_AGENT_AUTH_FAILURE, new Object[] { Integer.valueOf(responseCode) });
            }
        } else {
            Debug.log("PasswordValidator.isAgentAdminLoginValid() - " + "Error from OpenSSO:" + response.toString());
            returnMessage = LocalizedMessage.get(LOC_VA_ERR_IN_VAL_AGENT_GENERIC_FAILURE, new Object[] { Integer.valueOf(responseCode) });
        }
    } catch (UnknownHostException uhe) {
        Debug.log("PasswordValidator.isAgentAdminLoginValid() " + "threw exception :", uhe);
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_FAM_SERVER_URL, new Object[] { restAuthURL });
    } catch (ConnectException ce) {
        Debug.log("PasswordValidator.isAgentAdminLoginValid() " + "threw exception :", ce);
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_FAM_SERVER_URL, new Object[] { restAuthURL });
    } catch (FileNotFoundException ex) {
        Debug.log("PasswordValidator.isAgentAdminLoginValid() " + "threw exception :", ex);
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_NOT_FOUND_SERVER_URL, new Object[] { restAuthURL });
    } catch (IOException ex) {
        Debug.log("PasswordValidator.isAgentAdminLoginValid() " + "threw exception :", ex);
    }
    return new ValidationResult(validRes, null, returnMessage);
}
Also used : RESTUtils(com.sun.identity.install.tools.util.RESTUtils) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) LocalizedMessage(com.sun.identity.install.tools.util.LocalizedMessage) ConnectException(java.net.ConnectException)

Example 25 with ConnectException

use of java.net.ConnectException in project OpenAM by OpenRock.

the class PasswordValidator method isAgentLoginValid.

/*
     * Checks if Agent profile/User's name&password is valid.
     *
     * @param port @param props @param state
     *
     * @return ValidationResult
     */
public ValidationResult isAgentLoginValid(String passfileName, Map props, IStateAccess state) throws InstallException {
    ValidationResultStatus validRes = ValidationResultStatus.STATUS_FAILED;
    LocalizedMessage returnMessage = null;
    String agentUserName = null;
    String serverURL = null;
    String restAuthURL = null;
    String str = null;
    String serverURLValid = (String) state.get("isServerURLValid");
    String createAgentProfileKey = (String) state.get(InstallConstants.STR_CREATE_AGENT_PROFILE_KEY);
    if (createAgentProfileKey == null) {
        setCreateAgentProfile(state, "false");
    }
    if (serverURLValid != null && serverURLValid.equals("true")) {
        if (isAgentAdmin(props, state)) {
            return isAgentAdminLoginValid(passfileName, props, state);
        }
        String agentUserNameKey = (String) props.get(STR_AGENT_PROFILE_LOOKUP_KEY);
        if (agentUserNameKey != null) {
            agentUserName = (String) state.get(agentUserNameKey);
        }
        Map tokens = state.getData();
        if (tokens.containsKey("AM_SERVER_URL")) {
            serverURL = (String) tokens.get("AM_SERVER_URL");
        }
        String agentUserPasswd = readDataFromFile(passfileName);
        try {
            restAuthURL = serverURL + "/identity/authenticate";
            String encodingType = "UTF-8";
            String encodedPostData = "username=" + URLEncoder.encode(agentUserName, encodingType) + "&password=" + URLEncoder.encode(agentUserPasswd, encodingType) + "&uri=" + URLEncoder.encode("realm=/&module=Application", encodingType);
            RESTUtils.RESTResponse response = RESTUtils.callServiceURL(restAuthURL, encodedPostData);
            // Read response code
            int responseCode = response.getResponseCode();
            if (responseCode == HTTP_RESPONSE_OK) {
                validRes = ValidationResultStatus.STATUS_SUCCESS;
                setCreateAgentProfile(state, "false");
            } else if (responseCode == HTTP_RESPONSE_AUTHENTICATION_FAILED) {
                String responseStr = response.toString();
                if (responseStr.indexOf(STR_IDENTITY_INVALID_PASSWORD) > 0) {
                    // wrong password
                    returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_AGENT_PASSWORD, new Object[] { agentUserName });
                } else if (responseStr.indexOf(STR_IDENTITY_INVALID_CREDENTIALS) > 0) {
                    // create agent profile only when agent profile 
                    // does not exist.
                    setCreateAgentProfile(state, "true");
                    returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_AGENT_PROFILE_NOT_PRESENT, new Object[] { agentUserName });
                    validRes = ValidationResultStatus.STATUS_WARNING;
                } else {
                    Debug.log("PasswordValidator.isAgentLoginValid() - " + "Error from OpenSSO:" + response.toString());
                    returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_OTHER_AGENT_AUTH_FAILURE, new Object[] { Integer.valueOf(responseCode) });
                    validRes = ValidationResultStatus.STATUS_WARNING;
                }
            } else {
                Debug.log("PasswordValidator.isAgentLoginValid() - " + "Error from OpenSSO:" + response.toString());
                returnMessage = LocalizedMessage.get(LOC_VA_WRN_IN_VAL_AGENT_GENERIC_FAILURE, new Object[] { Integer.valueOf(responseCode) });
                validRes = ValidationResultStatus.STATUS_WARNING;
            }
        } catch (UnknownHostException uhe) {
            Debug.log("PasswordValidator.isAgentLoginValid() " + "threw exception :", uhe);
            returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_FAM_SERVER_URL, new Object[] { restAuthURL });
            validRes = ValidationResultStatus.STATUS_WARNING;
        } catch (ConnectException ce) {
            Debug.log("PasswordValidator.isAgentLoginValid() " + "threw exception :", ce);
            returnMessage = LocalizedMessage.get(LOC_VA_WRN_UN_REACHABLE_FAM_SERVER_URL, new Object[] { restAuthURL });
            validRes = ValidationResultStatus.STATUS_WARNING;
        } catch (FileNotFoundException ex) {
            Debug.log("PasswordValidator.isAgentLoginValid() " + "threw exception :", ex);
            returnMessage = LocalizedMessage.get(LOC_VA_WRN_NOT_FOUND_SERVER_URL, new Object[] { restAuthURL });
            validRes = ValidationResultStatus.STATUS_WARNING;
        } catch (IOException ex) {
            Debug.log("PasswordValidator.isAgentLoginValid() " + "threw exception :", ex);
        }
        return new ValidationResult(validRes, null, returnMessage);
    } else {
        returnMessage = LocalizedMessage.get(LOC_VA_WRN_SERVER_URL_NOT_RUNNING, new Object[] { serverURL });
        validRes = ValidationResultStatus.STATUS_WARNING;
        return new ValidationResult(validRes, null, returnMessage);
    }
}
Also used : RESTUtils(com.sun.identity.install.tools.util.RESTUtils) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) LocalizedMessage(com.sun.identity.install.tools.util.LocalizedMessage) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)521 IOException (java.io.IOException)211 Socket (java.net.Socket)84 SocketTimeoutException (java.net.SocketTimeoutException)69 Test (org.junit.Test)69 UnknownHostException (java.net.UnknownHostException)57 InetSocketAddress (java.net.InetSocketAddress)56 WebServiceException (javax.xml.ws.WebServiceException)48 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)48 ErrorCode (org.olat.modules.vitero.model.ErrorCode)48 FileNotFoundException (java.io.FileNotFoundException)39 URL (java.net.URL)36 InputStream (java.io.InputStream)33 NoRouteToHostException (java.net.NoRouteToHostException)33 SocketException (java.net.SocketException)33 ArrayList (java.util.ArrayList)31 InetAddress (java.net.InetAddress)29 InputStreamReader (java.io.InputStreamReader)28 OutputStream (java.io.OutputStream)28 HttpURLConnection (java.net.HttpURLConnection)28