Вот функция, которая у меня есть, которая пытается сделать простой вызов REST.
private String getWorkdayDataArray() throws IllegalArgumentException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {
String url = getWorkers();
HttpClient httpClient = HttpClientBuilder.create().build();
HttpResponse httpResponse = httpClient.execute(new HttpGet(url));
return EntityUtils.toString(httpResponse.getEntity());
}
private String getWorkers() throws IllegalArgumentException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException
{
RestTemplate restTemplate = getRestTemplate();
HttpEntity<String> entity = getEntityForWorkday();
String resp = null;
String url = String.format("https://XXXXXXXXXXX.com/dorqers/v5?key=%s",AUTH_KEY);
try {
ResponseEntity<String> respEntity = restTemplate.exchange(url,HttpMethod.GET,entity,String.class);
resp = respEntity.getBody();
resp.replaceAll(" ", "");
}
catch (Exception e){
e.printStackTrace();
}
return resp;
}
public HttpEntity<String> getEntityForWorkday()
{
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization",AUTHENTICATION_TOKEN);
headers.set("Content-Type","application/json");
return new HttpEntity<>("parameters",headers);
}
public RestTemplate getRestTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException
{
//Disable SSL
org.apache.http.conn.ssl.TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(csf)
.build();
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory);
return restTemplate;
}
Почтальон работает нормально в почтальоне. Когда я пытаюсь сделать это из моего API, я получаю следующую ошибку:
java.lang.IllegalArgumentException: Illegal character in scheme name at index 0: {"total_workers":2228,"workers":
[{"worker":{"update_identifier":"asssy25-JUN-18 06.24.52.429287 AM -05:00","identity":
{"first_name":"damam",
"middle_name":"A",
"last_name":"Craft",
"preferred_first_name":"damam",
"preferred_last_name":"Craft",
"lan_id":"T003","worker_type":"Team Member",
"active_directory_worker_id":"01039932","is_manager":"N"
},"location":{
"location_type":"OFFICE","work_state":"CA"
},"email":
{"work_email":"damam.craft@tt.com",
"supervisor_work_email":"barra.kosi@tt.com"
},"job":
{"job_description":"Sr Coordinator Service Center - US",
"job_entry_date":"2011-04-10",
"pay_type_code":"Hourly",
"position_entry_date":"2011-04-10",
"active_directory_supervisor_id":"hhhgffssaa",
"standard_hours":"40.00","weekly_work_hours":"40.00",
"time_type":"Full time"
},"employee":
{"employee_status_description":"Active"},
"employee_action":{"hire_date":"1978-04-04","rehire_date":"1978-04-04"}}},
Он отправляет и печатает весь объект JSON, который возвращается из вызова GET. Вот оставшаяся часть журнала ошибок:
at java.net.URI.create(URI.java:852)
at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:66)
at application.Collector.WorkdayCollector.getWorkdayDataArray(WorkdayCollector.java:65)
at application.Collector.WorkdayCollector.getWorkdayData(WorkdayCollector.java:43)
at application.Application.lambda$run$0(Application.java:26)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:732)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:716)
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:703)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:304)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
at application.Application.main(Application.java:13)
Caused by: java.net.URISyntaxException: Illegal character in scheme name at index 0: <Prints entire JSON Again>
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.checkChar(URI.java:3031)
at java.net.URI$Parser.parse(URI.java:3047)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)
... 11 more
Я провел некоторое исследование, и ошибка, скорее всего, произойдет, если в URL есть пробелы. Я дважды проверил, и в моем URL нет пробелов. Самое странное, что журнал печатает весь JSON, но я нигде не напечатал его в своем коде.
Любая помощь по этому вопросу высоко ценится.