Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can do that through the EJB 3.1 <a href="http://docs.oracle.com/javaee/6/api/javax/ejb/embeddable/EJBContainer.html" rel="nofollow">EJBContainer</a> API with a container that supports more than EJB lite. EJB lite is meant to be a minimum rather than a maximum.</p> <p>I know OpenEJB supports JAX-RS embedded, not sure on others. If they support JAX-RS through an embedded Arquillian adapter, they should be able to support it via the standard EJBContainer API which is meant for Java SE usage like testing or standalone apps.</p> <p>Here's an example:</p> <ul> <li><a href="http://openejb.apache.org/examples-trunk/rest-on-ejb" rel="nofollow">http://openejb.apache.org/examples-trunk/rest-on-ejb</a></li> </ul> <p>That one is not well documented, so here are the highlights.</p> <p>First, include the Embedded container libraries. In this case that is the following maven dependency:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.apache.openejb&lt;/groupId&gt; &lt;artifactId&gt;openejb-cxf-rs&lt;/artifactId&gt; &lt;version&gt;4.0.0-beta-3-SNAPSHOT&lt;/version&gt; &lt;scope&gt;test&lt;/scope&gt; &lt;/dependency&gt; </code></pre> <p>Then in your testcase, boot the EJBContainer:</p> <pre><code>final Properties properties = new Properties(); properties.setProperty("openejb.embedded.remotable", "true"); EJBContainer.createEJBContainer(properties); </code></pre> <p>You're good to go, now you can send requests to your service. Using the CXF WebClient, that might look like this:</p> <pre><code>Response response = WebClient.create("http://localhost:4204/rest-on-ejb") .path("/user/create") .query("name", "dummy") .query("pwd", "unbreakable") .query("mail", "foo@bar.fr") .put(null); // Then check the results via invoking the bean directly List&lt;User&gt; list = service.list(0, 100); for (User u : list) { if (!users.contains(u)) { service.delete(u.getId()); return; } } fail("user was not added"); </code></pre> <p>Of course plain URL or Commons HttpClient works as well.</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