List of usage examples for java.net URL toString
public String toString()
From source file:juzu.impl.plugin.amd.AmdMaxAgeTestCase.java
@Test @RunAsClient/* w w w .ja va 2s . co m*/ public void test() throws Exception { URL applicationURL = applicationURL(); driver.get(applicationURL.toString()); WebElement elt = driver.findElement(By.id("Foo")); URL url = new URL(applicationURL.getProtocol(), applicationURL.getHost(), applicationURL.getPort(), elt.getText()); HttpGet get = new HttpGet(url.toURI()); HttpResponse response = HttpClientBuilder.create().build().execute(get); Header[] cacheControl = response.getHeaders("Cache-Control"); assertEquals(1, cacheControl.length); assertEquals("max-age=1000", cacheControl[0].getValue()); }
From source file:com.ms.commons.test.classloader.IntlTestURLClassPath.java
private static URL translateURL(URL url) throws Exception { URLClassLoader ucl = new URLClassLoader(new URL[] { url }); // URL?autoconfig List<URL> autoConfigXmlList = AutoConfigUtil.loadAllAutoConfigFilesWithFind(ucl); if ((autoConfigXmlList == null) || (autoConfigXmlList.size() == 0)) { return url; }/* ww w . ja v a 2s. c om*/ AutoConfigMap acm = AutoConfigUtil.loadAutoConfigMapWithFind(ucl, IntlTestProperties.PROPERTIES); // ??URL boolean urlTranslated = false; // String outputPath; if ("file".equals(url.getProtocol()) && !url.toString().toLowerCase().endsWith(".jar")) { outputPath = FileUtil.convertURLToFilePath(url); } else if (url.toString().toLowerCase().endsWith(".jar")) { String fileN = FileUtil.convertURLToFile(url).getName(); String jarUrlPath = fileN + "@" + url.toString().hashCode(); jarUrlPath = jarUrlPath.replace(".jar", "").replace("alibaba", ""); outputPath = TESTCASE_JAR_TEMP_DIR + File.separator + StringUtil.replaceNoWordChars(jarUrlPath); // ?????? File signature = new File(outputPath + File.separator + TESTCASE_JAR_SIGNATURE); StringBuilder refAst = new StringBuilder(); if (isOutOfDate(signature, url, refAst)) { // JAR??JAR?JAR?? FileUtil.clearAndMakeDirs(outputPath); expandJarTo(new JarFile(FileUtil.convertURLToFile(url)), outputPath); FileUtils.writeStringToFile(signature, refAst.toString()); } urlTranslated = true; } else { throw new RuntimeException("URL protocol unknow:" + url); } // ?autoconfig? System.err.println("Auto config for:" + url); for (AutoConfigItem antxConfigResourceItem : acm.values()) { AutoConfigUtil.autoConfigFile(ucl, IntlTestProperties.PROPERTIES, antxConfigResourceItem, outputPath, true); } return urlTranslated ? (new File(outputPath)).toURI().toURL() : url; }
From source file:com.aurel.track.admin.customize.category.report.execute.ReportExecuteBL.java
/** * Serializes the data source into the response's output stream using a * ReportExporter//w w w . ja va 2 s. c o m * * @param templateID * @param datasource * @return */ static String prepareReportResponse(HttpServletResponse response, Integer templateID, Map<String, Object> contextMap, Map<String, Object> description, Object datasource, Map<String, Object> parameters, ServletContext servletContext, TPersonBean personBean, Locale locale) { URL baseURL = null; String logoFolder = null; URL completeURL = null; String baseFileName = null; if (templateID == null) { final String baseFolder = "/design/silver/"; // direct pdf/xls from report overview try { // set the baseURL to take some standard icons from // "/design/silver/icons" // which ale already used by the report overview anyway baseURL = servletContext.getResource(baseFolder + "16x16"); LOGGER.debug("baseURL: " + baseURL.toString()); } catch (final MalformedURLException e) { LOGGER.error("Getting the baseURL for " + baseFolder + "16x16 failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } // set the baseURL to take some standard icons from // "/design/silver/icons" // which ale already used by the report overview anyway logoFolder = HandleHome.getTrackplus_Home() + File.separator + HandleHome.LOGOS_DIR + File.separator; } else { // template exists final File template = ReportBL.getDirTemplate(templateID); final ILabelBean templateBean = ReportFacade.getInstance().getByKey(templateID); if (templateBean != null) { baseFileName = templateBean.getLabel(); } try { baseURL = template.toURL(); LOGGER.debug("baseURL: " + baseURL.toString()); } catch (final MalformedURLException e) { LOGGER.error("Wrong template URL for " + template.getName() + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); return null; } try { completeURL = new URL(baseURL.toExternalForm() /* * + * "/"File.separator */ + description.get(IDescriptionAttributes.MASTERFILE)); completeURL.openStream(); LOGGER.debug("completeURL: " + completeURL.toString()); } catch (final Exception me) { LOGGER.error(LocalizeUtil.getParametrizedString( "report.reportExportManager.err.masterFileTemplateNotFound", new String[] { me.getMessage() }, locale) + me); return null; } } if (parameters == null) { parameters = new HashMap<String, Object>(); } parameters.put(JasperReportExporter.REPORT_PARAMETERS.BASE_URL, baseURL); if (logoFolder != null) { parameters.put(JasperReportExporter.REPORT_PARAMETERS.LOGO_FOLDER_URL, logoFolder); } if (completeURL != null) { parameters.put(JasperReportExporter.REPORT_PARAMETERS.COMPLETE_URL, completeURL); } if (baseFileName == null) { baseFileName = "TrackReport"; } baseFileName += DateTimeUtils.getInstance().formatISODateTime(new Date()); response.reset(); final String format = (String) description.get(IDescriptionAttributes.FORMAT); if (ReportExporter.FORMAT_PDF.equals(format)) { response.setHeader("Content-Type", "application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".pdf\""); } else if (ReportExporter.FORMAT_RTF.equals(format)) { response.setHeader("Content-Type", "application/rtf"); response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".rtf\""); } else if (ReportExporter.FORMAT_XML.equals(format)) { response.setHeader("Content-Type", "text/xml"); response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".xml\""); } else if (ReportExporter.FORMAT_HTML.equals(format)) { response.setHeader("Content-Type", "text/html"); response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".html\""); } else if (ReportExporter.FORMAT_ZIP.equals(format)) { response.setHeader("Content-Type", "application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".zip\""); } else if (ReportExporter.FORMAT_XLS.equals(format)) { response.setHeader("Content-Type", "application/xls"); response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".xls\""); } else if (ReportExporter.FORMAT_CSV.equals(format)) { final String csvEncoding = personBean.getCsvEncoding(); LOGGER.debug("csvEncoding is " + csvEncoding); if (csvEncoding != null) { response.setContentType("text/plain; " + csvEncoding); } else { response.setContentType("text/plain; charset=UTF-8"); } response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".csv\""); } else if (ReportExporter.FORMAT_DOCX.equals(format)) { response.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".docx\""); } DownloadUtil.prepareCacheControlHeader(ServletActionContext.getRequest(), response); OutputStream outputStream = null; try { outputStream = response.getOutputStream(); } catch (final IOException e) { LOGGER.error("Getting the output stream failed with " + e.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } try { LOGGER.debug("Exporter type is " + description.get(IDescriptionAttributes.TYPE) + " exporter format is " + description.get(IDescriptionAttributes.FORMAT)); final ReportExporter exporter = ReportExecuteBL .getExporter((String) description.get(IDescriptionAttributes.TYPE)); exporter.exportReport((Document) datasource, personBean, locale, parameters, outputStream, contextMap, description); LOGGER.debug("Export done..."); } catch (final ReportExportException e) { LOGGER.error("Exporting the report failed with " + e.getMessage()); String actionMessage = ""; if (e.getCause() != null) { actionMessage = LocalizeUtil.getParametrizedString(e.getMessage(), new String[] { e.getCause().getMessage() }, locale); } else { actionMessage = LocalizeUtil.getLocalizedTextFromApplicationResources(e.getMessage(), locale); } LOGGER.error(actionMessage); if (LOGGER.isDebugEnabled()) { LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } catch (final Exception e) { LOGGER.error("Exporting the report failed with throwable " + e.getMessage()); if (LOGGER.isDebugEnabled()) { LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } return null; }
From source file:juzu.impl.plugin.asset.AbstractAssetTestCase.java
@Test public void testSatisfied() throws Exception { URL url = applicationURL(); driver.get(url.toString()); List<WebElement> scripts = driver.findElements(getFindBy()); String expected = getExpectedAsset(); if (expected != null) { if (scripts.size() != 1) { throw failure("Was expecting scripts to match the single asset " + expected + " instead of being " + scripts);//from w w w .j a v a2 s . c om } else { String src = scripts.get(0).getAttribute("src"); assertTrue("Was expecting " + src + " to end with " + expected, src.endsWith(expected)); url = new URL(url, src); HttpGet get = new HttpGet(url.toURI()); HttpResponse response = HttpClientBuilder.create().build().execute(get); assertEquals(200, response.getStatusLine().getStatusCode()); assertNotNull(response.getEntity()); Header[] headers = response.getHeaders("Cache-Control"); assertEquals(1, headers.length); assertEquals(getExpectedCacheControl(), headers[0].getValue()); assertEquals(getExpectedContent(), EntityUtils.toString(response.getEntity())); } } else { assertEquals(Collections.emptyList(), scripts); } }
From source file:com.mycompany.crawlertest.GrabPage.java
public void dump() { for (URL url1 : urlList) { System.out.println("Links to " + url1.toString()); }//from w ww . j a v a 2 s . c o m }
From source file:dk.statsbiblioteket.util.xml.XSLT.java
/** * Create or re-use a Transformer for the given xsltLocation. * The Transformer is {@link ThreadLocal}, so the method is thread-safe. * * Warning: A list is maintained for all XSLTs so changes to the xslt will * not be reflected. Call {@link #clearTransformerCache} to clear * the list./*from www.j a v a2 s . c om*/ * * @param xslt the location of the XSLT. * @param parameters for the Transformer. The keys must be Strings. If the map is null, it will be ignored. * @return a Transformer using the given XSLT. * @throws TransformerException if the Transformer could not be constructed. */ public static Transformer getLocalTransformer(URL xslt, Map parameters) throws TransformerException { if (xslt == null) { throw new NullPointerException("The xslt was null"); } Map<String, Transformer> map = localMapCache.get(); Transformer transformer = map.get(xslt.toString()); if (transformer == null) { transformer = createTransformer(xslt); map.put(xslt.toString(), transformer); } assignParameters(transformer, parameters); return transformer; }
From source file:core.GenerateYamlTest.java
@Test public void generateYAML() throws IOException { final int localPort = RULE.getLocalPort(); final String swagger_filename = "/swagger.yaml"; File destination = new File(System.getProperty("baseDir") + "/src/main/resources/", "swagger.yaml"); final URL url = new URL("http", "localhost", localPort, swagger_filename); System.out.println(url.toString()); FileUtils.copyURLToFile(url, destination); }
From source file:gobblin.source.extractor.hadoop.AvroFsHelperTest.java
@Test public void testGetFileStreamSucceedsWithUncompressedFile() throws FileBasedHelperException, IOException { SourceState sourceState = new SourceState(); URL rootUrl = getClass().getResource("/source/"); String rootPath = rootUrl.toString(); sourceState.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, rootPath); AvroFsHelper fsHelper = new AvroFsHelper(sourceState); fsHelper.connect();/* w w w .ja v a 2s. c om*/ URL url = getClass().getResource("/source/simple.tsv"); String path = url.toString(); InputStream in = fsHelper.getFileStream(path); String contents = IOUtils.toString(in, "UTF-8"); Assert.assertEquals(contents, "A\t1\nB\t2\n"); }
From source file:gobblin.source.extractor.hadoop.AvroFsHelperTest.java
@Test public void testGetFileStreamSucceedsWithGZIPFile() throws FileBasedHelperException, IOException { SourceState sourceState = new SourceState(); URL rootUrl = getClass().getResource("/source/"); String rootPath = rootUrl.toString(); sourceState.setProp(ConfigurationKeys.SOURCE_FILEBASED_FS_URI, rootPath); AvroFsHelper fsHelper = new AvroFsHelper(sourceState); fsHelper.connect();/*from w w w .j a v a 2 s .c o m*/ URL url = getClass().getResource("/source/simple.tsv.gz"); String path = url.toString(); InputStream in = fsHelper.getFileStream(path); String contents = IOUtils.toString(in, "UTF-8"); Assert.assertEquals(contents, "A\t1\nB\t2\n"); }
From source file:gov.nasa.jpl.celgene.labkey.LabkeyDumper.java
public LabkeyDumper(URL labkeyUrl, String username, String password) { this.connection = new Connection(labkeyUrl.toString(), username, password); this.labkeyUrl = labkeyUrl; }