List of usage examples for java.net URL toString
public String toString()
From source file:it.cloudicaro.disit.kb.rdf.HttpUtil.java
public static void delete(URL url, String user, String passwd) throws Exception { //System.out.println("DELETE "+url); HttpClient client = HttpClients.createDefault(); HttpDelete request = new HttpDelete(url.toURI()); HttpClientContext context = HttpClientContext.create(); if (user != null && passwd != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, passwd)); context.setCredentialsProvider(credsProvider); }//w w w .j a v a 2 s .c o m HttpResponse response = client.execute(request, context); StatusLine s = response.getStatusLine(); int code = s.getStatusCode(); //System.out.println(code); if (code != 204 && code != 404) throw new Exception( "failed access to " + url.toString() + " code: " + code + " " + s.getReasonPhrase()); }
From source file:org.jboss.as.test.integration.web.sso.SSOTestBase.java
public static void executeNoAuthSingleSignOnTest(URL serverA, URL serverB, Logger log) throws Exception { URL warA1 = new URL(serverA, "/war1/"); URL warB2 = new URL(serverB + "/war2/"); URL warB6 = new URL(serverB + "/war6/"); // Start by accessing the secured index.html of war1 DefaultHttpClient httpclient = new DefaultHttpClient(); checkAccessDenied(httpclient, warA1 + "index.html"); CookieStore store = httpclient.getCookieStore(); log.debug("Saw JSESSIONID=" + getSessionIdValueFromState(store)); // Submit the login form executeFormLogin(httpclient, warA1); String ssoID = processSSOCookie(store, serverA.toString(), serverB.toString()); log.debug("Saw JSESSIONIDSSO=" + ssoID); // Now try getting the war2 index using the JSESSIONIDSSO cookie log.debug("Prepare /war2/index.html get"); checkAccessAllowed(httpclient, warB2 + "index.html"); // Access a secured servlet that calls a secured ejb in war2 to test // propagation of the SSO identity to the ejb container. checkAccessAllowed(httpclient, warB2 + "EJBServlet"); // Do the same test on war6 to test SSO auth replication with no auth // configured war checkAccessAllowed(httpclient, warB6 + "index.html"); checkAccessAllowed(httpclient, warB2 + "EJBServlet"); }
From source file:com.comcast.cmb.test.tools.CNSTestingUtils.java
public static String sendHttpMessage(String endpoint, String message) throws Exception { if ((message == null) || (endpoint == null)) { throw new Exception("Message and Endpoint must both be set"); }//ww w . j a v a 2 s . c om String newPostBody = message; byte newPostBodyBytes[] = newPostBody.getBytes(); URL url = new URL(endpoint); logger.info(">> " + url.toString()); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); // POST no matter what con.setDoOutput(true); con.setDoInput(true); con.setFollowRedirects(false); con.setUseCaches(true); logger.info(">> " + "GET"); //con.setRequestProperty("content-length", newPostBody.length() + ""); con.setRequestProperty("host", url.getHost()); con.connect(); logger.info(">> " + newPostBody); int statusCode = con.getResponseCode(); BufferedInputStream responseStream; logger.info("StatusCode:" + statusCode); if (statusCode != 200 && statusCode != 201) { responseStream = new BufferedInputStream(con.getErrorStream()); } else { responseStream = new BufferedInputStream(con.getInputStream()); } int b; String response = ""; while ((b = responseStream.read()) != -1) { response += (char) b; } logger.info("response:" + response); return response; }
From source file:demo.wssec.sts.Server.java
protected Server() throws Exception { System.out.println("Starting STS"); SpringBusFactory bf = new SpringBusFactory(); URL busFile = new ClassPathResource("wssec-sts.xml").getURL(); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus);// ww w. ja va 2s . c o m }
From source file:demo.wssec.server.Server.java
protected Server() throws Exception { System.out.println("Starting Server"); SpringBusFactory bf = new SpringBusFactory(); URL busFile = new ClassPathResource("wssec-server.xml").getURL(); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus);/*w w w . ja v a2s. com*/ }
From source file:URLLabel.java
public URLLabel(URL url) { this(url, url.toString()); }
From source file:io.fabric8.maven.core.util.kubernetes.KubernetesResourceUtil.java
public static void validateKubernetesMasterUrl(URL masterUrl) throws MojoExecutionException { if (masterUrl == null || StringUtils.isBlank(masterUrl.toString())) { throw new MojoExecutionException( "Cannot find Kubernetes master URL. Have you started a cluster via `mvn fabric8:cluster-start` or connected to a remote cluster via `kubectl`?"); }// w w w . j av a 2 s . c o m }
From source file:com.alibaba.jstorm.blobstore.BlobStoreUtils.java
public static void downloadLocalStormCode(Map conf, String topologyId, String masterCodeDir) throws IOException, TException { // STORM_LOCAL_DIR/supervisor/tmp/(UUID) String tmpRoot = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString(); // STORM-LOCAL-DIR/supervisor/stormdist/storm-id String stormRoot = StormConfig.supervisor_stormdist_root(conf, topologyId); BlobStore blobStore = null;/*from w w w. j a v a 2 s .co m*/ try { blobStore = BlobStoreUtils.getNimbusBlobStore(conf, masterCodeDir, null); FileUtils.forceMkdir(new File(tmpRoot)); blobStore.readBlobTo(StormConfig.master_stormcode_key(topologyId), new FileOutputStream(StormConfig.stormcode_path(tmpRoot))); blobStore.readBlobTo(StormConfig.master_stormconf_key(topologyId), new FileOutputStream(StormConfig.stormconf_path(tmpRoot))); } finally { if (blobStore != null) blobStore.shutdown(); } File srcDir = new File(tmpRoot); File destDir = new File(stormRoot); try { FileUtils.moveDirectory(srcDir, destDir); } catch (FileExistsException e) { FileUtils.copyDirectory(srcDir, destDir); FileUtils.deleteQuietly(srcDir); } ClassLoader classloader = Thread.currentThread().getContextClassLoader(); String resourcesJar = resourcesJar(); URL url = classloader.getResource(StormConfig.RESOURCES_SUBDIR); String targetDir = stormRoot + '/' + StormConfig.RESOURCES_SUBDIR; if (resourcesJar != null) { LOG.info("Extracting resources from jar at " + resourcesJar + " to " + targetDir); JStormUtils.extractDirFromJar(resourcesJar, StormConfig.RESOURCES_SUBDIR, stormRoot); } else if (url != null) { LOG.info("Copying resources at " + url.toString() + " to " + targetDir); FileUtils.copyDirectory(new File(url.getFile()), (new File(targetDir))); } }
From source file:org.localmatters.lesscss4j.spring.SpringStyleSheetResourceLoader.java
public StyleSheetResource getResource(URL url) { return new SpringStyleSheetResource(getResourceLoader().getResource(url.toString())); }
From source file:net.sf.firemox.tools.Picture.java
/** * Download a file from the specified URL to the specified local file. * //from w ww . j av a 2 s .c om * @param localFile * is the new card's picture to try first * @param remoteFile * is the URL where this picture will be downloaded in case of the * specified card name has not been found locally. * @param listener * the component waiting for this picture. * @since 0.83 Empty file are deleted to force file to be downloaded. */ public static synchronized void download(String localFile, URL remoteFile, MonitoredCheckContent listener) { BufferedOutputStream out = null; BufferedInputStream in = null; File toDownload = new File(localFile); if (toDownload.exists() && toDownload.length() == 0 && toDownload.canWrite()) { toDownload.delete(); } if (!toDownload.exists() || (toDownload.length() == 0 && toDownload.canWrite())) { // the file has to be downloaded try { if ("file".equals(remoteFile.getProtocol())) { File localRemoteFile = MToolKit .getFile(remoteFile.toString().substring(7).replaceAll("%20", " "), false); int contentLength = (int) localRemoteFile.length(); Log.info("Copying from " + localRemoteFile.getAbsolutePath()); LoaderConsole.beginTask( LanguageManager.getString("downloading") + " " + localRemoteFile.getAbsolutePath() + "(" + FileUtils.byteCountToDisplaySize(contentLength) + ")"); // Copy file in = new BufferedInputStream(new FileInputStream(localRemoteFile)); byte[] buf = new byte[2048]; int currentLength = 0; boolean succeed = false; for (int bufferLen = in.read(buf); bufferLen >= 0; bufferLen = in.read(buf)) { if (!succeed) { toDownload.getParentFile().mkdirs(); out = new BufferedOutputStream(new FileOutputStream(localFile)); succeed = true; } currentLength += bufferLen; if (out != null) { out.write(buf, 0, bufferLen); } if (listener != null) { listener.updateProgress(contentLength, currentLength); } } // Step 3: close streams IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); in = null; out = null; return; } // Testing mode? if (!MagicUIComponents.isUILoaded()) { return; } // Step 1: open streams final URLConnection connection = MToolKit.getHttpConnection(remoteFile); int contentLength = connection.getContentLength(); in = new BufferedInputStream(connection.getInputStream()); Log.info("Download from " + remoteFile + "(" + FileUtils.byteCountToDisplaySize(contentLength) + ")"); LoaderConsole.beginTask(LanguageManager.getString("downloading") + " " + remoteFile + "(" + FileUtils.byteCountToDisplaySize(contentLength) + ")"); // Step 2: read and write until done byte[] buf = new byte[2048]; int currentLength = 0; boolean succeed = false; for (int bufferLen = in.read(buf); bufferLen >= 0; bufferLen = in.read(buf)) { if (!succeed) { toDownload.getParentFile().mkdirs(); out = new BufferedOutputStream(new FileOutputStream(localFile)); succeed = true; } currentLength += bufferLen; if (out != null) { out.write(buf, 0, bufferLen); } if (listener != null) { listener.updateProgress(contentLength, currentLength); } } // Step 3: close streams IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); in = null; out = null; return; } catch (IOException e1) { if (MToolKit.getFile(localFile) != null) { MToolKit.getFile(localFile).delete(); } if (remoteFile.getFile().equals(remoteFile.getFile().toLowerCase())) { Log.fatal("could not load picture " + localFile + " from URL " + remoteFile + ", " + e1.getMessage()); } String tmpRemote = remoteFile.toString().toLowerCase(); try { download(localFile, new URL(tmpRemote), listener); } catch (MalformedURLException e) { Log.fatal("could not load picture " + localFile + " from URL " + tmpRemote + ", " + e.getMessage()); } } } }