"模板为空或长度为零"使用泽西式声明式超链接

时间:2016-03-17 11:31:00

标签: java jax-rs jersey-2.0

我试图按照我在这里和那里找到的例子来整合声明性超链接。我发现有些使用... value = "/systemusers/{id}" ...,有些则使用... resource = SystemUser .class ...。在我的代码中,如果我使用第一个解决方案,我在我的JSon响应中正确地注入了链接,而后者则出现"Template is null or has zero length"错误。问题是什么,错误指的是哪个模板? 这是我的代码片段:

@XmlRootElement
public class SystemUser extends Account
{
  private String                        addrRow1;
  private String                        addrRow2;
  private String                        addrRow3;
  private String                        postCode;
  private String                        city;
  private String                        country;
  private String                        responsiblePerson;           // npid der resp. person
  private String                        responsibleAgroup;
  private String                        project;
  private String                        personRole;                  // for ex. selfreg_host, technical, nethz_guest, ...

  @InjectLink( value = "/users/{npid}", style = Style.ABSOLUTE, bindings = @Binding( name = "npid", value = "${instance.npid}" ), rel = "self" )
  @XmlJavaTypeAdapter( XmlAdapter.class )
  @XmlElement( name = "link" )
  Link                                  self;
...

如上所述,如果我指定value参数

"link": {
        "uri": "/IAMWS/services/users/10",
        "params": {
            "rel": "self"
        },
        "type": null,
        "rel": "self",
        "title": null,
        "rels": [
            "self"
        ],
        "uriBuilder": {
            "absolute": false
        }
    }

如果我指定了resource参数:

javax.servlet.ServletException: java.lang.IllegalArgumentException: Template is null or has zero length
    org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:487)
    org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
    org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
...

我错过了什么?

0 个答案:

没有答案