RAP application with entrypoint path defined to "/" is not working on Tomcat7 - tomcat7

My RAP application has entrypoint defined following
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.rap.ui.entrypoint">
<entrypoint
brandingId="com.ibm.kc.redirect.validator.rap.branding"
class="com.ibm.kc.redirect.validator.rap.app.ApplicationWorkbench"
id="entrypoint"
path="/">
</entrypoint>
</extension>
...
It works fine with IBM WAS Liberty but not on Tomcat7. Tomcat's context root is same as name of war in webapps. So when I access localhost:8080/kc-redirect-tester it should work.I defined entry point to "/" means servlet path after context root is only "/". I see lot of 404 where RWT resources going to localhost:8080/, like they had no idea of tomcat's context root.

In tomcat7, http://127.0.0.1:8080/{appname}/
The appname must be the name of the war (eg. appname.war) and not the value of in your web.xml servlet definition file. then add the context "/", => http://127.0.0.1:8080/{appname}/ (don't forget the last "/")

Related

Change mongo dbname through build script

What do I want:
I want to set up an automated deployment pipeline - my plan is as follows:
I create two .war files, let's call them prod.war and test.war, using a gradle build script, and deploy them to my tomcat server.
My problem:
The prod.war needs to access the production database (mongoprod), and the test.war to the test database (mongotest).
My attempt:
I thought I could use Spring profiles and simply...
...change a line in my application-context.xml from:
<mongo:db-factory id="mongoDbFactory" dbname="mongoprod"/>
to:
<mongo:db-factory id="mongoDbFactory" dbname="${mongo.db.name}"/>
...create two files, in the same folder (<filename>:<content>):
application-production.properties:mongo.db.name=mongotest
application-test.properties:mongo.db.name=mongoprod
...execute some gradle build script with an argument that can change the profile to production or test and then use the corresponding .property file to insert the desired mongo dbname...but that's where I ran out of luck!
I tried to add this to my build.gradle file:
bootRun { args = ["--spring.profiles.active=" + profiles] }
and then run it with $ ./gradlew bootRun -Ptest
but I just get the error:
Main class name has not been configured and it could not be resolved
and besides that I haven't used bootRun before, only a war task so far to create my .war files:
war {
archiveName = 'application.war'
dependsOn 'lessc', 'webpack'
from "$buildDir/webapp"
exclude 'WEB-INF/js/main.js'
rename 'main\\.min\\.js', 'main.js'
}
Does anyone know how I can get my problem to work or could give me useful information on this?
You need to provide a main class name to be run by the bootRun task, for example as follows:
springBoot {
mainClassName = 'org.baeldung.DemoApplication'
}
You can read more about it in thos tutorial
Update:
configuration for application plugin could be done as follows
application {
mainClassName = 'org.gradle.sample.Main'
}
As it's said in the plugin docs
I found out that for my case it turned out to be much easier (and I think better) to decide during runtime wether a test or a production DB should be used and I solved it the following way:
In my application-context.xml I created two beans instead of one, one for each DB (I had to nest them below a "root"-beans, otherwise I got errors during building):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.5.xsd">
<beans profile="prod">
<mongo:db-factory id="mongoDbFactory" dbname="mongoprod"/>
<mongo:mapping-converter id="mongoConverter" base-package="my.company.project">
<mongo:custom-converters base-package="my.company.project"/>
</mongo:mapping-converter>
<mongo:gridFsTemplate bucket="images" converter-ref="mongoConverter" db-factory-ref="mongoDbFactory"/>
</beans>
<beans profile="test">
<mongo:db-factory id="mongoDbFactory" dbname="mongotest"/>
<mongo:mapping-converter id="mongoConverter" base-package="my.company.project">
<mongo:custom-converters base-package="my.company.project"/>
</mongo:mapping-converter>
<mongo:gridFsTemplate bucket="images" converter-ref="mongoConverter" db-factory-ref="mongoDbFactory"/>
</beans>
</beans>
In order for the .war file creation to work properly I had to set enabled to true in my build.gradle file here:
war {
enabled = true //without this no .war file was created before - https://stackoverflow.com/a/52315049/4120196
dependsOn 'lessc', 'webpack'
from "$buildDir/webapp"
exclude 'WEB-INF/js/main.js'
rename 'main\\.min\\.js', 'main.js'
}
I then created a .war file, copied it and renamed it - so I had two: prod.war and test.war and put them into my Tomcat 8.5_Tomcat8.5.23\webapps folder (I'm working on Win10 in case this differs on other systems). Then I created two .xml files with the same name as the .war files where I defined the spring profile that decides which bean to take in Tomcat 8.5_Tomcat8.5.23\conf\Catalina\localhost:
prod.xml
<Context>
<Environment name="spring.profiles.active" value="prod" type="java.lang.String" override="false" />
</Context>
test.xml
<Context>
<Environment name="spring.profiles.active" value="test" type="java.lang.String" override="false" />
</Context>
I started up tomcat and finally everything worked as I wanted it to.
If you have any hints how my solution can be improved feel free to comment :)
I feel like my application-context.xml could be shortened somehow for example...

IBM Liberty Profile Context Root Not Found

I've deployed a spring application to IBM Liberty Profile. Both of the server and the application starts without problem, but when I would like to reach the application the browser says "Context Root Not Found"
I've configured the application in several ways in the server.xml
<application location="d:/Work/Installed Liberty Applications/OFRAdminEAR/OFRAdmin.ear"
name="OFRAdmin"
security-role="false"
id="OFRAdmin"
type="ear">
<classloader apiTypeVisibility="spec,ibm-api,api" privateLibraryRef="WebspherePlugins, OFRAdminsSharedLibrary"/>
</application>
<enterpriseApplication location="d:/Work/Installed Liberty Applications/OFRAdminEAR/OFRAdmin.ear"
id="OFRAdmin"
name="OFRAdmin"
security-role="false"
type="ear">
<classloader privateLibraryRef="WebspherePlugins, OFRAdminsSharedLibrary" />
</enterpriseApplication>
<webApplication location="d:/Work/Installed Liberty Applications/OFRAdminEAR/OFRAdmin.ear"
id="OFRAdmin"
name="OFRAdmin"
security-role="false"
type="war">
<classloader privateLibraryRef="WebspherePlugins, OFRAdminsSharedLibrary" />
</webApplication>
The application packed into an ear file, which contains a WAR file and META-INF folder with the application.xml. The application.xml looks like this.
<application-name>OFRAdmin</application-name>
<display-name>OFRAdmin</display-name>
<module>
<web>
<web-uri>OFRAdmin.war</web-uri>
<context-root>OFRAdmin</context-root>
</web>
</module>
</application>
What I missed? Where should I set the context root of the application? Can anybody help me?

Spring Boot logging : use of system variables in log4j2.xml

I am running spring boot application as jar.
java -Dlogs.location=<path/to/my/logs> -jar my-app.jar
or
java -Dlogs.location=<path/to/my/logs> -jar my-app.jar --logs.location=<path/to/my/logs>
Here is a sample log4j2.xml configuration file
<?xml version="1.0" encoding="UTF-8"?>
<Configuration >
<Properties>
<Property name="base.log.dir">${sys:logs.location}</Property>
</Properties>
....
</Configuration>
Spring boot app is creating ${sys:logs.location} folder instead of correctly resolving system properties from jvm args.
Same configuration file working fine with Spring application.
I am unable to make logs.location configurable with my custom log4j2.xml file. Any help or suggestion is appreciated.
Please refer this sample project on github
I am using log4j2-spring.xml to configure log4j2.
I have looked at the StackOverflow q's. This answer reads properties bundle. But I want to read sys properties
Define a property like
<Properties>
<Property name="filePathVar"> ${sys:filepath:-/logs/app.log} </Property>
</Properties>
and use filePathVar like "${filePathVar}" in your xml file
and refer this for runtime args - https://stackoverflow.com/a/37439625/5055762
Note - /logs/app.log will be the default value if none is passed as a runtime arg

How do I get the Tomcat 7 Embedded container to use another port?

I have Arquillian setup in Gradle to spin up a REST server and run some tests against a REST client. Everything works fine, except for the fact that the server hosting the CI already uses port 8080.
I have added the following settings to my build.gradle file
arquillian {
containers {
tomcat {
version = '7'
config = ['bindHttpPort': 18080]
type = 'embedded'
}
}
}
But it has no effect. How can I change the port used by the embedded tomcat 7 container?
EDIT
There is a workaround, which is to have the following in a file called arquillian.xml. Still, it would be nice to have the option of defining the port in the build.gradle file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="tomcat" default="true">
<configuration>
<!-- We need to change the port from the default of 8080 because 8080 is quite commonly not available -->
<property name="bindHttpPort">18080</property>
</configuration>
</container>
</arquillian>

jetty load multiple context

We have an maven+springMVC application that uses maven jetty plugin to start the app up when we do development. We use a jetty-env.xml file to set a context and JNDI config. The application will be part of a bigger portal.
We are using maven jetty plugin
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.0.v20101020</version>
with config
<webAppConfig>
<contextPath>/ASX/mainApp</contextPath>
<jettyEnvXml>src/main/resources/jetty-env.xml</jettyEnvXml>
</webAppConfig>
and use jetty-env.xml
<Configure id='jms-webapp-wac' class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/ASX/mainApp</Set>
...
...
</Configure>
Our dir structure is:
MainApp
/forms
page1.html
page2.html
etc...
/WEB-INF
web.xml
PortalApp
/BAL_S
/css
/images
/js
etc...
Now the PortalApp only has static files and is not really a web application i.e. it doesn't have web.xml
The application is dependent on javaScripts from the portal. The location of some of the javaScript are like:
<script src="/BAL_S/js/portal-jquery-lib.js"></script>
<script src="/BAL_S/js/libs/foundation.js"></script>
etc...
As you can see that the location starts with /BAL_S which we are finding tricky to get working as it's like referring to another webapp context. When we start the application with jetty we get javaScript errors because it cannot find /BAL_S
If we deploy our app in tomcat and configure it, as below, the application works fine without any javaScript errors.
<Context path="/" docBase="PortalApp"/>
So the question is how can I do the similar configuration in Jetty so when the application starts up it detects /BAL_S context?
I guess we need to have two contexts in Jetty. How do I configure that?
What is the webConfig for maven jetty plugin to refer to this config?
Hope someone can help. Example would be useful.
Thanks in advance.
GM
OK All I had to do was add to maven jetty plugin configuration, the following:
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<contextPath>/</contextPath>
<resourceBase>src/main/PortalApp/</resourceBase>
</contextHandler>
</contextHandlers>
So this configures context path '/' to 'src/main/PortalApp/' and now we are able to get to /BAL_S in the tag.

Resources