List of usage examples for java.io IOException toString
public String toString()
From source file:org.exoplatform.social.client.api.util.SocialHttpClientSupport.java
/** * Executes the HttpResponse with read the content to buffered. * * @param response HttpResponse to process. * @return Content of HttpResponse./*from w ww. j a v a 2 s . co m*/ * @throws IllegalStateException * @throws IOException */ public static String getContent(HttpResponse response) throws SocialHttpClientException { if (response == null) { throw new NullPointerException("HttpResponse argument is not NULL."); } HttpEntity entity = processContent(response); String content; try { if (entity.getContentLength() != -1) { content = EntityUtils.toString(entity); } else { throw new SocialHttpClientException("Content of response is empty."); } } catch (IOException ioex) { throw new SocialHttpClientException(ioex.toString(), ioex); } return content; }
From source file:services.ConfigurationService.java
public static File getPuppetNodeStartupScriptFile(String clusterName) throws GoogleComputeEngineException { try {/* w ww . j a va2 s . c om*/ File f = getStartupScriptFile(); FileUtils.writeFile(f, PuppetConfiguration.getNodeStartupScriptContent( getInternalServerName(getServerName(clusterName, NODE_NAME_PUPPET)))); return f; } catch (IOException e) { throw new GoogleComputeEngineException("cannot write the startup script: " + e.toString()); } catch (FileLockException e) { throw new GoogleComputeEngineException("cannot write the startup script: " + e.toString()); } }
From source file:services.ConfigurationService.java
public static File getTestNodeStartupScriptFile(String clusterName) throws GoogleComputeEngineException, GoogleCloudStorageException { try {/*www .j av a 2s.c o m*/ File f = getStartupScriptFile(); FileUtils.writeFile(f, TestConfiguration.getNodeStartupScriptContent( getInternalServerName(getServerName(clusterName, NODE_NAME_TEST_JUMP)), getTestNodeStartupScriptUrl(clusterName))); return f; } catch (IOException e) { throw new GoogleComputeEngineException("cannot write the startup script: " + e.toString()); } catch (FileLockException e) { throw new GoogleComputeEngineException("cannot write the startup script: " + e.toString()); } }
From source file:org.exoplatform.social.client.api.util.SocialHttpClientSupport.java
/** * Executes the HttpResponse with read the content to buffered. * * @param response HttpResponse to process. * @return/* ww w.j a v a2s . co m*/ * @throws IllegalStateException * @throws IOException */ public static HttpEntity processContent(HttpResponse response) throws SocialHttpClientException { if (response == null) { throw new NullPointerException("HttpResponse argument is not NULL."); } HttpEntity entity = response.getEntity(); //Reading the content to the buffered. //contentObtained = false: Content does not get yet. //contentObtained = true: Content is buffered by BufferedHttpEntity. if (entity != null && entity.isStreaming()) { try { entity = new BufferedHttpEntity(entity); //important to setEntity return to Response. If don't assign again, next to get //, you can not get the response content response.setEntity(entity); } catch (IOException ioex) { throw new SocialHttpClientException(ioex.toString(), ioex); } } return entity; }
From source file:exm.stc.ui.Main.java
/** * Setup input file. If necessary, run through CPP * @param logger/*www.j av a 2s .c o m*/ * @param preprocess * @param args * @return */ private static File setupInputFile(Logger logger, boolean preprocess, Args args) { File result; try { if (preprocess) { File input = new File(args.inputFilename); if (!input.isFile() || !input.canRead()) { System.out.println("Input file \"" + input + "\" is not readable"); System.exit(1); } result = File.createTempFile("stc-preproc", ".swift"); temporaries.add(result); runPreprocessor(logger, args.inputFilename, result.getPath(), args.preprocessorMacros); } else { result = new File(args.inputFilename); } if (!result.isFile() || !result.canRead()) { System.out.println("Input file \"" + result + "\" is not readable"); System.exit(1); } return result; } catch (IOException ex) { System.out.println("Error while setting up input file: " + ex.toString()); System.exit(1); } catch (Throwable t) { STCompiler.reportInternalError(logger, t); System.exit(1); } return null; }
From source file:com.nubits.nubot.utils.Utils.java
public static void launchBrowser(String url) { if (Desktop.isDesktopSupported()) { try {//from w w w. j a va2 s . co m Desktop.getDesktop().browse(new URI(url)); } catch (IOException e) { LOG.error(e.toString()); } catch (URISyntaxException e) { LOG.error(e.toString()); } } else { LOG.warn("Can't launch browser: Desktop not supported."); } }
From source file:org.exoplatform.social.client.api.util.SocialHttpClientSupport.java
/** * Invokes the social rest service via Get method * @param targetURL //w ww .jav a2 s . co m * @param authPolicy POLICY.NO_AUTH/POLICY.BASIC_AUTH * @param params HttpParams for Request * @return * @throws IOException * @throws ClientProtocolException */ public static HttpResponse executeGet(String targetURL, POLICY authPolicy, HttpParams params) throws SocialHttpClientException { SocialHttpClient httpClient = SocialHttpClientImpl.newInstance(); if (POLICY.BASIC_AUTH == authPolicy) { try { httpClient.setBasicAuthenticateToRequest(); } catch (SocialClientLibException e) { throw new SocialHttpClientException(e.getMessage(), e); } } HttpGet httpGet = new HttpGet(targetURL); Header header = new BasicHeader("Content-Type", "application/json"); httpGet.setHeader(header); HttpHost targetHost = new HttpHost(SocialClientContext.getHost(), SocialClientContext.getPort(), SocialClientContext.getProtocol()); //Get method with the HttpParams if (params != null) { httpGet.setParams(params); } try { HttpResponse response = httpClient.execute(targetHost, httpGet); //handleError(response); //Debugging in the devlopment mode if (SocialClientContext.isDeveloping()) { dumpHttpResponsetHeader(response); dumpContent(response); } return response; } catch (ClientProtocolException cpex) { throw new SocialHttpClientException(cpex.toString(), cpex); } catch (IOException ioex) { throw new SocialHttpClientException(ioex.toString(), ioex); } }
From source file:org.exoplatform.social.client.api.util.SocialHttpClientSupport.java
/** * Invokes the social rest service via Delete method with HttpParams * @param targetURL /*from ww w. j a v a 2 s . c om*/ * @param authPolicy POLICY.NO_AUTH/POLICY.BASIC_AUTH * @param params HttpParams for Request * @return * @throws IOException * @throws ClientProtocolException */ public static HttpResponse executeDelete(String targetURL, POLICY authPolicy, HttpParams params) throws SocialHttpClientException { HttpHost targetHost = new HttpHost(SocialClientContext.getHost(), SocialClientContext.getPort(), SocialClientContext.getProtocol()); SocialHttpClient httpClient = SocialHttpClientImpl.newInstance(); if (POLICY.BASIC_AUTH == authPolicy) { try { httpClient.setBasicAuthenticateToRequest(); } catch (SocialClientLibException e) { new SocialHttpClientException(e.getMessage(), e); } } HttpDelete httpDelete = new HttpDelete(targetURL); Header header = new BasicHeader("Content-Type", "application/json"); httpDelete.setHeader(header); //Delete method with the HttpParams if (params != null) { httpDelete.setParams(params); } try { HttpResponse response = httpClient.execute(targetHost, httpDelete); //handleError(response); //Debugging in the devlopment mode if (SocialClientContext.isDeveloping()) { dumpHttpResponsetHeader(response); dumpContent(response); } return response; } catch (ClientProtocolException cpex) { throw new SocialHttpClientException(cpex.toString(), cpex); } catch (IOException ioex) { throw new SocialHttpClientException(ioex.toString(), ioex); } }
From source file:org.exoplatform.social.client.api.util.SocialHttpClientSupport.java
/** * Invokes the social rest service via Post method * @param targetURL /*w ww . j a va 2s. c om*/ * @param authPolicy POLICY.NO_AUTH/POLICY.BASIC_AUTH * @param params HttpParams for Request * @return * @throws IOException * @throws ClientProtocolException */ public static HttpResponse executePost(String targetURL, POLICY authPolicy, HttpParams params, Model model) throws SocialHttpClientException { HttpHost targetHost = new HttpHost(SocialClientContext.getHost(), SocialClientContext.getPort(), SocialClientContext.getProtocol()); SocialHttpClient httpClient = SocialHttpClientImpl.newInstance(); if (POLICY.BASIC_AUTH == authPolicy) { try { httpClient.setBasicAuthenticateToRequest(); } catch (SocialClientLibException e) { throw new SocialHttpClientException(e.getMessage(), e); } } HttpPost httpPost = new HttpPost(targetURL); Header header = new BasicHeader("Content-Type", "application/json"); httpPost.setHeader(header); //Post method with the HttpParams if (params != null) { httpPost.setParams(params); } try { //Provides when uses post so does not have any data. byte[] postData = convertModelToByteArray(model); if (postData != null) { ByteArrayEntity entity = new ByteArrayEntity(convertModelToByteArray(model)); httpPost.setEntity(entity); } HttpResponse response = httpClient.execute(targetHost, httpPost); //handleError(response); //Debugging in the devlopment mode if (SocialClientContext.isDeveloping()) { dumpHttpResponsetHeader(response); dumpContent(response); } return response; } catch (ClientProtocolException cpex) { throw new SocialHttpClientException(cpex.toString(), cpex); } catch (IOException ioex) { throw new SocialHttpClientException(ioex.toString(), ioex); } }
From source file:services.ConfigurationService.java
public static File getTestJumpNodeStartupScriptFile(String clusterName, String networkName) throws GoogleComputeEngineException, GoogleCloudStorageException { try {/*from www . ja v a2 s.c om*/ String scriptUrl; File f = getStartupScriptFile(); try { checkGoogleAuthentication(); if (bucketId == null || bucketId.isEmpty()) { throw new GoogleCloudStorageException( "parameter 'google.bucketId' not specified in the configuration"); } StringBuilder scriptPath = new StringBuilder(); scriptPath.append("autostart/"); scriptPath.append(clusterName); scriptPath.append("/test_autostart.sh"); /** * There is a limit of 32K for the metadata in Google Compute Engine. To avoid any size problems * the application upload the file to Google Storage and store the link in the metadata. * * Limit can be exceeded in the case of a lot of cluster nodes. */ String scriptContent = TestConfiguration.getNodeRemoteStartupScriptContent( getInternalServerName(getServerName(clusterName, NODE_NAME_TEST_JUMP)), googleComputeService .getInstancesNames(Arrays.asList(ConfigurationService.NODE_TAG_CONF, clusterName)), googleComputeService.getInstancesNames( Arrays.asList(ConfigurationService.NODE_TAG_SHARD, clusterName))); scriptUrl = googleStorageClient.putFile(bucketId, scriptPath.toString(), "plain/text", scriptContent.getBytes()); FileUtils.writeFile(f, TestConfiguration.getJumpServerStartupScriptContent( googleComputeService.getNetworkRange(networkName), scriptUrl)); } catch (IOException e) { throw new GoogleComputeEngineException("cannot create the startup script: " + e.toString()); } return f; } catch (IOException e) { throw new GoogleComputeEngineException("cannot write the startup script: " + e.toString()); } catch (FileLockException e) { throw new GoogleComputeEngineException("cannot write the startup script: " + e.toString()); } }