Multiple JBoss Web Application Deployment Descriptor with same resources - java

I have an ear including several war deployed on jboss as 7.1.1.
Each war have a custom JBoss Web Application Deployment Descriptor (jboss-web.xml) declaring the context-root and several jndi datasources all shared between the different web-apps.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>${app.name}</context-root>
<resource-ref>
<res-ref-name>${datasource}</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/TenantDS</jndi-name>
</resource-ref>
<resource-ref>
<res-ref-name>${shared.datasource}</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/CustomerDS</jndi-name>
</resource-ref>
[...]
</jboss-web>
If I add another war with a jboss-web.xml file declaring only the first datasource (because it's the only one used by this war) then none of remaining war is able to reach the missing datasource anymore.
How a webapp specific deployment descriptor can have such a behavior ? And so, what is wrong in this config ? where should the datasource be declared ?

Do you have declared datasource in web.xml? You have to have it in jboss-web.xml and web.xml in each war application.

Related

JBoss EAP 6.2: Exchange auth-method of war-file

I have one application (packaged as war) for two customers running on JBoss EAP 6.2. One of them uses Basic JBoss Authentication, the other one Keycloak authentication provider.
Both war files are exactly the same with one difference: The WEB-INF/web.xml contains
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>ApplicationRealm</realm-name>
</login-config>
respectively
<login-config>
<auth-method>keycloak</auth-method>
<realm-name>application</realm-name>
</login-config>
I would like to prevent to build two different war files (because web.xml is inside of the war file) so I wondered how I can configure these lines in the JBoss configuration instead of in web.xml.
You can define your login-config as below:
<login-config>
<auth-method>${authentication.method}</auth-method>
<realm-name>${authentication.realm}</realm-name>
</login-config>
And then pass those parameters as system properties when application server starts:
-Dauthentication.method=BASIC -Dauthentication.realm=ApplicationRealm
But you should remember that by default WildFly/JBoss will not replace variables in deployment descriptors. You should explicitly enable this option in your server configurations under ee subsystem. In WildFly 13.0.0.Final it's like this:
<subsystem xmlns="urn:jboss:domain:ee:4.0">
<spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
<!-- remaining of the configurations -->
</subsystem>

JNDI DataSource: migrating from Weblogic to Jboss 7

I migrate my Weblogic application to JBoss 7 and I need that my migration code could be runnable on these both servers. JNDI name of WebLogic datasource is :
jdbc/powds
JNDI name of Jboss datasource is :
java:/powds
I've already known that JNDI syntax in JBOSS 7 is another and starts with the prefix "java:". In WebLogic application I use JNDI name in different files like web.xml and persistance.xml.
In code I use :
static final String dataSourceName = "jdbc/powds";
I read this article JNDI path Tomcat vs. Jboss and trying to configure my xmls descriptors files.
So finnaly I have error Required services that are not installed:" => ["jboss.naming.context.java.jdbc.powds"].
How I can avoid this error? How I can configure persistance.xml file to use different JNDI names depends on running the application server.
my web.xml file is:
<resource-ref>
<res-ref-name>jdbc/powds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
my jboss-web.xml file is:
<resource-ref>
<res-ref-name>jdbc/powds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/powds</jndi-name>
</resource-ref>
my weblogic.xml file is:
<resource-description>
<res-ref-name>jdbc/powds</res-ref-name>
<jndi-name>jdbc/powds</jndi-name>
</resource-description>
my weblogic.xml file is:
<resource-description>
<res-ref-name>jdbc/powds</res-ref-name>
<jndi-name>jdbc/powds</jndi-name>
</resource-description>
my persistance.xml file is:
<persistence-unit name="powpu" transaction-type="JTA" >
<jta-data-source>jdbc/powds</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
</persistence-unit>

Tomcat: context.xml and web.xml configs for jndi resource

I have been going over almost all the web.xml/context.xml related questions over the web but nowhere did i get a clear enough answer to my following question.
This says that the resource-ref tag in web.xml is equivalent to Resource tag in context.xml.
This says that resource-ref tag in web.xml looks up the Resource tag in context.xml. Now these two sound confusing specifically because both the links I have referred to are Tomcat doc links and still have seemingly contradictory statements. Any clarifications would be extremely helpful.
The "Resource" tag defines the resource and can be placed in a number of xml files that largely depend upon the deployment preferences. To get started I'd place a context.xml in the META-INF folder in the web app. This directory is at the same level in the web app as the WEB-INF folder an example being:-
META-INF/context.xml
<Context>
<Resource name="jdbc/TestDB" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/testdb"
username="dbuser"
password="dbpassword"
maxTotal="20" maxIdle="10" maxWaitMillis="-1"/>
</Context>
The above makes the resource available.
The resource-ref tag is used to refer to the resource to make it avaiable to your app. This can go in the web.xml file.
WEB-INF/web.xml
<web-app>
<!--- snipped -->
<resource-ref>
<description>Test DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Both of these can be configured in other ways. I usually go with something like this then dabble.

How to use custom module.xml and deploy after custom module of JBOSS EAP6.4 with Spring Boot Application

We are using artesia 3rd party product for our project and it is deployed in JBOSS EAP6.4, I want to use spring boot in our project and when I write sample REST webservices I am able to access the REST web service via URL.
As per the documentation of our product if we need to customize the project we need to write our custom war by specifying below two JBOSS files inside META-INF folder
jboss-all.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss umlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="artesia.ear" />
</jboss-deployment-dependencies>
</jboss>
so our custom logic should begin after successful start of artesia.ear.
our jboss-deployment-structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<sub-deployment>
<dependencies>
<module name="deploy" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Above deploy module contains all jars necessary for the project to run.
When I follow the same and created the war without spring in it, it was successful and there are no issues, we are able to use to customize war.
Now I want to do the same in Spring-boot 1.4.1 application, where my spring boot app should start after artesia.ear starts successfully and apart from spring jars my spring-boot app should use jars from module.xml.
I have placed the above two xml's inside META-INF of spring boot application but it is failing when deployed in JBOSS EAP6.4
Below is the error that I get
jboss-server.log
What I need to do to use same for my spring-boot app
EDIT 1:
I tried by placing both jboss files under WEB-INF folder of spring-boot application but still the facing the same issue
We need to make sure that META-INF and WEB-INF folders are lying side by side instead of keeping META-INF folder inside classes folder of WEB-INF which is where default spring-boot META-INF folder resides.

jboss 6.4 ignoring webapp directory structure

we are moving from jboss 5.1 to jboss 6.4 and i have below entries in my xxx.ear/META-INF/application.xml. it seems like jboss 6.4 is not able to identify webapp but when I change this to webapp.war then it is deployed, due to this I need to rename my webapp folder to webapp.war.
With jboss 5.1 it is working fine but jboss 6.4 needs this change, is their any way I can suppress this?
Application scripts needs update to rename webapp to webapp.war every where and I want to avoid it.
Thanks in advance.
<?xml version='1.0' encoding='UTF-8'?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>Web App</display-name>
<module>
<web>
<web-uri>webapp</web-uri>
<context-root>/app</context-root>
</web>
</module>
</application>

Categories

Resources