Using ServiceTasks with TimerCatchingEvents in activiti bpmn workflow behaving inconsistently - spring-boot

When using ServiceTasks with IntermediateTimerEvents sometimes it did not execute the service task due to exception raised in ACT_RU_JOB table. EXCEPTION_MSG_ column in ACT_RU_JOB table is populated with Unknown property used in expression: #{serviceTask1.execute(execution). value for that particular job.
Please refer the activiti workflow image i have attached below for clear picture of the usecase.
NOTE: I am using spring-boot microservice using maven to run the workflow.
spring-boot version: 1.5.5.RELEASE
activity version: 5.22.0
Activity and Connection Pool dependencies in pom.xml:
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>${activiti.version}</version>
</dependency>
Connection Pooling dependency:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</dependency>
application.properties configuration attached below:
spring.activiti.job-executor-activate=false
spring.activiti.async-executor-enabled=true
spring.activiti.async-executor-activate=true
spring.datasource.tomcat.initial-size=15
spring.datasource.tomcat.max-active=100
ANALYSIS: The error i am getting above is not consistent.
activiti workflow
Project link on Github:
https://github.com/cloudnativeview/spring-activiti-bpmn-kickstart

The exception is totally expected because you don't set the appropriate process variable when starting your process instance. Also Activiti engine is not able to resolve named bean serviceTask1.
From the Activiti 5.22.0 userguide docs (inside the file activiti-5.22.0.zip), more precisely section 8.5.3. Java Service Task you have 4 ways of declaring how to invoke Java logic.
Specifying a class that implements JavaDelegate or ActivityBehavior.
Evaluating an expression that resolves to a delegation object.
Invoking a method expression.
Evaluating a value expression.
In your BPMN process definition file you are invoking service task Java logic with method expression technique. If you want to successfully invoke your method you have to make sure your bean serviceTask1 is a process variable from your execution or a named object in Spring context.
Unfortunately you don't provide necessary information to your BPM engine on where to find your bean with Java logic.
I suggest you the following steps.
Read the technical and userguide documentation (chapter 8.5.3. Java Service Task), from the provided links.
Try to invoke Java logic with the way of specifying a class that implements JavaDelegate or ActivityBehavior. In my humble opinion it is far more easier to get the first touch with Activiti BPM engine.

Related

How to configure a non-AgroalDataSource within Quarkus and Panache

Apache ShardingSphere provides the ShardingSphereDataSource to encapsulate the routing mechanisme. So, if we inject a ShardingSphereDataSource into a EntityManager, we can easily persist our data and route to the planned destination via EntityManager#persist method.
I don't know my understanding is correct or not, Does Panache seems to only accept AgroalDataSource?
I refer to this project to produce a ShardingSphereDataSource bean, and use following code snippet to inspect whether the ShardingSphereDataSource is produced successfully.
CDI.current().getBeanManager().getBeans(DataSource.class).forEach(bean -> {
log.info("DataSource Bean name:{}, beanClass:{}", bean.getName(), bean.getBeanClass());
});
The result shows I have a ShardingSphereDataSource named defaultDs in the CDI context.
DataSource Bean name:defaultDs, beanClass:class org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource
Next, I config a persistent unit and refer to this datasource.
quarkus.hibernate-orm.datasource=defaultDs
quarkus.hibernate-orm.packages=x.y.x.domain
I get the error message.
Caused by: io.quarkus.runtime.configuration.ConfigurationException: The datasource 'defaultDs' is not configured but the persistence unit '<default>' uses it. To solve this, configure datasource 'defaultDs'. Refer to https://quarkus.io/guides/datasource for guidance.
So, how do we configure a non-AgroalDataSource within Quarkus and Panache?

Optaplanner Quarkus reflection issues

I'm creating a solver factory based on an XML file using the built in
solverFactory = SolverFactory.createFromXmlResource("solverConfig.xml");
This works fine until compiling into a Quarkus native application, now I get reflection issues from Optaplanner enums:
ERROR [io.qua.run.Application] (main) Failed to start application (with profile prod): java.lang.NoSuchFieldError: org.optaplanner.core.api.domain.common.DomainAccessType: REFLECTION
at com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getEnumConstants(ReflectionNavigator.java:25)
at com.sun.xml.bind.v2.model.nav.ReflectionNavigator.getEnumConstants(ReflectionNavigator.java:34)
at com.sun.xml.bind.v2.model.impl.EnumLeafInfoImpl.calcConstants(EnumLeafInfoImpl.java:117)
at com.sun.xml.bind.v2.model.impl.EnumLeafInfoImpl.getConstants(EnumLeafInfoImpl.java:181)
at com.sun.xml.bind.v2.model.impl.EnumLeafInfoImpl.link(EnumLeafInfoImpl.java:188)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.link(ModelBuilder.java:427)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.link(RuntimeModelBuilder.java:103)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:439)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:273)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:109)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1126)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:135)
at java.lang.reflect.Method.invoke(Method.java:566)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:275)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:264)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:403)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:691)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:632)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.<init>(GenericJaxbIO.java:89)
at org.optaplanner.core.impl.io.jaxb.GenericJaxbIO.<init>(GenericJaxbIO.java:81)
at org.optaplanner.core.impl.io.jaxb.SolverConfigIO.<init>(SolverConfigIO.java:27)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlReader(SolverConfig.java:207)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlInputStream(SolverConfig.java:182)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:122)
at org.optaplanner.core.config.solver.SolverConfig.createFromXmlResource(SolverConfig.java:97)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:55)
I can work through these issues by adding #RegisterForReflection on my class calling SolverFactory.createFromXmlResource("solverConfig.xml"), but it feels like these reflection registrations should not have to be a manual step. Currently I'm at #RegisterForReflection(targets = {EnvironmentMode.class, RandomType.class, DomainAccessType.class}), but I'm guessing there will be a lot more enums to add to that list... Should it really be this complex? I'm using the Quarkus Optaplanner dependency
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-quarkus</artifactId>
</dependency>
By doing it another way, I was able to solve the issue.
In my class that previously called solverFactory = SolverFactory.createFromXmlResource("solverConfig.xml"), I now just inject the factory:
#Inject
SolverFactory<Schedule> solverFactory;
And moved the XML file name to application.properties instead:
quarkus.optaplanner.solver-config-xml=solverConfig.xml

spring-cloud-azure-feature-management with application.yaml

I am attempting to implement a quick feature flag solution for my teams that run both .net core and java spring boot. I was able to easily get a solution running with .net core using feature-management and was excited to see the spring equivalent because I was hoping for essentially the same tooling for all teams.However, I am having a problem because I just want to start by providing the flag values in the application/bootstrap.yaml and it keeps yelling at me with the following error.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.cloud.azure.appconfiguration-com.microsoft.azure.spring.cloud.config.AppConfigurationProperties': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one config store has to be configured.
Caused by: java.lang.IllegalArgumentException: At least one config store has to be configured.
So, my question is, how do I specify a provider for a local file rather than spring cloud config? I do not have that implemented and it will take too long for me to do so in my environment.
I found my problem! I had an extra dependency that was not needed for what I was doing. Once I removed the following it worked fine.
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-cloud-azure-appconfiguration-config</artifactId>
<version>1.2.2</version>
</dependency>

Spring on WebSphere 8: Quartz job with web service call throws JAXBException "<class> is not known to this context"

I'm facing a JAXBException " is not known to this context" when calling a web service from within a job controlled by Quartz on Spring:
javax.xml.ws.WebServiceException: javax.xml.bind.JAXBException: com.xxxx.yyyy.zzzz.ImageMetaData is not known to this context
at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:175)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:128)
at org.apache.axis2.jaxws.marshaller.impl.alt.DocLitWrappedMinimalMethodMarshaller.demarshalResponse(DocLitWrappedMinimalMethodMarshaller.java:624)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.createResponse(JAXWSProxyHandler.java:593)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:432)
at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:213)
at com.sun.proxy.$Proxy299.findAllImageMetaData(Unknown Source)
I'm having a Spring 3.2.4 Java EE application with JSF running on IBM WebSphere v8.
When calling a specific web service from the JSF part of the application (i.e. from an action or a service), everything's ok.
The exception occurs only when the call is done from within a Quartz/Spring triggered job.
Executing exacty the same job code from the action does not result in an exception.
I tried a lot of different things like using a corresponding #XmlSeeAlso annotation in the JAXB generated classes but even using the annotation in the webservice interface itself does not solve the issue.
I also updated the Spring and Quartz libraries to more recent versions but this didn't help.
Anyone any idea?
I've finally solved the issue.
After much analysis I encountered the following issue in the Spring framework:
https://jira.spring.io/i#browse/SPR-11125
When a job is triggered via Spring/Quartz on WebSphere, the wrong ContextClassLoader is set.
This may cause many different problems - among them is the JAXBException as described.
The Spring bug is still open - so as a workaround I had to overwrite the context class loader of the current thread by the correct one:
ClassLoader cl = invoiceService.getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(cl);
The correct class loader can be simply retrieved by a class that has been loaded by the container. Using this class loader as the context class loader for the current thread solved my issue.

Spring-Social-facebook + Spring MVC integration

I am trying to access facebook data via spring social facebook integration using the instructions provided at http://spring.io/guides/gs/accessing-facebook.
But currently i am facing 2 type of problem
When i run example as mentioned in tutorial i get following error
No matching bean of type [org.springframework.social.facebook.api.Facebook] found for dependency
When i run this with #Configuration on FacebookConfig class, i get below mentioned error
A ConnectionFactory for provider 'facebook' has already been registered
Is there a workaround to it?
I have kept the war file with source code at https://skydrive.live.com/redir?resid=EA49CD7184E0E40!168&authkey=!AIkoKKx5-Um8AQE
What version are you using?
Try using the version 1.1.0.RELEASE
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-facebook</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
If it not works, please try post the stacktrace printed.
You need to create a the beans to your class, please post more information like your pom.xml and your spring context configuration.
Ihad the same problem. Spring Social Facebook will automatically add connection factory based on the configuration in application.properties. This auto-configured connection factory is clashing with the one that you're trying to add. Try just to remove your connection factory you add through addConnectionFactories.
Try to use different setting to load your custom connection factory...
E.g. Instead of using OOTB keys use different keys:
#Facebook Social App Details:
# Commented below 2 OOTB Keys & Bingo it worked.
#spring.social.facebook.appId=APP_ID
#spring.social.facebook.appSecret=APP_SECRET
facebook.app.id=APP_ID
facebook.app.secret=APP_SECRET
This will resolve your problem.

Resources