Получение файла .pom с помощью fign - PullRequest
0 голосов
/ 05 августа 2020

Я пытаюсь получить файлы pom из нашего артефакта, вот мой воображаемый клиент:

@FeignClient(name = "artifactory-retriever", decode404 = true)
public interface ArtifactoryClient {
    @GetMapping(path = "artifactory/{repository}/{groupId}/{artifactId}/{version}/{artifactId}-{version}.pom", consumes = MediaType.APPLICATION_XML_VALUE)
    ResponseEntity<ProjectFile> getProjectFile(@PathVariable("repository") String repository, @PathVariable("groupId") String groupId, @PathVariable("artifactId") String artifactId, @PathVariable("version") String version);
}

Файлы POM выглядят так:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>x.x.x</modelVersion>
  ...
    some more elements
  ...
</project>

Модель:

@XmlRootElement(name = "project")
@XmlAccessorType(XmlAccessType.FIELD)
@NoArgsConstructor
@Getter @Setter
public class ProjectFile {

    @XmlAttribute(name="xmlns")
    private String xmlns;

    @XmlAttribute(name="xsi:schemaLocation")
    private String xsiSchemaLocation;

    @XmlAttribute(name="xmlns:xsi")
    private String xmlnsXsi;

    @XmlElement(name="modelVersion")
    private String modelVersion;

    ...
    some more elements
    ...
}

Когда я вызываю getProjectFile, я получаю следующее сообщение об ошибке:

feign.codec.DecodeException: Error while extracting response for type [class com.bnpparibas.cib.community.infra.service.parsing.repository.ProjectFile] and content type [application/x-maven-pom+xml]; 
nested exception is org.springframework.http.converter.HttpMessageNotReadableException: Could not unmarshal to [class com.bnpparibas.cib.community.infra.service.parsing.repository.ProjectFile]: unexpected element (uri:"http://maven.apache.org/POM/4.0.0", local:"project"). Expected elements are <{}project>; 
nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://maven.apache.org/POM/4.0.0", local:"project"). Expected elements are <{}project>

Я уже использовал fign в этом проекте, чтобы получить файл xml, но без атрибутов внутри root элемент, и он сработал, поэтому я предполагаю, что проблема связана с синтаксическим анализом этих атрибутов.

Я также попытался получить файл как ResponseEntity и демаршалировать его, но это тоже не сработало.

Есть идеи по этому поводу?

...