List of usage examples for java.net URL getPath
public String getPath()
From source file:it.geosolutions.geofence.gui.server.service.impl.LoginService.java
public User authenticate(String userName, String password, HttpSession session) throws ApplicationException { logger.info("Authenticating '" + userName + "'"); GrantedAuths grantedAuths = null;/*ww w. j a v a 2s . c o m*/ String token = null; try { URL url = Class.forName("it.geosolutions.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); } User user = new User(); 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.aionlightning.commons.scripting.impl.javacompiler.ScriptClassLoaderImpl.java
/** * Returns list of classes that are members of a package * /*from ww w . j a v a2s. co m*/ * @param packageName * package to search for classes * @return list of classes that are package members * @throws IOException * if was unable to load class */ public Set<JavaFileObject> getClassesForPackage(String packageName) throws IOException { Set<JavaFileObject> result = new HashSet<JavaFileObject>(); // load parent ClassLoader parent = getParent(); if (parent instanceof ScriptClassLoaderImpl) { ScriptClassLoaderImpl pscl = (ScriptClassLoaderImpl) parent; result.addAll(pscl.getClassesForPackage(packageName)); } // load current classloader compiled classes for (String cn : classFileManager.getCompiledClasses().keySet()) { if (ClassUtils.isPackageMember(cn, packageName)) { BinaryClass bc = classFileManager.getCompiledClasses().get(cn); result.add(bc); } } // initialize set with class names, will be used to resolve classes Set<String> classNames = new HashSet<String>(); // load package members from this classloader Enumeration<URL> urls = getResources(packageName.replace('.', '/')); while (urls.hasMoreElements()) { URL url = urls.nextElement(); String path = URLDecoder.decode(url.getPath()); if (new File(path).isDirectory()) { Set<String> packageClasses = ClassUtils.getClassNamesFromPackage(new File(path), packageName, false); classNames.addAll(packageClasses); } else if (path.toLowerCase().contains(".jar!")) { File file = new File(path); while (!file.getName().toLowerCase().endsWith(".jar!")) { file = file.getParentFile(); } path = file.getPath().substring(0, file.getPath().length() - 1); path = path.replace('\\', '/'); path = path.substring(path.indexOf(":") + 1); file = new File(path); // add jar file as library. Actually it's doesn't matter if we have it as library // or as file in class path addJarFile(file); } } // add library class names from this classloader to available classes classNames.addAll(getLibraryClassNames()); // load classes for class names from this classloader for (String cn : classNames) { if (ClassUtils.isPackageMember(cn, packageName)) { BinaryClass bc = new BinaryClass(cn); try { byte[] data = getRawClassByName(cn); OutputStream os = bc.openOutputStream(); os.write(data); } catch (IOException e) { log.error("Error while loading class from package " + packageName, e); throw e; } result.add(bc); } } return result; }
From source file:info.novatec.testit.livingdoc.maven.plugin.SpecificationRunnerMojoTest.java
@Override public void setUp() throws Exception { super.setUp(); URL pomPath = SpecificationRunnerMojoTest.class.getResource("pom-runner.xml"); mojo = (SpecificationRunnerMojo) lookupMojo("run", URIUtil.decoded(pomPath.getPath())); mojo.classpathElements = new ArrayList<String>(); String core = dependency("livingdoc-core.jar").getAbsolutePath(); mojo.classpathElements.add(core);/*ww w .j a v a 2 s . c o m*/ mojo.classpathElements.add(dependency("guice-1.0.jar").getAbsolutePath()); mojo.pluginDependencies = new ArrayList<Artifact>(); mojo.pluginDependencies.add(new DependencyArtifact("commons-codec", dependency("commons-codec-1.3.jar"))); mojo.pluginDependencies.add(new DependencyArtifact("xmlrpc", dependency("xmlrpc-2.0.1.jar"))); assertEquals("en", mojo.locale); assertEquals(MySelector.class.getName(), mojo.selector); assertTrue(mojo.debug); }
From source file:com.edgenius.wiki.service.impl.TestVolumnPageService.java
@Before public void setUp() throws IOException { System.out.println("Load test file from URL:" + this.getClass().getClassLoader().getResource("testcase/pageservice/samplepagecontent.txt")); URL samplePage = this.getClass().getClassLoader().getResource("testcase/pageservice/samplepagecontent.txt"); content = FileUtils.readFileToString(new File(samplePage.getPath())); System.out.println("Load test file from URL:" + this.getClass().getClassLoader().getResource("testcase/pageservice/spacelist.txt")); URL spaceList = this.getClass().getClassLoader().getResource("testcase/pageservice/spacelist.txt"); spaces = FileUtils.readLines(new File(spaceList.getPath())); HttpServletRequest request = new MockHttpServletRequest() { public String getRemoteUser() { return "admin"; }// w ww.j a v a 2s .co m }; ServletUtils.setRequest(request); // MockServletContext servletContext = new MockServletContext(); // WebApplicationContext springContext; // servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE , springContext); // ServletUtils.setServletContext(servletContext); Authentication authentication = new UsernamePasswordAuthenticationToken("admin", "admin"); SecurityContextHolder.getContext().setAuthentication(authentication); //create spaces for (String uname : spaces) { Space space = new Space(); space.setUnixName(uname); space.setName("Title:" + uname); space.setDescription("Description:" + uname); WikiUtil.setTouchedInfo(userReadingService, space); try { spaceService.createSpace(space); } catch (SpaceException e) { e.printStackTrace(); Assert.fail(e.toString()); } } }
From source file:com.google.zxing.client.android.result.ClickVURIResultHandler.java
public void registerClickV(String uri) { String host = "http://lit-taiga-5566.herokuapp.com/"; String query = null, path = null; String telId = getTelNumber() == null ? getMacAddress() : getTelNumber(); try {/*from w w w .ja va2 s . com*/ URL url = new URL(uri.replaceAll("clickv://", host)); query = url.getQuery(); path = url.getProtocol() + "://" + url.getHost() + "/" + url.getPath(); } catch (MalformedURLException e) { e.printStackTrace(); } Toast.makeText(getActivity(), "??? :: " + query, Toast.LENGTH_SHORT).show(); try { new ServerConnenctionTask().execute(path, query, telId); Toast.makeText(getActivity(), "" + uri, Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(getActivity(), "?." + uri, Toast.LENGTH_SHORT).show(); } }
From source file:com.brightcove.com.zartan.verifier.video.PdFlvUrlVerifier.java
@ZartanCheck(value = "Primary Rendition is the correct type") public ResultEnum assertPrimaryRenditionTypeCorrect(UploadData upData) throws Throwable { URL u = getPrimaryRenditionUrl(upData); if (upData.getmOptions().getTargetCodec().equals("MP4") && (!upData.getmOptions().getIsVideoFileTypeFLV() || upData.getUploadMethod() == UploadType.BATCH)) { assertTrue("type should be mp4 of " + u.getPath(), u.getPath().toLowerCase().endsWith("mp4")); } else {//from www .j a v a 2s. c o m assertTrue("type should be flv of " + u.getPath(), u.getPath().toLowerCase().endsWith("flv")); } return ResultEnum.PASS; }
From source file:com.quartzdesk.executor.dao.schema.DatabaseSchemaManager.java
/** * Returns the list of QuartzDesk database schema SQL upgrade scripts to be * applied to the current schema version to upgrade it to the desired schema version. * * @param currentSchemaVersion the current database schema version. * @param desiredSchemaVersion the desired database schema version. * @return the list of SQL upgrade scripts. *//*from ww w . j ava2 s .co m*/ private List<URL> getUpgradeScriptUrls(Version currentSchemaVersion, Version desiredSchemaVersion) { List<URL> result = new ArrayList<URL>(); try { // sort the directories by version number Set<Version> dirVersions = new TreeSet<Version>(VersionComparator.INSTANCE); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] scriptResources = resolver.getResources(upgradeScriptsRoot + "/*/*.sql"); for (Resource scriptResource : scriptResources) { Matcher matcher = UPGRADE_SCRIPT_PATTERN.matcher(scriptResource.getURL().getPath()); if (matcher.find()) { String dirVersionStr = matcher.group(1); String[] dirVersionParts = dirVersionStr.split("_"); // 1_0_0 Version dirVersion = new Version().withMajor(Integer.parseInt(dirVersionParts[0])) .withMinor(Integer.parseInt(dirVersionParts[1])) .withMaintenance(Integer.parseInt(dirVersionParts[2])); dirVersions.add(dirVersion); } } for (Version dirVersion : dirVersions) { // currentSchemaVersion < dirVersion <= desiredSchemaVersion if (VersionComparator.INSTANCE.compare(dirVersion, currentSchemaVersion) > 0 && VersionComparator.INSTANCE.compare(dirVersion, desiredSchemaVersion) <= 0) { String dirVersionStr = dirVersion.getMajor().toString() + '_' + dirVersion.getMinor() + '_' + dirVersion.getMaintenance(); scriptResources = resolver.getResources(upgradeScriptsRoot + '/' + dirVersionStr + "/*.sql"); List<URL> scriptUrls = new ArrayList<URL>(); for (Resource scriptResource : scriptResources) { scriptUrls.add(scriptResource.getURL()); } // sort the scripts inside the dir by their name Collections.sort(scriptUrls, new Comparator<URL>() { @Override public int compare(URL o1, URL o2) { return o1.getPath().compareTo(o2.getPath()); } }); result.addAll(scriptUrls); } } } catch (IOException e) { throw new DaoException("Error getting database schema SQL upgrade script URLs.", e); } return result; }
From source file:com.snaplogic.snaps.uniteller.CustomUFSConfigMgr.java
private InputStream getInputStream(final URL fileUrl) throws UFSConfigMgrException { try {/* www . j ava 2 s . co m*/ urlConnection = fileUrl.openConnection(); urlConnection.connect(); return urlConnection.getInputStream(); } catch (IOException e) { log.error(String.format(ERR_URL_CONNECT, fileUrl.getPath())); throw new UFSConfigMgrException(String.format(ERR_URL_CONNECT, fileUrl.getPath())); } }
From source file:dk.netarkivet.common.distribute.HTTPRemoteFileRegistry.java
/** * Get the url for cleaning up after a remote file registered under some * URL./* w w w .j ava 2s . c o m*/ * @param url some URL * * @return the cleanup url. * @throws MalformedURLException If unable to construct the cleanup url */ URL getCleanupUrl(URL url) throws MalformedURLException { return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getPath() + UNREGISTER_URL_POSTFIX); }