1

I am trying to develope Java EE application in Eclipse IDE. I am using JBoss 7.0 app server.

My project contains 3 containers:

EAR:

-EJB (EJB 3.0 - business logic)

-JPA (JPA 2.0 - EclipseLink 2.3.x, entities from database, data access object layer)

-WAR (JSF 2.0 - managed beans and .xhtml pages)

App logic:

  • My JPA container manipulates with the database and perform basic CRUD operations.

  • EJB container is using the JPA's methods in order to communicate with the WAR (managed beans).

  • WAR perform the user requests and communicate with the EJB container in order to get required result from the database for specific user.

Problem that costs me too much time and still no solution:

I've configured those 3 containers to work together properly with test methods (only containing strings) but I am facing an issue when trying to inject @EJB SessionBean to WAR (managed bean) after setting up the real methods that actually returns something from DB.

HTTP STATUS 400: The requested resources is unavailable.

This is my JPA's DAO class where I am not pretty sure wheather I've instantiated the entitymanager and entity manager factory correctly (Should I use @PersistanceContext(unitName="testing-jpa") instead?):

public class TestDAOImpl implements ITestDAO {

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("testing-jpa");
    EntityManager manager = emf.createEntityManager();
    List<User> users = new ArrayList<User>();

    @Override
    public List<User> getList() {
        users = manager.createNamedQuery("User.findAll", User.class).getResultList();
        return users;
    }

}

OK. So the method getList() performs the query for User entity. This method is called in the EJB container. The EJB's TestStateless class that implements Remote interface:

@Stateless(mappedName = "testStateless")
public class TestStateless implements TestStatelessLocal {

    public TestStateless() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public String getText() {
        return "hello from ejb3";
    }

    @Override
    public List<User> getUsers() {
        ITestDAO testDao = new TestDAOImpl();
        return testDao.getList();
    }

}

Now, after I've defined EJB's TestStateless.getUsers() method I got 404 STATUS.

This is how my WAR's ManagedBean class looks like:

public class ManageBean {

    @EJB
    TestStatelessRemote testBean;

    public ManageBean() {

    }

    public String getSomeText() {
        return "" + 123;
    }

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

}

After this point, I should use ManagedBean's getUsers() method on .xhtml page and loop through the dataTable in order to list each user on the page.

This is my persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="testing-jpa" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>java:jboss/datasources/ExampleDS</non-jta-data-source>
        <class>com.model.User</class>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/cs450_pr"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value=""/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        </properties>
    </persistence-unit>
</persistence>

Update:

Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name>testing-war</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
  <welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
  </welcome-file-list>
</web-app>

Console log:

16:44:04,699 INFO  [org.jboss.modules] JBoss Modules version 1.0.1.GA
16:44:05,027 INFO  [org.jboss.msc] JBoss MSC version 1.0.0.GA
16:44:05,105 INFO  [org.jboss.as] JBoss AS 7.0.1.Final "Zap" starting
16:44:06,125 WARN  [org.jboss.as] No security realm defined for native management service, all access will be unrestricted.
16:44:06,137 INFO  [org.jboss.as] creating http management service using network interface (management) port (9990)
16:44:06,140 WARN  [org.jboss.as] No security realm defined for http management service, all access will be unrestricted.
16:44:06,155 INFO  [org.jboss.as.logging] Removing bootstrap log handlers
16:44:06,191 INFO  [org.jboss.as.connector.subsystems.datasources] (Controller Boot Thread) Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
16:44:06,212 INFO  [org.jboss.as.clustering.infinispan.subsystem] (Controller Boot Thread) Activating Infinispan subsystem.
16:44:06,486 INFO  [org.jboss.as.naming] (Controller Boot Thread) Activating Naming Subsystem
16:44:06,508 INFO  [org.jboss.as.naming] (MSC service thread 1-3) Starting Naming Service 
16:44:06,512 INFO  [org.jboss.as.osgi] (Controller Boot Thread) Activating OSGi Subsystem
16:44:06,592 INFO  [org.jboss.as.security] (Controller Boot Thread) Activating Security Subsystem
16:44:06,604 INFO  [org.jboss.remoting] (MSC service thread 1-7) JBoss Remoting version 3.2.0.Beta2
16:44:06,627 INFO  [org.xnio] (MSC service thread 1-7) XNIO Version 3.0.0.Beta3
16:44:06,671 INFO  [org.xnio.nio] (MSC service thread 1-7) XNIO NIO Implementation Version 3.0.0.Beta3
16:44:07,123 INFO  [org.apache.catalina.core.AprLifecycleListener] (MSC service thread 1-3) The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;native;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\MinGW\bin;C:\msys\1.0\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;.
16:44:07,140 INFO  [org.jboss.as.ee] (Controller Boot Thread) Activating EE subsystem
16:44:07,709 INFO  [org.jboss.as.jmx.JMXConnectorService] (MSC service thread 1-3) Starting remote JMX connector
16:44:07,801 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-7) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
16:44:07,929 INFO  [org.jboss.as.connector] (MSC service thread 1-3) Starting JCA Subsystem (JBoss IronJacamar 1.0.3.Final)
16:44:08,035 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) Bound data source [java:/miksijevJNDI]
16:44:08,074 INFO  [org.jboss.as.remoting] (MSC service thread 1-1) Listening on /127.0.0.1:9999
16:44:08,204 INFO  [org.jboss.as.deployment] (MSC service thread 1-2) Started FileSystemDeploymentService for directory C:\Users\Milan\jboss-as-7.0.1.Final\standalone\deployments
16:44:08,251 INFO  [org.jboss.as.deployment] (DeploymentScanner-threads - 1) Found testing-ear.ear in deployment directory. To trigger deployment create a file called testing-ear.ear.dodeploy
16:44:08,286 INFO  [org.jboss.as] (Controller Boot Thread) JBoss AS 7.0.1.Final "Zap" started in 4056ms - Started 93 of 148 services (55 services are passive or on-demand)
miksiii
  • 2,426
  • 26
  • 22
  • 1
    How much is the advance payment? – A4L Nov 07 '14 at 12:20
  • Let's get serious! ;-) I spent too much time searching for answer and still nothing. Any ideas? – miksiii Nov 07 '14 at 12:22
  • 1
    All the codes you have posted is not really relevant for the error you are getting `HTTP 404`. You get this error because you type an url in your browser for a certain resource and the app server cannot find it, that's where you should focus your trouble shooting. Your managed bean is not annotated with `@ManagedBean` and you haven't shown your `web.xml` and you haven't shown the url you use to do the request. Please add those informations to your question. And I still want to know about advance payment, and I am serious! – A4L Nov 07 '14 at 12:30
  • Thanks for your reply. As I mentioned, I've configured everything and it worked properly before I tryed to replace the test methods with the real stuff. I am accessing on _http://localhost:8080/testing-war/_. **Note:** that I can access to my index.xhtml normally when I make @EJB injection a comment in my managedbean. – miksiii Nov 07 '14 at 12:45
  • Post is updated, btw. – miksiii Nov 07 '14 at 12:46
  • did you check the logs of your app server for any exceptions? – A4L Nov 07 '14 at 12:48
  • I've provided a console log in the post. I've noticed that the last line of log is about some failure: _Composite operation failed and was rolled back. Steps that failed.._ Could this be a problem since it's throwing me an HTTP 404. – miksiii Nov 07 '14 at 12:57
  • The logs says that the context is not started, this explains 404 HTTP status code. Also you log complains about a `TestStateless`**`Remote`** but you bean only implements **Local**. Try to change `ManageBean` to have `@EJB TestStatelessLocal testBean;` – A4L Nov 07 '14 at 13:21
  • I did (_console log is updated_). I dont even know what keywords to use in order to google about it.. I've been developing java ee applications in NetBeans but not in Eclipse, it's confusing. – miksiii Nov 07 '14 at 15:55

0 Answers0