Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

In this page you can find the example usage for java.io IOException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.apporiented.hermesftp.server.impl.ServerRFC959Test.java

/**
 * Test case: Statistics./*from   ww w  .  j  a va2s.  com*/
 */
@Test
public void testStats() {
    String str;
    try {
        getClient().storeText(testFile, testText);
        getClient().retrieveText(testFile);
        str = getClient().sendAndReceive("STAT " + testFile);
        assertTrue(str.indexOf(testFile) > 0);
        str = getClient().sendAndReceive("STAT");
        assertTrue(str.indexOf("Bytes uploaded: ") > 0);
        assertTrue(str.indexOf("Bytes downloaded: ") > 0);
        assertTrue(str.indexOf("Files uploaded: ") > 0);
        assertTrue(str.indexOf("Files downloaded: ") > 0);
        getClient().sendAndReceive("DELE " + testFile);
    } catch (IOException e) {
        log.error(e);
        fail(e.toString());
    }
}

From source file:com.iiordanov.tigervnc.rfb.CSecurityTLS.java

private void initGlobal() {
    try {//from  w ww  .  j  av a  2s .  c o  m
        SSLSocketFactory sslfactory;
        SSLContext ctx = SSLContext.getInstance("TLS");

        if (anon) {
            ctx.init(null, null, null);
        } else {
            TrustManager[] myTM = new TrustManager[] { new MyX509TrustManager() };
            ctx.init(null, myTM, null);
        }

        sslfactory = ctx.getSocketFactory();
        try {
            ssl = (SSLSocket) sslfactory.createSocket(CConnection.sock,
                    CConnection.sock.getInetAddress().getHostName(), CConnection.sock.getPort(), true);
            ssl.setTcpNoDelay(true);
        } catch (java.io.IOException e) {
            throw new Exception(e.toString());
        }

        if (anon) {
            String[] supported;
            ArrayList<String> enabled = new ArrayList<String>();

            supported = ssl.getSupportedCipherSuites();

            for (int i = 0; i < supported.length; i++) {
                //Log.e("SUPPORTED CIPHERS", supported[i]);
                if (supported[i].matches("TLS_DH_anon.*"))
                    enabled.add(supported[i]);
            }

            if (enabled.size() == 0)
                throw new Exception("Your device lacks support for ciphers necessary for this encryption mode "
                        + "(Anonymous Diffie-Hellman ciphers). "
                        + "This is a known issue with devices running Android 2.2.x and older. You can "
                        + "work around this by using VeNCrypt with x509 certificates instead.");

            ssl.setEnabledCipherSuites(enabled.toArray(new String[0]));
        } else {
            ssl.setEnabledCipherSuites(ssl.getSupportedCipherSuites());
        }

        ssl.setEnabledProtocols(ssl.getSupportedProtocols());
        ssl.addHandshakeCompletedListener(new MyHandshakeListener());
    } catch (java.security.GeneralSecurityException e) {
        vlog.error("TLS handshake failed " + e.toString());
        return;
    }
}

From source file:com.streamsets.datacollector.execution.store.FilePipelineStateStore.java

private PipelineState loadState(String nameAndRev) throws PipelineStoreException {
    PipelineState pipelineState = null;//from w w w.  j a  va 2  s.c  om
    String[] nameAndRevArray = nameAndRev.split("::");
    String name = nameAndRevArray[0];
    String rev = nameAndRevArray[1];
    LOG.debug("Loading state from file for pipeline: '{}'::'{}'", name, rev);
    try {
        // SDC-2930: We don't check for the existence of the actual state file itself, since the DataStore will take care of
        // picking up the correct files (the new/tmp files etc).
        DataStore ds = new DataStore(getPipelineStateFile(name, rev));
        if (ds.exists()) {
            try (InputStream is = ds.getInputStream()) {
                PipelineStateJson pipelineStatusJsonBean = ObjectMapperFactory.get().readValue(is,
                        PipelineStateJson.class);
                pipelineState = pipelineStatusJsonBean.getPipelineState();
            }
        } else {
            throw new PipelineStoreException(ContainerError.CONTAINER_0209, getPipelineStateFile(name, rev));
        }
    } catch (IOException e) {
        throw new PipelineStoreException(ContainerError.CONTAINER_0101, e.toString(), e);
    }
    return pipelineState;
}

From source file:com.board.games.handler.smf.SMFPokerLoginServiceImpl.java

@Override
public LoginResponseAction handle(LoginRequestAction req) {
    // At this point, we should get the user name and password
    // from the request and verify them, but for this example
    // we'll just assign a dynamic player ID and grant the login
    try {//from   w w  w. ja  v a  2s . com
        Ini ini = new Ini(new File("JDBCConfig.ini"));
        String jdbcDriver = ini.get("JDBCConfig", "jdbcDriver");
        String connectionUrl = ini.get("JDBCConfig", "connectionUrl");
        String database = ini.get("JDBCConfig", "database");
        dbPrefix = ini.get("JDBCConfig", "dbPrefix");
        String user = ini.get("JDBCConfig", "user");
        String password = ini.get("JDBCConfig", "password");
        jdbcDriverClassName = ini.get("JDBCConfig", "driverClassName");
        connectionStr = "jdbc" + ":" + jdbcDriver + "://" + connectionUrl + "/" + database + "?user=" + user
                + "&password=" + password;
        log.debug("user " + user);
        log.debug("connectionStr " + connectionStr);
        String forceAgeAgreement = ini.get("JDBCConfig", "forceAgeAgreement");
        if (!forceAgeAgreement.equals("") && "Y".equals(forceAgeAgreement.toUpperCase())) {
            needAgeAgreement = true;
        }

    } catch (IOException ioe) {
        log.error("Exception in init " + ioe.toString());
    } catch (Exception e) {
        log.error("Exception in init " + e.toString());
    }

    LoginResponseAction response = null;
    try {
        log.debug("Performing authentication on " + req.getUser());
        String userIdStr = authenticate(req.getUser(), req.getPassword());
        if (!userIdStr.equals("")) {

            response = new LoginResponseAction(Integer.parseInt(userIdStr) > 0 ? true : false,
                    (req.getUser().toUpperCase().startsWith("GUESTXDEMO") ? req.getUser() + "_" + userIdStr
                            : req.getUser()),
                    Integer.parseInt(userIdStr)); // pid.incrementAndGet()
            log.debug(Integer.parseInt(userIdStr) > 0 ? "Authentication successful" : "Authentication failed");
            return response;
        }
    } catch (SQLException sqle) {
        log.error("Error authenticate", sqle);
        response = new LoginResponseAction(false, -1);
        response.setErrorMessage(getSystemErrorMessage(sqle));
        response.setErrorCode(getSystemErrorCode(sqle));
        log.error(sqle);
    } catch (Exception e) {
        log.error("Error system", e);
    }

    response = new LoginResponseAction(false, -1);
    response.setErrorMessage(getNotFoundErrorMessage());
    response.setErrorCode(getNotFoundErrorCode());
    return response;
}

From source file:com.apporiented.hermesftp.server.impl.ServerRFC959Test.java

/**
 * Test case: System commands./* w w w.jav  a2 s  .c  o m*/
 */
@Test
public void testSystem() {
    String str;
    try {
        str = getClient().sendAndReceive("SYST");
        assertTrue(str.indexOf("Hermes") > 0);
        str = getClient().sendAndReceive("TYPE A");
        assertTrue(str.indexOf("ASCII") > 0);
        str = getClient().sendAndReceive("TYPE E");
        assertTrue(str.indexOf("EBCDIC") > 0);
        str = getClient().sendAndReceive("TYPE I");
        assertTrue(str.indexOf("BINARY") > 0);
        str = getClient().sendAndReceive("HELP");
        assertTrue(str.startsWith("214"));
        str = getClient().sendAndReceive("ALLO 100");
        assertTrue(str.startsWith("200"));
        getClient().sendAndReceive("CLNT TestClient");
        assertTrue(str.startsWith("200"));
    } catch (IOException e) {
        log.error(e);
        fail(e.toString());
    }
}

From source file:ConnectionProtccol.HttpClient.java

/**
 *
 * @param urlParams/* w  w  w . j  a  va2s.c  o  m*/
 * @param postParams
 *
 */
public boolean httpPost(String url, MultipartEntityBuilder builder, UrlEncodedFormEntity formParams) {

    loggerObj.log(Level.INFO, "Inside httpsPost method");
    CloseableHttpClient httpclient = HttpClients.createDefault();

    try {
        //  HttpPost httppost = new HttpPost("https://reportsapi.zoho.com/api/harshavardhan.r@zohocorp.com/Test/Name_password?ZOHO_ACTION=IMPORT&ZOHO_OUTPUT_FORMAT=json&ZOHO_ERROR_FORMAT=json&authtoken=7ed717b94bc30455aad11ce5d31d34f9&ZOHO_API_VERSION=1.0");
        loggerObj.log(Level.INFO, "Going to post to the zoho reports api");

        HttpPost httppost = new HttpPost(url);

        //Need to understand the difference betwween multipartentitybuilder and urlencodedformentity//
        HttpEntity entity = null;
        if (builder != null) {
            entity = builder.build();
        }

        if (formParams != null) {
            entity = formParams;
        }

        httppost.setEntity(entity);
        loggerObj.log(Level.INFO, "executing request");
        System.out.println("executing request " + httppost.getRequestLine());
        CloseableHttpResponse response = null;
        try {
            response = httpclient.execute(httppost);
        } catch (IOException ex) {
            loggerObj.log(Level.INFO, "Cannot connect to reports.zoho.com" + ex.toString());
            return false;
        }
        try {
            loggerObj.log(Level.INFO, "----------------------------------------");
            loggerObj.log(Level.INFO, response.toString());
            response.getStatusLine();
            HttpEntity resEntity = response.getEntity();
            if (resEntity != null) {
                loggerObj.log(Level.INFO, "Response content length: " + resEntity.getContentLength());
                BufferedReader rd = null;
                try {
                    rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                } catch (IOException ex) {
                    loggerObj.log(Level.INFO,
                            "cannot read the response 1 from reports.zoho.com" + ex.toString());
                    return false;
                } catch (UnsupportedOperationException ex) {
                    loggerObj.log(Level.INFO, "cannot read the response 2" + ex.toString());
                    return false;
                }
                String line = "";
                try {
                    loggerObj.log(Level.INFO, "reading response line");
                    while ((line = rd.readLine()) != null) {
                        System.out.println(line);
                        loggerObj.log(Level.INFO, line);
                    }
                } catch (IOException ex) {
                    loggerObj.log(Level.INFO, "cannot read the response 3" + ex.toString());
                    return false;
                }
            }
            try {
                EntityUtils.consume(resEntity);
            } catch (IOException ex) {
                loggerObj.log(Level.INFO, "cannot read the response 4" + ex.toString());
                return false;
            }
        } finally {
            try {
                response.close();
            } catch (IOException ex) {
                loggerObj.log(Level.INFO, "cannot close the response" + ex.toString());
                return false;
            }
        }
    } finally {
        try {
            httpclient.close();
        } catch (IOException ex) {
            loggerObj.log(Level.INFO, "cannot read the https clinet" + ex.toString());
            return false;
        }
    }
    return true;
}

From source file:com.apporiented.hermesftp.server.impl.ServerRFC959Test.java

/**
 * Test case: Rename and size.//w  w w. j  av  a2s .  c o  m
 */
@Test
public void testRenameAndSize() {
    String str;
    try {
        getClient().sendAndReceive("DELE text.renamed");
        getClient().sendAndReceive("TYPE A");
        getClient().storeText(testFile, testText);
        str = getClient().sendAndReceive("RNFR " + testFile);
        assertTrue(str.startsWith("350"));
        str = getClient().sendAndReceive("RNTO text.renamed");
        assertTrue(str.startsWith("200"));
        str = getClient().sendAndReceive("SIZE text.renamed").trim();
        assertTrue(str.startsWith("213"));
        String[] parts = str.split(" ");
        Integer.parseInt(parts[1]);
        str = getClient().sendAndReceive("RNFR text.renamed");
        assertTrue(str.startsWith("350"));
        str = getClient().sendAndReceive("RNTO " + testFile);
        assertTrue(str.startsWith("200"));
        str = getClient().sendAndReceive("SIZE text.renamed");
        assertTrue(str.startsWith("550"));
        getClient().sendAndReceive("DELE " + testFile);
    } catch (IOException e) {
        log.error(e);
        fail(e.toString());
    }
}

From source file:com.apporiented.hermesftp.server.impl.ServerRFC959Test.java

/**
 * Test case: Folder creation, deletion and navigation.
 *//*ww w  . j a  va 2s .c  o m*/
@Test
public void testFolderHandling() {
    String str;
    try {

        getClient().sendAndReceive("RMD newtestfolder");
        str = getClient().sendAndReceive("MKD newtestfolder");
        assertTrue(str.startsWith("250"));
        getClient().list();
        str = getClient().getTextData();
        assertTrue(str.indexOf("newtestfolder") > 0);
        str = getClient().sendAndReceive("CWD newtestfolder");
        str = getClient().sendAndReceive("PWD");
        assertTrue(str.indexOf("newtestfolder") > 0);
        str = getClient().sendAndReceive("CDUP");
        str = getClient().sendAndReceive("PWD");
        assertFalse(str.indexOf("newtestfolder") > 0);
        str = getClient().sendAndReceive("RMD newtestfolder");
        assertTrue(str.startsWith("250"));
        getClient().list();
        str = getClient().getTextData();
        assertFalse(str.indexOf("newtestfolder") > 0);
    } catch (IOException e) {
        log.error(e);
        fail(e.toString());
    }
}

From source file:com.connection.factory.FtpConnectionApacheLib.java

@Override
public boolean getConnection() {
    boolean status;
    try {/*from   w  ww .  j  ava 2s  . c  o  m*/
        _ftpObj.connect(_ipAdress, _port);
        //  _ftpObj.setFileType(FTP.COMPRESSED_TRANSFER_MODE);
        _ftpObj.enterLocalPassiveMode();
        isConnected = true;
        status = true;
    } catch (IOException ex) {
        System.out.println(ex.toString());
        status = false;
    }
    if (status) {
        try {
            status = _ftpObj.login(_userName, _passWord);
            isLogin = true;
        } catch (IOException e) {
            System.out.println(e.toString());
            status = false;
        }
    }
    return status;
}