List of usage examples for java.net URL getPath
public String getPath()
From source file:io.squark.nestedjarclassloader.Module.java
private void addResource0(URL url) throws IOException { if (url.getPath().endsWith(".jar")) { if (logger != null) logger.debug("Adding jar " + url.getPath()); InputStream urlStream = url.openStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(urlStream); JarInputStream jarInputStream = new JarInputStream(bufferedInputStream); JarEntry jarEntry;/*from ww w .j ava 2 s.c o m*/ while ((jarEntry = jarInputStream.getNextJarEntry()) != null) { if (resources.containsKey(jarEntry.getName())) { if (logger != null) logger.trace("Already have resource " + jarEntry.getName() + ". If different versions, unexpected behaviour " + "might occur. Available in " + resources.get(jarEntry.getName())); } String spec; if (url.getProtocol().equals("jar")) { spec = url.getPath(); } else { spec = url.getProtocol() + ":" + url.getPath(); } URL contentUrl = new URL(null, "jar:" + spec + "!/" + jarEntry.getName(), new NestedJarURLStreamHandler(false)); resources.put(jarEntry.getName(), contentUrl); addClassIfClass(jarInputStream, jarEntry.getName()); if (logger != null) logger.trace("Added resource " + jarEntry.getName() + " to ClassLoader"); if (jarEntry.getName().endsWith(".jar")) { addResource0(contentUrl); } } jarInputStream.close(); bufferedInputStream.close(); urlStream.close(); } else if (url.getPath().endsWith(".class")) { throw new IllegalStateException("Cannot add classes directly"); } else { try { addDirectory(new File(url.toURI())); } catch (URISyntaxException e) { throw new IllegalStateException(e); } } }
From source file:com.quartzdesk.executor.dao.schema.DatabaseSchemaManager.java
/** * Returns the list of QuartzDesk database schema SQL init scripts. * * @return the list of SQL init scripts. *//*from www. j a v a2 s .c o m*/ public List<URL> getInitScriptUrls() { try { // find all .sql scripts ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] scriptResources = resolver.getResources(initScriptsRoot + "/*.sql"); List<URL> scriptUrls = new ArrayList<URL>(); for (Resource scriptResource : scriptResources) { scriptUrls.add(scriptResource.getURL()); } // sort the scripts by their name Collections.sort(scriptUrls, new Comparator<URL>() { @Override public int compare(URL o1, URL o2) { return o1.getPath().compareTo(o2.getPath()); } }); return scriptUrls; } catch (IOException e) { throw new DaoException("Error getting database schema SQL init script URLs.", e); } }
From source file:com.k42b3.aletheia.protocol.http.Request.java
private void parseUrl(URL url) { this.host = url.getHost(); this.path = url.getPath().isEmpty() ? "/" : url.getPath(); if (url.getQuery() != null) { this.path += "?" + url.getQuery(); }//w w w . j a v a2 s . c om if (url.getRef() != null) { this.path += "#" + url.getRef(); } }
From source file:org.geoserver.geofence.gui.server.service.impl.LoginService.java
public UserModel authenticate(String userName, String password, HttpSession session) throws ApplicationException { logger.info("Authenticating '" + userName + "'"); GrantedAuths grantedAuths = null;//from w ww .j av a 2s . c om String token = null; try { URL url = Class.forName("org.geoserver.geofence.gui.client.UserUI").getResource("client.keystore"); String path = url.getPath(); if (logger.isDebugEnabled()) { logger.debug(path); } System.setProperty("javax.net.ssl.trustStore", path); System.setProperty("javax.net.ssl.trustStorePassword", "geosolutions"); GFUser matchingUser = null; // a backdoor!?! :o if (userName.equals("1nt3rnAL-G30r3p0-admin")) { matchingUser = new GFUser(); matchingUser.setName(userName); matchingUser.setPassword("2c6fe6e260312c5aa94ef0ca42b0af"); } else { try { matchingUser = geofenceRemoteService.getGfUserAdminService().get(userName); } catch (NotFoundServiceEx ex) { logger.warn("User not found"); throw new ApplicationException("Login failed"); } // // grantedAuthorities = // List<GFUser> matchingUsers = geofenceRemoteService.getGfUserAdminService().getFullList(userName, null, // null); // logger.info(matchingUsers); // logger.info(matchingUsers.size()); // // if ((matchingUsers == null) || matchingUsers.isEmpty() || (matchingUsers.size() != 1)) // { // logger.error("Error :********** " + "Invalid username specified!"); // throw new ApplicationException("Error :********** " + "Invalid username specified!"); // } // // logger.info(matchingUsers.get(0).getName()); // logger.info(matchingUsers.get(0).getPassword()); // logger.info(matchingUsers.get(0).getEnabled()); // // if (!matchingUsers.get(0).getName().equals(userName) || !matchingUsers.get(0).getEnabled()) // { // logger.error("Error :********** " + "The specified user does not exist!"); // throw new ApplicationException("Error :********** " + "The specified user does not exist!"); // } // // matchingUser = matchingUsers.get(0); } token = geofenceRemoteService.getLoginService().login(userName, password, matchingUser.getPassword()); grantedAuths = geofenceRemoteService.getLoginService().getGrantedAuthorities(token); } catch (ClassNotFoundException e) { logger.error("Error :********** " + e.getMessage()); throw new ApplicationException(e); } catch (AuthException e) { logger.error("Login failed"); throw new ApplicationException(e.getMessage(), e); } UserModel user = new UserModel(); user.setName(userName); user.setPassword(password); // convert the server-side auths to client-side auths List<Authorization> guiAuths = new ArrayList<Authorization>(); for (Authority auth : grantedAuths.getAuthorities()) { guiAuths.add(Authorization.valueOf(auth.name())); } user.setGrantedAuthorizations(guiAuths); if ((grantedAuths != null) && !grantedAuths.getAuthorities().isEmpty()) { } session.setMaxInactiveInterval(7200); session.setAttribute(GeofenceKeySessionValues.USER_LOGGED_TOKEN.getValue(), token); /* session.setAttribute(GeofenceKeySessionValues.USER_LOGGED_TOKEN.getValue(), grantedAuthorities_NOTUSEDANYMORE.getToken()); */ return user; }
From source file:com.blackducksoftware.tools.scmconnector.integrations.mercurial.MercurialConnector.java
/** * Constructs a valid HTTP url if a user *and* password is provided. * * @throws Exception/*from www. j av a 2 s . com*/ */ private void buildURL() throws Exception { if (StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)) { URL url = new URL(repositoryURL); String protocol = url.getProtocol(); int port = url.getPort(); String host = url.getHost(); String path = url.getPath(); URIBuilder builder = new URIBuilder(); builder.setScheme(protocol); builder.setHost(host); builder.setPort(port); builder.setPath(path); builder.setUserInfo(user, password); repositoryURL = builder.toString(); // log.info("Using path: " + repositoryURL); // Reveals password } }
From source file:com.textuality.keybase.lib.prover.Twitter.java
@Override public boolean fetchProofData() { String tweetUrl = null;/*from w w w . jav a2 s. com*/ try { JSONObject sigJSON = readSig(mProof.getSigId()); // the magic string is the base64 of the SHA of the raw message mShortenedMessageHash = JWalk.getString(sigJSON, "sig_id_short"); // find the tweet's url and fetch it tweetUrl = mProof.getProofUrl(); Fetch fetch = new Fetch(tweetUrl); String problem = fetch.problem(); if (problem != null) { mLog.add(problem); return false; } // Paranoid Interlude: // 1. It has to be a tweet https://twitter.com/<nametag>/status/\d+ // 2. the magic string has to appear in the <title>; were worried that // someone could @-reply and fake us out with the magic string down in someone // elses tweet URL suspectUrl = new URL(tweetUrl); String scheme = suspectUrl.getProtocol(); String host = suspectUrl.getHost(); String path = suspectUrl.getPath(); String nametag = mProof.getNametag(); if (!(scheme.equals("https") && host.equals("twitter.com") && path.startsWith("/" + nametag + "/status/") && endsWithDigits(path))) { mLog.add("Unacceptable Twitter proof Url: " + tweetUrl); } // dig through the tweet to find the magic string in the <title> String tweet = fetch.getBody(); // make sure were looking only through the header int index1 = tweet.indexOf("</head>"); if (index1 == -1) { mLog.add("</head> not found in proof tweet"); mLog.add("Proof tweet is malformed."); return false; } tweet = tweet.substring(0, index1); index1 = tweet.indexOf("<title>"); int index2 = tweet.indexOf("</title>"); if (index1 == -1 || index2 == -1 || index1 >= index2) { mLog.add("Bogus head locations: " + index1 + "/" + index2); mLog.add("Unable to find proof tweet header."); return false; } // ensure the magic string appears in the tweets <title> tweet = tweet.substring(index1, index2); if (tweet.contains(mShortenedMessageHash)) { return true; } else { mLog.add("Encoded message not found in proof tweet."); return false; } } catch (KeybaseException e) { mLog.add("Keybase API problem: " + e.getLocalizedMessage()); } catch (JSONException e) { mLog.add("Broken JSON message: " + e.getLocalizedMessage()); } catch (MalformedURLException e) { mLog.add("Unparsable tweet URL: " + tweetUrl); } return false; }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.SamlConfig.java
public SamlConfig(Security security) { if (!security.getAuthn().getSaml().isEnabled()) { return;/*from w w w . j a va 2 s.co m*/ } Saml saml = security.getAuthn().getSaml(); this.enabled = saml.isEnabled(); this.issuerId = saml.getIssuerId(); this.metadataUrl = "file:" + saml.getMetadataLocal(); if (StringUtils.isNotEmpty(saml.getMetadataRemote())) { this.metadataUrl = saml.getMetadataRemote(); } this.keyStore = "file:" + saml.getKeyStore(); this.keyStoreAliasName = saml.getKeyStoreAliasName(); this.keyStorePassword = saml.getKeyStorePassword(); URL u = saml.getServiceAddress(); this.redirectProtocol = u.getProtocol(); this.redirectHostname = u.getHost(); if (u.getPort() != -1) { this.redirectHostname += ":" + u.getPort(); } if (StringUtils.isNotEmpty(u.getPath())) { this.redirectBasePath = u.getPath(); } }
From source file:com.springsense.nutch.indexer.SpringSenseIndexingFilter.java
protected String preprocessUrlOrPath(String urlOrPath) { if (StringUtils.isBlank(urlOrPath)) { return null; }/*from w w w. j ava 2 s . co m*/ String path = null; URL url; try { url = new URL(urlOrPath); path = url.getPath(); } catch (MalformedURLException e) { // Assume we got a file path... We'll attempt to treat it so. path = urlOrPath; } String decodedUrlOrPath = null; try { decodedUrlOrPath = URLDecoder.decode(path, "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.error(String.format("Couldn't decode URL or path: '%s' due to an error", urlOrPath), e); return null; } String fileBaseNameWithoutExtension = FilenameUtils .removeExtension(FilenameUtils.getBaseName(decodedUrlOrPath)); return splitCamelCase(fileBaseNameWithoutExtension); }
From source file:org.makersoft.activerecord.bootstrap.Bootstrap.java
private URL[] getPackagePaths() { URL classpathUrl = ClasspathUrlFinder.findClassBase(this.getClass()); try {//from ww w. java2s . co m String classpath = classpathUrl.getPath(); String testClasspath = classpath.substring(0, classpath.lastIndexOf("classes")) + "test-classes/"; return new URL[] { new URL("file:" + classpath + basePackage.replaceAll("\\.", "/") + "/"), new URL("file:" + testClasspath + basePackage.replaceAll("\\.", "/") + "/") }; } catch (MalformedURLException e) { e.printStackTrace(); } return null; }
From source file:com.gargoylesoftware.htmlunit.html.XmlSerializer.java
private String getFileExtension(final Page enclosedPage) { if (enclosedPage != null) { if (enclosedPage.isHtmlPage()) { return "html"; }/*from w w w . j a v a 2 s . c om*/ final URL url = enclosedPage.getUrl(); if (url.getPath().contains(".")) { return StringUtils.substringAfterLast(url.getPath(), "."); } } return ".unknown"; }