2012-04-10 133 views
2

我需要添加链接到我的resteasy api xml和json输出。 所以我写了一个JAXB AtomLink类如下HATEOAS链接可点击

package samples; 
import javax.xml.bind.annotation.XmlAttribute; 
import javax.xml.bind.annotation.XmlRootElement; 

@XmlRootElement(name="link", namespace="http://www.w3.org/2005/Atom") 

public class AtomLink { 
    private String rel; 
    private String href; 
    private String type; 

    public AtomLink() {} 

    public AtomLink(String rel, String href, String type) { 
     this.rel = rel; 
     this.href = href; 
     this.type = type; 
    } 

    public AtomLink(String rel, String href) { 
     this(rel,href,"application/xml"); 
    } 

    @XmlAttribute 
    public String getRel() { 
     return rel; 
    } 
    public void setRel(String rel) { 
     this.rel = rel; 
    } 

    @XmlAttribute 
    public String getHref() { 
     return href; 
    } 
    public void setHref(String href) { 
     this.href = href; 
    } 

    @XmlAttribute 
    public String getType() { 
     return type; 
    } 
    public void setType(String type) { 
     this.type = type; 
    } 

} 

,并在我的JAXB XML或JSON对象设置链接值。 我得到了如下输出。但链接不可点击。

输出:

<data xmlns:ns2="http://www.w3.org/2005/Atom"> 
<bucket id="2" name="2012-APR-09 12:05 AM"> 
<av_data unit="percent" value="100"/> 
<data_count unit="#" value="10"/> 
<pf_data unit="seconds" value="4.618"/> 
</bucket> 
<ns2:link href="http://localhost:8080/webapp/api/getrawdata?start=3&size=2" rel="next" type="application/xml"/> 
</data> 

我应该做的,以使链接点击。

在此先感谢。 Anitha

回答

2

XML和JSON只是基于文本的数据表示。点击链接的能力取决于您使用的浏览器来查看数据能力,以将该文本的一部分识别为链接并将其呈现为超链接。

+0

感谢您的回答,我的疑问得到了澄清。 – Anitha 2012-04-11 06:26:13