List of usage examples for java.net URL toString
public String toString()
From source file:au.csiro.casda.sodalint.ValidateAsync.java
private String getAsyncContent(final Reporter reporter, URL address) { try {//from ww w . j a v a2 s . co m String content = getXmlContentFromUrl(address.toString()); if (content == null) { reporter.report(SodaCode.E_ASCO, "Async response contains no content"); } return content; } catch (HttpResponseException e) { reporter.report(SodaCode.E_ASCO, "Unexpected http response: " + e.getStatusCode() + " Reason: " + e.getMessage()); } catch (UnsupportedEncodingException e) { reporter.report(SodaCode.E_ASCO, "Async response has an unexpected content type:" + e.getMessage()); } catch (IOException e) { reporter.report(SodaCode.E_ASCO, "Unable to read async response: " + e.getMessage()); } return null; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java
public static void DownloadFromUrl(final String media, final String messageId, final Context ctx, final ImageView container, final Object object, final String timelineId, final String localId, final Long fileSize) { new AsyncTask<Void, Void, Boolean>() { private boolean retry = true; private Bitmap imageDownloaded; private BroadcastReceiver mDownloadCancelReceiver; private HttpGet job; private AccountManager am; private Account account; private String authToken; @Override//w w w .j a va 2s . co m protected void onPreExecute() { IntentFilter downloadFilter = new IntentFilter(ConstantKeys.BROADCAST_CANCEL_PROCESS); mDownloadCancelReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String localIdToClose = (String) intent.getExtras().get(ConstantKeys.LOCALID); if (localId.equals(localIdToClose)) { try { job.abort(); } catch (Exception e) { log.debug("The process was canceled"); } cancel(false); } } }; // registering our receiver ctx.getApplicationContext().registerReceiver(mDownloadCancelReceiver, downloadFilter); } @Override protected void onCancelled() { File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG); File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP); if (file1.exists()) { file1.delete(); } if (file2.exists()) { file2.delete(); } file1 = null; file2 = null; System.gc(); try { ctx.getApplicationContext().unregisterReceiver(mDownloadCancelReceiver); } catch (Exception e) { log.debug("Receriver unregister from another code"); } for (int i = 0; i < AppUtils.getlistOfDownload().size(); i++) { if (AppUtils.getlistOfDownload().get(i).equals(localId)) { AppUtils.getlistOfDownload().remove(i); } } DataBasesAccess.getInstance(ctx.getApplicationContext()).MessagesDataBaseWriteTotal(localId, 100); Intent intent = new Intent(); intent.setAction(ConstantKeys.BROADCAST_DIALOG_DOWNLOAD_FINISH); intent.putExtra(ConstantKeys.LOCALID, localId); ctx.sendBroadcast(intent); if (object != null) { ((ProgressDialog) object).dismiss(); } } @Override protected Boolean doInBackground(Void... params) { try { File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG); File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP); // firt we are goint to search the local files if ((!file1.exists()) && (!file2.exists())) { account = AccountUtils.getAccount(ctx.getApplicationContext(), false); am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE); authToken = ConstantKeys.STRING_DEFAULT; authToken = am.blockingGetAuthToken(account, ctx.getString(R.string.account_type), true); MessagingClientService messageService = new MessagingClientService( ctx.getApplicationContext()); URL urlObj = new URL(Preferences.getServerProtocol(ctx), Preferences.getServerAddress(ctx), Preferences.getServerPort(ctx), ctx.getString(R.string.url_get_content)); String url = ConstantKeys.STRING_DEFAULT; url = Uri.parse(urlObj.toString()).buildUpon().build().toString() + timelineId + "/" + messageId + "/" + "content"; job = new HttpGet(url); // first, get free space FreeUpSpace(ctx, fileSize); messageService.getContent(authToken, media, messageId, timelineId, localId, false, false, fileSize, job); } if (file1.exists()) { imageDownloaded = decodeSampledBitmapFromPath(file1.getAbsolutePath(), 200, 200); } else if (file2.exists()) { imageDownloaded = ThumbnailUtils.createVideoThumbnail(file2.getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND); } if (imageDownloaded == null) { return false; } return true; } catch (Exception e) { deleteFiles(); return false; } } @Override protected void onPostExecute(Boolean result) { // We have the media try { ctx.getApplicationContext().unregisterReceiver(mDownloadCancelReceiver); } catch (Exception e) { log.debug("Receiver was closed on cancel"); } if (!(localId.contains(ConstantKeys.AVATAR))) { for (int i = 0; i < AppUtils.getlistOfDownload().size(); i++) { if (AppUtils.getlistOfDownload().get(i).equals(localId)) { AppUtils.getlistOfDownload().remove(i); } } DataBasesAccess.getInstance(ctx.getApplicationContext()).MessagesDataBaseWriteTotal(localId, 100); Intent intent = new Intent(); intent.setAction(ConstantKeys.BROADCAST_DIALOG_DOWNLOAD_FINISH); intent.putExtra(ConstantKeys.LOCALID, localId); ctx.sendBroadcast(intent); } if (object != null) { ((ProgressDialog) object).dismiss(); } // Now the only container could be the avatar in edit screen if (container != null) { if (imageDownloaded != null) { container.setImageBitmap(imageDownloaded); } else { deleteFiles(); imageDownloaded = decodeSampledBitmapFromResource(ctx.getResources(), R.drawable.ic_error_loading, 200, 200); container.setImageBitmap(imageDownloaded); Toast.makeText(ctx.getApplicationContext(), ctx.getApplicationContext().getText(R.string.donwload_fail), Toast.LENGTH_SHORT) .show(); } } else { showMedia(localId, ctx, (ProgressDialog) object); } } private void deleteFiles() { File file1 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_JPG); File file2 = new File(FileUtils.getDir(), localId + ConstantKeys.EXTENSION_3GP); if (file1.exists()) { file1.delete(); } if (file2.exists()) { file2.delete(); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:jp.go.nict.langrid.dao.entity.EmbeddableURL.java
/** * * */ public EmbeddableURL(URL value) { this.original = value; this.stringValue = value.toString(); }
From source file:com.betaplay.sdk.sender.JsonSender.java
/** * send out data to betaplay/*from ww w . j a v a 2 s . c om*/ * * @param data * @param url */ private void sendJson(String data, URL url) { HttpClient client = new HttpClient(url.toString()); client.setJsonBody(data); try { client.execute(); } catch (Exception e) { Log.e(LOG_TAG, "Unable to send to server", e); } }
From source file:juzu.impl.bridge.context.AbstractContextClientTestCase.java
protected void test(URL initialURL, String kind) throws Exception { driver.get(initialURL.toString()); WebElement link = driver.findElement(By.id(kind)); contentLength = -1;//from www .j av a 2 s . c om charset = null; contentType = null; content = null; URL url = new URL(link.getAttribute("href")); DefaultHttpClient client = new DefaultHttpClient(); // Little trick to force redirect after post client.setRedirectStrategy(new DefaultRedirectStrategy() { @Override protected boolean isRedirectable(String method) { return true; } }); try { HttpPost post = new HttpPost(url.toURI()); post.setEntity(new StringEntity("foo", ContentType.create("application/octet-stream", "UTF-8"))); HttpResponse response = client.execute(post); assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(3, contentLength); assertEquals("UTF-8", charset); assertEquals("application/octet-stream; charset=UTF-8", contentType); assertEquals("foo", content); assertEquals(kind, AbstractContextClientTestCase.kind); } finally { client.getConnectionManager().shutdown(); } }
From source file:org.jboss.additional.testsuite.jdkall.present.ejb.sfsb.SfsbTestCase.java
@Test @OperateOnDeployment(DEPLOYMENT)// w ww .j av a 2s . c om public void sfsbTest(@ArquillianResource URL url) throws Exception { URL testURL = new URL(url.toString() + "sfsbCache?product=makaronia&quantity=10"); final HttpGet request = new HttpGet(testURL.toString()); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); CloseableHttpResponse response = null; try { response = httpClient.execute(request); Assert.assertEquals("Failed to access " + testURL, HttpURLConnection.HTTP_OK, response.getStatusLine().getStatusCode()); Thread.sleep(1000); response = httpClient.execute(request); Assert.assertEquals("Failed to access " + testURL, HttpURLConnection.HTTP_OK, response.getStatusLine().getStatusCode()); } finally { IOUtils.closeQuietly(response); httpClient.close(); } }
From source file:com.blazemeter.bamboo.plugin.ServiceManager.java
public static void downloadJtlReport(Api api, String sessionId, File jtlDir, BuildLogger logger) { String dataUrl = null;//from w w w . j av a 2s . com URL url = null; try { JSONObject jo = api.retrieveJtlZip(sessionId); JSONArray data = jo.getJSONObject(JsonConstants.RESULT).getJSONArray(JsonConstants.DATA); for (int i = 0; i < data.length(); i++) { String title = data.getJSONObject(i).getString("title"); if (title.equals("Zip")) { dataUrl = data.getJSONObject(i).getString(JsonConstants.DATA_URL); break; } } File jtlZip = new File(jtlDir + "/" + sessionId + "-" + Constants.BM_ARTEFACTS); url = new URL(dataUrl); logger.addBuildLogEntry("Jtl url = " + url.toString() + " sessionId = " + sessionId); int i = 1; boolean jtl = false; while (!jtl && i < 4) { try { logger.addBuildLogEntry("Downloading JTLZIP for sessionId = " + sessionId + " attemp # " + i); int conTo = (int) (10000 * Math.pow(3, i - 1)); logger.addBuildLogEntry("Saving ZIP to " + jtlZip.getAbsolutePath()); FileUtils.copyURLToFile(url, jtlZip, conTo, 30000); jtl = true; } catch (Exception e) { logger.addErrorLogEntry("Unable to get JTLZIP from " + url + ", " + e); } finally { i++; } } String jtlZipCanonicalPath = jtlZip.getCanonicalPath(); unzip(jtlZip.getAbsolutePath(), jtlZipCanonicalPath.substring(0, jtlZipCanonicalPath.length() - 4), logger); File sample_jtl = new File(jtlDir, "sample.jtl"); File bm_kpis_jtl = new File(jtlDir, Constants.BM_KPIS); if (sample_jtl.exists()) { sample_jtl.renameTo(bm_kpis_jtl); } FileUtils.deleteQuietly(jtlZip); } catch (JSONException e) { logger.addErrorLogEntry("Unable to get JTLZIP from " + url + " " + e.getMessage()); } catch (MalformedURLException e) { logger.addErrorLogEntry("Unable to get JTLZIP from " + url + " " + e.getMessage()); } catch (IOException e) { logger.addErrorLogEntry("Unable to get JTLZIP from " + url + " " + e.getMessage()); } catch (Exception e) { logger.addErrorLogEntry("Unable to get JTLZIP from " + url + " " + e.getMessage()); } }
From source file:HttpConnections.DiffURIBuilder.java
public URL getFinalURIString() { URL endpoint = null;//from w ww.j ava 2 s . c o m try { endpoint = new URL(new URL(getFinalURI().build().toString()), "", new URLStreamHandler() { @Override protected URLConnection openConnection(URL url) throws IOException { URL target = new URL(url.toString()); URLConnection connection = target.openConnection(); // Connection settings connection.setConnectTimeout(30000); // 20 sec connection.setReadTimeout(60000); // 30 sec return (connection); } }); } catch (MalformedURLException ex) { Logger.getLogger(DiffURIBuilder.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(DiffURIBuilder.class.getName()).log(Level.SEVERE, null, ex); } //System.out.println("Soap URL:"+endpoint); return endpoint; }
From source file:modula.parser.env.URLResolver.java
/** * URL(URL, String)? URL// ww w . j a v a 2 s. co m * * @see PathResolver#resolvePath(java.lang.String) */ public String resolvePath(final String ctxPath) { URL combined; try { combined = new URL(baseURL, ctxPath); return combined.toString(); } catch (MalformedURLException e) { log.error("Malformed URL", e); } return null; }
From source file:de.digiway.rapidbreeze.client.model.collector.CollectorModel.java
public CollectorModel(URL url) { this.url.setValue(url.toString()); }