List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:edu.mit.media.funf.configured.ConfiguredPipeline.java
public void updateConfig(URL url) { String jsonString = IOUtils.httpGet(url.toExternalForm(), null); updateConfig(jsonString); }
From source file:alien4cloud.paas.cloudify2.rest.external.RestClientExecutor.java
/** * C'tor.// ww w.j a v a 2 s . c o m * * @param httpClient . * @param url . */ public RestClientExecutor(final DefaultHttpClient httpClient, final URL url) { this.httpClient = httpClient; this.urlStr = url.toExternalForm(); if (!this.urlStr.endsWith(FORWARD_SLASH)) { this.urlStr += FORWARD_SLASH; } }
From source file:org.uiautomation.ios.server.grid.SelfRegisteringRemote.java
private boolean isAlreadyRegistered() { HttpClient client = httpClientFactory.getHttpClient(); try {/*from w w w. j a v a 2s .c om*/ URL hubRegistrationURL = new URL(nodeConfig.getRegistrationURL()); URL api = new URL("http://" + hubRegistrationURL.getHost() + ":" + hubRegistrationURL.getPort() + "/grid/api/proxy"); HttpHost host = new HttpHost(api.getHost(), api.getPort()); String id = "http://" + nodeConfig.getHost() + ":" + nodeConfig.getPort(); BasicHttpRequest r = new BasicHttpRequest("GET", api.toExternalForm() + "?id=" + id); HttpResponse response = client.execute(host, r); if (response.getStatusLine().getStatusCode() != 200) { throw new GridException( "hub down or not responding. Reason : " + response.getStatusLine().getReasonPhrase()); } JSONObject o = extractObject(response); return (Boolean) o.get("success"); } catch (Exception e) { throw new GridException("Problem registering with hub", e); } }
From source file:org.eclipse.skalli.services.extension.validators.HostReachableValidator.java
protected void validate(SortedSet<Issue> issues, UUID entityId, Object value, final Severity minSeverity, int item) { if (value == null) { return;//w w w. j a v a 2s .c om } URL url = null; String label = null; if (value instanceof URL) { url = (URL) value; label = url.toExternalForm(); } else if (value instanceof Link) { Link link = (Link) value; try { url = URLUtils.stringToURL(link.getUrl()); label = link.getLabel(); } catch (MalformedURLException e) { CollectionUtils.addSafe(issues, getIssueByReachableHost(minSeverity, entityId, item, link.getUrl())); } } else { try { url = URLUtils.stringToURL(value.toString()); label = url != null ? url.toExternalForm() : value.toString(); } catch (MalformedURLException e) { CollectionUtils.addSafe(issues, getIssueByReachableHost(minSeverity, entityId, item, value.toString())); } } if (url == null) { return; } HttpClient client = Destinations.getClient(url); if (client != null) { HttpResponse response = null; try { HttpParams params = client.getParams(); HttpClientParams.setRedirecting(params, false); // we want to find 301 MOVED PERMANTENTLY HttpGet method = new HttpGet(url.toExternalForm()); LOG.info("GET " + url); //$NON-NLS-1$ response = client.execute(method); int status = response.getStatusLine().getStatusCode(); LOG.info(status + " " + response.getStatusLine().getReasonPhrase()); //$NON-NLS-1$ CollectionUtils.addSafe(issues, getIssueByResponseCode(minSeverity, entityId, item, response.getStatusLine(), label)); } catch (UnknownHostException e) { issues.add(newIssue(Severity.ERROR, entityId, item, TXT_HOST_UNKNOWN, url.getHost())); } catch (ConnectException e) { issues.add(newIssue(Severity.ERROR, entityId, item, TXT_CONNECT_FAILED, url.getHost())); } catch (MalformedURLException e) { issues.add(newIssue(Severity.ERROR, entityId, item, TXT_MALFORMED_URL, url)); } catch (IOException e) { LOG.warn(MessageFormat.format("I/O Exception on validation: {0}", e.getMessage()), e); //$NON-NLS-1$ } catch (RuntimeException e) { LOG.error(MessageFormat.format("RuntimeException on validation: {0}", e.getMessage()), e); //$NON-NLS-1$ } finally { HttpUtils.consumeQuietly(response); } } else { CollectionUtils.addSafe(issues, getIssueByReachableHost(minSeverity, entityId, item, url.getHost())); } }
From source file:com.digitalpebble.storm.crawler.bolt.SimpleFetcherBolt.java
private void handleRedirect(Tuple t, String sourceUrl, String newUrl, Metadata sourceMetadata) { // build an absolute URL URL sURL;//from www.ja v a 2 s.c o m try { sURL = new URL(sourceUrl); URL tmpURL = URLUtil.resolveURL(sURL, newUrl); newUrl = tmpURL.toExternalForm(); } catch (MalformedURLException e) { LOG.debug("MalformedURLException on {} or {}: {}", sourceUrl, newUrl, e); return; } // apply URL filters if (this.urlFilters != null) { newUrl = this.urlFilters.filter(sURL, sourceMetadata, newUrl); } // filtered if (newUrl == null) { return; } Metadata metadata = metadataTransfer.getMetaForOutlink(newUrl, sourceUrl, sourceMetadata); // TODO check that hasn't exceeded max number of redirections _collector.emit(com.digitalpebble.storm.crawler.Constants.StatusStreamName, t, new Values(newUrl, metadata, Status.DISCOVERED)); }
From source file:org.wildfly.test.integration.elytron.rolemappers.AbstractRoleMapperTest.java
private URL prepareRolesPrintingURL(URL webAppURL) throws MalformedURLException { final List<NameValuePair> qparams = new ArrayList<NameValuePair>(); for (final String role : allTestedRoles()) { qparams.add(new BasicNameValuePair(RolePrintingServlet.PARAM_ROLE_NAME, role)); }/*from w w w . j a va2 s . c o m*/ String queryRoles = URLEncodedUtils.format(qparams, "UTF-8"); return new URL( webAppURL.toExternalForm() + RolePrintingServlet.SERVLET_PATH.substring(1) + "?" + queryRoles); }
From source file:com.basho.riak.client.RiakConfig.java
public RiakConfig(URL url) { if (url == null) { throw new IllegalArgumentException(); }// ww w .ja va2 s.c om String protocol = url.getProtocol().toLowerCase(); if (!protocol.equals("http") && !protocol.equals("https")) { throw new IllegalArgumentException(); } this.setUrl(url.toExternalForm()); }
From source file:org.jbpm.formbuilder.server.RESTFileServiceTest.java
public void testSetContextOK() throws Exception { RESTFileService restService = new RESTFileService(); URL pathToClasses = getClass().getResource("/FormBuilder.properties"); String filePath = pathToClasses.toExternalForm(); //assumes compilation is in target/classes filePath = filePath.replace("target/classes/FormBuilder.properties", "src/main/webapp"); filePath = filePath + "/WEB-INF/springComponents.xml"; FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(filePath); ServiceFactory.getInstance().setBeanFactory(ctx); ServletContext context = EasyMock.createMock(ServletContext.class); EasyMock.replay(context);/*from ww w . j a v a 2 s.co m*/ restService.setContext(context); EasyMock.verify(context); FileService service = restService.getFileService(); assertNotNull("service shouldn't be null", service); }
From source file:at.newsagg.parser.FeedParser.java
public ChannelIF parse(ChannelIF cBuilder, File aFile) throws IOException, ParseException { URL aURL = null; try {/*from www.j av a 2 s .co m*/ aURL = aFile.toURL(); } catch (java.net.MalformedURLException e) { throw new IOException("File " + aFile + " had invalid URL " + "representation."); } return parse(cBuilder, new InputSource(aURL.toExternalForm()), aURL); }
From source file:de.jcup.code2doc.renderer.docbook.PDFSpecificationRenderer.java
@Override public File render() throws IOException { if (outputFile.exists()) { FileUtils.forceDelete(outputFile); }/* ww w . j a v a 2 s.c o m*/ /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ /* Create XML */ /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ String property = System.getProperty("code2doc.renderer.docbook.keep_temporary_files"); boolean deleteTempFilesOnExit = property == null; XMLSpecificationFileGenerator xmlFileGEno = new XMLSpecificationFileGenerator(); xmlFileGEno.setFilter(getFilter()); xmlFileGEno.setOutputFileParentFolder(outputFile.getParentFile()); xmlFileGEno.setOutputFileName(outputFile.getName()); xmlFileGEno.setOutputFileDeleteOnExit(deleteTempFilesOnExit); File xmlFile = xmlFileGEno.generate(spec); /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ /* Prepare PDF rendering */ /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ PDFRenderer pdfRenderer = PDFRenderer.create("file:" + xmlFile.getAbsolutePath()); pdfRenderer.parameter("toc.section.depth", "8"); pdfRenderer.parameter("chapter.autolabel", "1"); pdfRenderer.parameter("section.autolabel", "1"); /* * http://docbook.sourceforge.net/release/xsl/current/doc/fo/page.width. * portrait.html */ pdfRenderer.parameter("paper.type", "A4"); /* * http://www.sagehill.net/docbookxsl/SectionNumbering.html# * HTMLDepthSectionNumbers */ pdfRenderer.parameter("section.autolabel.max.depth", "8"); /* http://www.sagehill.net/docbookxsl/XrefPageNums.html */ pdfRenderer.parameter("insert.xref.page.number", "yes"); /* ------------------------- */ /* Source code highlighting */ /* ------------------------- */ // http://www.sagehill.net/docbookxsl/SyntaxHighlighting.html pdfRenderer.parameter("highlight.source", "1"); // http://sourceforge.net/p/xslthl/wiki/Usage/#xalan-27 // http://sourceforge.net/p/xslthl/wiki/Xslthl%20Configuration/ // works: System.setProperty(Config.CONFIG_PROPERTY, // "file:///C:/Temp/docbook/highlighting/xslthl-config.xml"); /* create FOP table of contents inside PDF too */ pdfRenderer.parameter("fop1.extensions", "1"); /* * 'fop.extensions' did * NOT work! */ pdfRenderer.parameter("ulink.show", "0"); URL config = getClass().getResource("/xsl/docbook/highlighting/xslthl-config.xml"); if (config == null) { throw new IllegalStateException("hightlight config not found! Must be inside docbook4j!"); } System.setProperty(Config.CONFIG_PROPERTY, config.toExternalForm()); /* * customize: * http://sagehill.net/docbookxsl/CustomMethods.html#WriteCustomization */ /* * parameter reference: * http://docbook.sourceforge.net/release/xsl/current /doc/fo/index.html */ pdfRenderer.xsl("res:pdf_template.xsl"); try { /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ /* Start PDF rendering*/ /* +++++++++++++++++++++++++++++++++++++++++++++++++ */ InputStream in = pdfRenderer.render(); FileOutputStream out = new FileOutputStream(outputFile); IOUtils.copy(in, out); return outputFile; } catch (Docbook4JException e) { throw new IOException("Cannot create file : " + outputFile.getAbsolutePath(), e); } }