使用 Seam 的 Web 服务 [英] Webservice using Seam

查看:51
本文介绍了使用 Seam 的 Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Seam 的新手,想使用 Seam 开发 Web 服务.我有一个紧迫的截止日期,我可以在那里找到使用 Seam 开发 Web 服务的详细信息.任何好的文档、书籍、网站等.

I am new to Seam and want to develop Webservice using Seam.I have an aggressive deadline Where i can find the details to develop the Webservice using Seam.Any good document, book, website etc.

推荐答案

另一个问题 你可以使用 JAX-WS.但是,如果您更愿意使用 REST 服务 (JAX-RS),那么要么:

As mentioned in the other question you could use JAX-WS. However if you'd rather use REST services (JAX-RS) then either:

  • 阅读 Seam 文档
  • 查看 Stéphane Épardaud 的文章这里;或
  • 看看 Sun Jersey,它是 JAX-RS 的一个实现.
  • Read up on JAX-WS in the Seam Docs
  • Check out Stéphane Épardaud's article here; or
  • Have a look at Sun Jersey which is an implementation of JAX-RS.

编辑:Seam 团队的 Norman Richards 刚刚发布了一篇博客文章关于 Seam 和 JAX-RS.看起来很棒,而且可能比泽西岛更符合您的需求.

EDIT: Norman Richards from the Seam team has just posted a blog article about Seam and JAX-RS. Looks fantastic and probably more what you are after than Jersey.

上周我查看了 Jersey,对您需要的代码如此之少感到惊讶.这是一个小指南:

I had a look at Jersey last week and was amazed at how little code you need. Here's a little guide:

  1. 下载 Jersey 罐子和JAXB 罐子(这样你就可以输出 XML和/或 JSON)并将它们添加到您的类路径
  2. 将 Jersey servlet 添加到您的web.xml(在下面的示例中,带有 service/*url-pattern)
  3. 注释保存您的 Bean带有 JAXB 注释的数据
  4. 创建一个服务类泽西注释.

以下是服务示例:

@Path("/users")
public class UsersService {
  @GET
  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  public Users getUsers() {
    return UserQuery.getUsers();
  }
}

这是用户类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "users")
public class Users {
  @XmlElement(name="users")
  private List<User> users = new ArrayList<User>();

  public List<User> getUsers() {
    return this.users;
  }

  public void setUsers(List<User> users) {
    this.users = users;
  }
}

这是用户类:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "user")
public class User implements Serializable {
  @XmlElement(name="id")
  private long userId;

  @XmlElement(name="firstName")
  private String firstName;

  @XmlElement(name="lastName")
  private String lastName;

  @XmlElement(name="email")
  private String email;

  public User() {}

  public User(long userId, String firstName, String lastName, String email) {
    this.userId = userId;
    this.firstName = firstName;
    this.lastName = lastName;
    this.email = email;
  }

  //And the getter/setters
}

然后您就可以通过 http://yourhost/service/users 访问该服务它会根据您的客户端的 HTTP Accepts 标头生成 XML 或 JSON.很酷吧?

Then you can access the service at http://yourhost/service/users It will produce XML or JSON depending on what your client has for it's HTTP Accepts header. Pretty cool huh?

这篇关于使用 Seam 的 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆