Instantiating EntityManagerFactory with GWT, JPA and Tomcat - eclipse

I am using GWT with JPA and Hibernate in Tomcat Apache container. When I try testing my dao and database connection from a Standalone java application it works fine. Howerver, when I use it in server enviornment, it SOMETIMES works sometimes doesn't. Here is an abridged sequence of logevents:
org.hibernate.type.BasicTypeRegistry
- Adding type registration boolean -> org.hibernate.type.BooleanType#82b436
INFO org.hibernate.cfg.Environment -
Hibernate 3.6.0.Final 42937
[btpool0-0] INFO org.hibernate.cfg.Environment -hibernate.properties not found 42940
[btpool0-0] INFO org.hibernate.cfg.Environment -Bytecode provider name : javassist
[btpool0-0] INFO org.hibernate.cfg.Environment - usingJDK 1.4 java.sql.Timestamp handling
43038 [btpool0-0] DEBUG org.hibernate.id.factory.DefaultIdentifierGeneratorFactor - Registering IdentifierGenerator strategy [uuid2] -> [class
org.hibernate.id.UUIDGenerator] 43069
[btpool0-0] INFO
org.hibernate.ejb.Version - Hibernate
EntityManager 3.6.0.Final
43090 [btpool0-0] DEBUG
org.hibernate.type.BasicTypeRegistry
- Adding type registration text -> org.hibernate.type.TextType#1cf00aa43106
[btpool0-0] DEBUG
org.hibernate.ejb.Ejb3Configuration -
Look up for persistence unit:
transactions-optional 43269
[btpool0-0] DEBUG org.hibernate.ejb.Ejb3Configuration Detect class: true; detect hbm: true
43285 [btpool0-0] DEBUG
org.hibernate.ejb.packaging.AbstractJarVisitor
- Searching mapped entities in jar/par: file://xxxxx 43378
[btpool0-0] DEBUG
org.hibernate.ejb.packaging.AbstractJarVisitor
- Filtering: com.demo.server.hello 43492 [btpool0-0] DEBUG
org.hibernate.ejb.packaging.AbstractJarVisitor
- Java element filter matched for com.demo.server.hello 43505
[btpool0-0] DEBUG
org.hibernate.ejb.Ejb3Configuration -
Detect class: true; detect hbm: true
43505 [btpool0-0] DEBUG
org.hibernate.ejb.Ejb3Configuration -
Creating Factory:
transactions-optional
After this I get no log message and my client layer can not talk to database layer. When my client layer is able to talk to database layer, the entry following above log entry is as follows:
1063 [main] DEBUG org.hibernate.cfg.Configuration - Processing hbm.xml files
If you could point out as to what might be going wrong, I will really appreciate it. I can't figure out if its eclipse compilation fault, or some problem in GWT plugin or (most likely) my programming bug.

Are you sure you are using JPA? I'm not familiar with GWT, but I assume it deploys your application as a WAR file. If so, check if you WAR file contains a META-INF/persistence.xml file, and verify the connection details from there.
1063 [main] DEBUG org.hibernate.cfg.Configuration - Processing hbm.xml files
It seems that Hibernate is creating a session every time your client is able to talk to the database. The fact that sometimes it's called (and works) indicates that it's not a problem with Hibernate. Otherwise, you'd see a consistent behavior. So, I would double-check if the requests are not failing before reaching Hibernate. For instance, I would try to add some debug log entries before and after Hibernate is called.

Related

Spring Data Geode register interest is not receiving events

Related to this question I've setup a Spring Data Geode Client application with
#EnableClusterDefinedRegions(clientRegionShortcut=ClientRegionShortcut.CACHING_PROXY)
and by ensuring all classes are autowired then using the #Resource the Geode server regions are setup and instantiated on the client.
#Resource(name = "request")
private Region<String, Request> request;
I can put and get on the regions like this. However when I try and register interest in a key on the server the updates from other clients to the server are received by the spring boot client. The register interest code:
request.registerInterestForAllKeys();
request.getAttributesMutator().addCacheListener(new myListener());
The logs show the interest is added to the region:
DEBUG [main] org.apach.geode.inter.cache.GemFireCacheImpl 4388 registerInterestStarted: registerInterestsStarted: new count = 1
TRACE [main] org.apach.geode.inter.InternalDataSerializer 2194 basicWriteObject: basicWriteObject: KEYS_VALUES
TRACE [main] org.apach.geode.inter.InternalDataSerializer 1535 writeDSFID: writeDSFID 37 class=class org.apache.geode.internal.cache.tier.sockets.InterestResultPolicyImpl
TRACE [main] org.apach.geode.cache.clien.inter.OpExecutorImpl 568 executeOnQueuesAndReturnPrimaryResult: sending org.apache.geode.cache.client.internal.RegisterInterestOp$RegisterInterestOpImpl#5e1a7d3 to backups: []
TRACE [main] org.apach.geode.cache.clien.inter.OpExecutorImpl 584 executeOnQueuesAndReturnPrimaryResult: sending org.apache.geode.cache.client.internal.RegisterInterestOp$RegisterInterestOpImpl#5e1a7d3 to primary: Connection[1.2.3.4:40404]#613231852
TRACE [main] org.apach.geode.cache.clien.inter.AbstractOp 85 attemptSend: Sending op=RegisterInterestOp$RegisterInterestOpImpl using Connection[1.2.3.4:40404]#613231852
When another client adds or changes a value on the server region that event is not getting to the spring boot client. The CacheListenerAdapter with usual afterCreate and afterUpdate overrides is not called.
The use case is to register and unregister to lots of different keys on the fly.
If I use the spring boot app itself to put to the local region, then the event handler is being called. So it's not an issue with the spring boot code this is a connection pool & server registration issue of some kind.
The problem was my application.properties had
spring.data.gemfire.cache.client.durable-client-id=myListener
For some reason a durable client cannot run a CacheListenerAdapter

Does Spring Cloud AWS Secrets Manager config compatible with Spring Boot 2?

I'm trying to run spring-cloud-starter-aws-secrets-manager-config with Spring Boot 2.1.0.RELEAS version and I have the following error:
14:26:59.423 [background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.13.Final
14:26:59.430 [background-preinit] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
14:26:59.434 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
14:26:59.435 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
14:26:59.436 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
14:26:59.436 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
14:26:59.561 [background-preinit] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
14:26:59.565 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
14:26:59.565 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
14:26:59.565 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
14:26:59.565 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
14:26:59.565 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
14:26:59.783 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:161)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:102)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:68)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:75)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:347)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:306)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)

Spring MVC on WebSphere Liberty, 404s on all Spring URLs

Eclipse Oxygen with WebSphere Development Tools (WDT), Spring MVC 4.3.14, WebSphere Liberty Core 18.0.0.1 on Java 8. Liberty Features enabled (deliberately not latest) are:
<featureManager>
<feature>adminCenter-1.0</feature>
<feature>localConnector-1.0</feature>
<feature>jaxrs-1.1</feature>
<feature>concurrent-1.0</feature>
<feature>webProfile-6.0</feature>
<feature>jaxb-2.2</feature>
</featureManager>
JSPs on the context root are working fine, so that's correct. Also, ibm-web-ext.xml has <context-root uri="/webapp/gatewaymvm/" />
The Spring startup logging indicates that my #Controller classes are binding to the paths I expect:
10:31:24,102 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Looking for request mappings in application context: WebApplicationContext for namespace 'Spring MVC Dispatcher-servlet': startup date [Thu Apr 05 10:31:22 CDT 2018]; parent: Root WebApplicationContext
....
10:31:24,125 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:1 request handler methods found on class mypackage.QueryTransactionController: {public mypackage.QueryTransResponse mypackage.QueryTransactionController.processRequest(mypackage.QueryTransRequest,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException={[/QueryTransaction],methods=[POST],consumes=[application/json || application/xml],produces=[application/json || application/xml]}}
10:31:24,125 INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Mapped "{[/QueryTransaction],methods=[POST],consumes=[application/json || application/xml],produces=[application/json || application/xml]}" onto public mypackage.QueryTransResponse mypackage.QueryTransactionController.processRequest(mypackage.QueryTransRequest,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException
...
10:31:24,130 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:1 request handler methods found on class mypackage.TestPostJSONDocumentController: {public java.lang.String mypackage.TestPostDocumentController.execute(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException={[/testPostJSONDoc],methods=[POST]}}
10:31:24,130 INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Mapped "{[/testPostJSONDoc],methods=[POST]}" onto public java.lang.String mypackage.TestPostDocumentController.execute(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException
Yet, when I hit any of those URLs, they produce 404 responses and log entries like the following:
10:32:40,067 DEBUG org.springframework.web.servlet.DispatcherServlet:DispatcherServlet with name 'Spring MVC Dispatcher' processing POST request for [/webapp/gatewaymvm/testPostJSONDoc]
10:32:40,067 DEBUG org.springframework.webflow.mvc.servlet.FlowHandlerMapping:No flow mapping found for request with URI '/webapp/gatewaymvm/testPostJSONDoc'
10:32:40,068 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Looking up handler method for path testPostJSONDoc
10:32:40,075 DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:Did not find handler method for [testPostJSONDoc]
10:32:40,076 WARN org.springframework.web.servlet.PageNotFound:No mapping found for HTTP request with URI [/webapp/gatewaymvm/testPostJSONDoc] in DispatcherServlet with name 'Spring MVC Dispatcher'
This same application, when deployed to "Traditional" WAS, works as expected. I imagine there's something obvious I'm missing about Liberty, Liberty under Eclipse, or Spring MVC under Liberty.
At some point during my testing, where I had code that constructed a URL from the current request, I had seen /webapp/gatewaymvm//resource, with two slashes together.
So I tried removing the trailing slash from the places where I had a context root of /webapp/gatewaymvm/, and that resolved the issue. Either from server.xml if I have the WAR installed there directly, or from application.xml if I have the WAR installed in an EAR/Enterprise project.
Interesting that the JSPs worked with the trailing slash there, but the Spring paths did not.

How can I implement Picketlink Authenticator in the war layer

As the title say, I created a class in the war layer that is annotated with #Picketlink. Note that I have an ear deployment structure (ejb, war).
The custom authenticator:
#PicketLink
public class PicketlinkAuthenticator extends BaseAuthenticator { }
If I put that class in the ejb layer, the authentication is ok but when I put it to the war layer it seems like it's not found by the project as it's throwing:
20:49:46,027 INFO [org.picketlink.common] (default task-10) Using logger implementation: org.picketlink.common.DefaultPicketLinkLogger
20:49:46,043 INFO [org.picketlink.idm] (default task-10) PLIDM001000: Bootstrapping PicketLink Identity Manager
20:49:46,068 WARN [org.picketlink.idm] (default task-10) PLIDM001101: Working directory [\tmp\pl-idm] is marked to be always created. All your existing data will be lost.
20:49:46,111 INFO [org.picketlink.idm] (default task-10) PLIDM001100: Using working directory [\tmp\pl-idm].
20:49:46,127 DEBUG [org.picketlink.idm] (default task-10) No partitions to load from \tmp\pl-idm\pl-idm-partitions.db
20:49:46,152 DEBUG [org.picketlink.idm] (default task-10) Initializing Partition [6a373282-0173-4b7d-bd6a-ff0e5dc43436] with id [6a373282-0173-4b7d-bd6a-ff0e5dc43436].
20:49:46,153 DEBUG [org.picketlink.idm] (default task-10) Loaded Agents for Partition [6a373282-0173-4b7d-bd6a-ff0e5dc43436].
20:49:46,154 DEBUG [org.picketlink.idm] (default task-10) Loaded Credentials for Partition [6a373282-0173-4b7d-bd6a-ff0e5dc43436].
Why not just move the authenticator to the ejb side?
->Because I'm throwing custom error like user expired, etc. I need jsf to post these error messages.
Why not move the picketlink dependency in the web layer?
->Because my account that extended the picketlink account is binded to my services.
As suggested here I already added the picketlink module in the war project:
https://docs.jboss.org/author/display/PLINK/JBoss+Modules
<jboss-deployment-structure>
<ear-subdeployments-isolated>false</ear-subdeployments-isolated>
<sub-deployment name="THE-WAR-MODULE-THAT-REQUIRES-PICKETLINK.war">
<dependencies>
<module name="org.picketlink" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Anyway around this? I just want to show some custom errors :-(
I was not able to solve this problem but I have a work-around solution and that is to move the picketlink module to the web layer and just pass the identity instance to the services that need it.
I have been missing around with the same problem as well for a while now (it's 2016 now ...). What seems to make it work is to add the following CDI annotations:
#PicketLink
#Name
#RequestScoped
public class PicketlinkAuthenticator extends BaseAuthenticator { }
I would have expected the core Authentication Manager to pick this up just based on the #PicketLink Annotation, but without the CDI Annotations, the custom Authenticator class is never even loaded. Maybe there is an other way that will require us to bootstrap PicketLink - but I could not find any references.

OpenEJB tries to bind a remote EJB twice

I am having a strange issue regarding OpenEJB and integration tests.
I am using Open EJB 4.5.1, JUnit 4.10 and Maven3 with surefire plugin 2.13
I start OpenEJB from my test doing:
InitialContext ic = new InitialContext();
It works (apparently) fine and deploys the EJB (CentrosBeanFacade) correctly, but after that it tries to bind it again, which causes the server to fail.
These are the interesting log parts:
First time --> [OK] :
DEBUG - bound ejb at name: openejb/Deployment/CentrosBeanFacade/com.csc.health.xhis.arqtest.api.CentrosLogica, ref: org.apache.openejb.core.ivm.naming.BusinessRemoteReference#6506fe2b
DEBUG - bound ejb at name: openejb/Deployment/CentrosBeanFacade/com.csc.health.xhis.arqtest.api.CentrosLogica!Remote, ref: org.apache.openejb.core.ivm.naming.BusinessRemoteReference#6506fe2b
INFO - Jndi(name=CentrosBeanFacade) --> Ejb(deployment-id=CentrosBeanFacade)
INFO - Jndi(name=global/classpath.ear/test-ejb/CentrosBeanFacade!com.csc.health.xhis.arqtest.api.CentrosLogica) --> Ejb(deployment-id=CentrosBeanFacade)
INFO - Jndi(name=global/classpath.ear/test-ejb/CentrosBeanFacade) --> Ejb(deployment-id=CentrosBeanFacade)
But then it tries to deploy it a second time.
DEBUG - failed to bind ejb at name: openejb/Deployment/CentrosBeanFacade/com.csc.health.xhis.arqtest.api.CentrosLogica, ref: org.apache.openejb.core.ivm.naming.BusinessRemoteReference#32f00d9a
ERROR - Jndi name could not be bound; it may be taken by another ejb. Jndi(name=openejb/Deployment/CentrosBeanFacade/com.csc.health.xhis.arqtest.api.CentrosLogica!Remote)
The internal BusinessRemoteReference from EJB is a different object than the first time, so it is trying to deploy it a second time. But I have checked the classpath and the EJB is not included twice. If I execute a similar procedure but from a plain Java class, it also fails.
Any clues?