@Override public String getRequestURI() { StringBuilder sb = new StringBuilder(); sb.append(getBaseRequestURI().orElseThrow(() -> new HttpClientInvocationException("Missing target base URI")) .toString()); sb.append(getRequestPath().map(p -> (sb.toString().endsWith("/") && p.startsWith("/")) ? p.substring(1) : p) .orElse("")); return sb.toString(); }
@Override public R authorizationBasic(String username, String password) { ObjectUtils.argumentNotNull(username, "Username must be not null"); ObjectUtils.argumentNotNull(password, "Password must be not null"); try { return header(HttpHeaders.AUTHORIZATION, HttpHeaders.SCHEME_BASIC + " " + Base64.getEncoder() .encodeToString(new String((username + ":" + password)).getBytes("ISO-8859-1"))); } catch (UnsupportedEncodingException e) { throw new HttpClientInvocationException(e); } }
@Override public <T, R> Optional<T> invokeForEntity(HttpMethod method, RequestEntity<R> requestEntity, ResponseType<T> responseType) { ResponseEntity<T> response = invoker.invoke(this, method, requestEntity, responseType, true); if (response == null) { throw new HttpClientInvocationException("The invoker [" + invoker + "] returned a null response"); } try { return response.getPayload(); } catch (Exception e) { throw new HttpClientInvocationException(e); } finally { if (responseType != null && InputStream.class != responseType.getType()) { try { response.close(); } catch (Exception e) { LOGGER.debug(() -> "Failed to close the response", e); } } } }