Example usage for java.net SocketTimeoutException printStackTrace

List of usage examples for java.net SocketTimeoutException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:it.cineca.iris.restclient.main.Command.java

public static void main(String[] argv) {
    Command command = new Command();
    try {// ww  w  . j  av  a2s .c  om
        command.createClient();

        //command.simpleTest();

        command.runReadTest();

        //command.runWriteTest();

    } catch (SocketTimeoutException e) {
        System.out.println("\n-----------------------------------------------------------");
        System.out.print("Time out!!!");
        System.out.println("\n-----------------------------------------------------------");
    } catch (Exception e) {
        System.out.println("\n-----------------------------------------------------------");
        System.out.println(e.getMessage());
        System.out.println("\n-----------------------------------------------------------");
        e.printStackTrace();
        System.out.println("\n-----------------------------------------------------------");
    } finally {
        if (command != null) {
            command.shutdownClient();
        }
    }
}

From source file:com.tc.simple.apn.quicktests.Test2.java

public static void send(byte[] p12, String token, int id, String json) {
    IAPNSocketPool factory = new APNSocketPool();
    SocketWrapper socket = null;//from www. ja va 2 s .c om
    try {

        socket = factory.checkOut(p12, "xxxxxxxxx", false);
        Payload payload = new Payload();
        payload.setJson(json);
        payload.setToken(token);

        byte[] message = new PushByteFactory().buildPushBytes(id, payload);
        socket.write(message);

        InputStream response = socket.getSocket().getInputStream();
        int errorCode = response.read();

        if (errorCode > 0) {
            new APNSocketPool().killSocket(socket);
        } else {

        }

    } catch (java.net.SocketTimeoutException n) {

    } catch (Exception n) {
        n.printStackTrace();
    } finally {
        factory.checkIn(socket);
    }
}

From source file:at.alladin.rmbt.client.v2.task.DnsTask.java

/**
 * /*from  www  .  ja v a 2  s .c  om*/
 * @param domainName
 * @param record
 * @param resolver
 * @return
 */
public static List<JSONObject> lookupDns(String domainName, String record, String resolver, int timeout,
        QoSTestResult testResult) {
    //List<String> result = new ArrayList<String>();
    List<JSONObject> result = new ArrayList<JSONObject>();

    //Lookup dnsLookup = null;
    try {
        System.out.println(
                "dns lookup: record = " + record + " for host: " + domainName + ", using resolver:" + resolver);

        ResolverConfig.refresh(); // refresh dns server

        DnsRequest req = Dig.doRequest(domainName, record, resolver, timeout);

        testResult.getResultMap().put(RESULT_QUERY, "OK");
        //dnsLookup = new Lookup(domainName, Type.value(record.toUpperCase()));
        //dnsLookup.setResolver(new SimpleResolver(resolver));         
        //Record[] records = dnsLookup.run();
        testResult.getResultMap().put(RESULT_STATUS, Rcode.string(req.getResponse().getRcode()));
        if (req.getRequest().getRcode() == Rcode.NOERROR) {
            Record[] records = req.getResponse().getSectionArray(Section.ANSWER);

            if (records != null && records.length > 0) {
                for (int i = 0; i < records.length; i++) {
                    JSONObject dnsEntry = new JSONObject();
                    if (records[i] instanceof MXRecord) {
                        dnsEntry.put(RESULT_PRIORITY, String.valueOf(((MXRecord) records[i]).getPriority()));
                        dnsEntry.put(RESULT_ADDRESS, ((MXRecord) records[i]).getTarget().toString());
                    } else if (records[i] instanceof CNAMERecord) {
                        dnsEntry.put(RESULT_ADDRESS, ((CNAMERecord) records[i]).getAlias());
                    } else if (records[i] instanceof ARecord) {
                        dnsEntry.put(RESULT_ADDRESS, ((ARecord) records[i]).getAddress().getHostAddress());
                    } else if (records[i] instanceof AAAARecord) {
                        dnsEntry.put(RESULT_ADDRESS, ((AAAARecord) records[i]).getAddress().getHostAddress());
                    } else if (records[i] instanceof A6Record) {
                        dnsEntry.put(RESULT_ADDRESS, ((A6Record) records[i]).getSuffix().toString());
                    } else {
                        dnsEntry.put(RESULT_ADDRESS, records[i].getName());
                    }

                    dnsEntry.put(RESULT_TTL, String.valueOf(records[i].getTTL()));

                    //result.add(records[i].toString());
                    result.add(dnsEntry);
                    System.out.println("record " + i + " toString: " + records[i].toString());
                }
            } else {
                return null;
            }
        } else {
            return null;
        }
    } catch (SocketTimeoutException e) {
        testResult.getResultMap().put(RESULT_QUERY, "TIMEOUT");
        e.printStackTrace();
        return null;
    } catch (Exception e) {
        testResult.getResultMap().put(RESULT_QUERY, "ERROR");
        e.printStackTrace();
        return null;
    }

    return result;
}

From source file:uk.sipperfly.utils.FTPUtil.java

/**
 * Upload a single file to the FTP server.
 *
 * @param ftpClient      an instance of org.apache.commons.net.ftp.FTPClient class.
 * @param localFilePath  Path of the file on local computer
 * @param remoteFilePath Path of the file on remote the server
 * @return true if the file was uploaded successfully, false otherwise
 * @throws IOException if any network or IO error occurred.
 *///from w  w  w. j  av  a 2s.c o m
public static boolean uploadSingleFile(FTPClient ftpClient, String localFilePath, String remoteFilePath)
        throws FileNotFoundException, IOException {
    File localFile = new File(localFilePath);
    try (InputStream inputStream = new FileInputStream(localFile)) {
        try {
            return ftpClient.storeFile(remoteFilePath, inputStream);
        } catch (SocketTimeoutException e) {
            Logger.getLogger(GACOM).log(Level.SEVERE, "upload Single File: ", e.getCause());
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getCause() != null) {
                e.getCause().printStackTrace();
                Logger.getLogger(GACOM).log(Level.SEVERE, "upload Single File: ", e.getCause());
            }
            return false;
        }
    }
}

From source file:zz.pseas.ghost.utils.HttpClinetUtil.java

/**
 * @author GS//from w ww  .ja va  2  s  .co m
 * @param url
 * @return
 * @throws IOException
 */
public static String get(String url) throws IOException {
    String responseBody = null;
    GetMethod getMethod = new GetMethod(url);
    getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ????
    try {
        int statusCode = hc.executeMethod(getMethod);
        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + getMethod.getStatusLine());
        }
        responseBody = getMethod.getResponseBodyAsString();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (UnknownHostException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (HttpException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } catch (IOException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } finally {
        getMethod.releaseConnection(); // 
    }
    return responseBody;
}

From source file:zz.pseas.ghost.utils.HttpClinetUtil.java

/**
 * HTTP??//from   ww w. j  ava2s . com
 * 
 * @author GS
 * @param url
 * @param para
 * @param cookie
 * @return
 * @throws IOException
 */
public static int getStatusCode(String url, String cookie) throws IOException {
    GetMethod getMethod = new GetMethod(url);
    getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ????
    if (!cookie.equals("")) {
        getMethod.setRequestHeader("cookie", cookie);
    }
    int statusCode = 0;
    try {
        statusCode = hc.executeMethod(getMethod);
        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + getMethod.getStatusLine());
        }
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (UnknownHostException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (HttpException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } catch (IOException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } finally {
        getMethod.releaseConnection(); // 
    }
    return statusCode;
}

From source file:zz.pseas.ghost.utils.HttpClinetUtil.java

/**
 * @author GS/* ww w .  jav  a  2 s . c o m*/
 * @param url
 * @param headers
 * @return
 * @throws IOException
 */
public static String get(String url, Header[] headers) throws IOException {
    String responseBody = null;
    GetMethod getMethod = new GetMethod(url);
    getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ????
    for (Header h : headers) {
        getMethod.addRequestHeader(h);
    }
    try {
        int statusCode = hc.executeMethod(getMethod);
        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + getMethod.getStatusLine());
        }
        responseBody = getMethod.getResponseBodyAsString();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (UnknownHostException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (HttpException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } catch (IOException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } finally {
        getMethod.releaseConnection(); // 
    }
    return responseBody;
}

From source file:zz.pseas.ghost.utils.HttpClinetUtil.java

/**
 * @author GS//from w  w w.  j a  v a2 s  .  c  om
 * @param url
 * @param para
 *            get??
 * @return
 * @throws IOException
 */
public static String get(String url, Map<String, String> para) throws IOException {
    String responseBody = null;
    GetMethod getMethod = new GetMethod(url);
    getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler()); // ????
    NameValuePair[] data = new NameValuePair[para.size()];
    int index = 0;
    for (String s : para.keySet()) {
        data[index++] = new NameValuePair(s, para.get(s)); // ??
    }
    getMethod.setQueryString(data); // ?
    try {
        int statusCode = hc.executeMethod(getMethod);
        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + getMethod.getStatusLine());
        }
        responseBody = getMethod.getResponseBodyAsString();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (UnknownHostException e) {
        e.printStackTrace();
        LOG.error("?,UnknownHostException,?" + e.getMessage());
    } catch (HttpException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } catch (IOException e) { // ?
        e.printStackTrace();
        LOG.error("?" + e.getMessage());
    } finally {
        getMethod.releaseConnection(); // 
    }
    return responseBody;
}

From source file:zz.pseas.ghost.utils.HttpClinetUtil.java

/**
 * @author GS// w w w .j  a  v  a  2s  .  c  o  m
 * @param url
 * @param para
 * @param cookie
 * @return
 * @throws IOException
 */
public static String post(String url, Map<String, String> para, String cookie) throws IOException {
    String responseBody = null;
    PostMethod postMethod = new PostMethod(url);
    NameValuePair[] data = new NameValuePair[para.size()];
    int index = 0;
    for (String s : para.keySet()) {
        data[index++] = new NameValuePair(s, para.get(s));
    }
    postMethod.setRequestBody(data); // ?
    if (!cookie.equals("")) {
        postMethod.setRequestHeader("cookie", cookie);
    }
    try {
        int statusCode = hc.executeMethod(postMethod);
        if (statusCode != HttpStatus.SC_OK) {
            LOG.error("Method failed: " + postMethod.getStatusLine());
        }
        responseBody = postMethod.getResponseBodyAsString();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (UnknownHostException e) {
        e.printStackTrace();
        LOG.error("??" + e.getMessage());
    } catch (HttpException e) {
        e.printStackTrace();
        LOG.error(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        LOG.error(e.getMessage());
    } finally {
        postMethod.releaseConnection(); // 
    }
    return responseBody;
}

From source file:com.concentricsky.android.khanacademy.util.ThumbnailManager.java

/**
 * Attempt to download a bitmap from the given url.
 * //from   ww w  .  j a v  a2 s .c  om
 * @param url The url of the thumbnail to download.
 * @return A {@link Bitmap} of the thumbnail, or {@code null} if it cannot be downloaded and is not cached locally.
 * @throws java.net.MalformedURLException if the url is malformed!
 * @throws java.io.IOException if a connection cannot be opened to the given url, or if an IOException is thrown by {@link ResponseCache} or by {@link CacheResponse}.
 */
public static Bitmap bitmap_from_url(String url) throws java.net.MalformedURLException, IOException {
    HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    connection.setConnectTimeout(CONNECT_TIMEOUT);
    connection.setUseCaches(true);

    InputStream input = null;
    try {
        connection.connect();
        input = connection.getInputStream();
        return BitmapFactory.decodeStream(input);
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        return null;
    } finally {
        if (input != null)
            input.close();
    }
}