-
May 5th, 2012, 09:33 AM
#1
Rest client with receive list of XML using annotations
Hi everyone,
I'm trying to receive atoms from a repository
the form of the xml i want to retrieve is the following:
<authors xmlns="http://www.../ckp" xmlns:atom="http://www.w3.org/2005/atom">
<author>
<atom:link rel="author" type="application/xml" href="http://www.../ckp/author/1"/>
</author>
<author>
<atom:link rel="author" type="application/xml" href="http://www.../ckp/author/2"/>
</author>
<author>
I declare a package-info:
@javax.xml.bind.annotation.XmlSchema (
namespace="http://www.../ckp",
elementFormDefault=XmlNsForm.QUALIFIED,
xmlns = {
@javax.xml.bind.annotation.XmlNs( prefix=" ", namespaceURI="http://www.../ckp"),
@javax.xml.bind.annotation.XmlNs( prefix="atom" ,namespaceURI="http://www.w3.org/2005/atom")
}
)
package org.client.model;
import javax.xml.bind.annotation.*;
I declare a class Author:
import javax.xml.bind.annotation.*;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Author {
@XmlAttribute
private String author;
private String name;
private String address;
private String affiliation;
private String email;
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getAffiliation() {
return affiliation;
}
public void setAffiliation(String affiliation) {
this.affiliation = affiliation;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
The aformentioned class says that each one of the authors has name,address,affiliation,email
Individual authors i can retrieve from the www.../ckp/author/1
But my problem is that i can not retrieve the list. The code i try is the following:
@XmlAccessorType(XmlAccessType.FIELD)
public class Atomlink {
@XmlAttribute
private String rel;
@XmlAttribute
private String type;
@XmlAttribute(required = true)
private String href;
public String getRel() {
return rel;
}
public void setRel(String rel) {
this.rel = rel;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
}
This is the class for the atom and after i create a class called AuthorMeta:
@XmlAccessorType(XmlAccessType.FIELD)
public class AuthorMeta {
@XmlElement(name="link")
private Atomlink link;
public Atomlink getLink() {
return link;
}
public void setLink(Atomlink link) {
this.link = link;
}
}
And finally the class authors:
@XmlRootElement(name="authors")
@XmlAccessorType(XmlAccessType.FIELD)
public class Authors {
@XmlAttribute
private String authors;
public void setAuthors(String authors) {
this.authors = authors;
}
public String getAuthors() {
return authors;
}
@XmlElement
private List<AuthorMeta> data;
public List<AuthorMeta> getData() {
return data;
}
public void setData(List<AuthorMeta> data) {
this.data = data;
}
}
And the view is the following:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Authors</h1>
<c:url var="addUrl" value="/add" />
<table style="border: 1px solid; width: 500px; text-align:center">
<thead style="background:#fcf">
<tr>
<th>Name</th>
<th>Address</th>
<th>Affiliation</th>
<th>Email</th>
<th colspan="4"></th>
</tr>
</thead>
<tbody>
<c:forEach items="${authors}" var="author">
<c:url var="editUrl" value="/update?id=${author.id}" />
<c:url var="deleteUrl" value="/delete?id=${author.id}" />
<c:url var="getUrl" value="/author?id=${author.id}" />
<tr>
<td><c:out value="${author.name}" /></td>
<td><c:out value="${author.address}" /></td>
<td><c:out value="${author.affiliation}" /></td>
<td><c:out value="${author.email}" /></td>
<td><a href="${editUrl}">Edit</a></td>
<td><a href="${deleteUrl}">Delete</a></td>
<td><a href="${addUrl}">Add</a></td>
<td><a href="${getUrl}">Get</a></td>
</tr>
</c:forEach>
</tbody>
</table>
<c:if test="${empty authors}">
There are currently no persons in the list. <a href="${addUrl}">Add</a> a person.
</c:if>
</body>
</html>
Can anyone tells me what i'm doing wrong?
-
May 5th, 2012, 06:29 PM
#2
Please help me. I'm trying to retrieve the atom list one week now
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules