我有一个CXF WebClient,它试图从REST服务中读取XML请求。
我正在使用代码:
WebClient client = WebClient.create(baseURL);
String authorizationHeader = "Basic "+ org.apache.cxf.common.util.Base64Utility.encode(("user:password").getBytes());
client.header("Authorization", authorizationHeader);
client.accept(MediaType.APPLICATION_XML).path(path);
System.out.println(client.get(String.class));
return client.get(Skill.class);
技能课程:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"self",
"skillId",
"skillName"
})
@XmlRootElement(name = "Skill")
public class Skill implements RootObject{
protected Self self;
protected int skillId;
@XmlElement(required = true)
protected String skillName;
getters...setters...
}
System.out.println返回:
<?xml version="1.0" encoding="UTF-8"?>
<Skill><self>http://192.168.45.159/adminapi/skill/4</self><skillId>4</skillId><skillName>ICD2</skillName></Skill>
但是我得到了例外:
com.sun.istack.internal.SAXParseException2; lineNumber: 2; columnNumber: 1; unexpected element (uri:"", local:"Skill"). Expected elements are <{}link>,<{}nameUriPair>,<{}trigger>
似乎它试图将Skill解析为其他东西,似乎包含link,nameUriPair和trigger。 我没有这样的课。 (我确实检查了导入,这是我的技能,而不是别的东西)
我在版本3.0.2和3.1.5中尝试了以下工件
的GroupID:
org.apache.cxf
ArtifactIDs:
CXF-RT-RS-客户端
CXF-RT-前端-JAXRS
CXF-RT-传输-HTTP
答案 0 :(得分:0)
我显然已经太晚了,但我认为问题在于:
return client.get(Skill.class);
我认为需要做的是:
Response r = client.get();
Skill skill = (Skill) r.readEntity(Skill.class);