Учитывая это очень простое приложение Spring Ботинок:преобразования XML терпит неудачу с весны загрузки RestTemplate
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
с Maven зависимостей
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
И типы
@XmlRootElement(name = "ICECAT-interface")
public class IceCatResponse {
private Product product;
/* getters, setters omitted */
}
@XmlRootElement(name = "Product")
public class Product {
private int code;
/* getters, setters omitted */
}
керлинг необходимые выходы URL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ICECAT-interface SYSTEM "http://data.icecat.biz/dtd/ICECAT-interface_response.dtd">
<!-- source: Icecat.biz 2017 -->
<ICECAT-interface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://data.icecat.biz/xsd/ICECAT-interface_response.xsd">
<Product Code="1"
HighPic="http://images.icecat.biz/img/norm/high/21900316-8020.jpg"
...>
...
</Product>
</ICECAT-interface>
Я пытаюсь выполнить этот вызов через RestTemplate и хочу получить результат, проанализированный в объект типа IceCatResponse
:
ResponseEntity<IceCatResponse> result = this.httpTemplate.exchange(url, HttpMethod.GET, request, IceCatResponse.class);
с request
, содержащими только в заголовке аутентификации.
Это приводит к сообщению об ошибке
Не удалось прочитать HTTP сообщение: org.springframework.http.converter.HttpMessageNotReadableException: Не удалось распаковать в [класс de.mischok.konfigurator.spikeicecat.model .IceCatResponse]: null; Вложенное исключение - javax.xml.bind.UnmarshalException - со связанным исключением: [org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 10; DOCTYPE IST Nicht zulässig, Венна дас Feature «http://apache.org/xml/features/disallow-doctype-decl» ауф «истинный» gesetzt ист.]
Я думаю, что DOCTYPE часть ответа моя проблема, кто-нибудь знает, как я могу настроить Spring игнорировать эта часть?