0

I receive an error saying org.springframework.web.client.HttpClientErrorException: 400 null from the console meaning that my URL sent a bad request that the server could not understand.

However, whenever i put a URL with no %20 or + signs for the spaces

Example: http://ksr-ca-qmaltjira.ca.kronos.com:8061/rest/api/2/search?jql=project=SUP&maxResults=2 it works and my data is displayed on my local page.

String username = "confidential";
String password = "confidential";

private static final String jiraBaseURL = "http://ksr-ca-qmaltjira.ca.kronos.com:8061/rest/api/search?jql=project%3D%22Customer%20Support%22%20%26%20type%20%3D%20%22Change%20Request%22%20&maxResults=2";
private RestTemplate restTemplate;
private HttpHeaders httpHeaders;





private HttpHeaders createHeadersWithAuthentication() {
    String plainCreds = username + ":" + password;
    byte[] base64CredsBytes = Base64.getEncoder().encode(plainCreds.getBytes());
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);

    return headers;
}




@RequestMapping("/cr-follow-up")
public @ResponseBody ResponseEntity<String> getData()
{
    restTemplate = new RestTemplate();
    httpHeaders = createHeadersWithAuthentication();
    httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
    HttpEntity<String> entity = new HttpEntity<String>(httpHeaders);
    ResponseEntity<String> response = restTemplate.exchange(jiraBaseURL, HttpMethod.GET, entity, String.class);

    return response;
}
leo jr silao
  • 37
  • 2
  • 11

1 Answers1

0

Try encoding your URL with URLEncoder.encode()

kbonnelly
  • 189
  • 1
  • 1
  • 11