Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Atom的超媒体_Java_Rest_Jaxb_Jersey_Atom Feed - Fatal编程技术网

Java 使用Atom的超媒体

Java 使用Atom的超媒体,java,rest,jaxb,jersey,atom-feed,Java,Rest,Jaxb,Jersey,Atom Feed,关于REST的每本书都使用;我还尝试了扩展名称空间前缀apper。但没有一个能起作用,最多只能输出这个: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <customer xmlns:ns2="http://www.w3.org/2005/Atom"> <first-name>Roland</first-name> <ns2:link href="/custom

关于REST的每本书都使用
;我还尝试了扩展
名称空间前缀apper
。但没有一个能起作用,最多只能输出这个:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customer xmlns:ns2="http://www.w3.org/2005/Atom">
    <first-name>Roland</first-name>
    <ns2:link href="/customer/1" rel="self" />
</customer>

罗兰
在泽西岛,使用名称空间和Atom似乎是不可能的。我错过了什么

另外,我将使用XSD生成
@xmlement
类,目前,我创建自己的链接类。是否有一个模式或JAR来实现这一点(
jersey atom
maven dependency使用
rome
,但没有任何帮助)

(假设您不关心名称空间前缀,只想创建链接)

下面是我创建链接的方法。在我的资源类(jersey rest服务)中,我返回一个java对象(在“Person”下面),该对象的类用jaxb注释修饰。其中一个属性返回atom链接对象

@XmlRootElement(namespace = Namespace.MyNamespace)
public class Person implements Serializable {
    private AtomLinks links = null;

    @XmlElement(name = "link", namespace = Namespace.Atom)
    public AtomLinks getLink() {
        if (this.links == null) {
            this.links = new AtomLinks();
        }

        return this.links;
    }
..
}

@XmlAccessorType(value = XmlAccessType.NONE)
public class AtomLinks extends ArrayList<AtomLink> {
..
}

@XmlAccessorType(value = XmlAccessType.NONE)
public class AtomLink implements Serializable {
    @XmlAttribute(name = "href")
    public URI getHref() {
        return href;
    }
    @XmlAttribute(name = "rel")
    public String getRel() {
        return rel;
    }
    @XmlAttribute(name = "type")
    public String getType() {
        return type;
    }
    @XmlAttribute(name = "hreflang")
    public String getHreflang() {
        return hreflang;
    }
    @XmlAttribute(name = "title")
    public String getTitle() {
        return title;
    }
..
}

public class Namespace {
    public final static String Atom = "http://www.w3.org/2005/Atom";
..
}
@XmlRootElement(namespace=namespace.MyNamespace)
公共类Person实现可序列化{
私有AtomLinks链接=null;
@XmlElement(name=“link”,namespace=namespace.Atom)
公共AtomLinks getLink(){
if(this.links==null){
this.links=新的AtomLinks();
}
返回此链接;
}
..
}
@XmlAccessorType(值=XmlAccessType.NONE)
公共类AtomLinks扩展了ArrayList{
..
}
@XmlAccessorType(值=XmlAccessType.NONE)
公共类AtomLink实现可序列化{
@xmltattribute(name=“href”)
公共URI getHref(){
返回href;
}
@XmlAttribute(name=“rel”)
公共字符串getRel(){
返回rel;
}
@XmlAttribute(name=“type”)
公共字符串getType(){
返回类型;
}
@XmlAttribute(name=“hreflang”)
公共字符串getHreflang(){
回程;
}
@XmlAttribute(name=“title”)
公共字符串getTitle(){
返回标题;
}
..
}
公共类命名空间{
公共最终静态字符串Atom=”http://www.w3.org/2005/Atom";
..
}

在返回我的对象(“人”)之前,我填写链接,创建一个自链接和指向其他相关链接的链接。我利用jersey注入的uriInfo对象获取基本url。如果这有帮助,但您想了解更多示例,请告诉我,我将填补空白。

如果我是对的,泽西岛有一种方法可以将链接注入到对象


请参阅:第6章。

您的问题是根本无法获取链接,还是希望链接具有“atom”名称空间前缀?我想要名称空间前缀。我还想知道我是否必须自己创建AtomLink类。Thank.RESTEasy对此有自己的解决方案:(类似于jayraynet的想法,但使用注释使其更简单),我想我在某处读到它可能是JAX-RS 2.0规范的一部分(这可能意味着它也将是Jersey的一部分)。