system-properties in JBoss AS7 - java

In the standlone.xml file in JBoss AS7, I have set the variable my.dir in system properties as
<system-properties>
<property name="my.dir" value="D:\\mylocation"
</system-properties>
Now I am trying to use this variable to specify the location of the keystore file in the standalone.xml in the following way
certificate-key-file="${my.dir}\cert\mycert.keystore"
However, while starting JBoss, I am getting IO exception as JBoss is not able to locate the path. Could you please let me know if I am doing anything wrong?

As far as I know the ssl element in the jboss web subsystem does not support system property substitution (yet). You have 3 choices:
Use an absolute path
Use a relative path from $JBOSS_AS7\bin location
Store the certificate in the default location where JBoss looks for them - ${user.home}/.keystore which is the operating system home directory the user running jboss.web.
See more details on jboss.web ssl configuration here.

Related

How to configure email properties in JBoss JBPM / WildFly?

I'm trying to configure the SMTP mail settings in JBPM Business Central + KIE Server (apps that run inside a WildFly server)
The documentations says that I should configure a JNDI resource OR place a file email.properties in the root of the classpath (info taken from here: https://access.redhat.com/documentation/en-us/red_hat_jboss_bpm_suite/6.4/html/user_guide/email_task)
I would prefer the second option, but I can't figure out where I should place that email.properties file. Looking around for a solution, I got into some complicated doc about creating a module with XML files and I don't know what.
Is there no easy way to place a file in the root of the WildFly classpath?
thanks!
Instead of a file in a classpath you could add the mail configuration by jboss-cli:
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=jbpm-mail-smtp/:add(host=smtp.gmail.com, port=465)
/subsystem=mail/mail-session=jbpm/:add(jndi-name=java:/jbpmMailSession, from=username#gmail.com)
/subsystem=mail/mail-session=jbpm/server=smtp/:add(outbound-socket-binding-ref=jbpm-mail-smtp, ssl=true, username=username#gmail.com, password=password)

Tomcat set application context using configuration (not war name)

My question is this - Say I have a war file called my-app-123.war. I want to deploy it on a Tomcat server (9.0.x), let it auto unpack.
The application would then be accessible by http://localhost:8080/my-app-123
Is there a way, without renaming the war file, to make the application accessible from http://localhost:8080/my-app?
I will preface this by saying I realize the easiest solution is to just name the war file. I'm curious if there is a way to do this in Tomcat configurations.
I did do this already (inside the host section of my server.xml file):
<Context path="/my-app" docBase="my-app-123"></Context>
But I read this online (https://tomcat.apache.org/tomcat-7.0-doc/config/context.html) in the path variable description:
Even when statically defining a Context in server.xml, this attribute must not be set unless either the docBase is not located under the Host's appBase or both deployOnStartup and autoDeploy are false. If this rule is not followed, double deployment is likely to result.
And I can access the app now at http://localhost:8080/my-app and http://localhost:8080/my-app-123, which isn't a real solution.
The following works for Tomcat deployments I have used - there are no double-deployment issues.
In the example I will use here, I have a simple "hello world" webapp in TomcatDemo-1.0-SNAPSHOT.war. It is deployed on Tomcat 9.0 in the standard location (webapps directory).
I want the application's context path to be /my-foo-app.
I use the following context entry in server.xml:
<Context path="/my-foo-app" docBase="TomcatDemo-1.0-SNAPSHOT.war"></Context>
I also use the following in server.xml:
<Host name="localhost"
appBase="webapps"
deployOnStartup="true"
deployIgnore="TomcatDemo-1.0-SNAPSHOT.war"
unpackWARs="true"
autoDeploy="false">
The important item here is deployIgnore. It is described here:
https://tomcat.apache.org/tomcat-9.0-doc/config/host.html#Automatic_Application_Deployment
When using automatic deployment, the docBase defined by an XML Context file should be outside of the appBase directory. If this is not the case, difficulties may be experienced deploying the web application or the application may be deployed twice. The deployIgnore attribute can be used to avoid this situation.
Alternatively, if you don't mind about automatic start-up deployments, you can set deployOnStartup="false" - in which case you don't need deployIgnore.
In these scenarios, the web app is available only here:
http://localhost:8080/my-foo-app/ <-- OK
Otherwise, as you note, with double-deployment the web app would also be available here (and you would see two exploded directories in webapps):
http://localhost:8080/TomcatDemo-1.0-SNAPSHOT/ <-- BAD!
Hope that helps.
Finally, it can get a little complicated, with all the various auto-deployment options. This page provides a set of summary tables and explanations:
https://tomcat.apache.org/tomcat-9.0-doc/config/automatic-deployment.html

How to set environment variables in JBoss

We are developing an application that is deployed in a JBoss.
we would like to define a properties files like this:
URL_DEVELOPMENT.properties = ...
URL_TEST.properties = ...
URL_PRODUCTION.properties = ...
and define an environment variable in the JBoss which contains the information about the execution context
for example --> ENVIRONMENT = DEVELOPMENT
Anyone knows:
How to set environment variables in JBoss.
How to get these variables from an applicacion deployed in JBoss in runtime execution?
The easiest and most straight forward way is to log into jboss web admin:
www.yoururl:9990
Then under configuration, look for system property.
At runtime, it is very easy: System.getProperty(yourPropertyKey) and the good thing is that a change in any of these properties is reflected immediately at runtime.
The other scenario is to open up standalone.xml
<server ...>
<system-properties>
<property name="eclipselink.archive.factory" value="org.jipijapa.eclipselink.JBossArchiveFactoryImpl"/>
</system-properties>
</server>
The other option is to read on jboss cli and configure system properties from there. (Only useful if you want to work with remote jboss and you cannot ssh into the server, and you cannot access the web admin)

JAAS Realm load internal config file

I have implement a simple JAAS module with realm configuration on Tomcat 7. It works properly when specifying the jaas.conf file in the catalina.sh like so
JAVA_OPTS=$JAVA_OPTS "-Djava.security.auth.login.config==$CATALINA_BASE/conf/jaas.config"
However, I wanted to simplify my application by adding this config file internally to the web application. Documentation states that you can use the configFile param
"The name of a JAAS configuration file to use with this Realm. It will be searched for using ClassLoader#getResource(String) so it is possible for the configuration to be bundled within a web application. If not specified, the default JVM global JAAS configuration will be used."
My context.xml in my web app:
<Realm appName="AppLogin" className="org.apache.catalina.realm.JAASRealm" configFile="WEB-INF/jaas.config" ...../>
The config file is located /WEB-INF/jaas.config
Why is my jaas config file not being loaded?
http://tomcat.apache.org/tomcat-7.0-doc/config/realm.html#JAAS_Realm_-_org.apache.catalina.realm.JAASRealm
It will be searched for using ClassLoader#getResource(String)
Then you need to put JAAS configuration file in the classpath: WEB-INF/classes or WEB-INF/lib but not WEB-INF directly.
And specify only the file name as it is written in the documentation:
configFile - The name of a JAAS configuration file to use with this
Realm.
It appears that configFile attribute is not implemented in Tomcat 7 even though the documentation states that it is. I examined the source for org.apache.catalina.realm.JAASRealm and there is no method for setConfigFile.
When you use a attribute that has no associated method implemented, Tomcat reports a message like the following:
WARNING: [SetPropertiesRule]{Context/Realm} Setting property
'configFile' to 'jaas.config' did not find a matching property.
That message indicates that configFile attribute is not recognized and therefore JAASRealm will not know where to look for jaas.config.
So it appears that for Tomcat 7, you can only specify jaas.config with -Djava.security.auth.login.config=$CATALINA_BASE/conf/jaas.config
Tomcat 8 source has method for setConfigFile in org.apache.catalina.realm.JAASRealm. I have not tried Tomcat 8.

SAP+Java : java.lang.NoClassDefFoundError: com.sap.conn.rfc.driver.CpicDriver

I have developed a java web application integrating with SAP. I have developed it with Linux Server and Tomcat 7.0. I have added sapjco3.jar and libsapjco3.so in WEB-INF/lib folder. It is working fine local server. But when deploying WAR file in remote server the following error is generating.
java.lang.NoClassDefFoundError: com.sap.conn.rfc.driver.CpicDriver
at com.sap.conn.rfc.engine.DefaultRfcRuntime.createChannel(DefaultRfcRuntime.java:52)
at com.sap.conn.rfc.engine.RfcIoOpenCntl.open_channel(RfcIoOpenCntl.java:1260)
at com.sap.conn.rfc.engine.RfcIoControl.ab_rfcopen(RfcIoControl.java:85)
at com.sap.conn.rfc.api.RfcApi.RfcOpen(RfcApi.java:83)
at com.sap.conn.jco.rt.MiddlewareJavaRfc$JavaRfcClient.connect(MiddlewareJavaRfc.java:1107)
at com.sap.conn.jco.rt.ClientConnection.connect(ClientConnection.java:659)
at com.sap.conn.jco.rt.PoolingFactory.init(PoolingFactory.java:103)
at com.sap.conn.jco.rt.ConnectionManager.createFactory(ConnectionManager.java:171)
at com.sap.conn.jco.rt.DefaultConnectionManager.createFactory(DefaultConnectionManager.java:44)
at com.sap.conn.jco.rt.ConnectionManager.getFactory(ConnectionManager.java:160)
at com.sap.conn.jco.rt.RfcDestination.initialize(RfcDestination.java:754)
at com.sap.conn.jco.rt.RfcDestination.ping(RfcDestination.java:964)
at com.my.ciry.sap.Connection.<init>(Connection.java:63)
The error is arising when ping the destination from Tomcat Server.
private JCoDestination dest;
public Connection(SapSystem system) {
dest = JCoDestinationManager.getDestination(SAP_SERVER);
dest.ping();
}
What's the cause of the problem.
SAP Servers are generally configured based on
System ID , the Message Server and possible a Group Server along with an Instance Number.
You probably need to pass these parameters when instantiating your connection. It could be that on localhost, these are not needed/ignorable, but on production, it is required.
Try connecting to the server using SAP's tools and try to provide all the settings that you would otherwise provide.
If you post what settings you are using for your JCO, perhaps I can help more.
Ideally, you should keep libsapjco3.so file outside your web application. Place it in any arbitary location and add that folder path to LD_LIBRARY_PATH environment variable. sapjco.jar can be in your classpath.
If the tomcat cannot load the .so file using the environment variable, you can try using System.setProperty("java.library.path", "folder_path_of_.so_file");
OR try to supply this variable by editing tomcat configuration files.
Finally, ensure that folder_path_of_.so_file has needed privileges for tomcat user.
This will solve your problem.
......

Categories

Resources