Template not being loaded with Kmodule.xml config in Drools - jboss

I am trying to load my drools template file(drt) with kmodule.xml as below.
<kbase packages="KieRule">
<ruleTemplate
dtable="kiedrl/template-data.xls"
template="kiedrl/validate-schedule-minor.drt"
row="3" col="2" />
<ksession name="templateRule" />
</kbase>
and my template and data table are present in resouces folder as shown in below image.
and I am creating a session as follows
KieSession ksession = KieServices.Factory.get().getKieClasspathContainer().newKieSession("templateRule");
But my template is not able to load into session. Any other configuration that I need to add in pom.xml or at any other?

Related

drools #KSession throws exception when using kmodule in separate jar

using Drools 6.2.0.Final
i am using drools with a kmodules.xml and decisiontable inside a separate jar file. when i attempt to bind the #KSession to the spring application context it throws an nullpointer exception deep inside the annotation.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oft.onlineservice.business.FeeRulesEngineTest': Injection of kie dependencies failed; nested exception is java.lang.NullPointerException
at org.kie.spring.annotations.AnnotationsPostProcessor.postProcessPropertyValues(AnnotationsPostProcessor.java:109)
using a simple junittest shows the problem.
public class FeeRulesEngineTest {
#KSession( "ksession1")
private StatelessKieSession ksession;
#KBase("feeDecisionTable")
private KieBase kbase;
the kmodule.xml
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="feeDecisionTable" packages="oft.rulesengine" default="true">
<ksession name="ksession1" type="stateless" default="true" >
</ksession>
</kbase>
</kmodule>
the spring config is using the annonation postprocessor.
<kie:import />
<bean id="kiePostProcessor"
class="org.kie.spring.annotations.KModuleAnnotationPostProcessor"/>
my curent work around to is to use #Autowire for the KSession and KBase.
any idea what i am doing wrong?
thanks
-lp
It's a bug in Kie Services / Spring integration. The annotation assumes there's always a ReleaseId.
I created a Pull Request some weeks ago, so it should be solved in an upcoming version.
Ticket link: https://issues.jboss.org/browse/DROOLS-845

How to add the description of job in spring batch admin user interface?

Is there any way to add the description of job at the user interface of spring batch admin?
Although, I tried to added the description of the job, spring batch admin cannot support it.
I would like to know that whether spring batch admin does not support it or not.
I know i'm late to the party but I figured it out and it works flawlessly for me. All you have to do is :
Add a messages.properties file in your classpath (under
src/main/resources).
Add yourJobName.description=Your description goes here in that file.
Override manager-context.xml for SBA by creating a file on path src/main/resources/META-INF/spring/batch/servlet/override/manager-context.xml
The content of the above created file should be :
`
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Override messageSource bean in order to provide custom text content -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
</beans>
`
That's it. Your custom description shows up in SBA. Hope this helps someone who's looking for it.
There isn't the ability out of the box to display the job's description. That is only contained in the XML and the data seen in the UI comes from the JobRepository. You'd have to extend the UI to add that functionality.

multiple applications single config file

I'm trying to write a service and configuration application. VB/C++ 2010 I've had a number of hits on google but they largely seem to be obsolete. What I have so far is a project with a single form app and a service app. The single form app has an "app.config" file and I have added a section:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="settings.config">
</appSettings>
</configuration>
In the Solution I have added a "settings.config" file and its contents is:
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
<add key="Setting1" value="This is Setting 1 from settings.config" />
<add key="Setting2" value="This is Setting 2 from settings.config" />
<add key="ConnectionString" value="ConnectString from settings.confg" />
</appSettings>
I have added a reference to then C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Configuration.dll
library in both the forms app and the service app
In the very simple forms app i have the following code
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim s As String = _
System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
TextBox1.Text = s
End Sub
It doesn't work! Now clearly I am missing something. Its probably very simple. But my limited understanding is that this is automatically configuered by the config files I have? MS in their usual helful fashion seem to only give samples for 2012 and net 4.5 or greater. I need this to work on a 2003 server (as well) so I'm limited to net 4.0
The problem here is that the line System.Configuration.ConfigurationManager.AppSettings("ConnectionString") is looking for the key ConnectionString in your application's app.config file.
The fact that you have included that file key in your app.config file doesn't magically tell the ConfigurationManager to load the settings from a different file. If that's what you want you will have to read the setting for the file key and then manually load the configuration from that file.
This has not changed since the early versions of .Net though so I'm not sure why you were conflicted by the examples.
Add reference on existing assembly in .Net section of your Add Reference Popup
But i suggest you to use connectionStrings section in your config file
<connectionStrings>
<add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings>
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;

Load jobs at startup to Spring Batch Admin

From the Spring Batch Admin documentation, it mentioned that jobs will be loaded if job configuration file is located in classpath under META-INF/spring/batch/jobs/*.xml
Documentation
In the spring-batch-admin-sample that comes with STS, the jobs are loaded when the admin web application is deployed, under the file classpath:\META-INF\batch\module-context.xml And it is bootstrapped at deployment. Not sure how that works...
While I can load the job configuration by uploading in the user interface, http://localhost:8080/simple-batch-admin/configuration, some of my custom beans were not autowired for some reason. So the desirable behavior would be to load all the jobs when Admin is deployed.
Thank you in advance.
After several round of digging, I was able to load the job file. I have to place my job file in /META-INF/spring/batch/jobs/ folder not /META-INF/batch/ Also, in order for my jobLauncher, jobRepository, dataSource, etc. to get discover at load time. I have to put it in src/main/resources/META-INF/spring/batch/spring/batch/bootstrap/**/
All because of two files in spring-batch-admin-resources-1.2.0.RELEASE.jar in org.springframework.batch.admin.web.resources
servlet-config.xml
<import resource="classpath*:/META-INF/spring/batch/servlet/resources/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/servlet/manager/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/servlet/override/*.xml" />
which allows me to add menu and controller under the src/main/resources/META-INF/spring/batch/servlet/override/*xml
and
webapp-config.xml
<import resource="classpath*:/META-INF/spring/batch/bootstrap/**/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/override/**/*.xml" />
where I put my launch context

Deploying a datasource w/ JAAS login module as a .sar in jboss

Does anyone have experience bundling a datasource (-ds.xml) definition + login-config.xml as a service archive in jboss? I've been fighting with this for awhile to no avail. I'm just looking for some pointers on how I should be laying the .sar out. I want the .sar to ultimately live in a .ear. Any pointers greatly appreciated!
This is relatively straightforward task.
Your EAR file needs to have following layout:
my-app.ear
|+ META-INF
|+ applications.xml and jboss-app.xml
|+ myapp.war
|+ myapp.jar
|+ lib
|+ my-ds.xml
|+ my-login-module-service.xml
where my-ds.xml contains datasource definition as usual. my-login-module-service.xml defines MBean based on the DynamicLoginConfig class. These modules are then referenced within jboss-app.xml (custom JBoss deployment descriptor) as demostrated here:
<jboss-app>
<module>
<service>my-login-module-service.xml</service>
</module>
<module>
<service>my-ds.xml</service>
</module>
</jboss-app>
Easiest way how to create Login Module definition is to use support for embedded XML documents as attributes values. Such a config (my-login-module-service.xml) will looks like this:
<server>
<mbean code="org.jboss.security.auth.login.DynamicLoginConfig"
name="jboss:service=DynamicLoginConfig">
<attribute name="PolicyConfig" serialDataType="jbxb">
<jaas:policy xsi:schemaLocation="urn:jboss:security-config:4.1 resource:security-config_4_1.xsd" xmlns:jaas="urn:jboss:security-config:4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<jaas:application-policy name="userinrole">
<jaas:authentication>
<jaas:login-module code="org.jboss.security.auth.spi.XMLLoginModule" flag="required">
<jaas:module-option name="my-policy-123">
<ur:users xsi:schemaLocation="urn:jboss:user-roles:1.0 resource:user-roles_1_0.xsd" xmlns:ur="urn:jboss:user-roles:1.0">
<ur:user name="admin" password="admin123">
<ur:role name="MyUserRole"></ur:role>
<ur:role name="AdminUser"></ur:role
</ur:user>
</ur:users>
</jaas:module-option>
<jaas:module-option name="unauthenticatedIdentity">guest</jaas:module-option>
</jaas:login-module>
</jaas:authentication>
</jaas:application-policy>
</jaas:policy>
</attribute>
<depends optional-attribute-name="LoginConfigService">jboss.security:service=XMLLoginConfig</depends>
<depends optional-attribute-name="SecurityManagerService">jboss.security:service=JaasSecurityManager</depends>
</mbean>
</server>
You can verify successful deployment using JNDIVIew bean (java:/jaas/my-policy-123 in this example).
For deployment including custom classes it's better to choose SAR archive deployment together with custom code. In such a case you can separate MBean definition and Login Module config (META-INF/jboss-service.xml) :
<server>
<mbean code="org.jboss.security.auth.login.DynamicLoginConfig" name="jboss:service=DynamicLoginConfig">
<attribute name="AuthConfig">META-INF/login-config.xml</attribute>
<depends optional-attribute-name="LoginConfigService">jboss.security:service=XMLLoginConfig</depends>
<depends optional-attribute-name="SecurityManagerService">jboss.security:service=JaasSecurityManager</depends>
</mbean>
</server>
META-INF/login-config.xml will then contain your policy configuration.
I'm using this approach on JBoss AS 4.x.