/** * Append Http headers to string builder. * * @param headers * @param builder */ private void appendHeaders(HttpHeaders headers, StringBuilder builder) { for (Entry<String, List<String>> headerEntry : headers.entrySet()) { builder.append(headerEntry.getKey()); builder.append(":"); builder.append(StringUtils.arrayToCommaDelimitedString(headerEntry.getValue().toArray())); builder.append(NEWLINE); } }
private void addGeoQueryParams(UriComponentsBuilder builder, GeoQuery geoQuery) { if (geoQuery != null) { StringBuilder georel = new StringBuilder(geoQuery.getRelation().name()); if (geoQuery.getRelation() == GeoQuery.Relation.near) { georel.append(';').append(geoQuery.getModifier()); georel.append(':').append(geoQuery.getDistance()); } builder.queryParam("georel", georel.toString()); builder.queryParam("geometry", geoQuery.getGeometry()); builder.queryParam( "coords", geoQuery .getCoordinates() .stream() .map(Coordinate::toString) .collect(Collectors.joining(";"))); } }
/** * Builds request content string from request and body. * * @param request * @param body * @return */ private String getRequestContent(HttpRequest request, String body) { StringBuilder builder = new StringBuilder(); builder.append(request.getMethod()); builder.append(" "); builder.append(request.getURI()); builder.append(NEWLINE); appendHeaders(request.getHeaders(), builder); builder.append(NEWLINE); builder.append(body); return builder.toString(); }
/** * Builds response content string from response object. * * @param response * @return * @throws IOException */ private String getResponseContent(CachingClientHttpResponseWrapper response) throws IOException { if (response != null) { StringBuilder builder = new StringBuilder(); builder.append("HTTP/1.1 "); builder.append(response.getStatusCode()); builder.append(" "); builder.append(response.getStatusText()); builder.append(NEWLINE); appendHeaders(response.getHeaders(), builder); builder.append(NEWLINE); builder.append(response.getBodyContent()); return builder.toString(); } else { return ""; } }