private HttpHeaders getHttpHeaders() { String auth = "Basic " + new String( Base64.getEncoder() .encode((userData.getEmail() + ":" + userData.getApiKey()).getBytes())); HttpHeaders headers = new HttpHeaders(); headers.put("Authorization", Arrays.asList(auth)); headers.add(CorrelationId.CORRELATION_ID_HEADER_KEY, correlationId.getCorrelationId()); return headers; }
@Override public FastbillResponse request(FastbillRequest parameter) { log.debug( "Requesting Fastbill for {} and correlation-id: {}", parameter.toJson(), correlationId.getCorrelationId()); try { HttpHeaders headers = getHttpHeaders(); HttpEntity entity = new HttpEntity(parameter.toJson(), headers); ResponseEntity<FastbillResponse> exchange = restTemplate.exchange(apiURI, HttpMethod.POST, entity, FastbillResponse.class); return exchange.getBody(); } catch (Exception e) { LOG.error("error making REST call", e); throw new RuntimeException(e); } }