List of usage examples for com.google.common.net UrlEscapers urlFragmentEscaper
public static Escaper urlFragmentEscaper()
From source file:com.spectralogic.ds3client.commands.PutObjectRequest.java
public PutObjectRequest(final String bucketName, final String objectName, final SeekableByteChannel channel, final String job, final long offset, final long size) { this.bucketName = bucketName; this.objectName = objectName; this.size = size; this.job = job; this.offset = offset; this.channel = channel; this.stream = new SeekableByteChannelInputStream(channel); this.getQueryParams().put("job", UrlEscapers.urlFragmentEscaper().escape(job).replace("+", "%2B")); this.getQueryParams().put("offset", Long.toString(offset)); }
From source file:com.kamike.misc.FsNameUtils.java
public static String escapeUrl(String name) { return UrlEscapers.urlFragmentEscaper().escape(name); }
From source file:org.bimserver.servlets.OAuthAuthorizationServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServletException, IOException { OAuthAuthzRequest oauthRequest = null; String authType = request.getParameter("auth_type"); if (request.getParameter("token") == null) { String location = "/apps/bimviews/?page=OAuth&auth_type=" + authType + "&client_id=" + request.getParameter("client_id") + "&response_type=" + request.getParameter("response_type") + "&redirect_uri=" + request.getParameter("redirect_uri"); if (request.getParameter("state") != null) { String state = request.getParameter("state"); LOGGER.info("Incoming state: " + state); String encodedState = UrlEscapers.urlFragmentEscaper().escape(state); LOGGER.info("Encoded state: " + encodedState); location += "&state=" + encodedState; }/*from w w w . ja v a 2 s .co m*/ LOGGER.info("Redirecting to " + location); httpServletResponse.sendRedirect(location); return; } OAuthAuthorizationCode oauthCode = null; String token = request.getParameter("token"); try (DatabaseSession session = getBimServer().getDatabase().createSession()) { OAuthServer oAuthServer = session.querySingle(StorePackage.eINSTANCE.getOAuthServer_ClientId(), request.getParameter("client_id")); org.bimserver.webservices.authorization.Authorization realAuth = org.bimserver.webservices.authorization.Authorization .fromToken(getBimServer().getEncryptionKey(), token); long uoid = realAuth.getUoid(); User user = session.get(uoid, OldQuery.getDefault()); for (OAuthAuthorizationCode oAuthAuthorizationCode : user.getOAuthIssuedAuthorizationCodes()) { if (oAuthAuthorizationCode.getOauthServer() == oAuthServer) { if (oAuthAuthorizationCode.getAuthorization() != null) { oauthCode = oAuthAuthorizationCode; } } } try { if (oauthCode == null) { throw new ServletException("No auth found for token " + token); } oauthRequest = new OAuthAuthzRequest(request); String responseType = oauthRequest.getParam(OAuth.OAUTH_RESPONSE_TYPE); OAuthASResponse.OAuthAuthorizationResponseBuilder builder = OAuthASResponse .authorizationResponse(request, HttpServletResponse.SC_FOUND); if (responseType.equals(ResponseType.CODE.toString())) { builder.setCode(oauthCode.getCode()); // } else if (responseType.equals(ResponseType.TOKEN))) { // builder.setAccessToken(oauthCode.get) } // if (responseType.equals(ResponseType.TOKEN.toString())) { // builder.setAccessToken(oauthIssuerImpl.accessToken()); //// builder.setTokenType(OAuth.DEFAULT_TOKEN_TYPE.toString()); // builder.setExpiresIn(3600l); // } String redirectURI = oauthRequest.getParam(OAuth.OAUTH_REDIRECT_URI); if (redirectURI != null && !redirectURI.equals("")) { if (redirectURI.equals("SHOW_CODE")) { httpServletResponse.getWriter().write( "Service token (copy&paste this into your application): <br/><br/><input type=\"text\" style=\"width: 1000px\" value=\"" + oauthCode.getCode() + "\"/><br/><br/>"); RunServiceAuthorization auth = (RunServiceAuthorization) oauthCode.getAuthorization(); String siteAddress = getBimServer().getServerSettingsCache().getServerSettings() .getSiteAddress(); httpServletResponse.getWriter().write( "Service address: <br/><br/><input type=\"text\" style=\"width: 1000px\" value=\"" + siteAddress + "/services/" + auth.getService().getOid() + "\"/><br/><br/>"); } else { URI uri = makeUrl(redirectURI, oauthCode, builder); LOGGER.info("Redirecting to " + uri); httpServletResponse.sendRedirect(uri.toString()); } } else { URI uri = makeUrl("http://fakeaddress", oauthCode, builder); httpServletResponse.getWriter().println("No redirectURI provided"); httpServletResponse.getWriter().println("Would have redirected to: " + uri); } } catch (OAuthProblemException e) { final Response.ResponseBuilder responseBuilder = Response.status(HttpServletResponse.SC_FOUND); String redirectUri = e.getRedirectUri(); if (OAuthUtils.isEmpty(redirectUri)) { throw new WebApplicationException( responseBuilder.entity("OAuth callback url needs to be provided by client!!!").build()); } try { OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_FOUND).error(e) .location(redirectUri).buildQueryMessage(); // final URI location = new URI(response.getLocationUri()); httpServletResponse.sendRedirect(response.getLocationUri()); } catch (OAuthSystemException e1) { e1.printStackTrace(); } } } catch (OAuthSystemException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } catch (BimserverLockConflictException e2) { e2.printStackTrace(); } catch (BimserverDatabaseException e2) { e2.printStackTrace(); } catch (AuthenticationException e2) { e2.printStackTrace(); } }
From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.AutoLinkSpan.java
private String escapeUri(String link) { return UrlEscapers.urlFragmentEscaper().escape(link).replace("%23", "#").replace("%25", "%"); }
From source file:com.spectralogic.ds3client.commands.PutMultiPartUploadPartRequest.java
public PutMultiPartUploadPartRequest(final String bucketName, final String objectName, final int partNumber, final long size, final InputStream stream, final String uploadId) { this.bucketName = bucketName; this.objectName = objectName; this.partNumber = partNumber; this.uploadId = uploadId; this.size = size; this.stream = stream; this.getQueryParams().put("part_number", Integer.toString(partNumber)); this.getQueryParams().put("upload_id", UrlEscapers.urlFragmentEscaper().escape(uploadId).replace("+", "%2B")); }
From source file:WeatherAPI.Providers.WeatherProvider.java
/** * Gets the location encoded for a Url// w ww . j av a2 s . c o m * * @return URL-safe location */ public String getUrlEncodedLocation() { return UrlEscapers.urlFragmentEscaper().escape(getLocation()); }
From source file:com.spectralogic.ds3client.commands.PutObjectRequest.java
public PutObjectRequest(final String bucketName, final String objectName, final String job, final long offset, final long size, final InputStream stream) { this.bucketName = bucketName; this.objectName = objectName; this.size = size; this.job = job; this.offset = offset; this.stream = stream; this.getQueryParams().put("job", UrlEscapers.urlFragmentEscaper().escape(job).replace("+", "%2B")); this.getQueryParams().put("offset", Long.toString(offset)); }
From source file:org.eclipse.hawkbit.api.PropertyBasedArtifactUrlHandler.java
private static Map<String, String> getReplaceMap(final UrlProtocol protocol, final URLPlaceholder placeholder, final URI requestUri) { final Map<String, String> replaceMap = Maps.newHashMapWithExpectedSize(19); replaceMap.put(IP_PLACEHOLDER, protocol.getIp()); replaceMap.put(HOSTNAME_PLACEHOLDER, protocol.getHostname()); replaceMap.put(HOSTNAME_REQUEST_PLACEHOLDER, getRequestHost(protocol, requestUri)); replaceMap.put(PORT_REQUEST_PLACEHOLDER, getRequestPort(protocol, requestUri)); replaceMap.put(HOSTNAME_WITH_DOMAIN_REQUEST_PLACEHOLDER, computeHostWithRequestDomain(protocol, requestUri)); replaceMap.put(ARTIFACT_FILENAME_PLACEHOLDER, UrlEscapers.urlFragmentEscaper().escape(placeholder.getSoftwareData().getFilename())); replaceMap.put(ARTIFACT_SHA1_PLACEHOLDER, placeholder.getSoftwareData().getSha1Hash()); replaceMap.put(PROTOCOL_PLACEHOLDER, protocol.getProtocol()); replaceMap.put(PORT_PLACEHOLDER, getPort(protocol)); replaceMap.put(TENANT_PLACEHOLDER, placeholder.getTenant()); replaceMap.put(TENANT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTenantId())); replaceMap.put(TENANT_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTenantId())); replaceMap.put(CONTROLLER_ID_PLACEHOLDER, placeholder.getControllerId()); replaceMap.put(TARGET_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTargetId())); replaceMap.put(TARGET_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTargetId())); replaceMap.put(ARTIFACT_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getSoftwareData().getArtifactId())); replaceMap.put(ARTIFACT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getSoftwareData().getArtifactId())); replaceMap.put(SOFTWARE_MODULE_ID_BASE10_PLACDEHOLDER, String.valueOf(placeholder.getSoftwareData().getSoftwareModuleId())); replaceMap.put(SOFTWARE_MODULE_ID_BASE62_PLACDEHOLDER, Base62Util.fromBase10(placeholder.getSoftwareData().getSoftwareModuleId())); return replaceMap; }
From source file:rogerthat.topdesk.bizz.IncidentFeedbackTask.java
private String getIncident(String incidentId) { try {//from w ww .j a v a 2s. com String apiKey = Util.getTopdeskApiKey(); String path = "/api/incident/number/" + UrlEscapers.urlFragmentEscaper().escape(incidentId); return topdeskAPIGet(apiKey, path); } catch (IOException | ParseException e) { log.log(Level.SEVERE, "Error", e); throw new TopdeskApiException("Unknown error"); } }
From source file:org.fao.geonet.api.records.attachments.FilesystemStore.java
@Override public List<MetadataResource> getResources(ServiceContext context, String metadataUuid, MetadataResourceVisibility visibility, String filter) throws Exception { ApplicationContext _appContext = ApplicationContextHolder.get(); String metadataId = getAndCheckMetadataId(metadataUuid); GeonetworkDataDirectory dataDirectory = _appContext.getBean(GeonetworkDataDirectory.class); SettingManager settingManager = _appContext.getBean(SettingManager.class); AccessManager accessManager = _appContext.getBean(AccessManager.class); boolean canEdit = accessManager.canEdit(context, metadataId); if (visibility == MetadataResourceVisibility.PRIVATE && !canEdit) { throw new SecurityException(String.format( "User does not have privileges to get the list of '%s' resources for metadata '%s'.", visibility, metadataUuid)); }//from www .j a va 2 s . c om Path metadataDir = Lib.resource.getMetadataDir(dataDirectory, metadataId); Path resourceTypeDir = metadataDir.resolve(visibility.toString()); List<MetadataResource> resourceList = new ArrayList<>(); if (filter == null) { filter = FilesystemStore.DEFAULT_FILTER; } try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(resourceTypeDir, filter)) { for (Path path : directoryStream) { MetadataResource resource = new FilesystemStoreResource( UrlEscapers.urlFragmentEscaper().escape(metadataUuid) + "/attachments/" + UrlEscapers.urlFragmentEscaper().escape(path.getFileName().toString()), settingManager.getNodeURL() + "api/records/", visibility, Files.size(path)); resourceList.add(resource); } } catch (IOException ignored) { } Collections.sort(resourceList, MetadataResourceVisibility.sortByFileName); return resourceList; }