Is there an issue to set the app.servlet.version to 3.0 in the application.properties for grails 2.0?
I created a new app, added the line app.servlet.version=3.0 to the application.properties and executed grails war (even tried clean before). However the web.xml still starts with:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Iwould have expected to see 3.0. I also tried this Procedere with 2.4 and it is still 2.5. Is it the wrong place, which I am looking at?
It looks like, that you need to change the BuildConfig.groovy as well, in order to achieve servlet version 3.0 in your web.xml. Add the following line into a plain grails project and the web.xml will start with desired version 3.0:
grails.servlet.version = "3.0"
Related
I have this configuration in my application.yml
server:
contextPath: /appname
session:
timeout: 7200 # 2 hours in seconds
This works fine when i run in Intellij IDEA, but when i deploy the build .war file to a tomcat instance this is ignored. Is this a bug or is it not expected to work like this?
Also i seem to be unable to locate a specification of what can be written in application.yml. Anyone know where this can be found?
How about the application.groovy config file? Cant seem to locate a specification for this?
My environment:
Grails version: 3.2.8
Gradle version: 3.4.1
Intellij IDEA version: 2017.1.2
Tomcat version: 8.0.26
JDK Version: 1.8.0_45
When you deploy a Grails 3 app to a standalone tomcat application you should not use springboot server.session.timeout configuration property. That it is only for an embeedded server.
To configure a session timeout in a SpringBoot app (Grails 3 app is built on top of SpringBoot app) deployed into a standalone tomcat you have two choices:
A) Timeout for every app deployed in that tomcat instance.
You could edit the session timeout directly in tomcat configuration files:
$TOMCAT_HOME/conf/web.xml
Look out for the block:
<!-- ==================== Default Session Configuration ================= -->
<!-- You can set the default session timeout (in minutes) for all newly -->
<!-- created sessions by modifying the value below. -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
B) You can add a web.xml file in your Grails 3 app, with the timeout you need per app.
Create a file in the path 'src/main/webapp/WEB-INF/web.xml' with the content:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
C) You can also use tomcat's HttpSession setMaxInactiveInterval(seconds) method to set in your Groovy code.
if (grailsApplication.config.getProperty("session.timeout")?.isInteger())
// session timeout in seconds
session.setMaxInactiveInterval(grailsApplication.config.session.timeout as int)
Note that with the (current latest) Grails 5.x and spring boot 2.5 the correct property name is server.servlet.session.timeout and hence the application.yml config would go like this:
server:
servlet:
session:
timeout: 3600 #seconds
Spring boot docs:
https://docs.spring.io/spring-boot/docs/2.5.5/reference/html/application-properties.html#application-properties.server.server.servlet.session.timeout
I am using the new Servlet 3.0 approach of packaging web resources (such as Javascript, CSS, and JSPs) in JAR files. The approach says that everything under JARROOT/src/META-INF/resources will get mounted to the WAR root when the application starts. All works file for CSS and Javascript but not so much for Struts tiles.
This is the structure I have in the JAR:
base.jar
|--src/
|----META-INF/
|------base.tld
|------resources/
|--------base/
|----------css/
|----------js/
|----------baseTiles.xml
In my application (WAR) web.xml I got this for the tiles:
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml,/base/baseTiles.xml</param-value>
</context-param>
When I start my application I do not get any errors about the baseTiles.xml so I assume it would the tiles files. However, trying to reference a tile from a JSP (using the <tiles:insertAttribute> tag) fails with
org.apache.tiles.jsp.taglib.NoSuchAttributeException: Attribute 'base.nav' not found.
What do you think the is?
Summary and other info:
Using JBoss eap 6.1 Alpha
Using Struts 2.1.4
The base JAR is included with the WAR in the lib directory
The base JAR contain all the files mentioned above (including baseTiles.xml)
Thank you for your help!!
Problem solved! Must point to the right Schema in your web.xml...
<web-app version="3.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_1.xsd">
Now everything works automagically !!
It is the right schema definition for 3.1 servlet specification:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
We're running grails 2.0 + jetty 7.6.6 and need to set JSESSIONID cookie to be httpOnly.
All of the answers on stackoverflow seem to refer to either Servlet 3.0 (which requires jetty 8) or to tomcat.
Can anyone provide me with a clear way of setting the JSESSIONID cookie be httpOnly for jetty 7.x?
I have tried adding jetty-web.xml file with the following contents, but it still didn't work (i.e. the JSESSIONID wasn't marked as httpOnly):
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Get name="sessionHandler">
<Get name="sessionManager">
<Set name="httpOnly" type="boolean">true</Set>
</Get>
</Get>
</Configure>
All I had to do is to put the jetty-web.xml in the right folder. Initially I was putting into jetty/etc folder, but instead it should have been in the WEB-INF directory.
It appears the Grails 2.1 log4j plugin resets the log4j configuration during initialization of the grails application (see stack trace below).
at org.apache.log4j.LogManager.resetConfiguration(LogManager.java:233)
at org.apache.log4j.LogManager$resetConfiguration.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at org.codehaus.groovy.grails.plugins.log4j.Log4jConfig.initialize(Log4jConfig.groovy:66)
at org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:48)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4389)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:313)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:145)
Is there any way to disable this "feature" or to remove this plugin altogether?
My JBoss server is already configured through jboss-log4j.xml and I do not want grails to make any changes to the configuration. I have already tried removing the log4j section of Config.groovy, but doing so had no effect.
As Kelly suggested, I have already removed all logging-related jars from my war file. Log4j classes are provided by JBoss.
EDIT I also tried the trick described in https://stackoverflow.com/a/1190438/539048 but that didn't seem to make any difference.
The solution was to remove the following section from the generated web.xml file:
<listener>
<listener-class>org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener</tag0:listener-class>
</listener>
To do so, I edited the scripts/Events.groovy file according to this blog but changed the listener class name to org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.
eventWebXmlEnd = {String tmpfile ->
def root = new XmlSlurper().parse(webXmlFile)
def log4j = root.listener.findAll {node ->
node.'listener-class'.text() == 'org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener'
}
log4j.replaceNode {}
webXmlFile.text = new StreamingMarkupBuilder().bind {
mkp.declareNamespace("": "http://java.sun.com/xml/ns/j2ee")
mkp.yield(root)
}
}
Modify your BuildConfig.groovy like this:
inherits("global") {
excludes 'log4j', 'jcl-over-slf4j', 'slf4j-api', 'slf4j-log4j12'
}
This should remove all the logging libraries.
I tried the above suggestion on this grails application, so that I could expect to exclude the log4j dependencies of grails. However, after applying the suggestion, the jar files expected to be removed are still there in the generated war file. These jar files are: ./lib/grails-plugin-log4j-2.4.4.jar and ./lib/log4j-1.2.17.jar
I'm migrating an app from grails 1.3.6 to 2.0 and I need to change its context root. If I remember correctly, in 1.3.6 I installed the template plugin and changed:
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>/newcontextroot</param-value>
</context-param>
I did the same in 2.0 with no success. Any hints ?
Thanks
You can configure the context in Config.groovy:
// grails-app/conf/Config.groovy
grails.app.context = '/newcontextroot'
or in application.properties:
app.context = /newcontextroot
Start your grails application with this command
grails -Dapp.context=/ run-app
In Grails version 3.3.9 I know changing:
project/grails-app/conf/application.yml
adding
server:
contextPath: /yourcontextpath
port: 9214
will do the trick.