[英]RestFul Service (spring3) CLIENT java?
我正在尝试在客户端解组JAXB,但是我正在获取Object的属性NULL。
那就是我要解组的事情
URL url = new URL("http://localhost:9191/service/firstName/tony?format=xml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/atom+xml");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
JAXBContext jaxbContext = JAXBContext.newInstance(LDAPUsers.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
LDAPUsers lu = (LDAPUsers) jaxbUnmarshaller.unmarshal(br);
ArrayList<LDAPUser> list = new ArrayList<LDAPUser>();
//list.addAll(lu.getCounty());
**System.out.println(lu.ldapUser.get(0).getFirstName());//this is giving NULL**
conn.disconnect();
请帮助!
您可以在Unmarshaller
上设置ValidationEventhandler
的实例,以在Unmarshaller
过程中发生任何问题时得到通知。 这可以帮助调试问题:
jaxbUnmarshaller.setEventHandler(new ValidationEventHandler() {
@Override
public boolean handleEvent(ValidationEvent event) {
System.out.println(event.getMessage());
return true;
}
});
客户实例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.