Issue Details (XML | Word | Printable)

Key: GLASSFISH-18585
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: sakshi.jain
Reporter: jst
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

embedded glassfish: jersey-test does not honor @Singleton and @ManagedBean

Created: 20/Aug/11 03:20 PM   Updated: 01/Apr/12 06:33 PM
Component/s: embedded
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Text File embedded_log.txt (27 kB) 07/Dec/11 06:13 AM - sakshi.jain
2. File UsingEmbeddedGlassfish.diff (44 kB) 06/Sep/11 09:52 AM - jst
3. File UsingExternalGlassfish.diff (45 kB) 06/Sep/11 09:50 AM - jst


Linux + Glassfish.

Participants: jbenoit, jst, Michal Gajdos, Pavel Bucek and sakshi.jain

 Description  « Hide

I am trying to switch my project to run in Glassfish. The application seems to work, but I have problems with tests. They all seem to fail, as my class, annoted as

import javax.annotation.ManagedBean;
import javax.inject.Singleton;

public class Quoridor {

is instantiate more than one per each test run. Could the Jersey framework honor the @Singleton + @ManagedBean annotation as glassfish does?

Michal Gajdos added a comment - 01/Apr/12 06:33 PM

is there any progress on this issue?

sakshi.jain added a comment - 27/Dec/11 09:21 AM

Since embedded glassfish was being bootstrapped twice, I declared the Glassfish instance as static so it will bootstrap only once.So after the first test, embedded glassfish would merely stop instead of shutting down, and for the second test it will start again.However, another issue is encountered here which looks like a design issue & we are looking into that.

sakshi.jain added a comment - 07/Dec/11 06:13 AM

I have been able to run the webidor test using external glassfish.Hence the issue does lie with embedded.
As you said the class annotated as Singleton is instantiated more than once.This is because it is bootstrapping embedded glassfish twice.
Attached herewith is the log which I obtain on running the webidor test.

jst added a comment - 30/Sep/11 09:35 PM

I don't know what can be wrong. Maybe patch does not work well on windows? Try:

$ hg up -C 92bd2090dd5f
$ wget
$ hg import --no-commit UsingExternalGlassfish.diff

These three commands just did the trick for me (on Linux).

jbenoit added a comment - 30/Sep/11 06:16 PM

I see attachments:
but when I execute command it shows error:

C:\a\fresh\jersey-757\2\quoridor>patch -p1 <UsingEmbeddedGlassfish.diff
Hmm... I can't seem to find a patch in there anywhere.

C:\a\fresh\jersey-757\2\quoridor>patch -p1 <UsingExternalGlassfish.diff
Hmm... I can't seem to find a patch in there anywhere.

jbenoit added a comment - 26/Sep/11 06:20 PM

Regarding your comments:

I have modified the sources, removed all but one test and I could successfully run the test against externally running glassfish.


$ hg up -C 92bd2090dd5f
$ patch -p1 <UsingExternalGlassfish.diff

I don't have "UsingExternalGlassfish.diff" file, here is what i see:

C:\a\fresh\jersey-757>hg up -C 92bd2090dd5f
abort: no repository found in 'C:\a\fresh\jersey-757' (.hg not found)!

C:\a\fresh\jersey-757>cd quoridor

C:\a\fresh\jersey-757\quoridor>hg up -C 92bd2090dd5f
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

C:\a\fresh\jersey-757\quoridor>patch -p1 <UsingExternalGlassfish.diff
The system cannot find the file specified.

C:\a\fresh\jersey-757\quoridor>find . | grep -i UsingExternalGlassfish.diff

jst added a comment - 06/Sep/11 09:52 AM

Here is another patch to show that embedded glassfish does not honor @Singleton. You can try:

$ hg up -C 92bd2090dd5f
$ patch -p1 <UsingEmbeddedGlassfish.diff
$ cd webidor
$ mvn install

The test fails with assert in the constructor of the Quoridor class.

jst added a comment - 06/Sep/11 09:50 AM

I have modified the sources, removed all but one test and I could successfully run the test against externally running glassfish.


$ hg up -C 92bd2090dd5f
$ patch -p1 <UsingExternalGlassfish.diff

and follow the tests described above. The test succeeds.

jbenoit added a comment - 05/Sep/11 02:35 PM


I did this:

  • added this <dependency> to quoridor/webidor/pom.xml, at line 57:


the above <dependency> was added right before:

then i built and deployed quoridor\webidor\target\webidor-1.19.war to external Glassfish, i.e.

// build webidor-1.19.war
C:\a\fresh\jersey-757\quoridor\webidor>mvn package -Dmaven.repo.local=C:\a\fresh\jersey-757\quoridor\repo -DargLine="-Dhttp.proxyHost=yourProxyHostNameGoesHere" -Dmaven.test.skip=true

// start external Glassfish, already installed into C:\a\fresh\1.8testing dir
// downloaded from
C:\a\fresh\jersey-757\quoridor>set AS_HOME=C:\a\fresh\1.8testing\glassfish3\glassfish

C:\a\fresh\jersey-757\quoridor>echo %AS_HOME%

C:\a\fresh\jersey-757\quoridor>set PATH=%AS_HOME%\bin;%PATH%

C:\a\fresh\jersey-757\quoridor>which asadmin

// start the domain
C:\a\fresh\jersey-757\quoridor> asadmin start-domain domain1

// deploy webidor-1.19.war
C:\a\fresh\jersey-757\quoridor\webidor> asadmin deploy target\webidor-1.19.war

//run, using proxy behind company firewall:
C:\a\fresh\jersey-757\quoridor>mvn install -Dmaven.repo.local=C:\a\fresh\jersey-757\quoridor\repo -DargLine="-Dhttp.proxyHost=yourProxyHostNameGoesHere" -Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory -Djersey.test.port=8080


Running cz.xelfi.quoridor.webidor.AllGamesTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.532 sec <<< FAILURE!
Running cz.xelfi.quoridor.webidor.FinishedGameTest
Tests run: 5, Failures: 0, Errors: 5, Skipped: 0, Time elapsed: 0.969 sec <<< FAILURE!
Running cz.xelfi.quoridor.webidor.GamesTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.328 sec
Running cz.xelfi.quoridor.webidor.QuoridorTest
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.641 sec <<< FAILURE!
Running cz.xelfi.quoridor.webidor.resources.ChatTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.515 sec <<< FAILURE!
Running cz.xelfi.quoridor.webidor.UsersTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.547 sec <<< FAILURE!

Results :

Tests in error:
testListGames(cz.xelfi.quoridor.webidor.AllGamesTest): PUT http://localhost:80
80/allgamess/login?name=Jarda&password=heslo returned a response status of 403
testNotLoggedIn(cz.xelfi.quoridor.webidor.FinishedGameTest): GET http://localh
ost:8080/finishedGame/login?id=not-logged-in returned a response status of 404
testCreateAGame(cz.xelfi.quoridor.webidor.FinishedGameTest): PUT http://localh
ost:8080/finishedGame/login?name=Jarda&password=heslo returned a response status
of 403
testResignAGame(cz.xelfi.quoridor.webidor.FinishedGameTest): PUT http://localh
ost:8080/finishedGame/login?name=Jarda&password=heslo returned a response status
of 403
testResignBGame(cz.xelfi.quoridor.webidor.FinishedGameTest): PUT http://localh
ost:8080/finishedGame/login?name=Jarda&password=heslo returned a response status
of 403
testResignForeignGame(cz.xelfi.quoridor.webidor.FinishedGameTest): PUT http://
localhost:8080/finishedGame/login?name=Jarda&password=heslo returned a response
status of 403
testApplicationWadl(cz.xelfi.quoridor.webidor.QuoridorTest): GET http://localh
ost:8080/quoTest/application.wadl returned a response status of 404
testCreateAGame(cz.xelfi.quoridor.webidor.QuoridorTest): PUT http://localhost:
8080/quoTest/login?name=Jarda&password=heslo returned a response status of 403
testCreateAGame(cz.xelfi.quoridor.webidor.resources.ChatTest): PUT http://loca
lhost:8080/context/login?name=Jarda&password=heslo returned a response status of
testListUsers(cz.xelfi.quoridor.webidor.UsersTest): PUT http://localhost:8080/
userstest/login?name=Jarda&password=heslo returned a response status of 403

Tests run: 13, Failures: 0, Errors: 10, Skipped: 0

I added webidor/src/main/webapp/WEB-INF/sun-web.xml containing <context-root>, rebuilt and redeployed .war:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "">
<sun-web-app error-url="">
<class-loader delegate="false"/>
<property name="classdebuginfo" value="true">
<description>Enable debug info compilation in the generated servlet class</description>
<property name="mappedfile" value="true">
<description>Maintain a one-to-one correspondence between static content and the generated servlet class' java code</description>

This is where I'd like you to see if you can get your project to work with external Glassfish, such that it avoids these 403/404 errors.

jst added a comment - 05/Sep/11 10:49 AM

Good to know the problem has been reproduced. I'll be happy to change my project testing code anyway you suggest. However I am don't have that much experience with application servers, so I don't know how to eliminate embedded glassfish properly.

jbenoit added a comment - 04/Sep/11 09:23 PM

I've reproduced your original reported error. To help confirm if problem using embedded glassfish, can you please try using external Glassfish instead of embedded glassfish? I've done so, but I encounter 403 & 404 errors whilest trying to confirm behavior.

jst added a comment - 23/Aug/11 12:29 PM

Should you check my usecase you'd find out that there is only single test method in
Still multiple instances are created.

Pavel Bucek added a comment - 23/Aug/11 08:05 AM

just my $0.02:

@Singleton and @ManagedBean (and others) should work as expected. I haven't seen your testcase, but Mu guess is that you are trying to access your singleton instance from various tests (@Test annotated methods), which should return (by definition) different instances. Why? Each test currently "restarts" Jersey, reloads all resource methods, providers, etc..

What you could do is try to access your @Singleton annotated class twice from one test method, that should work as you expect.

jst added a comment - 20/Aug/11 03:40 PM

Update Please "hg up -C 92bd2090dd5f" as I found out that with compile on save the debugging is broken. I had to disable it completely. With 92bd2090dd5f debugging part of my report works.

jst added a comment - 20/Aug/11 03:31 PM

Steps to reproduce:

$ hg clone
$ cd quoridor/
$ hg up -C accdcc2ab312
$ mvn install

The build fails with: Tests run: 13, Failures: 2, Errors: 6, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] Quoridor related projects ......................... SUCCESS [0.265s]
[INFO] Quoridor Library .................................. SUCCESS [1.752s]
[INFO] Quoridor Visual Board ............................. SUCCESS [0.794s]
[INFO] wsdor ............................................. SUCCESS [0.410s]
[INFO] webidor server .................................... FAILURE [49.682s]

Now you can open the quoridor/webidor project in NetBeans place a breakpoint into constructor of Quoridor class and debug for example ChatTest. You should see that the instances of Quoridor class are created multiple times, in spite it is a singleton.