GlassFish Error: JAX-RS EJB support is disabled - rest

I am trying a simple app using Jersey JAX-RS + EJB 3.1 on GlassFish 3.1.2.2. All seemed to look pretty well with Jersey REST on GlassFish until I added EJB. When deploying the war file, I got this error.
SEVERE: Error when configuring to use the EJB interceptor binding API. JAX-RS EJB support is disabled.
Anyone who has encountered this before? Is there a configuration in GlassFish to fix this?
My EJB is a simple pojo with #Singleton and #PostConstruct annotation.
#Singleton
public class PurchaseBean {
private String name;
#PostConstruct
public void init() {
System.out.println("Initializing PurchaseBean");
setName("Purchase Singleton EJB");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

Looks like this is an Eclipse issue. I did the deployment using Eclipse with the GlassFish adapter. Restarting Eclipse solved it.
Solution: Shutdown GlassFish, inside Eclipse go to Project->Clean(select project) and then start GlassFish again.
I don't know why but it worked. :)

Working solution or the ones who run the Glassfish standalone: Restart the Glassfish. Glassfish version number 4.1.2

Related

Java EE integration test with Spock

I have JBoss + Java EE application. I would like to run integration test against it using Spock.
So I claim it's possible to run tests after context started:
public class ExampleContextListener implements ServletContextListener {
#Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
// run Spock
}
}
Please, correct me if I am wrong. Point me to example.
Your question is too broad and cannot be covered here. You have a lot of reading ahead
First take a look at Arquillian
http://arquillian.org/
Then at the Spock extension
https://github.com/arquillian/arquillian-testrunner-spock

NullPointerException when I try to inject EJB in JAX-RS

I have seen all the issues noticed in this forum, but I still don't have any solution for my problem.
I work on a EAR project with Maven, Wildfly and JBoss.
When I try to browse to my resource I have NPE.
This is my JAX activator class:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/resource")
public class JaxRsActivator extends Application{
}
and this is my resource class:
#Path("/drivers")
public class DriverResource {
#Inject DriverCpoServiceLocal driverCpoServiceLocal;
#GET
#Produces(MediaType.APPLICATION_JSON)
public List<DriverCpo> doFindAllDrivers(){
return driverCpoServiceLocal.findAll();
}
}
This code works correctly on my personal computer, but in the work computer I see the NPE.
It is driving me crazy.

No equals method when deploying and running JBoss

I have class equals and hashcode
public class ObjectType {
...
In Eclipse outline view equals and hashcode methods are visible.
At runtime i get exception at JBoss 4.2.3.GA:
12:21:58,741 ERROR [STDERR] Exception in thread "Thread-29"
12:21:58,741 ERROR [STDERR] java.lang.NoSuchMethodError: core.notdb.ObjectType.equals(Lcom/alt1/cbc/core/notdb/ObjectType;)Z
for code:
#Override
public Entity getEntity(ObjectType objectType, Object id) {
if (BaseStationSubsystem.getBscObjectType().equals(objectType)) {
For some reason the method ObjectType#equals(ObjectType other) is called from JBoss instead of ObjectType#equals(Object other). Lombok correctly only generates the latter one.
Full Disclosure: I am one of the Project Lombok developers.
Possibly class compiled with another java version setting was deployed with other classes compiled with second java version setting.

Hibernate Eclipse WebProject configuration: How to specify file config?

Consider the following statement:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Where:
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
How to specify a file from which Hibernate will retrieve configuration data?
Explaining, I have a hibernate.cfg.xml with proper configuration data, but during runtime hibernate throws errors refering to configurations from another projects, like:
org.hibernate.MappingNotFoundException: resource: xx/AnotherNonRelatedProject/CertainClass.hbm.xml not found
Anyway, I'm guessing that default configuration is comming from another file. But I've searched my hbm.xml files, classes and references, and it seems to be ok.
Any idea on what would be happening here?
Eclipse: Indigo SR2;
Hibernate Tools: 3.5.1
Thanks!
if you want to set your own Hibernate configuration, then you must use the following:
private static final SessionFactory sessionFactory;
static {
try {
// Create your SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure(new File("hibernate1.cfg.xml"))
.buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
Best regards :)
I'm responding to my own question because I've discovered my specific problem, which I think would be the another one's problem on question's matter:
As my application is Web-based, Tomcat's lib folder has a .jar file from another project which had hibernate configuration problems. As Hibernate checks all dependencies related to some project (including all .jar), which includes all jars in Tomcat's lib. So, there were exceptions (totally strange to me at that time) raising during runtime. Solving hibernate configuration problems of .jar files or deleting them (if not necessary) from Tomcat's lib folder solves the problem.

Google Guice 3 and OSGi (Eclipse equinox) problem,

I have trouble running Guice 3 within an OSGi container.
Following is a simple test I wrote to test if Guice work well with OSGi.
A simple guice module like:
public class Module extends AbstractModule {
#Override
protected void configure() {
bind(IInterface.class).to(IImplement.class);
}
}
The IInterface and IImplement are both very trivial.
The OSGi activator like this:
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Injector inj = Guice.createInjector(new Module());
IInterface e = inj.getInstance(IInterface.class);
e.sayHello();
}
In Eclipse, I made a target contains all the Guice Jars, and to make guice resolve itself, I made two additional bundle for the aopalliance.jar and javax.injector.jar
However, this simple test fail to load the test bundle, gives me error message complaining cannot find a guice class cannot be found:
Exception in guicetest.Activator.start() of bundle guicetest
Caused by: java.lang.NoClassDefFoundError: com/google/inject/binder/AnnotatedBindingBuilder
at guicetest.guice.Module.configure(Module.java:11)
I hope I have made the problem clear. Can anyone show me how to resolve this problem?
Ah, after just posting the question I found the root of the problem. I didn't specify the com.google.inject.binder package, which the problematical class resides, in the test bundle's Import-Packages. Although the Module doesn't import directly that package, it looks it is still necessary to specify all the indirect dependent packages as well.