How do I programmatically disable the update checks for an Ehcache? - ehcache

I know that the attribute "updateCheck" can be set in "false" in the XMLlike this:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../config/ehcache.xsd"
updateCheck="false"
monitoring="autodetect">
But I need to do this programmatically. How should I do it?

Call this before you use any ehcache functions:
System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");

Related

Spring boot logging setup of FileAppender - where does it use the max-size property?

Overflowers
Please pardon my question if it's answer it or the answer is naive.
I have a very basic Spring Boot (1.5.4) logging setup in application.properties:
logging.level.org=WARN
logging.level.com=WARN
logging.level.springfox=OFF
logging.level.org.hibernate.hql.internal.ast=ERROR
logging.level.com.MyCompany.kph=DEBUG
logging.file=/var/MyProduct/logs/MyProduct.log
logging.file.max-size=2GB
logging.file.max-history=100
The 2GB is not being honoured. No value I put in there is being honoured. Even xxxxx as a value does not cause a blow-up.
logging.file does - and I can see that being used inside DefaultLogbackConfiguration.
From my source-following I can see method DefaultLogbackConfiguration#setMaxFileSize(a, b) being called. But that method is fixed at 10MB. This aligns with the behaviour i'm seeing.
Am I doing something wrong and triggering the very default behaviour? Or Does default behavior get loaded first then specific stuff goes on top? (If it does, I can't find it and it's not working for me).
Can someone point to me where max-size gets consumed and used?
Thanks
Rich
Christ just by writing this post and reading the docs for MY-SPRING-VERSION, I see max-size is not used at all. That is why it's not working.
https://docs.spring.io/spring-boot/docs/1.5.19.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-logging

How to use SpEL with hasRole to set html attribute?

In Spring/Thymeleaf: I want to set attribute based on whether user has ROLE_A or not.
I tried HTML below:
<section class="footer" ... th:someattr="#{hasRole('ROLE_A')} ? 'true' : 'false'">
It always rendered as <section class="footer" ... someattr="true"> regardless of whether user had ROLE_A or not:
I tried also ${hasRole('ROLE_A')} ? 'true' : 'false' but that failed to work ():
SpelEvaluationException: EL1004E:(pos 0): Method call: Method
hasRole(java.lang.String) cannot be found on
org.thymeleaf.spring4.expression.SPELContextMapWrapper type
How to set an attribute to true|false depending on assigned authentication roles.
Thanks.
Sometimes, this is cause, because of the configuration of your project. So, let's do some changes and use the following code.
<section class="footer" ... th:someattr="${#authorization.expression('hasRole(''ROLE_A'')' ? 'true' : 'false'}">
To use #authorization, you will need to add the following dependency though, thymeleaf-extras-springsecurity4.
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
If you are using <artifactId>spring-boot-starter-parent</artifactId>, you won't need to add any version to your Thymeleaf Extras, since Spring Boot manages that for you. If not, try adding this version <version>3.0.4.RELEASE</version>.
Note: If it doesn't work change it for thymeleaf-extras-springsecurity5, depending on your Spring version one will work and the other won't.
I think you are looking for something like:
<section class="footer" ... th:someattr="${#request.isUserInRole('A') ? 'true' : 'false'}">
(No "extras" needed.)

Loading multiple packages in a single kie session?

I have two packages a and b having different rule files. Right now I am using two sessions to load the rules. Is there a way I can load rules from both the packages in a single session?
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="rules_a" packages="rules_a">
<ksession name="ksession1"/>
</kbase>
<kbase name="rules_b" packages="rules_b">
<ksession name="ksession2"/>
</kmodule>
Can I pass something like: packages = {"rules_a", "rules_b"} ??
As stated in this section of the documentation, you can pass a comma separated list of packages when building a KieBase.
Another possibility is to create a KieBase that includes others. That same section of the documentation shows how to do it.
Hope it helps,
There is a packages attribute of kiebase, below is an example of how to include the packages rules1, rules2 in kiebase.
<kbase name="rules_12" packages="rules1,rules2">
From drools documentation:

Mule - getting primary key back after insert

From the below article, i understand that Mule won't return the auto-generated Primary key after insert statement. Is there any work-around to get the PrimaryKey? I don't prefer going for mybatis as mentioned in this article.
Any help is appreciated!
http://ricston.com/blog/rant-mule-jdbc-transport-introduction-mule-module-mybatis/
try using new DB module availabe in 3.5.0-M4 or wait a few weeks for Mule ESB 3.5.0. Here is a usage example of this new feature:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:db="http://www.mulesoft.org/schema/mule/db"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd">
<flow name="insertWithAutoGeneratedKeys">
<inbound-endpoint address="vm://insertWithAutoGeneratedKeys" exchange-pattern="request-response"/>
<db:insert config-ref="dbConfig" autoGeneratedKeys="true" autoGeneratedKeysColumnIndexes="1">
<db:parameterized-query>INSERT INTO PLANET(POSITION, NAME) VALUES (777, 'Mercury')</db:parameterized-query>
</db:insert>
</flow>
Alternative: Use UUIDs for primary key and generate the UUID in Mule before the insert.

Spring batch : call beforeProcess on ItemProcessListener only once

What I am trying to achive is - I want to call a method only once before executing the ItemProcessor.process method.
If I use the ItemProcessListener.beforeProcess , it is called for every item that is read in ItemReader.
Any idea, how to achive this ? Any other alternative to ItemProcessListener ?
Your best choice to be sure method is called once is to use a StepExecutionListener and bind this listener to step where you use your ItemProcessor.
Else, if you need to call just before ItemProcessor.process() add a ItemProcessListener and manage a flag in StepExecutionContext: if this flag is not setted (false) or absent call the method and set flag to true else do nothing.
But if you can be more precise about your use-case a better solution can be found.
Hope can help!

Resources