Hot questions for Using GlassFish in jboss

Question:

I have a question about the correct format and usage of the bean.xml file. In my projects I typically used this content for my bean.xml files (no explizit bean declaration used):

<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>

This works well in WildFly 8 and 9. But I have deployment issues in GlassFish 4. In the question: Glassfish 4, simple example in CDI fails with WELD-001408 Unsatisfied dependencies I wrote about an alternative format:

<beans
   xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                  http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
          bean-discovery-mode="all">
</beans>

There a different namespaces used. And GlassFish4 seems to care about that.

What is the correct format of an empty bean.xml File used for JEE7 ?


Answer:

Correct empty beans.xml can be totally empty file, really ;-)

But when you want to add some content, please notice that most of the XML deployment descriptor namespaces have been updated in Java EE 7. This post describes the details. Also bean-discovery-mode has been added.

BTW: Sample beans.xml which I'm using right now looks like:

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       version="1.2" bean-discovery-mode="annotated">

    <!-- some content -->
</beans>

You may notice the usage of version="1.2" attribute - you can freely set it to 1.1. It just serves as a reminder to the reader that project is using CDI 1.2 (which in fact is just a Maintenance release of the CDI 1.1 Specification).

Question:


Answer:

Anybody can implement the java ee specification (JSR342), or any jsr that's part of it. When they do, they can (after buying and passing Compatibility Test Suite) claim to be compatible with the specification. There is a number of vendors with their application servers which are compatible with java ee, but no vendor implement full java ee specification. For instance, glassfish (the java ee reference implementation) uses Red Hat's CDI implementation. Sometimes, the vendor does not implement any part of the java ee specification, they grab glassfish, add their vendor specific libraries, and release it under their name. To claim compatibility, they still need to go through the certification process and run CTS.

To find out all the vendors who implement the specification is not so easy, since not all of them go through the certification process. For instance, Apache CXF is not certified on its own, rather it gets certified as part of Red Hat's JBoss.

Each specification has an API and a written pdf, both of which define the mandatory behaviour of each implementation. That is what you use when write EJB code. For instance, when you create an ejb:

import javax.ejb.Singleton;
@Singleton
public class MySingleton{
   ... 
}

@Singleton annotation is part of the specification, but MySingleton class is your EJB code, it's not part of the specification. The EJB container then knows what to do with the class.

Question:

I need to be able to deploy .ear file containing .rar resource adapter to jBoss/Wildfly. It has been working previously for GF. Problem is that in my .war file (which is also part of the .ear) I have this web.xml:

<resource-ref>
  <res-ref-name>eis/host</res-ref-name>
  <res-type>javax.resource.cci.ConnectionFactory</res-type>
  <res-auth>Container</res-auth>
  <res-sharing-scope>Shareable</res-sharing-scope>
  <lookup-name>java:/env/eis/host-somehost</lookup-name>
</resource-ref>

and jBoss cannot find the resource:

Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.\"HostConnector-ear-1.17-SNAPSHOT\".\"HostConnector-war-1.17-SNAPSHOT\".env.eis.host is missing          [jboss.naming.context.java.jboss.resources.eis.host]"]}

I have created element in standalone.xml, but seams the naming is wrong or what:

<subsystem xmlns="urn:jboss:domain:resource-adapters:2.0">
        <resource-adapters>
            <resource-adapter id="Host-ra">
                <archive>
                    HostConnector-1.17-SNAPSHOT-local#HostConnector-rar-1.17-SNAPSHOT.rar
                </archive>
                <connection-definitions>
                    <connection-definition class-name=".....jca.spi.HostManagedConnectionFactory" jndi-name="java:/env/eis/host-somehost" enabled="true" use-java-context="false" pool-name="java:jboss/env/eis/host-somehost"/>
                </connection-definitions>
            </resource-adapter>
        </resource-adapters>
    </subsystem>

If I have .rar packaged in .ear is it enough to just deploy with ra.xml? Where is the resource-adapter JNDI name defined?


Answer:

The problem was in ra.xml, where the packages names were not properly set and Glassfish ignored this while JBoss failed. fixing the factories package name fixed that issue.

Question:

I'm making a small application. For now it has a couple of entity classes and a index.xhtml which just has the word TEST. It seems that when I try to run it on the server, the application doesn't create a database and the glassfish server gives me the error :

org.jboss.weld.exceptions.IllegalStateException: WELD-000227: Bean identifier index inconsistency detected - the distributed container probably does not work with identical applications
Expected hash: 1888662881
Current index: BeanIdentifierIndex [hash=-1322634367, indexed=12]:
0: WELD%AbstractBuiltInBean%WebProjectManager%HttpSession
1: WELD%AbstractBuiltInBean%com.ibm.jbatch.container.cdi.BatchCDIInjectionExtension%HttpSession
2: WELD%AbstractBuiltInBean%com.sun.faces.flow.FlowDiscoveryCDIExtension%HttpSession
3: WELD%AbstractBuiltInBean%org.glassfish.cdi.transaction.TransactionalExtension%HttpSession
4: WELD%AbstractBuiltInBean%org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider%HttpSession
5: WELD%AbstractBuiltInBean%org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScopeExtension%HttpSession
6: WELD%AbstractBuiltInBean%org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionInterceptorProvider%HttpSession
7: WELD%AbstractBuiltInBean%org.glassfish.jms.injection.JMSCDIExtension%HttpSession
8: WELD%AbstractBuiltInBean%org.glassfish.osgicdi.impl.OSGiServiceExtension%HttpSession
9: WELD%AbstractBuiltInBean%org.glassfish.sse.impl.ServerSentEventCdiExtension%HttpSession
10: WELD%AbstractBuiltInBean%org.hibernate.validator.internal.cdi.ValidationExtension%HttpSession
11: WELD%AbstractBuiltInBean%root_WebProjectManager%HttpSession

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.0">
<persistence-unit name="WebProjectManager">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 <exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
  <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>

  <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
  <property name="javax.persistence.jdbc.user" value="alexander"/>
  <property name="javax.persistence.jdbc.password" value="0898725863"/>

  <property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
  <property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL_ddlGeneration.jdbc"/>
  <property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL_ddlGeneration.jdbc"/>
  <property name="eclipselink.ddl-generation.output-mode" value="both"/>
</properties>
</persistence-unit>
</persistence>

Any ideas how to fix this ?

PS: I only have entity classes at this point so maybe that's the reason it doesn't create the database (maybe it needs, some ejb's and managed beans for example. Note sure.). Don't really know so here is the whole project so far: project


Answer:

That's a WELD bug.

Work around the issue by disabling session passivation on shutdown in Tomcat or GlassFish.

Question:

I am about to launch an application. I am using just structs and not even springs in the application. So, at this stage, I would like to know what would give the better performance out of Tomcat, Jboss AS and Glassfish for deploying my applications. And I need to use the Linux (RHEL 6.x) environment as the OS.

Please let me know if any other components that are being used in my application should be brought to your notice for getting an idea on the best tool.


Answer:

Tomcat is web server/container, and where as JBoss and Glassfish are application servers with much more capability.

And also most of the application servers use 'Tomcat' as base HTTP server. So based on your application requirement and budget select one.

For a basic structs application, I would use 'Tomcat' for better performance.

Question:

I was wondering if anyone knows of any solutions to run IIS and a java server side by side. Ideally what I'd love to do is not to be required to do ".com" and ".com:8080" for the two separate servers. What I'd really love is for something like dotnet.mysite.com to direct/route to an IIS server and java.mysite.com to direct/route to wildfly.

Does such a solution exist? or will multiple port numbers be required?


Answer:

I have used Application Request Routing to configure IIS to connect to tomcat on port 8080 on the server machine. Then IIS will act as a reverse proxy and will forward appropriately configured paths to the wildfly instance. And yes, you can set-up routes based on the host header.

Question:

I'm trying to run my .ear application in JBoss (wildfly-10.1.0.Final). Previously it was running with Glassfish 4.1 without any problem. On JBoss, I succeed to deploy it, but it throws tons of exceptions.

For Example:

2017-05-17 13:42:00,911 ERROR [org.jboss.as.ejb3.invocation] (default task-18) WFLYEJB0034: EJB Invocation failed on component VersionDao for method public abstract java.util.List com.valor.anthillprodashboard.db.dao.VersionDaoLocal.getAllVersions(): javax.ejb.EJBTransactionRolledbackException: NamedQuery of name: Version.findAll not found.
            at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:159)

2017-05-17 13:40:03,504 ERROR [org.jboss.as.ejb3.invocation] (default task-110) WFLYEJB0034: EJB Invocation failed on component DataAccessFacade for method public abstract java.util.List com.valor.anthillprodashboard.bl.da.DataAccessFacadeLocal.getAllVersions(): javax.ejb.EJBTransactionRolledbackException: NamedQuery of name: Version.findAll not found.
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:159)

In both cases I use eclipselink & MySQL.

I tried to configure JBoss with the same parameters I have in Glassfish.

Glassfish Config:

  • JDBC Resource:
  • JDBC Connection Pool:

JBoss Config (from standalone.xml):

<datasources>
    <datasource jta="true" jndi-name="java:/jdbc/anthillprodashboard" pool-name="mysql_anthillprodashboard_rootPool" enabled="true" use-java-context="true" use-ccm="true">
        <connection-url>jdbc:mysql://localhost:3306/anthillprodashboard?zeroDateTimeBehavior=convertToNull</connection-url>
        <driver>mysql</driver>
        <security>
            <user-name>****</user-name>
            <password>****</password>
        </security>
        <statement>
            <prepared-statement-cache-size>100</prepared-statement-cache-size>
            <share-prepared-statements>true</share-prepared-statements>
        </statement>
    </datasource>
    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
        <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
        <driver>h2</driver>
        <security>
            <user-name>sa</user-name>
            <password>sa</password>
        </security>
    </datasource>
    <drivers>
        <driver name="mysql" module="com.mysql"/>
        <driver name="h2" module="com.h2database.h2">
            <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
        </driver>
    </drivers>
</datasources>

My Persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="AnthillProDashboard-ejbPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/anthillprodashboard</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>NONE</shared-cache-mode>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
    </properties>
  </persistence-unit>
</persistence>

The exceptions doesn't make any sense, because same methods worked fine on glassfish. What could be the cause of these exceptions?


Answer:

For some reason, JBoss could not identify the Entities and I had to specify them in the persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="AnthillProDashboard-ejbPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/anthillprodashboard</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>NONE</shared-cache-mode>
    <class>com.valor.anthillprodashboard.db.entity.Build</class>
    <class>com.valor.anthillprodashboard.db.entity.Commit</class>
    <class>com.valor.anthillprodashboard.db.entity.Project</class>
    <class>com.valor.anthillprodashboard.db.entity.ProjectVersion</class>
    <class>com.valor.anthillprodashboard.db.entity.ProjectVersionPK</class>
    <class>com.valor.anthillprodashboard.db.entity.Status</class>
    <class>com.valor.anthillprodashboard.db.entity.TestSet</class>
    <class>com.valor.anthillprodashboard.db.entity.TestSetUpdate</class>
    <class>com.valor.anthillprodashboard.db.entity.TestStatus</class>
    <class>com.valor.anthillprodashboard.db.entity.Version</class>
    <class>com.valor.anthillprodashboard.db.entity.Workflow</class>

    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
    </properties>
  </persistence-unit>
</persistence>