EHCache Disable/Shutdown - java

Is there a way to disable ehache externally using a property file?
CacheManager.shutdown() doesnt seem to work?
Actually we have 2 app with the same source code i require ehcache in one and not the other.
one where i dont need cache is a webapp!
Unable to figure to out yet how to go about this?

Setting this System Property to true disables caching in ehcache. If disabled no elements will be added to a cache. i.e. puts are silently discarded.
-Dnet.sf.ehcache.disabled=true

Related

Totally disabling java net ssl debug logging

I've found tons of documentation on how to enable javax.net.debug for SSL, TLS and similar, but even in the reference documentation I've not found how to totally disable it overriding programmatically a previous setting.
My exact problem is that in a Tomcat instance another application performs the following instruction:
System.setProperty("javax.net.debug","all");
and this causes the catalina.out file to rise his dimension quickly and unwanted.
I've already tried to overwrite it from my Java code with the same instruciton, with "none", "off" and "false" values but with no result, still logging a plenty of TLS stuff.
For example in my application I've added this instruction:
System.setProperty("javax.net.debug","none");
but still I'm getting full log.
The problem is that the tomcat application is overwriting whatever value you give from command line, and if there is no way to control what this code is doing, you can't really overwrite it from commandline arguments. While a security manager would be able to prevent setting a property, it can only do so by throwing an exception, which is probably going to cause more issues than it solves.
In this case, your only option is to set the value yourself from code, after the other code sets it.
In case of the javax.net.debug, the option needs to be set to it's final value before the static static initializer of sun.* Debug class runs, which is before the first message would appear. This can be disabled by any value that isn't used as some option (empty string, or none should disable it). If it's set later, it will have no effect with no way to turn it off after the fact (with the exception of doing some bad reflection hacks to access internals of that class anyway, that are only possible with java 8 and earlier)
If there are some VM argument that enable SSL logging try to remove them, in addition you can check eclipse.ini file to see if those arguments are declared there or not.
You can disable it by removing the following from the run configuration in your IDE:
-Djavax.net.debug=all
To anyone who may need this, I set the value to an empty string: System.setProperty("javax.net.debug","");
It worked for me.

Intershop code deploy workflow

I'm not sure if this is a valid question, but what is the least amount of code change before you need to stop the application server, run gradlew publish, gradlew deployCartridges and then start up the application server?
It's not clear to me to what extent can I make code changes.
What would be the preferred development work flow?
First, make sure you have intershop configured correctly for code reloading. You should have these settings set:
# switch auto reload on for all Intershop artifacts
intershop.extensions.CheckSource=true
intershop.queries.CheckSource=true
intershop.pipelines.CheckSource=true
intershop.pagelets.CheckSource=true
intershop.webforms.CheckSource=true
intershop.template.CheckSource=true
intershop.template.CheckSourceModified=true
intershop.template.CompileOnStartup=false
intershop.template.PrintTemplateName=true
intershop.template.PrintTemplateMarker=true
intershop.template.isfilebundle.CheckSource=true
intershop.localization.CheckContent=true
#let intershop run on all cpu cores
intershop.cpu.id=
#dont let session timeout so quickly
intershop.session.TimeOut=60
# switch all preload functionality off
intershop.pipelines.PreloadFromCartridges=
intershop.pipelines.PreloadFromSites=
intershop.pipelets.PreloadFromCartridges=
intershop.webforms.Preload=false
intershop.queries.Preload=false
# Monitor the urlrewrite.properties files for modifications
# and refresh when needed.
intershop.urlrewrite.CheckSource=true
# The time interval in seconds, after which a lookup should be performed
# if CheckSource is "true". 0 means every time (not recommended).
intershop.urlrewrite.CheckSourceInterval=5
These setting are usually in the development.properties file under eserver/server/share/system/config/cluster.
Also make sure that your environment is set to development. The file eserver/server/share/system/config/cluster/environment.properties should have this configured : environment=development. This setting makes intershop load your settings in the development.properties file.
Disable the page cache (in SMC), including the SLDSystem (urlrewriting is cached here). I have fallen into this trap more than I like to admit.
With this setup, you can just edit/save and refresh the browser for isml/pipelines/pagelet,query file,webforms,filebundles,urlrewriting and localization labels. Everything that is not java basically. When it comes to java things get a bit complicated.
For a simple pipelet you can run gradlew publish and it should reload. However, it won't reload other classes that it depends on that has been modified. Sometimes it doesn't reload at all, I have to admit, I don't know why this happens. For new pipelets and changes in the component framework, u always need to compile/restart intershop.
Like Rainer mentioned Jrebel can reload your plain java classes and I can also highly recommend it. However, you would need a license for this.
With code change you mean Java code?
In Development mode you can enable the reloading of pipelet code. There is a special classloader from Intershop for this.
You need to restart the server if you modify any other classes unless you use JRebel, or some other classloader which can detect code modifications.
You of ofcourse have to compile the code with "gradlew publish" for all this.
You also need to restart the server if you made changes in the configuration framework.
While developing you don't need "gradlew deployCartridges" for code changes since the server is reading code from your project directory.

Reinitialization of spring bean during runtime?

I have a problem ."This is just a configuration which I would like to manage during runtime. I don't want to redeploy whole app to update configuration".I am reading some values from the property files.How can i acheive this?
There are lots of possible solutions, depending on the exact need (and this like possibility to reload these properties on demand etc.).
The simplest one seems to be this one:
Create a bean that internally has a cache defined (like Guava Cache)
Set certain TTL for the cache contents (this will cause your properties to be reloaded every TTL seconds)
Provide a way to populate the cache
Optionally provide a way to force refresh of cache contents
As for the last point I cannot give you a way to do this because I know nothing of your project, but there are at least few good options here depending on the project you are working on.
Assuming your file is not part of deployable (WAR/EAR/JAR), you can watch for directory changes and identify whether your file has changed (refer Can I watch for single file change with WatchService (not the whole directory)?). Once you notice the file has changed, you can execute your logic.

Java web app: Force browser to load static content (js, css, html) if deployed file changed

We're trying to force the client's browser to reload static files when they change. Currently, we have our build scripts automatically creating a new directory with the build timestamp and replace the content in the code to point to that directory.
However, I feel this is hardly an optimal solution. It forces the client browser to load every single file if a new build exists, even if only 1 file changed, and build time increases considerably by scanning every file and replace every static file reference.
I know we can also set the version when we declare files (something like < link src="blahblah.css?version=1.1" />), but this forces us to change all our code to include a version placeholder and still have our build scripts replacing it.
Is there a smarter way to do this? We're using Spring MVC. Is there any option in mvc:resources that I'm not aware of to do this without changing code? Or something on web.xml?
We're using tomcat. Is there a way to do this at server level? Would it help to use a cache like Varnish or something? Or these caches only allow to set expiry times and not check that the file changed? Bear in mind I'm not comfortable at all in server and cache configuration tasks.
I found out about this project https://code.google.com/p/modpagespeed/, but since it's far from my comfort zone, I'm struggling to understand capabilities and if this helps with what I want.
Anyone has any ideas?
Thanks
You can use version as a query parameter, e.g. /resources/foo.js?_version=1.0.0. If you are using Maven, it is not that hard to get version information from /META-INF/maven/{groupId}/{artifactId}/pom.properties. Of course this will force reload all scripts with every new version... but new versions are probably not deployed that often.
Then it is always a good practice to properly set HTTP caching headers. <mvc:resources> should correctly handle Last-Modified header for you. And you can set cache-period to make browser check the for resource modifications more often.
Here is a working solution: CorrectBrowserCacheHandlerFilter.java
Basically, when your browser requests the static files, the server will redirect every requests to the same one but with a hash query parameter (?v=azErT for example) which depends on the content of the target static file.
Doing this, the browser will never cache the static files declared in your index.htmlfor example (because will always received a 302 Moved Temporarily), but will only cache the ones with the hash version (the server will answer 200 for them). So the browser cache will be used efficiently for those static files with hash version.
Disclaimer: I'm the author of CorrectBrowserCacheHandlerFilter.java.

modifying properties-service.xml

I have a question related to the properties-service.xml. There is a value inside this file that needs to be updated every once in a while programmatically. So I have the following questions about this operation which I wasn't able to find some details about them:
Is there a way to update properties-service.xml programatically other than parsing it and changing the value? If parsing is the only way, is there an available method of retrieving the location of the used properties file?
Can we reload the properties-service.xml after the update without restarting jboss or do I need to set the property manually?
Any help is appreciated.
Thanks,
Sami
To get location of the properties file - acquire System property "jboss.server.home.dir" and suffix "/deploy/properties-service.xml" to it.
Once you save your changes to properties files, JBoss will hot-deploy it as it scans for changes every 5 seconds. If it doesn't hot deploy check value of attribute "ScanEnabled" in /conf/jboss-service.xml to confirm that hot deploy is enabled

Categories