Example usage for java.net SocketException getMessage

List of usage examples for java.net SocketException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:person.daizhongde.virtue.util.test.TFTPExample.java

private static void open(TFTPClient tftp) {
    try {//from w  w  w .  j a va2 s  .  c  o m
        tftp.open();
    } catch (SocketException e) {
        System.err.println("Error: could not open local UDP socket.");
        System.err.println(e.getMessage());
        System.exit(1);
    }
}

From source file:org.apache.stratos.cli.utils.CliUtils.java

/**
 * Extract HTTP response body as a string
 *
 * @param response/*from w  w  w  .  j a  v  a  2  s.c om*/
 * @return
 */
public static String getHttpResponseString(HttpResponse response) {
    try {
        String output;
        String result = "";

        if ((response != null) && (response.getEntity() != null)
                && (response.getEntity().getContent() != null)) {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader((response.getEntity().getContent())));
            while ((output = reader.readLine()) != null) {
                result += output;
            }
        }
        return result;
    } catch (SocketException e) {
        String message = "A connection error occurred while reading response message: " + e.getMessage();
        System.out.println(message);
        log.error(message, e);
        return null;
    } catch (IOException e) {
        String message = "An IO error occurred while reading response message: " + e.getMessage();
        System.out.println(message);
        log.error(message, e);
        return null;
    } catch (Exception e) {
        String message = "An unknown error occurred while reading response message: " + e.getMessage();
        System.out.println(message);
        log.error(message, e);
        return null;
    }
}

From source file:jp.terasoluna.fw.web.struts.actions.FileDownloadUtil.java

/**
 * uEU_E??[h?B/*  ww w.  jav  a2 s.  c om*/
 *
 * @param result _E??[hf?[^?CX^X?B
 * @param request NGXg?B
 * @param response X|X?B
 */
@SuppressWarnings("unchecked")
public static void download(Object result, HttpServletRequest request, HttpServletResponse response) {
    List<AbstractDownloadObject> downloadList = new ArrayList<AbstractDownloadObject>();

    if (result instanceof AbstractDownloadObject) {
        downloadList.add((AbstractDownloadObject) result);
    } else {
        BeanWrapper wrapper = new BeanWrapperImpl(result);
        PropertyDescriptor[] propertyDescriptors = wrapper.getPropertyDescriptors();
        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
            Method readMethod = propertyDescriptor.getReadMethod();
            if (readMethod == null) {
                continue;
            }
            Class type = readMethod.getReturnType();
            if (AbstractDownloadObject.class.isAssignableFrom(type)) {
                downloadList
                        .add((AbstractDownloadObject) wrapper.getPropertyValue(propertyDescriptor.getName()));
            }
        }
    }

    if (downloadList.isEmpty()) {
        return;
    }
    // _E??[hIuWFNg???O
    if (downloadList.size() != 1) {
        throw new SystemException(new IllegalStateException("Too many AbstractDownloadObject properties."),
                TOO_MANY_DOWNLOAD_ERROR);
    }

    try {
        download(downloadList.get(0), request, response, true);
    } catch (SocketException e) {
        if (log.isDebugEnabled()) {
            log.debug(e.getMessage(), e);
        }
    } catch (IOException e) {
        if (log.isErrorEnabled()) {
            log.error("IOException has occurred while downloading", e);
        }
    }
}

From source file:com.buaa.cfs.net.DNS.java

/**
 * Returns all the IPs associated with the provided interface, if any, in textual form.
 *
 * @param strInterface        The name of the network interface or sub-interface to query (eg eth0 or eth0:0) or the
 *                            string "default"
 * @param returnSubinterfaces Whether to return IPs associated with subinterfaces of the given interface
 *
 * @return A string vector of all the IPs associated with the provided interface. The local host IP is returned if
 * the interface name "default" is specified or there is an I/O error looking for the given interface.
 *
 * @throws UnknownHostException If the given interface is invalid
 *//*from   ww w. ja  va2  s  .c om*/
public static String[] getIPs(String strInterface, boolean returnSubinterfaces) throws UnknownHostException {
    if ("default".equals(strInterface)) {
        return new String[] { cachedHostAddress };
    }
    NetworkInterface netIf;
    try {
        netIf = NetworkInterface.getByName(strInterface);
        if (netIf == null) {
            netIf = getSubinterface(strInterface);
        }
    } catch (SocketException e) {
        LOG.warn("I/O error finding interface " + strInterface + ": " + e.getMessage());
        return new String[] { cachedHostAddress };
    }
    if (netIf == null) {
        throw new UnknownHostException("No such interface " + strInterface);
    }

    // NB: Using a LinkedHashSet to preserve the order for callers
    // that depend on a particular element being 1st in the array.
    // For example, getDefaultIP always returns the first element.
    LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>();
    allAddrs.addAll(Collections.list(netIf.getInetAddresses()));
    if (!returnSubinterfaces) {
        allAddrs.removeAll(getSubinterfaceInetAddrs(netIf));
    }

    String ips[] = new String[allAddrs.size()];
    int i = 0;
    for (InetAddress addr : allAddrs) {
        ips[i++] = addr.getHostAddress();
    }
    return ips;
}

From source file:org.ossmeter.platform.communicationchannel.nntp.local.NntpUtil.java

public static NNTPClient connectToNntpServer(NntpNewsGroup newsgroup) {

    NNTPClient client = new NNTPClient();
    client.setDefaultPort(newsgroup.getPort());
    String serverUrl = newsgroup.getUrl().substring(0, newsgroup.getUrl().lastIndexOf("/"));
    try {/*  w ww.jav  a 2  s  . c  o  m*/
        client.connect(serverUrl);
        if (newsgroup.getAuthenticationRequired()) {
            client.authenticate(newsgroup.getUsername(), newsgroup.getPassword());
        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        System.err.println("SocketException while connecting to NNTP server: '" + newsgroup.getUrl() + "': "
                + e.getMessage());
        //           System.exit(1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.err.println(
                "IOException while connecting to NNTP server: '" + newsgroup.getUrl() + "': " + e.getMessage());
        //           System.exit(1);
    }
    return client;
}

From source file:org.ossmeter.platform.communicationchannel.nntp.NntpUtil.java

public static NNTPClient connectToNntpServer(NntpNewsGroup newsgroup) {

    NNTPClient client = new NNTPClient();
    client.setDefaultPort(newsgroup.getPort());
    String serverUrl = newsgroup.getUrl();

    if (serverUrl.endsWith("/")) {
        serverUrl = newsgroup.getUrl().substring(0, newsgroup.getUrl().lastIndexOf("/"));
    }/*from w  w w.j a  v a2  s  . c  o  m*/

    try {
        client.connect(serverUrl);
        if (newsgroup.getAuthenticationRequired()) {
            client.authenticate(newsgroup.getUsername(), newsgroup.getPassword());
        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        System.err.println("SocketException while connecting to NNTP server: '" + newsgroup.getUrl() + "': "
                + e.getMessage());
        e.printStackTrace();
        //           System.exit(1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.err.println(
                "IOException while connecting to NNTP server: '" + newsgroup.getUrl() + "': " + e.getMessage());
        e.printStackTrace();
        //           System.exit(1);
    }
    return client;
}

From source file:org.spoutcraft.launcher.util.Utils.java

public static String executePost(String targetURL, String urlParameters, JProgressBar progress)
        throws PermissionDeniedException {
    URLConnection connection = null;
    try {/* w ww  . j a v  a2s.com*/
        URL url = new URL(targetURL);
        connection = url.openConnection();
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        connection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length));
        connection.setRequestProperty("Content-Language", "en-US");

        connection.setUseCaches(false);
        connection.setDoInput(true);
        connection.setDoOutput(true);

        connection.setConnectTimeout(10000);

        connection.connect();

        DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(urlParameters);
        wr.flush();
        wr.close();

        InputStream is = connection.getInputStream();
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));

        StringBuilder response = new StringBuilder();
        String line;
        while ((line = rd.readLine()) != null) {
            response.append(line);
            response.append('\r');
        }
        rd.close();

        return response.toString();
    } catch (SocketException e) {
        if (e.getMessage().equalsIgnoreCase("Permission denied: connect")) {
            throw new PermissionDeniedException("Permission to login was denied");
        }
    } catch (Exception e) {
        String message = "Login failed...";
        progress.setString(message);
    }
    return null;
}

From source file:davmail.exchange.ExchangeSessionFactory.java

/**
 * Check if at least one network interface is up and active (i.e. has an address)
 *
 * @return true if network available/* w  ww. ja  v a  2 s .c  om*/
 */
static boolean checkNetwork() {
    boolean up = false;
    Enumeration<NetworkInterface> enumeration;
    try {
        enumeration = NetworkInterface.getNetworkInterfaces();
        while (!up && enumeration.hasMoreElements()) {
            NetworkInterface networkInterface = enumeration.nextElement();
            up = networkInterface.isUp() && !networkInterface.isLoopback()
                    && networkInterface.getInetAddresses().hasMoreElements();
        }
    } catch (NoSuchMethodError error) {
        ExchangeSession.LOGGER.debug("Unable to test network interfaces (not available under Java 1.5)");
        up = true;
    } catch (SocketException exc) {
        ExchangeSession.LOGGER.error(
                "DavMail configuration exception: \n Error listing network interfaces " + exc.getMessage(),
                exc);
    }
    return up;
}

From source file:org.apache.hadoop.net.DNS.java

/**
 * Returns all the IPs associated with the provided interface, if any, as
 * a list of InetAddress objects.//from   w  w  w .  ja  v a 2s  . com
 *
 * @param strInterface
 *            The name of the network interface or sub-interface to query
 *            (eg eth0 or eth0:0) or the string "default"
 * @param returnSubinterfaces
 *            Whether to return IPs associated with subinterfaces of
 *            the given interface
 * @return A list of all the IPs associated with the provided
 *         interface. The local host IP is returned if the interface
 *         name "default" is specified or there is an I/O error looking
 *         for the given interface.
 * @throws UnknownHostException
 *             If the given interface is invalid
 *
 */
public static List<InetAddress> getIPsAsInetAddressList(String strInterface, boolean returnSubinterfaces)
        throws UnknownHostException {
    if ("default".equals(strInterface)) {
        return Arrays.asList(InetAddress.getByName(cachedHostAddress));
    }
    NetworkInterface netIf;
    try {
        netIf = NetworkInterface.getByName(strInterface);
        if (netIf == null) {
            netIf = getSubinterface(strInterface);
        }
    } catch (SocketException e) {
        LOG.warn("I/O error finding interface " + strInterface + ": " + e.getMessage());
        return Arrays.asList(InetAddress.getByName(cachedHostAddress));
    }
    if (netIf == null) {
        throw new UnknownHostException("No such interface " + strInterface);
    }

    // NB: Using a LinkedHashSet to preserve the order for callers
    // that depend on a particular element being 1st in the array.
    // For example, getDefaultIP always returns the first element.
    LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>();
    allAddrs.addAll(Collections.list(netIf.getInetAddresses()));
    if (!returnSubinterfaces) {
        allAddrs.removeAll(getSubinterfaceInetAddrs(netIf));
    }
    return new Vector<InetAddress>(allAddrs);
}

From source file:com.hoccer.tools.HttpHelper.java

private static HttpResponse executeHTTPMethod(HttpRequestBase pMethod, int pConnectionTimeout,
        Boolean pRedirect) throws IOException, HttpClientException, HttpServerException {

    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams, pConnectionTimeout);
    HttpConnectionParams.setSoTimeout(httpParams, pConnectionTimeout);
    if (!pRedirect) {
        HttpClientParams.setRedirecting(httpParams, false);
    }/*from   w w  w  .  j  a v a  2  s . co  m*/
    DefaultHttpClient httpclient = new HttpClientWithKeystore(httpParams);

    // Log redirects
    httpclient.setRedirectHandler(new DefaultRedirectHandler() {
        @Override
        public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException {
            URI uri = super.getLocationURI(response, context);
            return uri;
        }
    });

    HttpResponse response;
    try {
        response = httpclient.execute(pMethod);
    } catch (SocketException e) {
        e = new SocketException(e.getMessage() + ": " + pMethod.getURI());
        e.fillInStackTrace();
        throw e;
    }
    HttpException.throwIfError(pMethod.getURI().toString(), response);
    return response;
}