List of usage examples for com.google.common.net UrlEscapers urlPathSegmentEscaper
public static Escaper urlPathSegmentEscaper()
From source file:de.appsolve.padelcampus.controller.page.PageController.java
@RequestMapping() public ModelAndView getIndex(@PathVariable("moduleId") String moduleTitle) { RedirectView red = new RedirectView("/" + UrlEscapers.urlPathSegmentEscaper().escape(moduleTitle)); red.setStatusCode(HttpStatus.MOVED_PERMANENTLY); return new ModelAndView(red); }
From source file:com.offbytwo.jenkins.model.Computer.java
public ComputerWithDetails details() throws IOException { String name;/* w w w . j ava2s .com*/ if ("master".equals(displayName)) { name = "(master)"; } else { name = UrlEscapers.urlPathSegmentEscaper().escape(displayName); } // TODO: Check if depth=2 is a good idea or if it could be solved // better. ComputerWithDetails computerWithDetails = client.get("/computer/" + name + "/?depth=2", ComputerWithDetails.class); computerWithDetails.setClient(client); return computerWithDetails; }
From source file:org.eclipse.packagedrone.repo.channel.util.AbstractChannelInterfaceExtender.java
protected static String escapePathSegment(final String segment) { return UrlEscapers.urlPathSegmentEscaper().escape(segment); }
From source file:de.dentrassi.eclipse.provider.ProjectProvider.java
/** * Fetch project information from the PMI * * @param ctx/*from ww w .ja v a 2 s . c o m*/ * the parse context * @param projectId * the project ID * @return the project information, or {@code null} if the project could not * be found * @throws IOException * in case of any IO error */ protected static Project fetchProjectInformation(final ParseContext ctx, final String projectId) throws IOException { final Request.Builder req = new Request.Builder(); req.url("https://projects.eclipse.org/json/project/" + UrlEscapers.urlPathSegmentEscaper().escape(projectId)); final Response result = ctx.newCall(req.build()); if (!result.isSuccessful()) { if (result.code() == 404) { return null; } throw new ShieldRequestException(result.message(), result.code()); } final GsonBuilder gb = new GsonBuilder(); final Gson gson = gb.create(); final ProjectsInformation projects = gson.fromJson(result.body().charStream(), ProjectsInformation.class); if (projects.getProjects() == null) { return null; } return projects.getProjects().get(projectId); }
From source file:org.apache.james.webadmin.dto.HealthCheckDto.java
public String getEscapedComponentName() { return UrlEscapers.urlPathSegmentEscaper().escape(componentName.getName()); }
From source file:org.apache.james.webadmin.dto.HealthCheckExecutionResultDto.java
public String getEscapedComponentName() { return UrlEscapers.urlPathSegmentEscaper().escape(healthCheckResult.getComponentName().getName()); }
From source file:com.offbytwo.jenkins.model.ComputerWithDetails.java
/** * This will explicitly get the whole statistics for the given computer * (node) name./*from w ww . j a v a 2 s . com*/ * * @return {@link LoadStatistics} * @throws IOException */ public LoadStatistics getLoadStatistics() throws IOException { // TODO: Think about the following handling, cause that has also being // done in Computer#details(). String name; if ("master".equals(displayName)) { name = "(master)"; } else { name = UrlEscapers.urlPathSegmentEscaper().escape(displayName); } // TODO: ?depth=2 good idea or could this being done better? return client.get("/computer/" + name + "/" + "loadStatistics/?depth=2", LoadStatistics.class); }
From source file:org.gradle.plugin.use.resolve.service.internal.PluginResolutionServiceClient.java
@Nullable Response<PluginUseMetaData> queryPluginMetadata(final PluginRequest pluginRequest, String portalUrl) { Escaper escaper = UrlEscapers.urlPathSegmentEscaper(); String escapedId = escaper.escape(pluginRequest.getId().toString()); String escapedPluginVersion = escaper.escape(pluginRequest.getVersion()); String escapedGradleVersion = escaper.escape(GradleVersion.current().getVersion()); final String requestUrl = String.format(portalUrl + REQUEST_URL, escapedGradleVersion, escapedId, escapedPluginVersion);/* w w w.j a va2s .c o m*/ final URI requestUri = toUri(requestUrl, "plugin request"); HttpResponseResource response = null; try { response = resourceAccessor.getRawResource(requestUri); final int statusCode = response.getStatusCode(); if (!response.getContentType().equalsIgnoreCase("application/json")) { final String message = String.format( "Response from '%s' was not a valid plugin resolution service response (returned content type '%s', not 'application/json')", requestUri, response.getContentType()); if (LOGGER.isInfoEnabled()) { response.withContent(new Action<InputStream>() { public void execute(InputStream inputStream) { try { String content = IOUtils.toString(inputStream, "utf8"); // might not be UTF8, but good enough LOGGER.info("{}, content:\n{}", message, content); } catch (IOException e) { LOGGER.info(String.format("exception raised while trying to log response from %s", requestUri), e); } } }); } throw new GradleException(message); } return response.withContent(new Transformer<Response<PluginUseMetaData>, InputStream>() { public Response<PluginUseMetaData> transform(InputStream inputStream) { Reader reader; try { reader = new InputStreamReader(inputStream, "utf-8"); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); } try { if (statusCode == 200) { PluginUseMetaData metadata = new Gson().fromJson(reader, PluginUseMetaData.class); metadata.verify(); return new SuccessResponse<PluginUseMetaData>(metadata, statusCode); } else if (statusCode >= 400 && statusCode < 600) { ErrorResponse errorResponse = new Gson().fromJson(reader, ErrorResponse.class); return new ErrorResponseResponse<PluginUseMetaData>(errorResponse, statusCode); } else { throw new GradleException("Received unexpected HTTP response status " + statusCode + " from " + requestUrl); } } catch (JsonSyntaxException e) { throw new GradleException("Failed to parse plugin resolution service JSON response.", e); } catch (JsonIOException e) { throw new GradleException("Failed to read plugin resolution service JSON response.", e); } } }); } catch (IOException e) { throw new UncheckedIOException(e); } finally { try { if (response != null) { response.close(); } } catch (IOException e) { LOGGER.warn("Error closing HTTP resource", e); } } }
From source file:org.onosproject.codec.impl.IntentCodec.java
@Override public ObjectNode encode(Intent intent, CodecContext context) { checkNotNull(intent, "Intent cannot be null"); final ObjectNode result = context.mapper().createObjectNode().put(TYPE, intent.getClass().getSimpleName()) .put(ID, intent.id().toString()) .put(APP_ID, UrlEscapers.urlPathSegmentEscaper().escape(intent.appId().name())); final ArrayNode jsonResources = result.putArray(RESOURCES); for (final NetworkResource resource : intent.resources()) { jsonResources.add(resource.toString()); }/*w w w .jav a2 s .c o m*/ IntentService service = context.getService(IntentService.class); IntentState state = service.getIntentState(intent.key()); if (state != null) { result.put(STATE, state.toString()); } return result; }
From source file:ratpack.http.internal.DefaultHttpUriBuilder.java
@Override public HttpUriBuilder pathComponent(String pathComponent) { escaper = UrlEscapers.urlPathSegmentEscaper(); if (!this.pathComponent.isEmpty()) { this.pathComponent += escaper.escape("/" + pathComponent); } else {/*ww w. j av a2 s . co m*/ this.pathComponent += String.format("/%s", escaper.escape(pathComponent)); } return this; }