Custom configuration for JBoss applications? - java

I've built a simple alert monitor to display the health of various applications. This is configured by XML, as each monitor instance needs to show different metrics. An example configuration may be:
<machine>
<monitors>
<check type="connectivity" name="Production Server">
<property key="host" value="ops01.corp" />
<alarm />
</check>
</monitors>
</machine>
Currently, I'm storing this in the root of the C:\ drive of the server. What would be nice is if I could put it in the deploy directory of the JBoss server, and could somehow get a reference to it. Is this possible? I looked at MBeans but it didn't seem to support complex XML structures.
Robert

Try JOPR - http://www.jboss.org/jopr .
For custom metrics, you can write your own plug-in.

You can get an input stream for any file in the classpath by using the ClassLoader#getResourceAsStream(String name) method. Just pass the location of the file relative to the classpath.

Related

how to add a parameter to spring project before <projectname>/login and after <localhost>:<portnumber> without hardcode?

I'm working on a Spring MVC project. When I run the application the URL is:
http://localhost:8080/insureYou/login
but I want:
http://localhost:8080/contextroot/insureYou/login
Is there any way of doing it without hardcoding?
In a spring-boot project you can set the context-root by specifying the following property in the application.properties file:
server.servlet.context-path=/yourcontextroot
Without spring-boot, it depends on the webserver and Tomcat offers a number of options.
I would personally opt for a META-INF/context.xml file in your war file containing the necessary information but you can also include the information in the server.xml file or in a ROOT.xml file.
See the following links for further guidance:
How to set the context path of a web application in Tomcat 7.0
https://tomcat.apache.org/tomcat-8.0-doc/config/context.html
https://www.baeldung.com/tomcat-root-application
This type of deployment however sometimes is handled separately, through an Apache server reverse-proxy or through URL rewriting.
I recommend you ascertain whether this type of need is already taken care of by your company's deployment procedures, as you may not need to deal with it at all.

How to access configurations specified in XML of a jetty server from code

I've a jetty Server, what I want to configure for HTTPS traffic, I could do this, just simply modified some XML, and ini files (since this IoC is the preferred way), however I would like to access to some of these things which were configured in the xml from other classes, this is in the xml:
<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
<Set name="KeyStoreType">PKCS12</Set>
<Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.keystore" default="etc/keystore"/></Set>
<Set name="KeyStorePassword"><Property name="jetty.keystore.password" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
...
What I want is to call the sslContextFactory.getKeyStorePath() function somewhere in my codebase. But where is this sslContextFactory instance, where can I find it, how can I have a reference to it?
I am not entirely clear on what you are asking, but I am going to take a stab at it anyway. It sounds like you are familiar with running Jetty as a distribution and editing Jetty XML and ini files but now want to use some of the Jetty functionality as part of your embedded code?
For SSLContextFactory specifically, the class is included as part of the jetty-util jar file that comes with the distribution. You could also download that jar file by itself on Maven Central.
The official documentation for Jetty includes several examples of embedded Jetty functionality. This page may help you, specifically the example on Multiple Connectors, which uses SSL.
In fact it is not likely to be able to access the jetty standalone server's SSLContextFactory. Jetty by definition can host multiple applications at the same time, and acts like a container for those java web applications.
One option may be to use the embedded jetty server (a solution here), where you can start the jetty server within a java application (e.g. a jar package) and hold the references to your SSLContextFactory instance so that you can reload it whenever you like.
Another option may be using the maven jetty runner, again from another customized application, controlling the SslContextFactory yourself. This I cannot confirm at the moment, bu will update you as soon as I try it.

Coherence config default override path

I've already spent more than 2 days trying to make this work without any result. The server is WebLogic 12c with embedded Coherence server. It is important to mention that I do not run Coherence in standalone mode, instead it starts automatically alongside the application server that has access to Coherence via JNDI context. I am trying to implement POF serialization approach using PortableObject interface to serialize certain objects I save in Coherence. I've also created the corresponding pof-config.xml registering the objects I'm planning to serialize. The only problem is: How do I add the override to the coherence class path?
According to http://docs.oracle.com/cd/E24290_01/coh.371/e22837/gs_config.htm#COHDG5014 I can use the following system property:
java -Dtangosol.pof.config=MyPOF.xml -cp COHERENCE_HOME;COHERENCE_HOME\lib\coherence.jar com.tangosol.net.DefaultCacheServer
The only problem here is that I have no idea which sh/cmd file to edit, since all edits I made to the files in Oracle_Home\coherence\bin\ had no effect.
Also the same article says that there is a way to confirm the pof-config override:
The output for a Coherence node indicates the location and name of the POF configuration deployment descriptors that are loaded at startup. The configuration messages are among the messages that display after the Coherence copyright text is emitted and are associated with the cache service that is configured to use POF. The output is especially helpful when developing and testing Coherence applications and solutions.
Loading POF configuration from resource "file:/D:/coherence/my-pof-config.xml"
But I couldn't find any of the mentioned lines in the logs produced by the server instance.
Any ideas?
Instead of editing files inside of your Oracle_Home, try the following inside of the weblogic admin console:
Login to admin console
Servers link -> Server Name
Click the Server Start tab
Edit the Arguments: text box and add in -Dtangosol.pof.config=MyPOF.xml
You can also change the classpath, Class Path: box, here if you need to
Every time your server starts it should have that property. If you are not using the nodemanager to start your server, you should do the following instead. Keep in mind this will change the properties for every server in your weblogic domain:
Navigate to your <domain home>/bin directory
Edit startWebLogic.sh/cmd
Edit the JAVA_OPTIONS= line and add in -Dtangosol.pof.config=MyPOF.xml
You can also change the classpath CLASSPATH= here if you need to

JBoss ESB - How to have multiple input folders for file system provider

I m using Jboss ESB for my application. I want to implement ESB that listen the input folders which are dynamically created and when the file comes do the business logic. I have paced a problem at creating the dynamic input folders for esb .
I'm using following codes for configure the file system provider.
<fs-message-filter
directory="C:\Project_Root\Projects\FinESB\build\dirs\input"
input-suffix=".XML"
work-suffix=".esbWorking"
post-delete="true"
post-directory="C:\Project_Root\Projects\FinESB\build\dirs\output"
post-suffix=".ACK"
error-delete="false"
error-directory="C:\Project_Root\Projects\FinESB\build\dirs\error"
error-suffix=".IN_ERROR"
/>
if you have sn idea please reply me.
The directory attribute in the configuration file doesn't actually cause a directory to be created in your file system, so it's not "dynamic". JBoss ESB assumes that this directory has already been created. If you attempt to deploy an fs-provider whose directory doesn't exist, you will get a deployment error.
To configure your fs-provider with multiple directories, simply add another <fs-bus> to your provider's configuration.
<fs-provider name="MyFSProvider">
<fs-bus busid="fileChannel1">
<fs-message-filter directory="C:\fileIngestion\test1"
error-delete="false" error-directory="C:\fileIngestion\error"
input-suffix=".txt" post-delete="false" post-directory="C:\fileIngestion\complete" />
</fs-bus>
<fs-bus busid="fileChannel2">
<fs-message-filter directory="C:\fileIngestion\test2"
error-delete="false" error-directory="C:\fileIngestion\error"
input-suffix=".txt" post-delete="false" post-directory="C:\fileIngestion\complete" />
</fs-bus>
</fs-provider>

log4j configuration with Java Web Start

Our Java WebStart application does not include a log4j configuration file; it simply sets up some hardcoded loggers and appenders.
I would like individual clients to be able to drop a log4j.properties file in somewhere and set up their own custom logging in troubleshooting situations. I could bundle a log4j.properties file into one of the jars of our application somewhere and that would allow configuration, but then the configuration would be the same for each client instead of only affecting the client that I want to troubleshoot. Plus, I wouldn't be able to change settings on the fly.
Is there a way I can hijack the log4j initialization procedure to use a per-client configuration file?
The basic problem here, is that Java Web Start severely restricts the access to the machine.
You should be able to do this, if you are running a signed application AND the user allows you full access to the machine. If not, you cannot do this with log4j with the default mechanism.
You may want to write your own configurator which reads from the file system using the Java WebStart API an then feeds that to log4j, but it will require some elbow grease.
You could use the PersistenceService to store the log4j configuration on the local user's machine (works without signing), or at least store a flag on whether to load a special config or not at startup of your web start application.
There is also a FileOpenService with which the end-user could open a local log4j.xml file to re-configure the logging facility on the fly. That way, the user has the control over the configuration and he has the control when and where to apply it.
Your app code which uses the FileOpenService to get the stream to the log4j configuration file can then use the DOMConfigurator.configure(InputStream) to reconfigure log4j.

Categories

Resources