List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:ca.nrc.cadc.sc2pkg.PackageIntTest.java
@Test public void testSingleArtifactRedirectCAOM() { try {//w w w . j a va2 s. com URL serviceURL = reg.getServiceURL(URI.create(SERVICE_ID), Standards.PKG_10, AuthMethod.ANON); URL url = new URL(serviceURL.toExternalForm() + "?ID=" + SINGLE_ARTIFACT); log.info("testSingleArtifactRedirect: " + url); ByteArrayOutputStream bos = new ByteArrayOutputStream(); HttpDownload get = new HttpDownload(url, bos); get.setFollowRedirects(false); get.run(); Assert.assertNull("throwable", get.getThrowable()); Assert.assertEquals(303, get.getResponseCode()); URL rurl = get.getRedirectURL(); log.info("testSingleArtifactRedirect location: " + rurl); Assert.assertNotNull(rurl); Assert.assertEquals("/data/pub/IRIS/I212B1H0", rurl.getPath()); } catch (Exception unexpected) { log.error("unexpected exception", unexpected); Assert.fail("unexpected exception: " + unexpected); } }
From source file:ca.nrc.cadc.sc2pkg.PackageIntTest.java
@Test public void testSingleArtifactRedirectIVO() { try {/* w ww . j a v a 2 s. c o m*/ URL serviceURL = reg.getServiceURL(URI.create(SERVICE_ID), Standards.PKG_10, AuthMethod.ANON); URL url = new URL(serviceURL.toExternalForm() + "?ID=" + SINGLE_ARTIFACT_PUB); log.info("testSingleArtifactRedirect: " + url); ByteArrayOutputStream bos = new ByteArrayOutputStream(); HttpDownload get = new HttpDownload(url, bos); get.setFollowRedirects(false); get.run(); Assert.assertNull("throwable", get.getThrowable()); Assert.assertEquals(303, get.getResponseCode()); URL rurl = get.getRedirectURL(); log.info("testSingleArtifactRedirect location: " + rurl); Assert.assertNotNull(rurl); Assert.assertEquals("/data/pub/IRIS/I212B1H0", rurl.getPath()); } catch (Exception unexpected) { log.error("unexpected exception", unexpected); Assert.fail("unexpected exception: " + unexpected); } }
From source file:com.esri.gpt.catalog.arcgis.metadata.AGSInterrogator.java
/** * Interrogates the character response from a target resource URL attempting to * determine the REST and SOAP endpoints for an ArcGIS server services catalog. * @param url the target URL associated with the resource being interrogated * @param response the character based response previously returned from the target URL * @return <code>true</code> if the target was recognized as an ArcGIS server endpoint *//*from w w w .j a v a 2s. c o m*/ public boolean interrogate(URL url, String response) throws IOException { String fullUrl = url.toExternalForm(); this.target.setTargetUrl(fullUrl); String servicesRoot = ""; boolean likelyRestHtml = response .contains("<meta name=\"keywords\" content=\"ArcGIS Services Directory Root\"") || response.contains("ArcGIS Services Directory Root") || response.contains("<td id=\"breadcrumbs\">"); // determine the services directory root (REST) if (likelyRestHtml) { String chk = "<td id=\"breadcrumbs\">"; String tmp; int idx = response.indexOf(chk); if (idx != -1) { tmp = response.substring(idx + chk.length()); chk = "<a href=\""; idx = tmp.indexOf(chk); if (idx != -1) { tmp = tmp.substring(idx + chk.length()); chk = "\">"; //chk = "\">Home</a>"; idx = tmp.indexOf(chk); if (idx != -1) { String relative = Val.chkStr(tmp.substring(0, idx)); if (relative.length() > 0) { idx = fullUrl.toLowerCase().indexOf(relative.toLowerCase()); if (idx != -1) { servicesRoot = fullUrl.substring(0, (idx + relative.length())); } } } } } } // if a services directory root (REST) was found, // flag and attempt to determine the services directory root (SOAP) if (servicesRoot.length() > 0) { this.target.setRestUrl(servicesRoot); this.target.setWasRecognized(true); boolean isRoot = servicesRoot.equals(fullUrl); boolean hasFolders = response.contains("<ul id='folderList'>"); boolean hasServices = response.contains("<ul id='serviceList'>"); boolean isContainer = isRoot || hasFolders || hasServices || response.contains("<title>Folder:"); if (isRoot) { this.target.setTargetType(AGSTarget.TargetType.ROOT); } else if (isContainer) { this.target.setTargetType(AGSTarget.TargetType.FOLDER); } // determine the services directory root (SOAP) this.determineSoapUrl(); } return this.target.getWasRecognized(); }
From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java
@Test public void testIgnorePatternsWithExactMatching() throws Exception { final AuthenticationFilter f = new AuthenticationFilter(); final MockServletContext context = new MockServletContext(); context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL); final URL url = new URL(CAS_SERVICE_URL + "?param=valueToIgnore"); context.addInitParameter("ignorePattern", url.toExternalForm()); context.addInitParameter("ignoreUrlPatternType", "EXACT"); context.addInitParameter("service", CAS_SERVICE_URL); f.init(new MockFilterConfig(context)); final MockHttpServletRequest request = new MockHttpServletRequest(); request.setScheme(url.getProtocol()); request.setServerName(url.getHost()); request.setServerPort(url.getPort()); request.setQueryString(url.getQuery()); request.setRequestURI(url.getPath()); final MockHttpSession session = new MockHttpSession(); request.setSession(session);/* w w w .ja v a2 s .c om*/ final MockHttpServletResponse response = new MockHttpServletResponse(); final FilterChain filterChain = new FilterChain() { public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { } }; f.doFilter(request, response, filterChain); assertNull(response.getRedirectedUrl()); }
From source file:eu.markov.jenkins.plugin.mvnmeta.MavenMetadataParameterDefinition.java
private MavenMetadataVersions getArtifactMetadata() { InputStream input = null;/*from w ww . j a va 2s. c o m*/ try { URL url = new URL(getArtifactUrlForPath("maven-metadata.xml")); LOGGER.finest("Requesting metadata from URL: " + url.toExternalForm()); URLConnection conn = url.openConnection(); if (StringUtils.isNotBlank(url.getUserInfo())) { LOGGER.finest("Using implicit UserInfo"); String encodedAuth = new String(Base64.encodeBase64(url.getUserInfo().getBytes(UTF8)), UTF8); conn.addRequestProperty("Authorization", "Basic " + encodedAuth); } if (StringUtils.isNotBlank(this.username) && StringUtils.isNotBlank(this.password)) { LOGGER.finest("Using explicit UserInfo"); String userpassword = username + ":" + password; String encodedAuthorization = new String(Base64.encodeBase64(userpassword.getBytes(UTF8)), UTF8); conn.addRequestProperty("Authorization", "Basic " + encodedAuthorization); } input = conn.getInputStream(); JAXBContext context = JAXBContext.newInstance(MavenMetadataVersions.class); Unmarshaller unmarshaller = context.createUnmarshaller(); MavenMetadataVersions metadata = (MavenMetadataVersions) unmarshaller.unmarshal(input); if (sortOrder == SortOrder.DESC) { Collections.reverse(metadata.versioning.versions); } metadata.versioning.versions = filterVersions(metadata.versioning.versions); return metadata; } catch (Exception e) { LOGGER.log(Level.WARNING, "Could not parse maven-metadata.xml", e); MavenMetadataVersions result = new MavenMetadataVersions(); result.versioning.versions.add("<" + e.getClass().getName() + ": " + e.getMessage() + ">"); return result; } finally { try { if (input != null) input.close(); } catch (IOException e) { // ignore } } }
From source file:ca.nrc.cadc.sc2pkg.PackageIntTest.java
public void testSingleArtifactRedirectAuthCAOM() { try {/*ww w . j a v a2s . com*/ URL serviceURL = reg.getServiceURL(URI.create(SERVICE_ID), Standards.PKG_10, AuthMethod.PASSWORD); URL url = new URL(serviceURL.toExternalForm() + "?ID=" + SINGLE_ARTIFACT); log.info("testSingleArtifactRedirectAuth: " + url); ByteArrayOutputStream bos = new ByteArrayOutputStream(); HttpDownload get = new HttpDownload(url, bos); get.setRequestProperty("Authorization", "***REDACTED***"); get.setFollowRedirects(false); get.run(); Assert.assertNull("throwable", get.getThrowable()); Assert.assertEquals(303, get.getResponseCode()); URL rurl = get.getRedirectURL(); log.info("testSingleArtifactRedirectAuth location: " + rurl); Assert.assertNotNull(rurl); Assert.assertEquals("http", rurl.getProtocol()); Assert.assertEquals("/data/auth/IRIS/I212B1H0", rurl.getPath()); } catch (Exception unexpected) { log.error("unexpected exception", unexpected); Assert.fail("unexpected exception: " + unexpected); } }
From source file:ca.nrc.cadc.sc2pkg.PackageIntTest.java
public void testSingleArtifactRedirectAuthIVO() { try {// w ww.j av a 2 s .c o m URL serviceURL = reg.getServiceURL(URI.create(SERVICE_ID), Standards.PKG_10, AuthMethod.PASSWORD); URL url = new URL(serviceURL.toExternalForm() + "?ID=" + SINGLE_ARTIFACT_PUB); log.info("testSingleArtifactRedirectAuth: " + url); ByteArrayOutputStream bos = new ByteArrayOutputStream(); HttpDownload get = new HttpDownload(url, bos); get.setRequestProperty("Authorization", "***REDACTED***"); get.setFollowRedirects(false); get.run(); Assert.assertNull("throwable", get.getThrowable()); Assert.assertEquals(303, get.getResponseCode()); URL rurl = get.getRedirectURL(); log.info("testSingleArtifactRedirectAuth location: " + rurl); Assert.assertNotNull(rurl); Assert.assertEquals("http", rurl.getProtocol()); Assert.assertEquals("/data/auth/IRIS/I212B1H0", rurl.getPath()); } catch (Exception unexpected) { log.error("unexpected exception", unexpected); Assert.fail("unexpected exception: " + unexpected); } }
From source file:de.kp.ames.web.core.rss.RssConsumer.java
/** * Executes a service request and returns * a ROME SyndFeed object/*from w w w . j a va 2 s .c o m*/ * * @param method * @param params * @return */ public SyndFeed execute(String method, Map<String, String> params) { URL feedUrl = buildUrl(method, params); SyndFeed feed = null; try { feed = fetcher.retrieveFeed(feedUrl); } catch (FetcherException e) { throw new RuntimeException("Failed to fetch URL:[" + feedUrl.toExternalForm() + "]. HTTP Response code:[" + e.getResponseCode() + "]", e); } catch (FeedException e) { throw new RuntimeException("Failed to parse response for URL:[" + feedUrl.toString() + "]", e); } catch (IOException e) { throw new RuntimeException("IO Error fetching URL:[" + feedUrl.toString() + "]", e); } return feed; }
From source file:javarestart.WebClassLoader.java
public InputStream getPreLoadedResourceAsStream(URL url) throws IOException { byte[] bytes = getPreloadResource(url); if (bytes == null) { throw new FileNotFoundException("Resource not found: " + url.toExternalForm()); }//from w w w .j ava 2 s. c om return new ByteArrayInputStream(bytes); }
From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityStoreConnector.java
public String getCurrentTraceabilityRecordId(URL serviceId) { // URI encoded RestTemplate restTemplate = new RestTemplate(); // restTemplate.get ResponseEntity<String> traceabilityResponseEntity = null; try {/*w w w . j a va 2 s . c o m*/ traceabilityResponseEntity = restTemplate.getForEntity(serviceId.toExternalForm(), String.class); if (traceabilityResponseEntity.getStatusCode().value() == 200) { return traceabilityResponseEntity.getBody(); } else { return null; } } catch (org.springframework.web.client.HttpClientErrorException ex) { logger.warn(ex.toString()); return null; } }