private String buildPath(String rawPath, List<RestParameter> params) throws ActionException { String path = rawPath; for (RestParameter param : params) { String encodedParam = encodePathParam(param.getStringValue()); path = path.replace("{" + param.getName() + "}", encodedParam); } return path; }
private List<RestParameter> getGlobalQueryParamsForAction(RestAction<?> action) { List<RestParameter> queryParams = Lists.newArrayList(); for (RestParameter parameter : globalQueryParams.get(action.getHttpMethod())) { String value = parameter.getStringValue(); if (value != null) { queryParams.add(new RestParameter(parameter.getName(), value)); } } return queryParams; }
private String buildQueryString(List<RestParameter> params) throws ActionException { StringBuilder queryString = new StringBuilder(); for (RestParameter param : params) { queryString .append("&") .append(param.getName()) .append("=") .append(encodeQueryParam(param.getStringValue())); } if (queryString.length() != 0) { queryString.deleteCharAt(0); } return queryString.toString(); }
private void buildHeaders(RequestBuilder requestBuilder, String xsrfToken, RestAction<?> action) throws ActionException { String path = action.getPath(); List<RestParameter> actionParams = action.getHeaderParams(); Collection<RestParameter> applicableGlobalParams = globalHeaderParams.get(action.getHttpMethod()); // By setting the most generic headers first, we make sure they can be overridden by more // specific ones requestBuilder.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); requestBuilder.setHeader(HttpHeaders.CONTENT_TYPE, JSON_UTF8); if (!isAbsoluteUrl(path)) { requestBuilder.setHeader(MODULE_BASE_HEADER, baseUrl); } if (!Strings.isNullOrEmpty(xsrfToken)) { requestBuilder.setHeader(securityHeaderName, xsrfToken); } for (RestParameter parameter : applicableGlobalParams) { String value = parameter.getStringValue(); if (value != null) { requestBuilder.setHeader(parameter.getName(), value); } } for (RestParameter param : actionParams) { requestBuilder.setHeader(param.getName(), param.getStringValue()); } }