List of usage examples for java.net UnknownHostException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.teleca.jamendo.api.util.Caller.java
/** * Performs HTTP GET using Apache HTTP Client v 4 * /* www . ja 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 * // ww w. j a v a 2s . com * @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 * //from w w w . j a v a2 s .c o 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:net.straylightlabs.archivo.model.Tivo.java
/** * Create a new Tivo object from a JSON String. * * @param json String containing the Tivo object in JSON * @param mak Media access key to use for the resulting Tivo * @return A new Tivo object/*from www .j av a2 s . c om*/ * @throws IllegalArgumentException */ public static Tivo fromJSON(final String json, final String mak) throws IllegalArgumentException { JSONObject jo = new JSONObject(json); String name = jo.getString(JSON_NAME); String tsn = jo.getString(JSON_TSN); int port = jo.getInt(JSON_PORT); JSONArray jsonAddresses = jo.getJSONArray(JSON_ADDRESSES); Set<InetAddress> addresses = new HashSet<>(); Base64.Decoder decoder = Base64.getDecoder(); for (int i = 0; i < jsonAddresses.length(); i++) { try { addresses.add(InetAddress.getByAddress(decoder.decode(jsonAddresses.getString(i)))); } catch (UnknownHostException e) { throw new IllegalArgumentException("TiVo address in invalid: " + e.getLocalizedMessage()); } } return new Builder().name(name).tsn(tsn).port(port).addresses(addresses).mak(mak).build(); }
From source file:com.lostad.app.base.util.RequestUtil.java
/** * PostHttps?//from w w w. j a v a 2s . c o m * @param url; ? * @param json * @return * @throws Exception */ public static synchronized String postHttps(String url, String json) throws Exception { // ? HttpParams httpParameters = new BasicHttpParams(); // HttpConnectionParams.setConnectionTimeout(httpParameters, 3000); // socket HttpConnectionParams.setSoTimeout(httpParameters, 3000); // ?HttpClient ? HttpClient hc = HttpClientManager.getHttpClientSSL(httpParameters); HttpPost post = new HttpPost(url); // ??? post.addHeader("Content-Type", "application/json;charset=utf-8"); // ?? post.addHeader("Accept", "application/json"); // StringEntity entity = new StringEntity(json, "UTF-8"); post.setEntity(entity); post.setParams(httpParameters); HttpResponse response = null; try { response = hc.execute(post); } catch (UnknownHostException e) { throw new Exception("Unable to access " + e.getLocalizedMessage()); } catch (SocketException e) { e.printStackTrace(); } int sCode = response.getStatusLine().getStatusCode(); if (sCode == HttpStatus.SC_OK) { return EntityUtils.toString(response.getEntity()); } else throw new Exception("StatusCode is " + sCode); }
From source file:org.apache.kylin.job.cube.CubingJob.java
@Override protected Pair<String, String> formatNotifications(ExecutableState state) { final Output output = jobService.getOutput(getId()); String logMsg;/*from w ww . ja v a 2 s. co m*/ switch (output.getState()) { case ERROR: logMsg = output.getVerboseMsg(); break; case DISCARDED: logMsg = ""; break; case SUCCEED: logMsg = ""; break; default: return null; } String content = ExecutableConstants.NOTIFY_EMAIL_TEMPLATE; content = content.replaceAll("\\$\\{job_name\\}", getName()); content = content.replaceAll("\\$\\{result\\}", state.toString()); content = content.replaceAll("\\$\\{cube_name\\}", getCubeName()); content = content.replaceAll("\\$\\{start_time\\}", new Date(getStartTime()).toString()); content = content.replaceAll("\\$\\{duration\\}", getDuration() / 60000 + "mins"); content = content.replaceAll("\\$\\{mr_waiting\\}", getMapReduceWaitTime() / 60000 + "mins"); content = content.replaceAll("\\$\\{last_update_time\\}", new Date(getLastModified()).toString()); content = content.replaceAll("\\$\\{submitter\\}", getSubmitter()); content = content.replaceAll("\\$\\{error_log\\}", logMsg); try { InetAddress inetAddress = InetAddress.getLocalHost(); content = content.replaceAll("\\$\\{job_engine\\}", inetAddress.getCanonicalHostName()); } catch (UnknownHostException e) { logger.warn(e.getLocalizedMessage(), e); } String title = "[" + state.toString() + "] - [Kylin Cube Build Job]-" + getCubeName(); return Pair.of(title, content); }
From source file:com.photon.phresco.service.api.MongoConfig.java
@Override @Bean/*w w w .j ava2s . c om*/ public Mongo mongo() throws PhrescoException { if (isDebugEnabled) { LOGGER.debug("MongoConfig.mongo : Entry"); LOGGER.debug("MongoConfig.mongo", "host=" + config.getDbHost(), "port=" + config.getDbPort()); } Mongo mongo = null; try { mongo = new Mongo(config.getDbHost(), config.getDbPort()); } catch (UnknownHostException e) { LOGGER.error("MongoConfig.mongo ", "status=\"Failure\"", "message=\"" + e.getLocalizedMessage() + "\""); throw new PhrescoException(e, EX_PHEX00002); } catch (MongoException e) { LOGGER.error("MongoConfig.mongo ", "status=\"Failure\"", "message=\"" + e.getLocalizedMessage() + "\""); throw new PhrescoException(e, EX_PHEX00003); } if (isDebugEnabled) { LOGGER.debug("MongoConfig.mongo : Exit"); } return mongo; }
From source file:com.photon.phresco.service.api.MongoConfig.java
@Bean public Mongo mongoMaster() throws PhrescoException { if (isDebugEnabled) { LOGGER.debug("MongoConfig.mongo : Entry"); LOGGER.debug("MongoConfig.mongo", "host=" + config.getMasterDbHost(), "port=" + config.getMasterDbPort()); }//from w ww . ja va 2s. c o m Mongo mongo = null; try { mongo = new Mongo(config.getMasterDbHost(), config.getMasterDbPort()); } catch (UnknownHostException e) { LOGGER.error("MongoConfig.mongo ", "status=\"Failure\"", "message=\"" + e.getLocalizedMessage() + "\""); throw new PhrescoException(e, EX_PHEX00002); } catch (MongoException e) { LOGGER.error("MongoConfig.mongo ", "status=\"Failure\"", "message=\"" + e.getLocalizedMessage() + "\""); throw new PhrescoException(e, EX_PHEX00003); } if (isDebugEnabled) { LOGGER.debug("MongoConfig.mongo : Exit"); } return mongo; }
From source file:net.straylightlabs.archivo.controller.TelemetryController.java
public synchronized void sendFoundTivosEvent(int numFound, int retriesNeeded) { JSONObject eventProps = new JSONObject(); eventProps.put("Number Found", numFound); eventProps.put("Retries Needed", retriesNeeded); JSONObject event = messageBuilder.event(userId, "Found TiVos", eventProps); eventQueue.addLast(event);// w w w . j av a2s .com JSONObject userDetails = new JSONObject(); userDetails.put("Found TiVos", numFound); userDetails.put("Search Retries", retriesNeeded); userDetails.put("No TiVos Found", numFound < 1); try { userDetails.put("Localhost", InetAddress.getLocalHost()); } catch (UnknownHostException e) { logger.error("Error fetching localhost address: {}", e.getLocalizedMessage()); } eventQueue.addLast(messageBuilder.set(userId, userDetails)); sendAll(); }
From source file:net.straylightlabs.archivo.controller.TelemetryController.java
public synchronized void sendNoTivosFoundEvent(int retries, boolean searchFailed) { JSONObject eventProps = new JSONObject(); eventProps.put("Search Failed", searchFailed); eventProps.put("Retries", retries); JSONObject event = messageBuilder.event(userId, "No TiVos Found", eventProps); eventQueue.addLast(event);/* www .j a v a 2 s. co m*/ JSONObject userDetails = new JSONObject(); userDetails.put("Found TiVos", 0); userDetails.put("Search Retries", retries); userDetails.put("No TiVos Found", true); int i = 0; for (String nic : getNetworkInterfaces()) { userDetails.put(String.format("Network Interface %d", i), nic); i++; } try { userDetails.put("Localhost", InetAddress.getLocalHost()); } catch (UnknownHostException e) { logger.error("Error fetching localhost address: {}", e.getLocalizedMessage()); } eventQueue.addLast(messageBuilder.set(userId, userDetails)); sendAll(); }