Search in sources :

Example 26 with ConnectException

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

the class AMSetupUtils method getRemoteServerInfo.

/**
     * Obtains misc config data from a remote OpenAM server:
     * <ul>
     *     <li>OpendDJ admin port</li>
     *     <li>config basedn</li>
     *     <li>replication ready flag</li>
     *     <li>OpenDJ replication port or OpenDJ suggested port</li>
     * </ul>
     *
     * @param serverUrl URL string representing the remote OpenAM server.
     * @param userId The admin user id on remote server, (only amadmin).
     * @param password The admin password.
     * @return A {@code Map} of config parameters.
     * @throws ConfigurationException for the following error code:
     * <ul>
     *     <li>400=Bad Request - user id/password param missing</li>
     *     <li>401=Unauthorized - invalid credentials</li>
     *     <li>405=Method Not Allowed - only POST is honored</li>
     *     <li>408=Request Timeout - requested timed out</li>
     *     <li>500=Internal Server Error</li>
     *     <li>701=File Not Found - incorrect deploy/server uri</li>
     *     <li>702=Connection Error - failed to connect</li>
     * </ul>
     */
public static Map<String, String> getRemoteServerInfo(String serverUrl, String userId, String password) throws ConfigurationException {
    HttpURLConnection connection = null;
    try {
        connection = openConnection(serverUrl + "/getServerInfo.jsp");
        writeToConnection(connection, "IDToken1=" + URLEncoder.encode(userId, "UTF-8") + "&IDToken2=" + URLEncoder.encode(password, "UTF-8"));
        // Remove any additional /n's from the result, often seen at the beginning of the response.
        return BootstrapData.queryStringToMap(readFromConnection(connection).replace("\n", ""));
    } catch (IllegalArgumentException e) {
        debug.warning("AMSetupUtils.getRemoteServerInfo()", e);
        throw newConfigurationException("702");
    } catch (IOException e) {
        debug.warning("AMSetupUtils.getRemoteServerInfo()", e);
        if (e instanceof FileNotFoundException) {
            throw newConfigurationException("701");
        } else if (e instanceof SSLHandshakeException || e instanceof MalformedURLException || e instanceof UnknownHostException || e instanceof ConnectException) {
            throw newConfigurationException("702");
        } else {
            int status = 0;
            if (connection != null) {
                try {
                    status = connection.getResponseCode();
                } catch (Exception ignored) {
                }
            }
            if (status == 400 || status == 401 || status == 405 || status == 408) {
                throw newConfigurationException(String.valueOf(status));
            } else {
                throw new ConfiguratorException(e.getMessage());
            }
        }
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HttpURLConnection(java.net.HttpURLConnection) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) ConnectException(java.net.ConnectException)

Example 27 with ConnectException

use of java.net.ConnectException in project voltdb by VoltDB.

the class RegressionSuite method getFullyConnectedClient.

public Client getFullyConnectedClient(long timeout) throws IOException {
    final List<String> listeners = m_config.getListenerAddresses();
    final Random r = new Random();
    ClientConfig config = new ClientConfigForTest(m_username, m_password);
    config.setConnectionResponseTimeout(timeout);
    config.setProcedureCallTimeout(timeout);
    final Client client = ClientFactory.createClient(config);
    for (String listener : listeners) {
        // Use the port generated by LocalCluster if applicable
        try {
            client.createConnection(listener);
        }// retry once
         catch (ConnectException e) {
            listener = listeners.get(r.nextInt(listeners.size()));
            client.createConnection(listener);
        }
    }
    m_clients.add(client);
    return client;
}
Also used : Random(java.util.Random) ClientConfig(org.voltdb.client.ClientConfig) ClientConfigForTest(org.voltdb.client.ClientConfigForTest) Client(org.voltdb.client.Client) ConnectException(java.net.ConnectException)

Example 28 with ConnectException

use of java.net.ConnectException in project voltdb by VoltDB.

the class RegressionSuite method getClientToHostId.

/**
     * Get a VoltClient instance connected to a specific server driven by the
     * VoltServerConfig instance. Find the server by the config's HostId.
     *
     * @return A VoltClient instance connected to the server driven by the
     * VoltServerConfig instance.
     */
public Client getClientToHostId(int hostId, long timeout) throws IOException {
    final String listener = m_config.getListenerAddress(hostId);
    ClientConfig config = new ClientConfigForTest(m_username, m_password);
    config.setConnectionResponseTimeout(timeout);
    config.setProcedureCallTimeout(timeout);
    final Client client = ClientFactory.createClient(config);
    try {
        client.createConnection(listener);
    }// retry once
     catch (ConnectException e) {
        client.createConnection(listener);
    }
    m_clients.add(client);
    return client;
}
Also used : ClientConfig(org.voltdb.client.ClientConfig) ClientConfigForTest(org.voltdb.client.ClientConfigForTest) Client(org.voltdb.client.Client) ConnectException(java.net.ConnectException)

Example 29 with ConnectException

use of java.net.ConnectException in project ats-framework by Axway.

the class AtsDbLoggerUtilities method attachFileToCurrentTest.

/**
     * Attach a local file to the current test case in the Test Explorer DB.
     * </br>The file must not be bigger than 10MB
     * 
     * @param fileLocation the absolute path to the file
     * @param testExplorerContextName the name of the web application, e.g. "TestExplorer" or "TestExplorer-3.11.0" etc.
     * @param testExplorerPort the port of the web application, e.g. 8080
     * @return TRUE if the operation was successful and false if not. A warning will be logged on failure.
     */
@PublicAtsApi
public boolean attachFileToCurrentTest(String fileLocation, String testExplorerContextName, int testExplorerPort) {
    ERR_MSG_PREFIX = ERR_MSG_PREFIX.replace("{FILE}", fileLocation);
    if (!checkFileExist(fileLocation)) {
        return false;
    }
    if (!checkFileSizeIsNotTooLarge(fileLocation)) {
        return false;
    }
    ActiveDbAppender dbAppender = ActiveDbAppender.getCurrentInstance();
    if (dbAppender == null) {
        logger.warn(ERR_MSG_PREFIX + "Perhaps the database logging is turned off");
        return false;
    }
    final int runId = dbAppender.getRunId();
    final int suiteId = dbAppender.getSuiteId();
    final int testcaseId = dbAppender.getTestCaseId();
    if (runId < 1 || suiteId < 1 || testcaseId < 1) {
        logger.warn(ERR_MSG_PREFIX + "Perhaps the database logging is turned off or you are trying to log while a testcase is not yet started");
        return false;
    }
    final String database = dbAppender.getDatabase();
    final String host = dbAppender.getHost();
    final String URL = "http://" + host + ":" + testExplorerPort + "/" + testExplorerContextName + "/UploadServlet";
    URL url = null;
    try {
        CloseableHttpClient client = HttpClients.createDefault();
        HttpPost post = new HttpPost(URL);
        url = post.getURI().toURL();
        if (!isURLConnetionAvailable(url)) {
            return false;
        }
        logger.debug("POSTing " + fileLocation + " on " + URL);
        File file = new File(fileLocation);
        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, fileLocation);
        builder.addTextBody("dbName", database);
        builder.addTextBody("runId", Integer.toString(runId));
        builder.addTextBody("suiteId", Integer.toString(suiteId));
        builder.addTextBody("testcaseId", Integer.toString(testcaseId));
        HttpEntity entity = builder.build();
        post.setEntity(entity);
        checkPostExecutedSuccessfully(client.execute(post), fileLocation);
    } catch (FileNotFoundException fnfe) {
        logger.warn(ERR_MSG_PREFIX + "it does not exist on the local file system", fnfe);
        return false;
    } catch (ClientProtocolException cpe) {
        logger.warn(ERR_MSG_PREFIX + "Upload to \"" + url + "\" failed", cpe);
        return false;
    } catch (ConnectException ce) {
        logger.warn(ERR_MSG_PREFIX + "Upload to \"" + url + "\" failed", ce);
        return false;
    } catch (IOException ioe) {
        logger.warn(ERR_MSG_PREFIX + "Upload to \"" + url + "\" failed", ioe);
        return false;
    }
    logger.info("Successfully attached \"" + fileLocation + "\" to the current Test Explorer testcase");
    return true;
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) HttpEntity(org.apache.http.HttpEntity) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) URL(java.net.URL) ClientProtocolException(org.apache.http.client.ClientProtocolException) ActiveDbAppender(com.axway.ats.log.appenders.ActiveDbAppender) File(java.io.File) ConnectException(java.net.ConnectException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 30 with ConnectException

use of java.net.ConnectException in project Gradle-demo by Arisono.

the class RetryIntercepter method intercept.

@SuppressWarnings("resource")
@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    Response response = chain.proceed(request);
    try {
        // OkhttpUtils.println("重试拦截器:"+response.isSuccessful());
        while (!response.isSuccessful() && retryNum < maxRetry) {
            retryNum++;
            response = chain.proceed(request);
        }
    } catch (ConnectException e) {
        OkhttpUtils.println("服务器拒绝连接.....");
    } catch (IOException e) {
        OkhttpUtils.println("服务器拒绝连接.....");
    }
    return response;
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException) 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