Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6543939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:24:23+00:00 2026-05-25T11:24:23+00:00

I know I can expose a class inside a web-module as a restful interface

  • 0

I know I can expose a class inside a web-module as a restful interface using only annotations. Now I want to do something a little more complex.

I’m having a stateless EJB in an ejb-module inside my ear and want to expose this bean as a restful interface using jax-rs. In the first step I annotated the EJB class with @Path and @GET. It didn’t work.

It works when I create an additional web-module with a web.xml that contains

<context-param>
    <param-name>resteasy.jndi.resources</param-name>
    <param-value>myear/testService/no-interface,myear/testService2/no-interface</param-value>
</context-param>
<listener>
    <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
    <servlet-name>rest</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>rest</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

I can expose a simple class with only annotations, so I can’t quite believe that I have to explicitly configure every EJB that I want to expose in a config file.

Is there a simpler/better way?

I’m working with JBoss 6.1

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:24:24+00:00Added an answer on May 25, 2026 at 11:24 am

    There shouldn’t be any config required. If you’re willing to look at another container — at least for reference purposes — here’s an example that exposes an @Singleton EJB as both a JAX-RS service and @LocalBean.

    The bean itself uses Container-Managed Transactions and JPA, with the JPA @Entity objects used in the actual JAX-RS messages — effectively turning the EntityManager into a transactional JAX-RS service.

    Small chunk of the EJB class:

    @Singleton
    @Lock(LockType.WRITE)
    @Path("/user")
    @Produces(MediaType.APPLICATION_XML)
    public class UserService {
    
        @PersistenceContext
        private EntityManager em;
    
        @Path("/create")
        @PUT
        public User create(@QueryParam("name") String name,
                           @QueryParam("pwd") String pwd,
                           @QueryParam("mail") String mail) {
            User user = new User();
            user.setFullname(name);
            user.setPassword(pwd);
            user.setEmail(mail);
            em.persist(user);
            return user;
        }
    
        @Path("/list")
        @GET
        public List<User> list(@QueryParam("first") @DefaultValue("0") int first,
                               @QueryParam("max") @DefaultValue("20") int max) {
            List<User> users = new ArrayList<User>();
            List<User> found = em.createNamedQuery("user.list", User.class).setFirstResult(first).setMaxResults(max).getResultList();
            for (User u : found) {
                users.add(u.copy());
            }
            return users;
        }
    

    And here’s a chunk of the unit test for it (uses the Embeddable EJBContainer API):

    public class UserServiceTest {
        private static Context context;
        private static UserService service;
        private static List<User> users = new ArrayList<User>();
    
        @BeforeClass
        public static void start() throws NamingException {
            Properties properties = new Properties();
            properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
            context = EJBContainer.createEJBContainer(properties).getContext();
    
            // create some records
            service = (UserService) context.lookup("java:global/rest-on-ejb/UserService");
            users.add(service.create("foo", "foopwd", "foo@foo.com"));
            users.add(service.create("bar", "barpwd", "bar@bar.com"));
        }
    
        @Test
        public void list() throws Exception {
            String users = WebClient.create("http://localhost:4204")
                    .path("/user/list")
                    .get(String.class);
            assertEquals(
                "<users>" +
                    "<user>" +
                        "<email>foo@foo.com</email>" +
                        "<fullname>foo</fullname>" +
                        "<id>1</id>" +
                        "<password>foopwd</password>" +
                    "</user>" +
                    "<user>" +
                        "<email>bar@bar.com</email>" +
                        "<fullname>bar</fullname>" +
                        "<id>2</id>" +
                        "<password>barpwd</password>" +
                    "</user>" +
                "</users>", users);
        }
    

    Full source of the example here. The entire example is just three classes (that includes the test) and a persistence.xml file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a module to extend the Core/Catalog/Product/View/Media.php class so I can expose
This is something I know can be done somehow , because I've done it
I have a query that I know can be done using a subselect, but
I know I can do most of this by hacking Trac and using Git
I want to expose a class to CLR classes. The reason I have is
How can I expose a Java bean to a JSP page by using struts?
I am using boost::signal in a native C++ class, and I now I am
You can know if the event stack is empty calling the gtk.events_pending() method, but
I know you can look at the row.count or tables.count, but are there other
I know you can do redirection based on the domain or path to rewrite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.