Example usage for java.net ConnectException ConnectException

List of usage examples for java.net ConnectException ConnectException

Introduction

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

Prototype

public ConnectException(String msg) 

Source Link

Document

Constructs a new ConnectException with the specified detail message as to why the connect error occurred.

Usage

From source file:com.tc.admin.UpdateCheckRequestTest.java

public static String getResponseBody(URL url, HttpClient client) throws ConnectException, IOException {
    GetMethod get = new GetMethod(url.toString());

    get.setFollowRedirects(true);//from w  w w. j a  va 2 s. co  m
    try {
        int status = client.executeMethod(get);
        if (status != HttpStatus.SC_OK) {
            throw new ConnectException(
                    "The http client has encountered a status code other than ok for the url: " + url
                            + " status: " + HttpStatus.getStatusText(status));
        }
        return get.getResponseBodyAsString();
    } finally {
        get.releaseConnection();
    }
}

From source file:org.sakuli.services.receiver.database.dao.impl.Dao.java

public Dao(DataSource dataSource) throws SakuliException {

    try {//from w ww  . j av a2  s  .c om
        if (dataSource == null) {
            throw new ConnectException("Cannot get a connection to the Database!");
        }
        setDataSource(dataSource);
    } catch (Throwable e) {
        logger.debug("Suppressed Exception for missing DB connection: ", e);
        throw new RuntimeException("Database is not reachable, please check your 'db.properties' !!!");
    }
}

From source file:org.sakuli.services.forwarder.database.dao.impl.Dao.java

public Dao(DataSource dataSource) throws SakuliException {

    try {/*from   w w  w . ja v  a2  s .  c om*/
        if (dataSource == null) {
            throw new ConnectException("Cannot get a connection to the Database!");
        }
        setDataSource(dataSource);
    } catch (Throwable e) {
        LOGGER.debug("Suppressed Exception for missing DB connection: ", e);
        throw new RuntimeException("Database is not reachable, please check your 'db.properties' !!!");
    }
}

From source file:com.surfs.storage.common.util.HttpUtils.java

public static String invokeHttpForGet(String path, String... agrs) throws IOException {
    URL url = new URL(path);
    LogFactory.info("rest url:" + url.toString());
    HttpURLConnection con = null;
    try {/*  ww  w  .  j  a v  a 2 s. c o  m*/
        con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("GET");
        con.setConnectTimeout(10000);
        con.setReadTimeout(1000 * 60 * 30);
        con.setDoOutput(true);
        con.setDoInput(true);
        con.setUseCaches(false);

        for (String string : agrs) {
            con.setRequestProperty("Content-type", "application/json");
            con.setRequestMethod("POST");
            OutputStream out = con.getOutputStream();
            out.write(string.getBytes("UTF-8"));
        }

        if (con.getResponseCode() != 200)
            throw new ConnectException(con.getResponseMessage());

        InputStream is = con.getInputStream();

        return readResponse(is);

    } catch (IOException e) {
        throw e;
    } finally {
        if (con != null) {
            con.disconnect();
        }
    }
}

From source file:org.accelio.jxio.jxioConnection.impl.SimpleConnection.java

public SimpleConnection(URI uri, int msgIn, int msgOut, int msgCount) throws ConnectException {
    eqh = JxioResourceManager.getEqh();/* w ww .jav a 2s. c om*/
    msgPool = JxioResourceManager.getMsgPool(msgCount, msgIn, msgOut);
    long startTime = System.nanoTime();
    cs = new ClientSession(eqh, uri, new ClientCallbacks());
    eqh.runEventLoop(1, EventQueueHandler.INFINITE_DURATION); // session established event
    if (!established) {
        throw new ConnectException(this.toString() + " could not connect to " + uri.getHost() + " on port "
                + uri.getPort() + ", got " + connectErrorType);
    }
    long endTime = System.nanoTime();

    LOG.info(cs.toString() + " session established with host " + uri.getHost() + ", time taken to open: "
            + (endTime - startTime));
}

From source file:br.com.bea.androidtools.api.proxy.AppProxy.java

@Override
public List<JSONArray> request(final byte[] data) throws ConnectException {
    if (null == connection)
        throw new ConnectException("Conexo no realizada!");
    try {/*from   www  . j  a  v  a2 s.c o m*/
        if (null != data) {
            connection.setDoOutput(true);
            connection.setFixedLengthStreamingMode(data.length);
            output = connection.getOutputStream();
            output.write(data);
            output.flush();
        }
        input = connection.getInputStream();
        final StringBuilder sb = new StringBuilder();
        if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
            final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8"), 8);
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        }
        return Arrays.asList(new JSONArray(sb.toString()));
    } catch (final Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.accelio.jxio.jxioConnection.JxioConnection.java

private URI appendStreamType(String type) throws ConnectException {
    String uriStr = uri.toString();
    if (uri.getQuery() == null) {
        uriStr += "?stream=" + type;
    } else {/*from ww w . jav a  2s  .  c om*/
        uriStr += "&stream=" + type;
    }
    try {
        uri = new URI(uriStr);
    } catch (URISyntaxException e) {
        throw new ConnectException("could not append the stream type");
    }
    return uri;
}

From source file:com.microsoft.azuretools.utils.WebAppUtils.java

public static FTPClient getFtpConnection(PublishingProfile pp) throws IOException {

    FTPClient ftp = new FTPClient();

    System.out.println("\t\t" + pp.ftpUrl());
    System.out.println("\t\t" + pp.ftpUsername());
    System.out.println("\t\t" + pp.ftpPassword());

    URI uri = URI.create("ftp://" + pp.ftpUrl());
    ftp.connect(uri.getHost(), 21);/*from  w  ww .j a  va 2  s.  com*/
    final int replyCode = ftp.getReplyCode();
    if (!FTPReply.isPositiveCompletion(replyCode)) {
        ftp.disconnect();
        throw new ConnectException("Unable to connect to FTP server");
    }

    if (!ftp.login(pp.ftpUsername(), pp.ftpPassword())) {
        throw new ConnectException("Unable to login to FTP server");
    }

    ftp.setControlKeepAliveTimeout(Constants.connection_read_timeout_ms);
    ftp.setFileType(FTP.BINARY_FILE_TYPE);
    ftp.enterLocalPassiveMode();//Switch to passive mode

    return ftp;
}

From source file:camelinaction.RiderAutoPartsPartnerTest.java

@Test
public void testNoConnectionToDatabase() throws Exception {
    RouteBuilder rb = new RouteBuilder() {
        @Override/*  w w w .j ava 2 s.  c om*/
        public void configure() throws Exception {
            interceptSendToEndpoint("jdbc:*").skipSendToOriginalEndpoint()
                    .throwException(new ConnectException("Cannot connect to the database"));
        }
    };

    // adviseWith enhances our route by adding the interceptor from the route builder
    // this allows us here directly in the unit test to add interceptors so we can simulate the connection failure
    context.getRouteDefinition("partnerToDB").adviceWith(context, rb);

    // there should be 0 row in the database when we start
    assertEquals(0, jdbc.queryForInt("select count(*) from partner_metric"));

    String xml = "<?xml version=\"1.0\"?><partner id=\"123\"><date>200911150815</date><code>200</code><time>4387</time></partner>";
    template.sendBody("activemq:queue:partners", xml);

    // wait for the route to complete (note we can use use mock to be notified when the route is complete)
    Thread.sleep(5000);

    // data not inserted so there should be 0 rows
    assertEquals(0, jdbc.queryForInt("select count(*) from partner_metric"));
}

From source file:br.ufc.mdcc.mpos.net.endpoint.service.DiscoveryService.java

@Override
public void run() {
    boolean foundService = false;
    String requestMessage = "mpos_serv_req_droid:" + appName + ":" + appVersion;

    while (!stopTask && !foundService) {
        Log.i(clsName, "# Started Discovery Service for endpoint: " + server.getType() + " and app: " + appName
                + "/" + appVersion);
        foundService = true;//from  w  ww  .ja  v a 2  s  .  c o m

        ClientTcp client = (ClientTcp) FactoryClient.getInstance(Protocol.TCP_STREAM);
        try {
            if (server.getType() == EndpointType.SECONDARY_SERVER
                    && !MposFramework.getInstance().getDeviceController().isOnline()) {
                throw new ConnectException("The mobile is completly offline!");
            }

            client.connect(server.getIp(), servicePort);

            send(client.getOutputStream(), requestMessage);
            receive(client.getInputStream());

        } catch (IOException e) {
            Log.w(clsName, "Any problem with I/O in Discovery System: " + server.getType(), e);
            foundService = false;
        } catch (MissedEventException e) {
            Log.e(clsName, "Didn't TCP Manual?", e);
            foundService = false;
        } catch (JSONException e) {
            Log.e(clsName, "Any problem with json processing!", e);
            foundService = false;
        } finally {
            if (!stopTask && !foundService) {
                Log.i(clsName, ">> Retry Discovery Service for endpoint: " + server.getType() + ", in "
                        + EndpointController.REPEAT_DISCOVERY_TASK + " ms");
                try {
                    Thread.sleep(EndpointController.REPEAT_DISCOVERY_TASK);
                } catch (InterruptedException e) {
                    // sent canceled timer because app and mpos api finished!
                }
            } else {
                Log.i(clsName, ">> Finished Discovery Service for endpoint: " + server.getType() + " on "
                        + server.getIp());
                MposFramework.getInstance().getEndpointController().startDecisionMaker(server);
            }
            close(client);
        }
    }
}