【发布时间】:2016-05-22 08:19:51
【问题描述】:
我有一个尝试从 REST 服务读取 XML 请求的 CXF WebClient。
我正在使用代码:
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>
它似乎正在尝试将技能解析为其他内容,其中似乎包含链接、nameUriPair 和触发器。 我没有这样的课。 (我确实检查了导入,这是我的技能,而不是别的)
我在 3.0.2 和 3.1.5 版本中都尝试过使用以下工件
组ID:
org.apache.cxf
ArtifactID:
cxf-rt-rs-client
cxf-rt-frontend-jaxrs
cxf-rt-transsports-http
【问题讨论】: