I'm trying to POST a XML body to a HTTP endpoint with RESTTemplate, however the following exception is being thrown - "org.springframework.web.client.RestClientException: Cannot extract response: no Content-Type found".
I have checked and the XML file is being posted to the endpoint successfully, however I cannot resolve this exception - clearly I'm doing something wrong. I think I may need to use a HTTP Mapping Converter , but I don't know how to implement this.
def post(String jenkinsURL, String username, String apiCredentials, String jobName) {
RestTemplate rest = new RestTemplate()
String url = "http://$jenkinsURL//createItem?name=$jobName"
def jenkinsConfigPath = "src/main/resources/JenkinsConfig.xml"
def encoding = Base64.getEncoder().encodeToString((username + ":" + apiCredentials).getBytes())
String xmlConfigFile = jenkinsConfigReader.read(jenkinsConfigPath)
HttpHeaders headers = new HttpHeaders()
headers.setContentType(MediaType.APPLICATION_XML)
headers.add("Authorization", "Basic " + encoding)
HttpEntity<String> entity = new HttpEntity<String>(xmlConfigFile, headers)
rest.exchange(url, HttpMethod.POST, entity, String.class)