List of usage examples for java.net SocketTimeoutException getMessage
public String getMessage()
From source file:it.cineca.iris.restclient.main.Command.java
public static void main(String[] argv) { Command command = new Command(); try {/* w w w . j a v a 2 s . 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.android.utility.util.Network.java
public static boolean isReachable(String url_string) { boolean result = false; try {//from w ww . ja va2 s .c o m HttpGet request = new HttpGet(url_string); HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 3000); HttpClient httpClient = new DefaultHttpClient(httpParameters); HttpResponse response = httpClient.execute(request); int status = response.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_OK) { result = true; } } catch (SocketTimeoutException e) { result = false; // this is somewhat expected } catch (ClientProtocolException e) { // TODO Auto-generated catch block Logger.e(LogModule.NETWORK, TAG, e.getMessage()); result = false; } catch (IOException e) { // TODO Auto-generated catch block Logger.e(LogModule.NETWORK, TAG, e.toString()); result = false; } return result; }
From source file:com.github.cc007.headsinventory.search.HeadsSearch.java
public static void saveHead(Player player, String headName) { Translator t = HeadsInventory.getTranslator(); Head newHead = null;/*from w ww . j av a2 s. c om*/ try { HeadsUtils hu = HeadsUtils.getInstance(); hu.setDatabaseLoader(new MineSkinLoader()); newHead = hu.saveHead(player, headName); hu.setDatabaseLoader(HeadsPlugin.getDefaultDatabaseLoader()); } catch (SocketTimeoutException ex) { Bukkit.getLogger().log(Level.SEVERE, ex.getMessage()); player.sendMessage( HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-msg-sockettimeout")); return; } catch (MalformedURLException ex) { // prob no heads found Bukkit.getLogger().log(Level.WARNING, t.getText("search-warning-malformedurl"), ex); } catch (UnknownHostException ex) { Bukkit.getLogger().log(Level.WARNING, t.getText("search-warning-unknownhost"), ex); } catch (IOException ex) { Bukkit.getLogger().log(Level.SEVERE, null, ex); player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-msg-io")); return; } catch (AuthenticationException ex) { //legacy exception Bukkit.getLogger().log(Level.SEVERE, null, ex); return; } if (newHead == null) { player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-error-addhead-failure")); return; } ItemStack newHeadStack = HeadCreator.getItemStack(newHead); putHeadInInventory(newHeadStack, player); player.sendMessage(HeadsInventory.pluginChatPrefix(true) + t.getText("search-error-addhead-success")); }
From source file:com.github.cc007.headsinventory.search.HeadsSearch.java
public static void searchFirst(final Player player, final String searchString, final String searchDatabase) { Translator t = HeadsInventory.getTranslator(); Thread thread = new Thread(() -> { ItemStack head = null;//from w ww .j ava 2 s . co m try { switch (searchDatabase) { case "freshcoal": HeadsUtils.getInstance().setDatabaseLoader(new FreshCoalLoader()); break; case "mineskin": HeadsUtils.getInstance().setDatabaseLoader(new MineSkinLoader()); break; case "minecraftheads": HeadsUtils.getInstance().setDatabaseLoader(new MinecraftHeadsLoader(player)); break; default: HeadsUtils.getInstance().setDatabaseLoader(HeadsPlugin.getDefaultDatabaseLoader()); } head = HeadCreator.getItemStack(HeadsUtils.getInstance().getHead(searchString)); HeadsUtils.getInstance().setDatabaseLoader(HeadsPlugin.getDefaultDatabaseLoader()); } catch (SocketTimeoutException ex) { Bukkit.getLogger().log(Level.SEVERE, ex.getMessage()); player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-msg-sockettimeout")); return; } catch (MalformedURLException ex) { // prob no heads found Bukkit.getLogger().log(Level.WARNING, t.getText("search-warning-malformedurl"), ex); } catch (UnknownHostException ex) { Bukkit.getLogger().log(Level.WARNING, t.getText("search-warning-unknownhost"), ex); } catch (IOException ex) { Bukkit.getLogger().log(Level.SEVERE, null, ex); player.sendMessage( HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-msg-io")); return; } catch (AuthenticationException ex) { //legacy exception Bukkit.getLogger().log(Level.SEVERE, null, ex); return; } if (head == null) { player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.GOLD + t.getText("search-msg-search-noheads")); return; } putHeadInInventory(head, player); player.sendMessage( HeadsInventory.pluginChatPrefix(true) + ChatColor.GREEN + t.getText("search-info-headgiven")); }); thread.start(); }
From source file:com.github.cc007.headsinventory.search.HeadsSearch.java
public static void search(final Player player, final String searchString, final String searchDatabase) { Translator t = HeadsInventory.getTranslator(); Thread thread = new Thread(() -> { List<ItemStack> heads = null; try {//w ww . ja va 2s. c o m switch (searchDatabase) { case "freshcoal": HeadsUtils.getInstance().setDatabaseLoader(new FreshCoalLoader()); break; case "mineskin": HeadsUtils.getInstance().setDatabaseLoader(new MineSkinLoader()); break; case "minecraftheads": HeadsUtils.getInstance().setDatabaseLoader(new MinecraftHeadsLoader(player)); break; default: HeadsUtils.getInstance().setDatabaseLoader(HeadsPlugin.getDefaultDatabaseLoader()); } heads = HeadCreator.getItemStacks(HeadsUtils.getInstance().getHeads(searchString)); HeadsUtils.getInstance().setDatabaseLoader(HeadsPlugin.getDefaultDatabaseLoader()); } catch (SocketTimeoutException ex) { Bukkit.getLogger().log(Level.SEVERE, ex.getMessage()); player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-msg-sockettimeout")); return; } catch (MalformedURLException ex) { // prob no heads found Bukkit.getLogger().log(Level.WARNING, t.getText("search-warning-malformedurl"), ex); } catch (UnknownHostException ex) { Bukkit.getLogger().log(Level.WARNING, t.getText("search-warning-unknownhost"), ex); } catch (IOException ex) { Bukkit.getLogger().log(Level.SEVERE, null, ex); player.sendMessage( HeadsInventory.pluginChatPrefix(true) + ChatColor.RED + t.getText("search-msg-io")); return; } catch (AuthenticationException ex) { //legacy exception Bukkit.getLogger().log(Level.SEVERE, null, ex); return; } if (heads == null || heads.isEmpty()) { player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.GOLD + t.getText("search-msg-search-noheads")); return; } player.sendMessage(HeadsInventory.pluginChatPrefix(true) + ChatColor.GREEN + t.getText("search-msg-search-choose")); showInventory(searchString, player, heads); }); thread.start(); }
From source file:edu.harvard.i2b2.eclipse.plugins.ontology.ws.CRCServiceDriver.java
/** * Function to send getChildrenCount request to CRC web service * /*from ww w.ja v a 2 s . c o m*/ * @param String containing name of parentNode we wish to get data for * @return A String containing the CRC web service response */ public static String getChildrenCount(String parentNode) throws Exception { String response = null; try { GetPsmRequestMessage reqMsg = new GetPsmRequestMessage(); AnalysisDefinitionRequestType analysisData = reqMsg.getAnalysisDefinitionRequestType(parentNode); String getCountRequestString = reqMsg.doBuildXML(analysisData); // log.info(getCountRequestString); if (serviceMethod.equals("SOAP")) { // response = sendSOAP(getCountRequestString, "http://rpdr.partners.org/GetChildren", "GetChildren", type ); } else { response = sendREST(crcEPR, getCountRequestString); } } catch (SocketTimeoutException e) { log.info("Got timeout interrupt"); throw e; } catch (AxisFault e) { log.error(e.getMessage()); //throw new AxisFault(e); } catch (Exception e) { log.error(e.getMessage()); throw new Exception(e); } return response; }
From source file:edu.harvard.i2b2.eclipse.plugins.ontology.ws.CRCServiceDriver.java
/** * Function to send getChildrenCount request to CRC web service * //from www .j a va 2 s . c o m * @param QueryResultInstanceType containing resultInstance we wish to get data for * @return A String containing the CRC web service response */ public static String getChildrenCount(QueryResultInstanceType resultInstance) throws Exception { String response = null; try { GetPsmRequestMessage reqMsg = new GetPsmRequestMessage(); ResultRequestType resultData = reqMsg.getResultRequestType(resultInstance); String getCountRequestString = reqMsg.doBuildXML(resultData); // log.info(getCountRequestString); if (serviceMethod.equals("SOAP")) { // response = sendSOAP(getChildrenRequestString, "http://rpdr.partners.org/GetChildren", "GetChildren", type ); } else { response = sendREST(crcEPR, getCountRequestString); } } catch (SocketTimeoutException e) { log.info("Got timeout interrupt"); throw e; } catch (AxisFault e) { log.error(e.getMessage()); //throw new AxisFault(e); } catch (Exception e) { log.error(e.getMessage()); throw new Exception(e); } return response; }
From source file:edu.harvard.i2b2.eclipse.plugins.ontology.ws.CRCServiceDriver.java
/** * Function to send getAnalysisPluginsMetadata request to CRC web service * /*from w w w. j a va2s . com*/ * @return A String containing the CRC web service response */ public static String getAnalysisPlugins() throws Exception { String response = null; try { GetPsmRequestMessage reqMsg = new GetPsmRequestMessage(); AnalysisPluginMetadataRequestType request = reqMsg.getAnalysisPluginMetadataRequestType(); String requestString = reqMsg.doBuildXML(request); // log.info(requestString); if (serviceMethod.equals("SOAP")) { // response = sendSOAP(getChildrenRequestString, "http://rpdr.partners.org/GetChildren", "GetChildren", type ); } else { response = sendREST(crcEPR, requestString); } } catch (SocketTimeoutException e) { log.info("Got timeout interrupt"); throw e; } catch (AxisFault e) { log.error(e.getMessage()); //throw new AxisFault(e); } catch (Exception e) { log.error(e.getMessage()); throw new Exception(e); } // log.info(response); return response; }
From source file:org.artifactory.cli.rest.RestClient.java
/** * Writes the response stream to the selected outputs * * @param method The method that was executed * @param printStream True if should print response stream to system.out * @return byte[] Response/*from w w w.ja va 2s .c o m*/ * @throws IOException */ private static byte[] analyzeResponse(HttpMethod method, boolean printStream) throws IOException { InputStream is = method.getResponseBodyAsStream(); if (is == null) { return null; } byte[] buffer = new byte[1024]; int r; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream os = baos; if (printStream) { os = new TeeOutputStream(baos, System.out); } while ((r = is.read(buffer)) != -1) { os.write(buffer, 0, r); } if (printStream) { System.out.println(""); } return baos.toByteArray(); } catch (SocketTimeoutException e) { CliLog.error("Communication with the server has timed out: " + e.getMessage()); CliLog.error("ATTENTION: The command on the server may still be running!"); String url = method.getURI().toString(); int apiPos = url.indexOf("/api"); String logsUrl; if (apiPos != -1) { logsUrl = url.substring(0, apiPos) + "/webapp/systemlogs.html"; } else { logsUrl = "http://" + method.getURI().getHost() + "/artifactory/webapp/systemlogs.html"; } CliLog.error("Please check the server logs " + logsUrl + " before re-running the command."); return null; } }
From source file:zz.pseas.ghost.utils.HttpClinetUtil.java
/** * @author GS/*from w w w. j a va 2 s. c o 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; }