Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As mentioned in <a href="https://stackoverflow.com/questions/911424/which-is-the-best-way-to-implement-soap-web-services-on-jboss-seam">the other question</a> you could use JAX-WS. However if you'd rather use REST services (JAX-RS) then either:</p> <ul> <li>Read up on JAX-WS in the <a href="http://docs.jboss.com/seam/2.1.2/reference/en-US/html/webservices.html" rel="nofollow noreferrer">Seam Docs</a></li> <li>Check out Stéphane Épardaud's article <a href="http://blog.lunatech.com/2008/03/20/restful-web-services-java-ee-resteasy-jax-rs" rel="nofollow noreferrer">here</a>; or</li> <li>Have a look at Sun <a href="http://jersey.java.net/" rel="nofollow noreferrer">Jersey</a> which is an implementation of JAX-RS.</li> </ul> <p><strong>EDIT</strong>: Norman Richards from the Seam team has just posted a <a href="http://in.relation.to/Bloggers/RESTSupportInLatestSeam21" rel="nofollow noreferrer">blog article about Seam and JAX-RS</a>. Looks fantastic and probably more what you are after than Jersey.</p> <p>I had a look at Jersey last week and was amazed at how little code you need. Here's a little guide:</p> <ol> <li>Download the Jersey Jars and the JAXB Jars (so you can output XML and/or JSON) and add them to your classpath</li> <li>Add the Jersey servlet to your web.xml (in the example below with a <code>url-pattern</code> of <code>service/*</code>)</li> <li>Annotate the Bean that holds your data with JAXB annotations</li> <li>Create a Service class with the Jersey annotations.</li> </ol> <p>Here's an example of a Service:</p> <pre class="lang-java prettyprint-override"><code>@Path("/users") public class UsersService { @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public Users getUsers() { return UserQuery.getUsers(); } } </code></pre> <p>Where this is the Users class:</p> <pre class="lang-java prettyprint-override"><code>@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "users") public class Users { @XmlElement(name="users") private List&lt;User&gt; users = new ArrayList&lt;User&gt;(); public List&lt;User&gt; getUsers() { return this.users; } public void setUsers(List&lt;User&gt; users) { this.users = users; } } </code></pre> <p>And this is the User class:</p> <pre class="lang-java prettyprint-override"><code>@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 } </code></pre> <p>Then you can access the service at <strong><code>http://yourhost/service/users</code></strong> It will produce XML or JSON depending on what your client has for it's HTTP Accepts header. Pretty cool huh?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload