Example usage for java.net UnknownHostException printStackTrace

List of usage examples for java.net UnknownHostException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:com.teleca.jamendo.api.util.Caller.java

/**
 * Performs HTTP GET using Apache HTTP Client v 4
 * //from  w w  w. j  a v a 2 s .c  o m
 * @param url
 * @return
 * @throws WSError 
 */
public static String doGet(String url) throws WSError {

    String data = null;
    if (requestCache != null) {
        data = requestCache.get(url);
        if (data != null) {
            Log.d(JamendoApplication.TAG, "Caller.doGet [cached] " + url);
            return data;
        }
    }

    URI encodedUri = null;
    HttpGet httpGet = null;

    try {
        encodedUri = new URI(url);
        httpGet = new HttpGet(encodedUri);
    } catch (URISyntaxException e1) {
        // at least try to remove spaces
        String encodedUrl = url.replace(' ', '+');
        httpGet = new HttpGet(encodedUrl);
        e1.printStackTrace();
    }

    // initialize HTTP GET request objects
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse httpResponse;

    try {
        // execute request
        try {
            httpResponse = httpClient.execute(httpGet);
        } catch (UnknownHostException e) {
            throw new WSError("Unable to access " + e.getLocalizedMessage());
        } catch (SocketException e) {
            throw new WSError(e.getLocalizedMessage());
        }

        // request data
        HttpEntity httpEntity = httpResponse.getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            data = convertStreamToString(inputStream);
            // cache the result
            if (requestCache != null) {
                requestCache.put(url, data);
            }
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(JamendoApplication.TAG, "Caller.doGet " + url);
    return data;
}

From source file:net.dian1.player.api.util.Caller.java

/**
 * Performs HTTP GET using Apache HTTP Client v 4
 * //  w  ww .  ja  v a2s .c o  m
 * @param url
 * @return
 * @throws WSError 
 */
public static String doGet(String url) throws WSError {

    String data = null;
    if (requestCache != null) {
        data = requestCache.get(url);
        if (data != null) {
            Log.d(Dian1Application.TAG, "Caller.doGet [cached] " + url);
            return data;
        }
    }

    URI encodedUri = null;
    HttpGet httpGet = null;

    try {
        encodedUri = new URI(url);
        httpGet = new HttpGet(encodedUri);
    } catch (URISyntaxException e1) {
        // at least try to remove spaces
        String encodedUrl = url.replace(' ', '+');
        httpGet = new HttpGet(encodedUrl);
        e1.printStackTrace();
    }

    // initialize HTTP GET request objects
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse httpResponse;

    try {
        // execute request
        try {
            httpResponse = httpClient.execute(httpGet);
        } catch (UnknownHostException e) {
            throw new WSError("Unable to access " + e.getLocalizedMessage());
        } catch (SocketException e) {
            throw new WSError(e.getLocalizedMessage());
        }

        // request data
        HttpEntity httpEntity = httpResponse.getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            data = convertStreamToString(inputStream);
            // cache the result
            if (requestCache != null) {
                requestCache.put(url, data);
            }
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(Dian1Application.TAG, "Caller.doGet " + url);
    return data;
}

From source file:com.teleca.jamendo.util.Caller.java

/**
 * Performs HTTP GET using Apache HTTP Client v 4
 * /* www. j ava2 s  .co m*/
 * @param url
 * @return
 * @throws ErrorMsg 
 */
public static String doGet(String url) throws ErrorMsg {

    String data = null;
    if (requestCache != null) {
        data = requestCache.get(url);
        if (data != null) {
            Log.d(MyApplication.TAG, "Caller.doGet [cached] " + url);
            return data;
        }
    }

    // initialize HTTP GET request objects
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    HttpResponse httpResponse;

    try {
        // execute request
        try {
            httpResponse = httpClient.execute(httpGet);
        } catch (UnknownHostException e) {
            ErrorMsg wsError = new ErrorMsg();
            wsError.setMessage(e.getLocalizedMessage());
            throw wsError;
        } catch (SocketException e) {
            ErrorMsg wsError = new ErrorMsg();
            wsError.setMessage(e.getLocalizedMessage());
            throw wsError;
        }

        // request data
        HttpEntity httpEntity = httpResponse.getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            data = convertStreamToString(inputStream);
            // cache the result
            if (requestCache != null) {
                requestCache.put(url, data);
            }
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Log.d(MyApplication.TAG, "Caller.doGet " + url);
    return data;
}

From source file:de.fhg.fokus.diameter.DiameterPeer.peer.StateMachine.java

private static byte[] convertIpAddToByteArray(String localIp) {
    byte[] address = null;

    try {/*  ww  w  .j  av  a2s.  c om*/
        InetAddress bindLocalAdd = InetAddress.getByName(localIp);
        address = bindLocalAdd.getAddress();
    } catch (UnknownHostException e) {
        log.error(e, e);
        e.printStackTrace();
    }

    return address;
}

From source file:com.github.yongchristophertang.database.guice.provider.MongoTemplateFactory.java

/**
 * Transfer an annotation to a T object.
 *
 * @param anno Mongo annotation/*from   w ww.  j a va2s .c  om*/
 */
@Override
protected MongoTemplate createClient(Mongo anno) {
    if (StringUtils.isBlank(anno.database()) || StringUtils.isBlank(anno.host())) {
        throw new IllegalArgumentException("Mongo annotation must has database argument configured");
    }
    try {
        return new MongoTemplate(new MongoClient(anno.host(), anno.port()), anno.database());
    } catch (UnknownHostException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:uk.ac.ebi.atlas.acceptance.utils.URLBuilder.java

public String getLocalHostAddress() {
    try {//from  w  w w .ja  va 2 s  .  com
        InetAddress localHost = InetAddress.getLocalHost();
        return localHost.getHostAddress();
    } catch (UnknownHostException e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
    }
}

From source file:cloud.thrift.server.conf.ZooKeeperConfig.java

public ZkClient registService() {
    String servicePath = "/" + serviceName;// 
    ZkClient zkClient = new ZkClient(serverList);
    boolean rootExists = zkClient.exists(servicePath);
    if (!rootExists) {
        zkClient.createPersistent(servicePath);
    }/*  w w  w.  j  av  a 2s  . c  om*/
    InetAddress addr = null;
    try {
        addr = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    String ip = addr.getHostAddress().toString();
    String serviceInstance = System.nanoTime() + "-" + ip;
    // ??
    zkClient.createEphemeral(servicePath + "/" + serviceInstance);
    System.out.println("???" + servicePath + "/" + serviceInstance);
    return zkClient;
}

From source file:com.madadipouya.neatgeoip.service.MaxMindServiceImpl.java

private CityResponse lookup(String ip) {
    try {/*from  w w  w . j  a  va  2  s . com*/
        return getReader().city(InetAddress.getByName(ip));
    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (GeoIp2Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.polyvi.xface.http.XAsyncHttpRequest.java

/**
 * ?//from w w w .  j a  va2 s  .c  o  m
 */
private void makeRequest() {
    //FIXME:??
    try {
        HttpResponse response = mClient.execute(mRequest, mContext);
        mResponseHandler.sendResponseMessage(response);
        return;
    } catch (UnknownHostException e) {
        e.printStackTrace();
        mResponseHandler.sendFailureMessage(e, "can't resolve host");
        return;
    } catch (SocketException e) {
        e.printStackTrace();
        mResponseHandler.sendFailureMessage(e, "socket exception");
        return;
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        mResponseHandler.sendFailureMessage(e, "socket time out");
        return;
    } catch (IOException e) {
        e.printStackTrace();
        mResponseHandler.sendFailureMessage(e, "IOException");
        return;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.avanux.livetracker.mobile.ConfigurationProvider.java

private Properties buildConfiguration() {
    Properties configuration = new Properties();
    configuration.put(ConfigurationConstants.ID, "" + TrackingManager.createTracking().getTrackingID());
    configuration.put(ConfigurationConstants.SERVER_API_VERSION, "1");
    configuration.put(ConfigurationConstants.MIN_TIME_INTERVAL,
            "" + Configuration.getInstance().getMinTimeInterval());
    configuration.put(ConfigurationConstants.MESSAGE_TO_USERS, Configuration.getInstance().getMessageToUsers());

    // FIXME: this is a hack during main development phase to switch easily between development server and deployment server
    String hostname = null;/*  www. j av a 2 s .c  o m*/
    try {
        InetAddress addr = InetAddress.getLocalHost();
        hostname = addr.getHostName();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }

    if ((hostname != null) && hostname.equals("miraculix")) {
        configuration.put(ConfigurationConstants.LOCATION_RECEIVER_URL,
                "http://miraculix.localnet:8080/LiveTrackerServer/LocationReceiver");
    } else {
        configuration.put(ConfigurationConstants.LOCATION_RECEIVER_URL,
                "http://livetracker.dyndns.org/LocationReceiver");
    }
    return configuration;
}