List of usage examples for java.net URL toString
public String toString()
From source file:org.dozer.spring.DozerBeanMapperFactoryBean.java
private void loadMappingFiles() throws IOException { if (this.mappingFiles != null) { final List<String> mappings = new ArrayList<String>(this.mappingFiles.length); for (Resource mappingFile : this.mappingFiles) { URL url = mappingFile.getURL(); mappings.add(url.toString()); }/* w w w. jav a2s . com*/ this.beanMapper.setMappingFiles(mappings); } }
From source file:br.com.uol.runas.classloader.JarClassLoader.java
private void addUrlsFromJar(URL url) throws IOException, MalformedURLException { final JarURLConnection jarConnection = (JarURLConnection) url.openConnection(); jarFile = jarConnection.getJarFile(); final Enumeration<JarEntry> entries = jarFile.entries(); final URL jarUrl = new File(jarFile.getName()).toURI().toURL(); final String base = jarUrl.toString(); addURL(jarUrl);//from w w w . j a va 2s . c o m while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (entry.isDirectory() || endsWithAny(entry.getName(), ".jar", ".war", ".ear")) { addURL(new URL(base + entry.getName())); } } }
From source file:it.cloudicaro.disit.kb.rdf.HttpUtil.java
public static String post(URL url, String data, String contentType, String user, String passwd) throws Exception { //System.out.println("POST "+url); HttpClient client = HttpClients.createDefault(); HttpPost request = new HttpPost(url.toURI()); request.setEntity(new StringEntity(data, ContentType.create(contentType, "UTF-8"))); HttpClientContext context = HttpClientContext.create(); if (user != null && passwd != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, passwd)); context.setCredentialsProvider(credsProvider); }// ww w.j a v a 2s .com HttpResponse response = client.execute(request, context); StatusLine s = response.getStatusLine(); int code = s.getStatusCode(); //System.out.println(code); if (code == 204) return ""; if (code != 200) throw new Exception( "failed access to " + url.toString() + " code: " + code + " " + s.getReasonPhrase()); Reader reader = null; try { reader = new InputStreamReader(response.getEntity().getContent()); StringBuilder sb = new StringBuilder(); { int read; char[] cbuf = new char[1024]; while ((read = reader.read(cbuf)) != -1) { sb.append(cbuf, 0, read); } } return sb.toString(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.google.apphosting.vmruntime.jetty9.VmRuntimeJettySessionTest.java
public void testSsl_WithSSL() throws Exception { HttpClient httpClient = new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000); URL url = createUrl("/test-ssl"); GetMethod get = new GetMethod(url.toString()); get.addRequestHeader(VmApiProxyEnvironment.HTTPS_HEADER, "on"); int httpCode = httpClient.executeMethod(get); assertEquals(200, httpCode);// w w w . j a v a 2 s. co m assertEquals("true:https:https://localhost/test-ssl", get.getResponseBodyAsString()); }
From source file:halfpipe.properties.UrlPropertiesSource.java
/** * Retrieve the content of the property files. For each poll, it always * returns the complete union of properties defined in all URLs. If one * property is defined in content of more than one URL, the value in file later on the * list will override the value in the previous one. * * @param initial this parameter is ignored by the implementation * @param checkPoint this parameter is ignored by the implementation * @throws IOException IOException occurred in file operation *///from ww w. j ava 2s .com @Override public PollResult poll(boolean initial, Object checkPoint) throws IOException { if (configUrls == null || configUrls.length == 0) { return PollResult.createFull(null); } Map<String, Object> map = new HashMap<String, Object>(); for (URL url : configUrls) { String urlString = url.toString().toLowerCase(); if (urlString.endsWith(".yaml") || urlString.endsWith(".yml")) { try { loadConfig(map, new YamlProperties(url)); } catch (ConfigurationException e) { throw new IOException("Error loading YamlProperties file " + url, e); } } else { loadConfig(map, url); } } return PollResult.createFull(map); }
From source file:net.sf.nmedit.jtheme.store.StorageContext.java
protected Image getImage(URL imageURL) { String key = imageURL.toString(); Image image = imageMap.get(key); if (image == null) { try {/* w w w.java 2s. c o m*/ image = ImageIO.read(imageURL); imageMap.put(key, image); } catch (IOException e) { Log log = getLog(); if (log.isWarnEnabled()) { log.warn("getImage(" + imageURL + ") failed", e); } } } return image; }
From source file:fr.norad.visuwall.core.persistence.entity.SoftwareAccess.java
public void setUrl(URL url) { this.url = url.toString(); }
From source file:com.omertron.omdbapi.OmdbApi.java
private String requestWebPage(URL url) throws OMDBException { LOG.trace("Requesting: {}", url.toString()); try {//from www . j a v a2 s . c o m final HttpGet httpGet = new HttpGet(url.toURI()); httpGet.addHeader("accept", "application/json"); httpGet.addHeader(HTTP.USER_AGENT, UserAgentSelector.randomUserAgent()); final DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, charset); if (response.getStatusCode() >= HTTP_STATUS_500) { throw new OMDBException(ApiExceptionType.HTTP_503_ERROR, response.getContent(), response.getStatusCode(), url); } else if (response.getStatusCode() >= HTTP_STATUS_300) { throw new OMDBException(ApiExceptionType.HTTP_404_ERROR, response.getContent(), response.getStatusCode(), url); } return response.getContent(); } catch (URISyntaxException ex) { throw new OMDBException(ApiExceptionType.INVALID_URL, "Invalid URL", url, ex); } catch (IOException ex) { throw new OMDBException(ApiExceptionType.CONNECTION_ERROR, "Error retrieving URL", url, ex); } }
From source file:eu.matejkormuth.crawler2.PageFetcher.java
/** * Returns Document representation of content on specified URL. * /*from ww w . ja v a 2 s . com*/ * @param url * URL of document * @return Document representating content of specified URL */ public Document fetch(URL url) { HttpUriRequest request = this.createRequest(url); try { LOG.debug("Fetching " + url.toString() + "..."); return this.execute(request, url); } catch (IOException e) { LOG.error("Can't execute request.", e); return null; } }
From source file:org.fcrepo.auth.oauth.integration.api.ContainerWrapper.java
public void start() throws Exception { final JAXBContext context = JAXBContext.newInstance(WebAppConfig.class); final Unmarshaller u = context.createUnmarshaller(); final WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResource(this.configLocation)); final URI uri = URI.create("http://localhost:" + port + "/"); final Map<String, String> initParams = new HashMap<String, String>(); server = GrizzlyWebContainerFactory.create(uri, initParams); // create a "root" web application final WebappContext wac = new WebappContext(o.displayName(), ""); for (final ContextParam p : o.contextParams()) { wac.addContextInitParameter(p.name(), p.value()); }//from ww w . ja v a 2 s . c o m for (final Listener l : o.listeners) { wac.addListener(l.className()); } for (final Servlet s : o.servlets) { final ServletRegistration servlet = wac.addServlet(s.servletName(), s.servletClass()); final Collection<ServletMapping> mappings = o.servletMappings(s.servletName()); for (final ServletMapping sm : mappings) { servlet.addMapping(sm.urlPattern()); } for (final InitParam p : s.initParams()) { servlet.setInitParameter(p.name(), p.value()); } } for (final Filter f : o.filters) { final FilterRegistration filter = wac.addFilter(f.filterName(), f.filterClass()); final Collection<FilterMapping> mappings = o.filterMappings(f.filterName()); for (final FilterMapping sm : mappings) { final String urlPattern = sm.urlPattern(); final String servletName = sm.servletName(); if (urlPattern != null) { filter.addMappingForUrlPatterns(null, urlPattern); } else { filter.addMappingForServletNames(null, servletName); } } for (final InitParam p : f.initParams()) { filter.setInitParameter(p.name(), p.value()); } } wac.deploy(server); final URL webXml = this.getClass().getResource("/web.xml"); logger.error(webXml.toString()); logger.debug("started grizzly webserver endpoint at " + server.getHttpHandler().getName()); }