List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:org.seedstack.coffig.provider.JacksonProvider.java
private MapNode buildTreeFromSource(URL url) { try {// www . j a v a 2 s .co m return buildTreeFromFields(jacksonMapper.readTree(url)); } catch (IOException e) { throw ConfigurationException.wrap(e, ConfigurationErrorCode.FAILED_TO_READ_CONFIGURATION).put("url", url.toExternalForm()); } }
From source file:org.jboss.as.test.clustering.cluster.web.shared.SharedSessionTestCase.java
@Test public void test(@ArquillianResource @OperateOnDeployment(DEPLOYMENT_1) URL baseURLDep1, @ArquillianResource @OperateOnDeployment(DEPLOYMENT_2) URL baseURLDep2) throws URISyntaxException, IOException { URI baseURI1 = new URI(baseURLDep1.toExternalForm() + "/"); URI baseURI2 = new URI(baseURLDep2.toExternalForm() + "/"); URI uri11 = SimpleServlet.createURI(baseURI1.resolve(MODULE_1 + "/")); URI uri12 = SimpleServlet.createURI(baseURI1.resolve(MODULE_2 + "/")); URI uri21 = SimpleServlet.createURI(baseURI2.resolve(MODULE_1 + "/")); URI uri22 = SimpleServlet.createURI(baseURI2.resolve(MODULE_2 + "/")); try (CloseableHttpClient client = TestHttpClientUtils.promiscuousCookieHttpClient()) { int expected = 1; try (CloseableHttpResponse response = client.execute(new HttpGet(uri11))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); }/* ww w .j ava2 s.c om*/ try (CloseableHttpResponse response = client.execute(new HttpGet(uri12))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri21))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } try (CloseableHttpResponse response = client.execute(new HttpGet(uri22))) { Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatusLine().getStatusCode()); Assert.assertEquals(expected++, Integer.parseInt(response.getFirstHeader(SimpleServlet.VALUE_HEADER).getValue())); } } }
From source file:org.picketbox.test.config.ProtectedResourceManagerUnitTestCase.java
@Override protected void establishUserApps() { ClassLoader tcl = Thread.currentThread().getContextClassLoader(); if (tcl == null) { tcl = getClass().getClassLoader(); }//from w ww . j a v a2s . c o m final String WEBAPPDIR = "auth/webapp"; final String CONTEXTPATH = "/auth"; // for localhost:port/admin/index.html and whatever else is in the webapp directory final URL warUrl = tcl.getResource(WEBAPPDIR); final String warUrlString = warUrl.toExternalForm(); WebAppContext webapp = createWebApp(CONTEXTPATH, warUrlString); server.setHandler(webapp); /* * Context context = new WebAppContext(warUrlString, CONTEXTPATH); server.setHandler(context); */ // Thread.currentThread().setContextClassLoader(context.getClassLoader()); Thread.currentThread().setContextClassLoader(webapp.getClassLoader()); System.setProperty(PicketBoxConstants.USERNAME, "Aladdin"); System.setProperty(PicketBoxConstants.CREDENTIAL, "Open Sesame"); FilterHolder filterHolder = new FilterHolder(DelegatingSecurityFilter.class); /* * Map<String, String> contextParameters = new HashMap<String, String>(); * contextParameters.put(PicketBoxConstants.AUTHENTICATION_KEY, PicketBoxConstants.HTTP_DIGEST); * contextParameters.put(PicketBoxConstants.USER_ATTRIBUTE_NAME, "authenticatedUser"); * contextParameters.put(PicketBoxConstants.HTTP_CONFIGURATION_PROVIDER, * ProtectedResourcesConfigurationProvider.class.getName()); context.setInitParams(contextParameters); * * context.addFilter(filterHolder, "/*", 1); */ webapp.setInitParameter(PicketBoxConstants.AUTHENTICATION_KEY, PicketBoxConstants.HTTP_DIGEST); webapp.setInitParameter(PicketBoxConstants.HTTP_CONFIGURATION_PROVIDER, ProtectedResourcesConfigurationProvider.class.getName()); /* * context.setInitParams(contextParameters); * * context.addFilter(filterHolder, "/*", 1); */ ServletHandler servletHandler = new ServletHandler(); servletHandler.addFilter(filterHolder, createFilterMapping("/*", filterHolder)); webapp.setServletHandler(servletHandler); }
From source file:fr.jayasoft.ivy.url.HttpClientDownloader.java
private GetMethod doGet(URL url) throws IOException, HttpException { HttpClient client = new HttpClient(); if (useAuthentication()) { client.getState().setCredentials(_realm, _host, new UsernamePasswordCredentials(_userName, _passwd)); }/*from w w w . j ava2s .c o m*/ GetMethod get = new GetMethod(url.toExternalForm()); get.setDoAuthentication(useAuthentication()); client.executeMethod(get); return get; }
From source file:jp.dip.komusubi.botter.Configuration.java
/** * //from w ww. j a v a 2 s . c o m * @param url * @param modified */ public void setLastModified(URL url, Date modified) { // ????????? if (getPropertyDate(url.toExternalForm()).after(modified)) { logger.warn( "???????????????: " + "property: {}, modified: {}", getPropertyDate(url.toExternalForm()), modified); return; } setLastModified(url, DateFormatUtils.format(modified, getDateFormatPattern()[0])); }
From source file:com.opensymphony.xwork2.util.finder.UrlSet.java
private List<URL> getUrls(ClassLoaderInterface classLoader, Set<String> protocols) throws IOException { if (protocols == null) { return getUrls(classLoader); }/*ww w . j a v a 2 s . co m*/ List<URL> list = new ArrayList<URL>(); //find jars ArrayList<URL> urls = Collections.list(classLoader.getResources("META-INF")); for (URL url : urls) { if (protocols.contains(url.getProtocol())) { String externalForm = url.toExternalForm(); //build a URL pointing to the jar, instead of the META-INF dir url = new URL(StringUtils.substringBefore(externalForm, "META-INF")); list.add(url); } else if (LOG.isDebugEnabled()) LOG.debug("Ignoring URL [#0] because it is not a valid protocol", url.toExternalForm()); } return list; }
From source file:com.opensymphony.xwork2.util.finder.UrlSet.java
private List<URL> getUrls(ClassLoaderInterface classLoader) throws IOException { List<URL> list = new ArrayList<URL>(); //find jars// ww w . j ava 2 s .c om ArrayList<URL> urls = Collections.list(classLoader.getResources("META-INF")); for (URL url : urls) { if ("jar".equalsIgnoreCase(url.getProtocol())) { String externalForm = url.toExternalForm(); //build a URL pointing to the jar, instead of the META-INF dir url = new URL(StringUtils.substringBefore(externalForm, "META-INF")); list.add(url); } else if (LOG.isDebugEnabled()) LOG.debug("Ignoring URL [#0] because it is not a jar", url.toExternalForm()); } //usually the "classes" dir list.addAll(Collections.list(classLoader.getResources(""))); return list; }
From source file:de.smartics.maven.plugin.jboss.modules.parser.ModulesXmlLocator.java
private void loadModules(final List<ModulesDescriptor> modules, final URL url, final List<String> fileList) throws IOException { for (final String file : fileList) { if (!file.endsWith(".xml")) { continue; }// w ww.j a va 2s .com final URL fileUrl = new URL(url.toExternalForm() + '/' + file); final InputStream input = new BufferedInputStream(fileUrl.openStream()); final String urlString = fileUrl.toExternalForm(); try { final ModulesDescriptor descriptor = parser.parse(urlString, input); modules.add(descriptor); } catch (final JDOMException e) { throw new IOException("Cannot parse XML file: " + urlString, e); } finally { IOUtils.closeQuietly(input); } } }
From source file:com.aurel.track.dbase.HandleHome.java
public static void initGroovyPlugins(ServletContext servletContext) { URL groovyURL = null; try {/*w ww .ja v a 2s . c o m*/ groovyURL = servletContext.getResource("/WEB-INF/" + TORQUE_FILE); String path = groovyURL.toExternalForm(); path = path.substring(0, path.lastIndexOf(TORQUE_FILE) - 1) + File.separator + "classes" + File.separator + PLUGINS_DIR + File.separator + "groovy" + File.separator; groovyURL = new URL(path); } catch (Exception ge) { System.err.println("Can't get the Groovy URL"); // What can we do here? } Constants.setGroovyURL(groovyURL); }