Deltaspike service layer catching PersistenceException unexpected behavior - cdi

I have a java ee 8 web app using deltaspike using core, data and jsf modules.
I also added cdi bean (RegisterService using #trasactional) which calls a UserRepository
public void createNewUser(User newUser){
try{
userRepository.save(newUser)
}catch(PersistenceException ex){
throw new RegisterException("Error", ex); //it never falls at this point
}
}
When service layer calls repository I’m catching a PersistenceException and rethrowing a service layer exception but the repository never throws PersistenceException even if the primary ID is duplicated (I just can see the stacktrace in console output), of course I’m running into a contraint exception to try to execute the expected flow
I’m using a deltaspike exception handler but I have not added a #handler for PersistenceException
Does somebody knows what could be happening here?
this is a reproducible example: https://github.com/gdiazs/javaee8-fullstack
Since there is no tables in DB it will throw an PersitenceException.
I ran this example in 2 laptops.
Mine: OSx 10.14.6
JDK: Open JDK Zulu 1.8
eclipse and also maven terminal execution
Work: OSx 10.14.6 (it works as I expect good here)
JDK: Oracle 1.8
Intellij and also maven terminal execution
So now I`m really confused, no idea why is working just in one.

Related

enableTransaction not working with J2ee Container

I get below error when I consume message in a Jboss ejb container
2022-05-18 22:37:24,699 ERROR [org.jboss.resource.adapter.jms.inflow.JmsActivation] Unable to reconnect org.jboss.resource.adapter.jms.inflow.JmsActivationSpec#8315a9(ra=org.jboss.resource.adapter.jms.JmsResourceAdapter#10a62f0 destination=queues/Subscriber.global.globalvirtual.e2e.cmdm.changepub.Virtual destinationType=javax.jms.Queue tx=true durable=false reconnect=10 provider=java:/ACTIVEMQJMSNONXAProviderAsync user=ldcp.cmdm pass= )
javax.jms.JMSException: Please enable transactions on PulsarConnectionFactory with enableTransaction=true
After getting this error - I set enableTransaction=true and started getting different error
javax.jms.JMSException: not supported
at com.datastax.oss.pulsar.jms.PulsarConnection.createConnectionConsumer(PulsarConnection.java:685)
the error is in createConnectionConsumer.
This is the method called by the JBoss container.
This method is currently not implemented
https://github.com/datastax/pulsar-jms/blob/96606d0f22a1af8fdde0c5eff0f5dde086d9862c/pulsar-jms/src/main/java/com/datastax/oss/pulsar/jms/PulsarConnection.java#L685
the implementation should be quite straighforward.
There are integration tests for Payara and Apache TomEE but JBoss is still not covered.
Please open an issue on github.

Broaleaf 5.2 ROOT.war issue with Filters

I am trying to deploy Broadleaf demo site version 5.2.0 on external tomcat 8.5.16 with MYSQL as DB and standalone external Solr server running on port 8983.
I am able to access the admin application.
When I try deploying the ROOT.war, I get error
12-Aug-2017 16:33:52.733 SEVERE [localhost-startStop-1]
org.apache.catalina.core.StandardContext.filterStart Exception starting
filter [blDeviceResolverRequestFilter]
javax.naming.NameNotFoundException: Name [blDeviceResolver] is not bound
in this Context. Unable to find [blDeviceResolver].
I tried creating a bean so that it autowires correctly in
BroadleafDeviceResolverRequestFilter as
#Bean(name="blDeviceResolver")
public DeviceResolver getDeviceResolver() {
return new LiteDeviceResolver();
}
But the error is still the same and I am unable to run the demo application.
So the issues was that class BroadleafDeviceResolverRequestFilter was using
#Resource
private DeviceResolver deviceResolver;
But #Resource annotation is generic and means different things to Tomcat and Spring (Reference: Spring Boot WAR deployed in Tomcat 7 tries to perform weird automatic #Resource lookup)
I replaced #Resource with #Autowired and added a bean to com.community.core.config.CoreConfig
#Bean(name="blDeviceResolver")
public DeviceResolver getDeviceResolver() {
return new LiteDeviceResolver();
}
and my issue was resolved.

Why does this NServiceBus message handler throw System.MethodAccessException on call to Task.CompletedTask?

After looking through the documentation and trying to find other examples of developers getting this error, I am a bit stuck. We are working with NServiceBus 6 and are occasionally getting a System.MethodAccessException in our message handlers on the call to return Task.CompletedTask. It seems to only occur when the handler is deployed in an Azure Worker Role (as opposed to running in the emulator). We are using the Azure Service Bus transport.
public Task Handle(UpdatePatientAccommodationCode message, IMessageHandlerContext context)
{
Console.WriteLine($"Handling [{message.GetType()}]");
var patientVisit = LoadByExternalPatientId(message.ClientId, message.ExternalPatientId);
var mappedEvent = patientVisit.HandleCommand(message);
if (patientVisit.IsEventAdded)
PatientVisitEventStore.Save(patientVisit);
return mappedEvent == null ? Task.CompletedTask : context.Publish(mappedEvent);
}
The actual exception looks like this:
System.MethodAccessException: Attempt by method 'XXX.Handlers.PatientVisitHandler.Handle(XXX.UpdatePatientAccommodationCode, NServiceBus.IMessageHandlerContext)' to access method 'System.Threading.Tasks.Task.get_CompletedTask()' failed.
at XXX.Handlers.PatientVisitHandler.Handle(UpdatePatientAccomm odationCode message, IMessageHandlerContext context) in PatientVisitHandler.cs: line 314
at NServiceBus.InvokeHandlerTerminator.Terminate(IInvokeHandlerContext context) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\Incoming\Invok eHandlerTerminator.cs: line 24
at NServiceBus.LoadHandlersConnector.<Invoke>d__1.MoveNext() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\Incoming\LoadH andlersConnector.cs: line 40
I suspect your code locally has .NET framework 4.6.x which supports Task.CompletedTask. When you deploy to CS and use OS family less than version 5 won't have support for 4.6.x You either will need to use a startup task to install 4.6.x or migrate to OS Family 5 (Server 2016).
That is strange. Judging by the reference sources of Task.CompletedTask I can't come up with a scenario where this could happen. The task that is statically cached is initialized with RAN_TO_COMPLETION and DO_NOT_DISPOSE. Based on that I would suggest you determine whether you are using the .NET Framework version 4.6 or higher. If you do and you still see the exception try to replace Task.CompletedTask with
static class TaskEx
{
public static readonly Task CompletedTask = Task.FromResult(0);
}

Grails 2.1.1 and spring security messages

Anyone experiencing the error messages for failed logins not appearing?
I am upgrading a grails 1.3.7 app to grails 2.1.1 and I have 2 issues with the spring security core functionality.
First, if I try an invalid login the auth fails but there is no error message just {} in the flash message.
Second, I was using a method like this to get the current count of active sessions. It no longer is accurate, as it just increases and doesn't recognize a logout.
def getCurrentSessionCount(){
def sessioncount = 0
sessionRegistry.getAllPrincipals().each{
sessioncount += sessionRegistry.getAllSessions(it, false).size()
}
return sessioncount;
}
Okay well this was a difference in the LoginController how the error messages were getting populated. In 1.3.7 and previous security plugin the code looks like:
msg = SpringSecurityUtils.securityConfig.errors.login.expired
but for 2.1.1 and the upgraded spring security plugin 1.2.7.3 the code needs to use the context like:
msg = g.message(code: "springSecurity.errors.login.disabled")
The session count has to do with a modification to the web.xml that you need to make to add the session listener, however in the new spring 3.0 it was moved so the new entry should look like:
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>

Tomcat misteriously loses application-scoped objects after a few days of running

I have a very strange problem which I can't figure out by myself. I have a JSF application that I'm developing and it's deployed on a Tomcat server at client site. It works just fine. However, after a few days, it starts to behave very weird, and I'm getting a lot of exceptions such as the following in the log:
SEVERE: Error Rendering View[/index.xhtml]
com.sun.facelets.tag.TagAttributeException: /menu.xhtml #21,53 test="${!empty bean.menuItems}" /menu.xhtml #21,53 test="${!empty bean.menuItems}": Error reading 'menuItems' on type com.blabla.bean.ApplicationBean
at com.sun.facelets.tag.TagAttribute.getObject(TagAttribute.java:235)
at com.sun.facelets.tag.TagAttribute.getBoolean(TagAttribute.java:79)
at com.sun.facelets.tag.jstl.core.IfHandler.apply(IfHandler.java:49)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
.....
Please note that bean refers to an object of type com.blabla.bean.ApplicationBean which is an application-scoped bean. The above xhtml code is inside a c:if, that's why I use the $ notation. As mentioned, the application runs just fine for the first 2-3 days, it is only after a few days when these exceptions occur in the log, and they are only related to the only bean that's in application scope. Normally, when I get such exceptions I check if the getter for the 'menuItems' field is in the bean, but it is there and if it wasn't, the application would not work at all and not work fine for 2 days and then crash.
I also encounter exceptions related to the custom resource bundle that I have in my application:
Caused by: javax.faces.FacesException: Could not load resource bundle for name 'messages': Can't find bundle for base name com.blabla.messages.CustomResourceBundle, locale de
Again, the bundle was loaded during the first 2-3 days of the application life, but then this exception occurs all of a sudden.
Has anybody encountered a similar situation? Can anybody point me in the right direction as to where to look for the problem, since I'm completely out of ideas here.
Thank you in advance.

Resources