List of usage examples for java.net URL toString
public String toString()
From source file:LNISmokeTest.java
/** * Get an item with WebDAV GET http request. * //from w w w . j av a 2 s .c o m * @param lni the lni * @param itemHandle the item handle * @param packager the packager * @param output the output * @param endpoint the endpoint * * @throws RemoteException the remote exception * @throws ProtocolException the protocol exception * @throws IOException Signals that an I/O exception has occurred. * @throws FileNotFoundException the file not found exception */ private static void doGet(LNISoapServlet lni, String itemHandle, String packager, String output, String endpoint) throws java.rmi.RemoteException, ProtocolException, IOException, FileNotFoundException { // assemble URL from chopped endpoint-URL and relative URI String itemURI = doLookup(lni, itemHandle, null); URL url = LNIClientUtils.makeDAVURL(endpoint, itemURI, packager); System.err.println("DEBUG: GET from URL: " + url.toString()); // connect with GET method, then copy file over. HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setDoInput(true); fixBasicAuth(url, conn); conn.connect(); int status = conn.getResponseCode(); if (status < 200 || status >= 300) { die(status, "HTTP error, status=" + String.valueOf(status) + ", message=" + conn.getResponseMessage()); } InputStream in = conn.getInputStream(); OutputStream out = new FileOutputStream(output); copyStream(in, out); in.close(); out.close(); System.err.println("DEBUG: Created local file " + output); System.err.println( "RESULT: Status=" + String.valueOf(conn.getResponseCode()) + " " + conn.getResponseMessage()); }
From source file:kr.ac.kaist.wala.hybridroid.callgraph.AndroidHybridAnalysisScope.java
private static AndroidHybridAnalysisScope setUpJsAnalysisScope(String dir, AndroidHybridAnalysisScope scope, Set<URL> htmls) throws IllegalArgumentException, IOException { JavaScriptLoader.addBootstrapFile(WebUtil.preamble); if (SystemUtils.IS_OS_WINDOWS) { scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(AndroidHybridAppModel.class.getResource("prologue.js")) { @Override/*from ww w .jav a 2 s. c om*/ public String getName() { return "prologue.js"; } }); scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(AndroidHybridAppModel.class.getResource("preamble.js")) { @Override public String getName() { return "preamble.js"; } }); } else { scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(AndroidHybridAppModel.class.getResource("prologue.js")) { @Override public String getName() { return "prologue.js"; } }); scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(AndroidHybridAppModel.class.getResource("preamble.js")) { @Override public String getName() { return "preamble.js"; } }); //scope.addToScope(scope.getJavaScriptLoader(), JSCallGraphBuilderUtil.getPrologueFile("prologue.js")); //scope.addToScope(scope.getJavaScriptLoader(), JSCallGraphBuilderUtil.getPrologueFile("preamble.js")); } for (URL url : htmls) { try { File f = WebUtil.extractScriptFromHTML(url, DefaultSourceExtractor.factory).snd; scope.addToScope(scope.getJavaScriptLoader(), new SourceURLModule(f.toURI().toURL())); String jspath = f.getCanonicalPath(); addScopeMap(Atom.findOrCreateAsciiAtom(url.toString()), Atom.findOrCreateAsciiAtom( jspath.substring(jspath.lastIndexOf(File.separator) + 1, jspath.length()))); if (DEBUG) System.err.println("#Loaded html: " + url.getFile()); } catch (Error | RuntimeException e) {// | UnimplementedError | // Error e) { if (url.toString().startsWith("http")) { System.err.println("Cannot receive the response from the url: " + url); } else { String path = url.getPath(); SourceModule dummy = new SourceURLModule(FileWriter .makeHtmlFile(dir, path.substring(path.lastIndexOf(File.separator) + 1, path.length() - 1), "") .toURI().toURL()); String dummypath = dummy.getName(); if (DEBUG) System.err.println("make dummy: " + dummypath); addScopeMap(Atom.findOrCreateAsciiAtom(url.toString()), Atom .findOrCreateAsciiAtom(dummypath.substring(dummypath.lastIndexOf(File.separator) + 1))); scope.addToScope(scope.getJavaScriptLoader(), dummy); } } } return scope; }
From source file:org.activiti.spring.SpringConfigurationHelper.java
public static ProcessEngine buildProcessEngine(URL resource) { log.debug(/* w ww . ja v a 2 s .co m*/ "==== BUILDING SPRING APPLICATION CONTEXT AND PROCESS ENGINE ========================================="); ApplicationContext applicationContext = new GenericXmlApplicationContext(new UrlResource(resource)); Map<String, ProcessEngine> beansOfType = applicationContext.getBeansOfType(ProcessEngine.class); if ((beansOfType == null) || (beansOfType.isEmpty())) { throw new ActivitiException("no " + ProcessEngine.class.getName() + " defined in the application context " + resource.toString()); } ProcessEngine processEngine = beansOfType.values().iterator().next(); log.debug( "==== SPRING PROCESS ENGINE CREATED =================================================================="); return processEngine; }
From source file:io.stallion.utils.ResourceHelpers.java
public static File findDevModeFileForResource(String plugin, String resourcePath) { if (!Settings.instance().getDevMode()) { throw new UsageException("You can only call this method in dev mode!"); }// w w w .j av a 2 s .c o m try { if (!resourcePath.startsWith("/")) { resourcePath = "/" + resourcePath; } // We find the URL of the root, not the actual file, since if the file was just created, we want it to be // accessible even if mvn hasn't recompiled the project. This allows us to iterate more quickly. URL url = pluginPathToUrl(plugin, resourcePath); // Maybe the file was just created? We'll try to find the root folder path, and then add the file path if (url == null) { url = new URL(StringUtils.stripStart(url.toString(), "/") + resourcePath); } return urlToFileMaybe(url, plugin); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.tesora.dve.common.PEFileUtils.java
public static URI convert(final URL url) throws PEException { try {//from www . ja va 2 s .c o m return url.toURI(); } catch (final URISyntaxException e) { throw new PEException("Malformed resource URI '" + url.toString() + "'", e); } }
From source file:com.hp.test.framework.Reporting.Utlis.java
public static String replacelogs() throws IOException { URL location = Test.class.getProtectionDomain().getCodeSource().getLocation(); String path = location.toString(); path = path.substring(6, path.indexOf("lib")); path = path.replace("%20", " "); String Logos_path = path + "ATU Reports/HTML_Design_Files/IMG"; String Source_logs_path = path + "HTML_Design_Files/IMG"; String Source_Framework_Logo_path = Source_logs_path + "/Framework_Logo.jpg"; String Source_hp_logo_path = Source_logs_path + "/hp.png"; String Source_reports_path = Source_logs_path + "/reports.jpg"; File Target_dir = new File(Logos_path); File Source = new File(Source_Framework_Logo_path); FileUtils.copyFileToDirectory(Source, Target_dir); File Source_Reports = new File(Source_reports_path); FileUtils.copyFileToDirectory(Source_Reports, Target_dir); File Source_hp = new File(Source_hp_logo_path); FileUtils.copyFileToDirectory(Source_hp, Target_dir); return path;/*w ww.j ava2s.c o m*/ }
From source file:LNISmokeTest.java
/** * Implement WebDAV PUT http request./*w w w . j a va2 s . c o m*/ * * This might be simpler with a real HTTP client library, but * java.net.HttpURLConnection is part of the standard SDK and it * demonstrates the concepts. * * @param lni the lni * @param collHandle the coll handle * @param packager the packager * @param source the source * @param endpoint the endpoint * * @throws RemoteException the remote exception * @throws ProtocolException the protocol exception * @throws IOException Signals that an I/O exception has occurred. * @throws FileNotFoundException the file not found exception */ private static void doPut(LNISoapServlet lni, String collHandle, String packager, String source, String endpoint) throws java.rmi.RemoteException, ProtocolException, IOException, FileNotFoundException { // assemble URL from chopped endpoint-URL and relative URI String collURI = doLookup(lni, collHandle, null); URL url = LNIClientUtils.makeDAVURL(endpoint, collURI, packager); System.err.println("DEBUG: PUT file=" + source + " to URL=" + url.toString()); // connect with PUT method, then copy file over. HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("PUT"); conn.setDoOutput(true); fixBasicAuth(url, conn); conn.connect(); InputStream in = null; OutputStream out = null; try { in = new FileInputStream(source); out = conn.getOutputStream(); copyStream(in, out); } finally { if (in != null) { try { in.close(); } catch (IOException e) { log.error("Unable to close input stream", e); } } if (out != null) { try { out.close(); } catch (IOException e) { log.error("Unable to close output stream", e); } } } int status = conn.getResponseCode(); if (status < 200 || status >= 300) { die(status, "HTTP error, status=" + String.valueOf(status) + ", message=" + conn.getResponseMessage()); } // diagnostics, and get resulting new item's location if avail. System.err.println("DEBUG: sent " + source); System.err.println( "RESULT: Status=" + String.valueOf(conn.getResponseCode()) + " " + conn.getResponseMessage()); String loc = conn.getHeaderField("Location"); System.err.println("RESULT: Location=" + ((loc == null) ? "NULL!" : loc)); }
From source file:org.kie.smoke.wb.util.RestUtil.java
private static String createBaseUriString(URL deploymentUrl, String relativeUrl) { String uriStr = null;//from ww w. ja va 2s. c o m try { uriStr = deploymentUrl.toURI() + relativeUrl; } catch (URISyntaxException urise) { logAndFail("Invalid uri :" + deploymentUrl.toString(), urise); } return uriStr; }
From source file:org.kie.remote.tests.base.RestUtil.java
private static String createBaseUriString(URL deploymentUrl, String relativeUrl) { String uriStr = null;//from ww w . j a va2 s . co m try { uriStr = deploymentUrl.toURI() + relativeUrl; } catch (URISyntaxException urise) { failAndLog("Invalid uri :" + deploymentUrl.toString(), urise); } return uriStr; }
From source file:com.aurel.track.dbase.InitReportTemplateBL.java
public static void addReportTemplates() { URL urlSrc; File srcDir = null;/* ww w . j ava2 s. c o m*/ //first try to get the template dir through class.getResource(path) urlSrc = PluginUtils.class.getResource("/resources/reportTemplates"); urlSrc = PluginUtils.createValidFileURL(urlSrc); if (urlSrc != null) { LOGGER.info("Retrieving report templates from " + urlSrc.toString()); srcDir = new File(urlSrc.getPath()); Long uuid = new Date().getTime(); File tmpDir = new File( System.getProperty("java.io.tmpdir") + File.separator + "TrackTmp" + uuid.toString()); if (!tmpDir.isDirectory()) { tmpDir.mkdir(); } tmpDir.deleteOnExit(); File[] files = srcDir.listFiles(new InitReportTemplateBL.Filter()); if (files == null || files.length == 0) { LOGGER.error("Problem unzipping report template: No files."); return; } for (int index = 0; index < files.length; index++) { ZipFile zipFile = null; try { String sname = files[index].getName(); String oid = sname.substring(sname.length() - 6, sname.length() - 4); zipFile = new ZipFile(files[index], ZipFile.OPEN_READ); LOGGER.debug("Extracting template from " + files[index].getName()); unzipFileIntoDirectory(zipFile, tmpDir); File descriptor = new File(tmpDir, "description.xml"); InputStream in = new FileInputStream(descriptor); //parse using builder to get DOM representation of the XML file Map<String, Object> desc = ReportBL.getTemplateDescription(in); String rname = "The name"; String description = "The description"; String expfmt = (String) desc.get("format"); Map<String, String> localizedStuff = (Map<String, String>) desc .get("locale_" + Locale.getDefault().getLanguage()); if (localizedStuff != null) { rname = localizedStuff.get("listing"); description = localizedStuff.get("description"); } else { localizedStuff = (Map<String, String>) desc.get("locale_en"); rname = localizedStuff.get("listing"); description = localizedStuff.get("description"); } addReportTemplateToDatabase(new Integer(oid), rname, expfmt, description); } catch (IOException e) { LOGGER.error("Problem unzipping report template " + files[index].getName()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } } }