Showing posts with label glassfish. Show all posts
Showing posts with label glassfish. Show all posts

Monday, December 16, 2013

Oracle JDK 1.7.0_u45 incompatibility with Glassfish 3.x (Corba)

Q: Did you give a try to Glassfish 3.1.x with latest stable JDK (1.7.0_u45)?
A: Well, you might be interested in possible trouble there.

After quite some debugging of weird error happening, namely:
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1636631191
at java.util.HashMap.put(HashMap.java:498)
at java.util.HashSet.add(HashSet.java:217)
...
I ended up creating: https://java.net/jira/browse/GLASSFISH-20927 (Btw, it was quite weird, but I'm not allowed to add attachments in their jira :)
The problem seems to be in internals of the HashSet -> HashMap. Where Corba doesn't seem to set the expected reference to EMPTY_TABLE in case of empty Set. Let's see how they proceed with the analysis.

Tuesday, September 3, 2013

EJB 3.1 - Local and Remote business interfaces must differ

Have you ever seen something like this?
Exception during lifecycle processing
java.lang.IllegalStateException: The interface XYZ cannot be both a local and a remote business interface
 at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:518)
 at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:446)
 at com.sun.enterprise.deployment.archivist.Archivist.readRestDeploymentDescriptors(Archivist.java:419)
 at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:396)
 at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:271)
 at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:280)
 at com.sun.enterprise.deployment.archivist.ApplicationArchivist.readModulesDescriptors(ApplicationArchivist.java:611)
 at com.sun.enterprise.deployment.archivist.ApplicationArchivist.openWith(ApplicationArchivist.java:229)
 at com.sun.enterprise.deployment.archivist.ApplicationFactory.openWith(ApplicationFactory.java:232)
 at org.glassfish.javaee.core.deployment.DolProvider.processDOL(DolProvider.java:188)
 at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:222)
 at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:96)
 at com.sun.enterprise.v3.server.ApplicationLifecycle.loadDeployer(ApplicationLifecycle.java:878)
 at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(ApplicationLifecycle.java:818)
 at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:374)
 at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
 at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
 at java.security.AccessController.doPrivileged(Native Method)
 at javax.security.auth.Subject.doAs(Subject.java:356)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
 at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
 at org.glassfish.admin.rest.resources.admin.CommandResource.executeCommand(CommandResource.java:396)
 at org.glassfish.admin.rest.resources.admin.CommandResource.execCommandSimpInMultOut(CommandResource.java:234)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
 at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:125)
 at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
 at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:91)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:346)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:341)
 at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:101)
 at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:224)
 at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
 at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
 at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
 at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:198)
 at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:946)
 at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:331)
 at org.glassfish.admin.rest.adapter.JerseyContainerCommandService$3.service(JerseyContainerCommandService.java:165)
 at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:181)
 at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
 at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
 at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
 at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
 at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
 at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
 at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
 at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
 at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
 at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
 at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
 at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
 at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
 at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
 at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
 at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
 at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
 at java.lang.Thread.run(Thread.java:724)
Caused by: The interface XYZ cannot be both a local and a remote business interface
 at org.glassfish.ejb.deployment.annotation.handlers.AbstractEjbHandler.setBusinessAndHomeInterfaces(AbstractEjbHandler.java:471)
 at org.glassfish.ejb.deployment.annotation.handlers.StatelessHandler.setEjbDescriptorInfo(StatelessHandler.java:143)
 at org.glassfish.ejb.deployment.annotation.handlers.AbstractEjbHandler.processAnnotation(AbstractEjbHandler.java:270)
 at com.sun.enterprise.deployment.annotation.factory.SJSASFactory$LazyAnnotationHandler.processAnnotation(SJSASFactory.java:148)
 at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:344)
 at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:375)
 at org.glassfish.apf.impl.AnnotationProcessorImpl.processAnnotations(AnnotationProcessorImpl.java:289)
 at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:195)
 at org.glassfish.apf.impl.AnnotationProcessorImpl.process(AnnotationProcessorImpl.java:134)
 at com.sun.enterprise.deployment.archivist.Archivist.processAnnotations(Archivist.java:626)
 at com.sun.enterprise.deployment.archivist.Archivist.readAnnotations(Archivist.java:462)
 ... 69 more
where XYZ would be the name of the interface referred as Local and Remote from some stateless session bean.

Well, once I did migration to Glassfish 4.0 I've noticed that. The message is quite clear, however the question is why that would be a problem. As having one interface serving as Local as well as Remote for stateless session EJB is quite common practice I think.

Root cause

The JBoss forum message pointed me to the right direction.

The thing is that EJB 3.1 specs (implemented in Glassfish 4.0) section 4.9.7 says:
The same business interface cannot be both a local and a remote business interface of the bean.
For those interested, see the full specs on: http://download.oracle.com/otndocs/jcp/ejb-3.1-fr-eval-oth-JSpec/

Solution

OK, but how to fix it? I recommend you to read Adam Bien's suggestion.

Basically, the idea might be the analogy to package protection present in java and easy solution can be creation of extra interface that would inherit existing one and be used as Local. Possibly having Local suffix.

Monday, September 2, 2013

Is Glassfish 4.0 with Hibernate JPA a dead end?

Glassfish 4.0 with Hibernate JPA stable? Nope, see: https://java.net/jira/browse/GLASSFISH-20716

You need to go for JPA 2.1. But there is no stable release of Hibernate supporting it yet (https://hibernate.atlassian.net/browse/HHH?selectedTab=com.atlassian.jira.plugin.system.project%3aversions-panel&subset=-1)!

Well, what can I say, I was disappointed as well. Unless you do some non-production code, feel free to give it a try with 4.3.0 BetaX. Otherwise, have some rest and cross your fingers for Hibernate guys or look elsewhere.

Wednesday, March 27, 2013

Glassfish: showing jndi tree

To list the jndi tree entries in the glassfish use:

$GLASSFISH_HOME/glassfish/bin/asadmin list-jndi-entries

Thursday, February 14, 2013

Glassfish: default keystore and truststore

Q: Do you need to use keystores/truststores of the glassfish OSE?

There are 2 files you should be interested in (please note domain1 used by me):
  • $GLASSFISH_HOME/domains/domain1/config/cacerts.jks - truststore - holding all the public keys
  • $GLASSFISH_HOME/domains/domain1/config/keystore.jks - keystore - holding all the private keys

The default alias used for the secured http-listeners is called: s1as.

To examine the contents


To list truststore contents use:
keytool -list -v -storepass changeit -keystore $GLASSFISH_HOME/domains/domain1/config/keystore.jks
keytool -list -v -storepass changeit -keystore $GLASSFISH_HOME/domains/domain1/config/cacerts.jks
Please note that you need to adapt path to keystores, depending on domains used as well as password you have configured for glassfish to protect the keystore/truststore.

Digging deeper


Default keys are generated during domain creation via asadmin's create-domain command.

Implementation is present in (in my case I refer to version 3.1.1): https://svn.java.net/svn/glassfish~svn/tags/3.1.1/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/KeystoreManager.java
see methods:
createKeyStore()
createTrustStore()

Glassfish: sources

Where are all those sources of the glassfish that one can use for addapting the behavior/studing the way it operates?

I've found following link for svn access:
https://svn.java.net/svn/glassfish~svn

Therefor as in my case if I need 3.1.1 version I can obtain it simply via:
svn co https://svn.java.net/svn/glassfish~svn/tags/3.1.1/ glassfish_3.1.1

Tuesday, February 5, 2013

Glassfish: Exception while shutting down application container : java.lang.NullPointerException

OK, this one is one of the crazy ones :)
Have you ever seen exception like this in your glassfish server logs during ear deployment?
[#|2013-02-05T08:08:40.769+0100|SEVERE|glassfish3.1.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=90;_ThreadName=Thread-2;|Exception while shutting down application container|#]

[#|2013-02-05T08:08:40.938+0100|SEVERE|glassfish3.1.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=90;_ThreadName=Thread-2;|Exception while shutting down application container : java.lang.NullPointerException|#]
Well I did, today. And as I've googled, noone could ever get some more meaningfull stacktrace out of it. Sounds like a nightmare. So where the problem could be?

In development following rule usually works for me:
If you can't get any meaningful information on the problem you're facing and googling didn't help, think of what has been changed since the last success. 
(Well this doesn't seem to be always applicable, but most of the time it is)

This rule was also worked for another guy facing similar exception.

Well in my case too many things changed, but I had backup of the last successfully built artifact. Comparing it with the latest one I've found out that I forgot to include commons-pool dependency in my ear file. So finally following did the trick for me:
<dependency>
 <groupId>commons-pool</groupId>
 <artifactId>commons-pool</artifactId>
 <version>1.6</version>
 <scope>runtime</scope>
</dependency>
As I introduced for client-server communication spring remoting (as a corba alternative) where pooling is used.

So hey, that wasn't so bad although exception handling of glassfish didn't show something useful! I tought I'll be stuck here for at least a day :)

Friday, November 16, 2012

Glassfish 3.1.1 OSE with Hibernate Validator 4.3.0.Final

Goal: Use hibernate validator 4.3.0.Final with Glassfish 3.1.1 OSE.

Lately I came across an issue, that I wasn't able to use the latest stable hibernate validator (hiberante validator 4.3.0.Final) with Glassfish 3.1.1 OSE.

Problem is that older version is beeing used as a glassfish module (glassfish/modules/bean-validator.jar). If you check the contents of the package (in MANIFEST.MF) you'd see that version 4.1.0.Final is beeing used.

OK, so how to deal with that? I've found out that I'm not the only one having issue here.
http://stackoverflow.com/questions/10548931/how-to-upgrade-the-hibernate-validator-4-3-0-final-to-the-glassfish-3-1-2

Suggestion gave me some motivation, as it seems to be possible to achieve :)

As I'm using ear, the simple solution provided in answer was not feasable for me (as it was a war case). OK, let's see how far we can get. There are multiple references (finally I ended up with the following 2 links):
I read the later one, as it seemd like a good idea to learn creating modules deployable to glassfish, however even if I created maven osgi bundle it neither contained all the dependencies required nor the descriptor seemed to be OK. Sounds like a wrong way for me then.

Going back to the 1.st link, I found following svn repository and tried to build things: https://svn.java.net/svn/glassfish~svn/trunk/external/source-build
However only once it has been achieved (and the way there was quite long) I realized that this just rebuilds the hibernate validator with it's dependencies, and that is of course not needed, as these are already built and available in public maven repositories :).

OK, going via next steps in the article, I ended up with the following solution:
  1. checked out glassfish sources
    svn co https://svn.java.net/svn/hk2~svn/branches/hk2-gf-3.1.1/
    
  2. updated bean-validation related pom, see my diff:
    Index: pom.xml
    ===================================================================
    --- pom.xml (revision 4105)
    +++ pom.xml (working copy)
    @@ -54,9 +54,10 @@
              maven-bundle-plugin and hk2-maven-plugin together -->
         <packaging>jar</packaging>
         <properties>
    -      <hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
    +      <hibernate-validator.version>4.3.0.Final</hibernate-validator.version>
           <javax.validation.version>1.0</javax.validation.version>
           <slf4j.version>1.6.1</slf4j.version>
    +      <jboss-logging.version>3.1.0.CR2</jboss-logging.version>
         </properties>
         <name>Validation API (JSR 303) version ${javax.validation.version}, Hibernate Validator version ${hibernate-validator.version} and its dependencies repackaged as OSGi bundle</name>
     
    @@ -89,7 +90,7 @@
                             <Embed-Dependency>
                                 <!-- Only specify root artifacts that need to be embedded, everything else
                                      will be pulled in automatically based on Private-Package settings. -->
    -                            *; artifactId=hibernate-validator|slf4j-api|slf4j-jdk14; inline=true
    +                            *; artifactId=hibernate-validator|jboss-logging|slf4j-api|slf4j-jdk14; inline=true
                             </Embed-Dependency>
                             <Export-Package>
                                  <!-- 
    @@ -105,7 +106,7 @@
     
                             <Private-Package>
                                  <!-- Have a private copy of external non-standard dependencies -->
    -                             org.slf4j.*; com.googlecode.jtype.*; org.joda.time.*; org.jsoup.*
    +                             org.jboss.logging.*; org.slf4j.*; com.googlecode.jtype.*; org.joda.time.*; org.jsoup.*
                             </Private-Package>
     
                             <Import-Package>
    @@ -117,6 +118,12 @@
                                    which is a JPA 2 class.
                                -->
                                org.slf4j; org.slf4j.spi; org.slf4j.helpers; version=${slf4j.version}; resolution:=optional,
    +                           org.jboss.logging; version=${jboss-logging.version}; resolution:=optional,
    +                           org.apache.log4j;resolution:=optional,
    +                           org.jboss.logmanager;resolution:=optional,
    +                           com.ibm.uvm.tools;resolution:=optional,
    +                           com.sun.jdmk.comm;resolution:=optional, 
    +                           javax.jmdns;resolution:=optional,
                                javax.persistence.*; version="2.0"; resolution:=optional,
                                *
                            </Import-Package>
    @@ -263,6 +270,13 @@
             </dependency>
     
     
    + <dependency>
    +  <groupId>org.jboss.logging</groupId>
    +  <artifactId>jboss-logging</artifactId>
    +  <version>${jboss-logging.version}</version>
    +            <optional>true</optional>
    + </dependency>
    +
             <!-- We bundle jdk binding inside this OSGi bundle -->
             <dependency>
                <groupId>org.slf4j</groupId>
    
  3. built:
    cd hk2-gf-3.1.1/external/bean-validator
    mvn clean install
    
  4. copied to glassfish modules and removed old one:
    rm ${GLASSFISH_HOME}/glassfish/modules/bean-validator.jar
    cp hk2-gf-3.1.1/external/bean-validator/target/bean-validator-1.1.15-SNAPSHOT.jar ${GLASSFISH_HOME}/glassfish/modules/
    
  5. done :)

Issues? well, we'll see later, during testing :) But very first try worked perfectly.

Comments? Feel free to share, as I'm not the osgi expert (yet :)), so some of my updates might ... let's say won't make too much sense.