List of usage examples for org.apache.commons.httpclient.util URIUtil decode
public static String decode(String escaped) throws URIException
From source file:org.apache.webdav.lib.WebdavFile.java
public String getParent() { if (relPath != null) return null; String escapedPath = httpUrl.getEscapedPath(); String parent = escapedPath.substring(0, escapedPath.lastIndexOf('/', escapedPath.length() - 2) + 1); if (parent.length() <= 1) return null; try {/*from w ww . ja v a2 s . c o m*/ return URIUtil.decode(parent); } catch (URIException e) { return parent; } }
From source file:org.asqatasun.util.http.HttpRequestHandler.java
private String getEncodedUrl(String url) { try {// ww w .j a v a 2s . c o m return URIUtil.encodeQuery(URIUtil.decode(url)); } catch (URIException ue) { LOGGER.warn("URIException on " + url); return url; } }
From source file:org.gots.server.auth.TempTokenAuthenticationServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Get request parameters String applicationName = req.getParameter(APPLICATION_NAME_PARAM); String deviceId = req.getParameter(DEVICE_ID_PARAM); String deviceDescription = req.getParameter(DEVICE_DESCRIPTION_PARAM); String permission = req.getParameter(PERMISSION_PARAM); String revokeParam = req.getParameter(REVOKE_PARAM); boolean revoke = Boolean.valueOf(revokeParam); // If one of the required parameters is null or empty, send an // error with the 400 status if (!revoke && (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(permission))) { log.error(//from www . j ava2 s . c om "The following request parameters are mandatory to acquire an authentication token: applicationName, deviceId, permission."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } if (revoke && (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(deviceId))) { log.error( "The following request parameters are mandatory to revoke an authentication token: applicationName, deviceId."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } // Decode parameters applicationName = URIUtil.decode(applicationName); deviceId = URIUtil.decode(deviceId); if (!StringUtils.isEmpty(deviceDescription)) { deviceDescription = URIUtil.decode(deviceDescription); } if (!StringUtils.isEmpty(permission)) { permission = URIUtil.decode(permission); } // Get user name from request Principal Principal principal = req.getUserPrincipal(); if (principal == null) { resp.sendError(HttpStatus.SC_UNAUTHORIZED); return; } String userName = principal.getName(); log.error("The principal user is " + userName); // Write response String response = null; TokenAuthenticationService tokenAuthService = Framework.getLocalService(TokenAuthenticationService.class); try { // Token acquisition: acquire token and write it to the response // body if (!revoke) { response = tokenAuthService.acquireToken(userName, applicationName, deviceId, deviceDescription, permission); } // Token revocation else { String token = tokenAuthService.getToken(userName, applicationName, deviceId); if (token == null) { response = String.format( "No token found for userName %s, applicationName %s and deviceId %s; nothing to do.", userName, applicationName, deviceId); } else { tokenAuthService.revokeToken(token); response = String.format("Token revoked for userName %s, applicationName %s and deviceId %s.", userName, applicationName, deviceId); } } sendTextResponse(resp, response); } catch (Exception e) { // Should never happen as parameters have already been checked resp.sendError(HttpStatus.SC_NOT_FOUND); } }
From source file:org.jdesktop.wonderland.modules.webdav.common.AuthenticatedWebdavResource.java
protected AuthenticatedWebdavResource(HttpURL url, String authCookieName, String authCookieValue) throws HttpException, IOException { super(URIUtil.decode(url.getEscapedURI()), new TokenCredentials(authCookieName, authCookieValue), true); }
From source file:org.kie.commons.java.nio.fs.file.SimpleFileSystemProvider.java
@Override public Path getPath(final URI uri) throws IllegalArgumentException, FileSystemNotFoundException, SecurityException { checkNotNull("uri", uri); checkCondition("uri scheme not supported", uri.getScheme().equals(getScheme()) || uri.getScheme().equals("default")); try {//from w w w . j a va 2s . co m return getDefaultFileSystem().getPath(URIUtil.decode(uri.getPath())); } catch (final URIException e) { return null; } }
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemProvider.java
@Override public Path getPath(final URI uri) throws IllegalArgumentException, FileSystemNotFoundException, SecurityException { checkNotNull("uri", uri); checkCondition("uri scheme not supported", uri.getScheme().equals(getScheme()) || uri.getScheme().equals("default")); checkURI("uri", uri); final JGitFileSystem fileSystem = fileSystems.get(extractRepoName(uri)); if (fileSystem == null) { throw new FileSystemNotFoundException(); }/* w w w. ja va2 s. c o m*/ try { return JGitPathImpl.create(fileSystem, URIUtil.decode(extractPath(uri)), extractHost(uri), false); } catch (final URIException e) { return null; } }
From source file:org.kie.commons.java.nio.fs.jgit.JGitPathTest.java
@Test public void testSimpleBranchedGitRoot2Spaced() throws URIException { when(fs.getSeparator()).thenReturn("/"); final Path path = JGitPathImpl.create(fs, URIUtil.decode("/path/to/some/some%20place.txt"), "master@my-host", false); assertThat(path).isNotNull();//from w ww. j av a 2s . c om assertThat(path.isAbsolute()).isTrue(); assertThat(path.toString()).isEqualTo("/path/to/some/some place.txt"); assertThat(path.toUri().toString()).isEqualTo("git://master@my-host/path/to/some/some%20place.txt"); assertThat(path.getNameCount()).isEqualTo(4); assertThat(path.getName(0).toString()).isNotNull().isEqualTo("path"); assertThat(path.getRoot().toString()).isNotNull().isEqualTo("/"); }
From source file:org.nuxeo.ecm.tokenauth.servlet.TokenAuthenticationServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Don't provide token for anonymous user unless 'allowAnonymous' parameter is explicitly set to true in // the authentication plugin configuration Principal principal = req.getUserPrincipal(); if (principal instanceof NuxeoPrincipal && ((NuxeoPrincipal) principal).isAnonymous()) { PluggableAuthenticationService authenticationService = (PluggableAuthenticationService) Framework .getRuntime().getComponent(PluggableAuthenticationService.NAME); AuthenticationPluginDescriptor tokenAuthPluginDesc = authenticationService .getDescriptor(TOKEN_AUTH_PLUGIN_NAME); if (tokenAuthPluginDesc == null || !(Boolean .valueOf(tokenAuthPluginDesc.getParameters().get(TokenAuthenticator.ALLOW_ANONYMOUS_KEY)))) { log.debug("Anonymous user is not allowed to acquire an authentication token."); resp.sendError(HttpStatus.SC_UNAUTHORIZED); return; }/* w w w . ja v a2s . c om*/ } // Get request parameters String applicationName = req.getParameter(APPLICATION_NAME_PARAM); String deviceId = req.getParameter(DEVICE_ID_PARAM); String deviceDescription = req.getParameter(DEVICE_DESCRIPTION_PARAM); String permission = req.getParameter(PERMISSION_PARAM); String revokeParam = req.getParameter(REVOKE_PARAM); boolean revoke = Boolean.valueOf(revokeParam); // If one of the required parameters is null or empty, send an // error with the 400 status if (!revoke && (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(permission))) { log.error( "The following request parameters are mandatory to acquire an authentication token: applicationName, deviceId, permission."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } if (revoke && (StringUtils.isEmpty(applicationName) || StringUtils.isEmpty(deviceId))) { log.error( "The following request parameters are mandatory to revoke an authentication token: applicationName, deviceId."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } // Decode parameters applicationName = URIUtil.decode(applicationName); deviceId = URIUtil.decode(deviceId); if (!StringUtils.isEmpty(deviceDescription)) { deviceDescription = URIUtil.decode(deviceDescription); } if (!StringUtils.isEmpty(permission)) { permission = URIUtil.decode(permission); } // Get user name from request Principal if (principal == null) { resp.sendError(HttpStatus.SC_UNAUTHORIZED); return; } String userName = principal.getName(); // Write response String response = null; int statusCode; TokenAuthenticationService tokenAuthService = Framework.getLocalService(TokenAuthenticationService.class); try { // Token acquisition: acquire token and write it to the response // body if (!revoke) { response = tokenAuthService.acquireToken(userName, applicationName, deviceId, deviceDescription, permission); statusCode = 201; } // Token revocation else { String token = tokenAuthService.getToken(userName, applicationName, deviceId); if (token == null) { response = String.format( "No token found for userName %s, applicationName %s and deviceId %s; nothing to do.", userName, applicationName, deviceId); statusCode = 400; } else { tokenAuthService.revokeToken(token); response = String.format("Token revoked for userName %s, applicationName %s and deviceId %s.", userName, applicationName, deviceId); statusCode = 202; } } sendTextResponse(resp, response, statusCode); } catch (TokenAuthenticationException e) { // Should never happen as parameters have already been checked resp.sendError(HttpStatus.SC_NOT_FOUND); } }
From source file:org.nuxeo.ecm.webdav.resource.ExistingResource.java
private Response copyOrMove(String method, @HeaderParam("Destination") String destination, @HeaderParam("Overwrite") String overwrite) throws Exception { if (backend.isLocked(doc.getRef()) && !backend.canUnlock(doc.getRef())) { return Response.status(423).build(); }// w ww .j a v a 2 s . c o m destination = Util.encode(destination.getBytes(), "ISO-8859-1"); destination = URIUtil.decode(destination); WebDavBackend root = Backend.get("/", request); Set<String> names = new HashSet<String>(root.getVirtualFolderNames()); Path destinationPath = new Path(destination); String[] segments = destinationPath.segments(); int removeSegments = 0; for (String segment : segments) { if (names.contains(segment)) { break; } else { removeSegments++; } } destinationPath = destinationPath.removeFirstSegments(removeSegments); String destPath = destinationPath.toString(); String davDestPath = destPath; WebDavBackend destinationBackend = Backend.get(davDestPath, request); destPath = destinationBackend.parseLocation(destPath).toString(); log.debug("to " + davDestPath); // Remove dest if it exists and the Overwrite header is set to "T". int status = 201; if (destinationBackend.exists(davDestPath)) { if ("F".equals(overwrite)) { return Response.status(412).build(); } destinationBackend.removeItem(davDestPath); status = 204; } // Check if parent exists String destParentPath = Util.getParentPath(destPath); PathRef destParentRef = new PathRef(destParentPath); if (!destinationBackend.exists(Util.getParentPath(davDestPath))) { return Response.status(409).build(); } if ("COPY".equals(method)) { DocumentModel destDoc = backend.copyItem(doc, destParentRef); backend.renameItem(destDoc, Util.getNameFromPath(destPath)); } else if ("MOVE".equals(method)) { if (backend.isRename(doc.getPathAsString(), destPath)) { backend.renameItem(doc, Util.getNameFromPath(destPath)); } else { backend.moveItem(doc, destParentRef); } } backend.saveChanges(); return Response.status(status).build(); }
From source file:org.pengyou.client.lib.DavResource.java
public String getPath() { try {//from w w w .j a v a 2 s .com return URIUtil.decode(path); } catch (URIException e) { return path; } }