Plugin supporting developing and running Apache Struts 2 based application on Google AppEngine.
Just add this plugin as a dependency in pom.xml
:
<dependency>
<groupId>com.gruuf</groupId>
<artifactId>struts2-gae-plugin</artifactId>
<version>[VERSION]</version>
</dependency>
To provide a proper file upload support on the Google AppEngine you must use the below filter instead of the one provided
by Struts, update web.xml
as follow:
<filter>
<filter-name>struts2</filter-name>
<filter-class>com.gruuf.struts2.gae.dispatcher.GaePrepareAndExecuteFilter</filter-class>
</filter>
This filter detects if OGNL was properly configured, to do so add the following listener to web,xml
<listener>
<listener-class>com.gruuf.struts2.gae.dispatcher.GaeInitListener</listener-class>
</listener>
It also redefine Dispatcher
's getSaveDir
to allow properly upload files on AppEngine.
Now define fields to keep information about the uploaded file, please be aware that there is an abstraction layer in the Apache Struts which uses a UploadedFile
interface instead of the File
class (there is a fallback to File
but it won't work in GAE). This means you must define your file as follow:
private UploadedFile file;
// getter & setter
There is a dedicated interceptor with connected interface to allow perform reCAPTCHA validation per action.
First you must define your reCAPTCHA secret using a constant:
<constant name="struts.gae.reCaptchaSecret" value="${env.GRUUF_RECAPTCHA_SECRET}"/>
Now your action can implement ReCaptchaAware
interface and implement the below methods:
setReCaptchaResult
- you will gettrue
when reCAPTCHA validation has passedisReCaptchaEnabled
- allows you enabling/disabling reCAPTCHA validation per action, e.g.: when user is logged-in you don't want to perform the validation
The last thing is to define the reCAPTCHA interceptor and add it to your interceptors stack:
<interceptor name="reCaptcha" class="com.gruuf.struts2.gae.recaptcha.ReCaptchaInterceptor"/>
<interceptor-stack name="reCaptchaStack">
<interceptor-ref name="strutsDefault"/>
<interceptor-ref name="reCaptcha"/>
</interceptor-stack>
And finally you can add the reCAPTCHA code to your page.
This plugin is based on a code developed here https://code.google.com/archive/p/struts2-gae/
More details can be found here https://squarepusher782.wordpress.com/2010/10/01/file-upload-on-google-app-engine-using-struts2-revisited/
I have also taken some inspiration from here https://github.com/triologygmbh/reCAPTCHA-V2-java