Wildfly Clustering Does not work with web-fragment.xml - java

I am trying to setup a clustering environment with Wildfly-10.
I have a web-fragment.xml for general purpose configuration and a web.xml for project specific configuration. With these configurations, clustering does not work.
But if I delete web-fragment.xml and move its content to web.xml, everything works fine.
I wonder what is the reason of this. Any idea?

Placing </distributable> tag to both web.xml and web-fragment.xml has solved the problem.

Related

Want to change the context path in Spring boot application in an external Tomact server version 9

I want to deploy a Spring boot application in an external Tomcat server version 9. I am able to deploy it and working the endpoints also. But properties I have set in application.properties file those are not working. Like server.servlet.context-path=/myapp is is not working instead the context path which I am getting is http://localhost:8080/myapp-0.0.1-SNAPSHOT/api/ping.
I am using 2.3.10.RELEASE and Java 1.8 and Tomcat version 9.0.46 Can anyone please help me out with this.
But everything is perfectly working on embedded tomcat. Thanks in advance and any suggestion, comment is highly appreciated.
Can anyone please help me with how I can do this - My war file name would be myapp-0.1.war but the context path of the application would be like this localhost:8080/myapp/api/ping
Use finalName property in your build file (pom.xml for maven)
<finalName>myapp</finalName>
When you run a Spring Boot application in an external servlet container, the server.* properties do not apply.
If you are willing to change the naming convention you can drop a WAR file named myapp##0.1.war in the $CATALINA_BASE/webapps directory and benefit from parallel deployment (cf. parallel deployment).
If you want to stick to your naming convention, you can create a folder for your WAR files (e.g. $CATALINA_BASE/webapps-available) and create a deployment descriptor $CATALINA_BASE/conf/<engine_name>/<host_name>/<context_path>.xml (in your case probably $CATALINA_BASE/conf/Catalina/localhost/myapp.xml) with the following content:
<Context docBase="${catalina.base}/webapps-available/myapp-0.1.war" />

Resource reference with name 'jdbc/devl' not found in ibm-web-bnd.xml

RAD 7, WebSphere 7.
ibm-web-bnd.xml:
<resource-ref name="jdbc/devl" binding-name="jdbc/devl" />
web.xml:
<resource-ref>
<res-ref-name>jdbc/devl</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
<mapped-name>jdbc/devl</mapped-name>
</resource-ref>
This conforms to the examples I see on the internet. This comes up because I am converting this app to servlet 2.5. As I understand it, the res-ref-name in web.xml should match the name attribute in resource-ref. The binding-name then matches the datasource defined in the admin console. To make it simple, I made them all match.
Is there another setting somewhere? Because this produces the error described in the title of the question.
I have the same issue many times. It disappeared when I closed the eclipse and when I reopened it I made a "project -> clean". I hope it works for the next person who has this error.
Also make sure you have the web.xml header updated to 2.5 or higher (3.0).This is related to the facets of the project, make sure they are with the same version
if it doesn't let you change it, you should change it in this file : "org.eclipse.wst.common.project.facet.core.xml"
If the error continues, you should generate the binding file again. Make sure you have the correct server settings in the facets of the project
To generate the file you must do it from java EE Tools.
Remember that ibm-web-bnd.xml and web.xml must be in the same directory
Build, and clean project.
If you are using Eclipse, try to update the web module version in project.facet.core.xml. It should be in synch with the web.xml web-app version.

JSF 2.0 app under Tomcat 6: "No Factories configured."

I am trying to run a JSF 2.0 webapp using Apache MyFaces 2.1.7 on a Tomcat 6 webserver. The App uses Tomahawk 1.1.11 and expression language 2.2 (el-impl-2.2.jar). For that purpose I've put the myfaces-api and myfaces-impl into Tomcats lib folder and exchanged Tomcats el-api.jar for the 2.2 variant.
When I call the first page of the app I always get the error:
java.lang.IllegalStateException: No Factories configured for this Application. This
happens if the faces-initialization does not work at all - make sure that you properly
include all configuration settings necessary for a basic faces application and that all
the necessary libs are included. Also check the logging output of your web application
and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use
some special web-containers which do not support registering context-listeners via TLD
files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
javax.faces.FactoryFinder._getFactory(FactoryFinder.java:286)
javax.faces.FactoryFinder.getFactory(FactoryFinder.java:206)
javax.faces.webapp.FacesServlet.init(FacesServlet.java:116)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:679)
I definitely have the xml snippet mentioned in my web.xml. I tried to debug into the code and found that registeredFactoryNames on line 267 of javax.faces.FactoryFinder is empty which causes the error. I however do not understand why this is the case. What should be in there and how do I get it there?
The funny thing is that the webapp runs perfectly using embedded jetty 8. So it must be some dependency issue.
Hope someone with more insight into all of this can help me here.
Ok
I found the problem. The error results from having the myfaces-api.jar twice on your classpath. So for me the problem was I placed the myfaces-api.jar in the tomcat lib folder and in the WEB-INF/lib folder of the webapp.
While using an embedded tomcat with maven I had the myfaces-api.jar in the dependencies of the whole application and in the dependencies of the tomcat6-maven-plugin with scope compile both. I changed the scope from compile to provided in the global dependencies section and it worked.
I think it could be solved just adding an empty faces-config.xml file under /WEB-INF/ folder, to indicate the application uses JSF and MyFaces continue the initialization step. See the class org.apache.myfaces.ee6.MyFacesContainerInitializer for details.

Why does weblogic not use my deployment plan?

I am having some trouble trying to adjust the deployment settings of our application in weblogic. I feel what I'm trying to do ought to be quite simple, but it's not working as expected.
I am just trying to override the context-root in weblogic.xml and the JNDI name for the data source, so these can both be configured at deployment time.
I have removed the application.xml from the ear file, so that shouldn't be affecting the overrides.
What I have so far:
weblogic.xml:
<context-root>mosaic</context-root>
<resource-description>
<res-ref-name>jdbc/LogicalDS</res-ref-name>
<jndi-name>LogicalDS</jndi-name>
</resource-description>
web.xml
<resource-ref>
<description>A logical reference to the datasource - mapped in deployment plan</description>
<res-ref-name>jdbc/LogicalDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
plan.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:deployment-plan xmlns:wls="http://xmlns.oracle.com/weblogic/deployment-plan" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd" global-variables="true">
<!--weblogic-version:10.3.5-->
<wls:application-name>mosaic.ear</wls:application-name>
<wls:variable-definition>
<wls:variable>
<wls:name>datasource_name</wls:name>
<wls:value xsi:nil="true"></wls:value>
<wls:description>The name of the datasource to map to the mosaic application</wls:description>
</wls:variable>
<wls:variable>
<wls:name>new_context_root</wls:name>
<wls:value xsi:nil="true"></wls:value>
<wls:description>URL to deploy Mosaic at</wls:description>
</wls:variable>
</wls:variable-definition>
<wls:module-override>
<wls:module-name>mosaic.war</wls:module-name>
<wls:module-type>war</wls:module-type>
<wls:module-descriptor>
<wls:root-element>weblogic-web-app</wls:root-element>
<wls:uri>WEB-INF/weblogic.xml</wls:uri>
<wls:variable-assignment>
<wls:name>new_context_root</wls:name>
<wls:xpath>/weblogic-web-app/context-root</wls:xpath>
<wls:operation>replace</wls:operation>
</wls:variable-assignment>
<wls:variable-assignment>
<wls:description>Data source for mosaic application</wls:description>
<wls:name>datasource_name</wls:name>
<wls:xpath>/weblogic-web-app/resource-env-description/resource-env-ref-name</wls:xpath>
<wls:operation>replace</wls:operation>
</wls:variable-assignment>
<wls:variable-assignment>
<wls:name>datasource_name</wls:name>
<wls:xpath>/weblogic-web-app/resource-description/[res-ref-name="jdbc/LogicalDS"]/jndi-name</wls:xpath>
<wls:operation>replace</wls:operation>
</wls:variable-assignment>
</wls:module-descriptor>
</wls:module-override>
</wls:deployment-plan>
Nothing happens when I use the deployment plan, and none of the variables appear under the Deployment Plan configuration screens in the admin console. From what I understand, I should at least be asked for these variables, since I have specified that they are null in the deployment plan.
When I use WLST to browse the tree, I find that the runtime configuration just stays as the values in the deployment descriptors.
I have verified the deployment plan is being used in the general tab of the admin console.
Can anyone help me find out what I am doing wrong here ?
I see that you have "datasource_name" variable replacement twice. Is that intended? Your xpath appears to be incorrect:
resource-description/[res-ref-name=
etc.
Should it be:
resource-description[res-ref-name=
etc.
My suggestion is to change one thing at at time, for example, the web app context first, and test. The web app context can be also set in the admin console, so you should see the value there.
There are few good articles about deployment plan:
https://blogs.oracle.com/jamesbayer/entry/11gr1_update_and_a_deployment
http://m-button.blogspot.com/2008/08/how-to-use-deployment-plan.html
A good resource mapping doc:
http://docs.oracle.com/cd/E15523_01/web.1111/e13737/packagedjdbc.htm
(look for the diagram near the bottom).
Is your variable a "replace" or "define"?

Extending spring based app

I have a spring-based Web Service. I now want to build a sort of plugin for it that extends it with beans. What I have now in web.xml is:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/*-configuration.xml</param-value>
</context-param>
My core app has main-configuration.xml which declares its beans. My plugin app has plugin-configuration.xml which declares additional beans. Now when I deploy, my build deploys plugin.jar into /WEB-INF/lib/ and copies plugin-configuration.xml into /WEB-INF/classes/ all under main.war.
This is all fine (although I think there could be a better solution), but when I develop the plugin, I don't want to have two projects in Eclipse with dependencies. I wish to have main.jar that I include as a library. However, web.xml from main.jar isn't automatically discovered. How can I do this? Bean injection? Bean discovery of some sort? Something else?
Note: I expect to have multiple different plugins in production, but development of each of them will be against pure main.jar
Thank you.
I think there is a simpler approach:
In your host application (the webapp) define something like the following contextConfigLocation parameter:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/META-INF/foo/*-configuration.xml</param-value>
</context-param>
The crucial parts are classpath*:as it results in scanning the entire classpath for config files matching the following pattern. If you only use classpath: the lookup will stop at the first file found. It also won't traverse JARs if not starred correctly.
The second crucial part is having at least one non-wildcarded basepath for the lookup to work. This is due to Classloader traits that only reliably returns all resources if they contain a base path (see the Javadoc on PathMatchingResourcePatternResolver for details).
What you now have to do with your plugin projects is place your plugin-configuration.xml in /META-INF/foo/, package that as JAR and place it into your classpath (in case you build with Maven just add the dependency).
On application start Spring will now also pickup all config files from your plugins and build the ÀpplicationContext` from em.
You also might wanna checkout another post I did on application modularity with Spring: How do you make a multi-module spring configuration?
Instead of /WEB-INF/classes/*-configuration.xml, try classpath:*-configuration.xml
You can also list configuration files, each on a new line.
You will have to make sure that main.jar ends up in WEB-INF/lib, if you're not using maven you can do this in eclipse by marking you webapp as dependent on the project that creates the main.jar, via the project properties.

Categories