-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from rollbar/add-struts2-integration
Add struts2 integration with examples
- Loading branch information
Showing
17 changed files
with
586 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.bmuschko:gradle-tomcat-plugin:2.3' | ||
} | ||
} | ||
|
||
apply plugin: 'war' | ||
apply plugin: 'com.bmuschko.tomcat' | ||
|
||
dependencies { | ||
implementation project(":rollbar-struts2") | ||
|
||
implementation 'javax.servlet:javax.servlet-api:3.1.0' | ||
implementation 'org.apache.struts:struts2-core:2.5.25' | ||
implementation 'org.apache.struts:struts2-spring-plugin:2.5.25' | ||
|
||
def tomcatVersion = '7.0.57' | ||
|
||
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", | ||
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}" | ||
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") | ||
} | ||
|
||
tomcatRun.contextPath = '/' | ||
tomcatRunWar.contextPath = '/' |
38 changes: 38 additions & 0 deletions
38
...r-struts2-spring/src/main/java/com/example/rollbar/struts2/action/HelloRollbarAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.rollbar.struts2.action; | ||
|
||
import com.opensymphony.xwork2.ActionSupport; | ||
import com.opensymphony.xwork2.inject.Inject; | ||
import com.rollbar.notifier.Rollbar; | ||
import com.rollbar.struts.RollbarFactory; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
|
||
/** | ||
* Struts2 action with Spring CDI. | ||
*/ | ||
public class HelloRollbarAction extends ActionSupport { | ||
|
||
private static final AtomicInteger counter = new AtomicInteger(1); | ||
|
||
private final Rollbar rollbar; | ||
|
||
@Inject | ||
public HelloRollbarAction(RollbarFactory rollbarFactory) { | ||
this.rollbar = rollbarFactory.build(); | ||
} | ||
|
||
public String index() { | ||
rollbar.info("Executing index action in HelloRollbarAction"); | ||
|
||
return SUCCESS; | ||
} | ||
|
||
public String hello() { | ||
int current = counter.getAndAdd(1); | ||
if (current % 2 == 0) { | ||
throw new RuntimeException("Fatal error at hello rollbar action. Number: " + current); | ||
} | ||
return SUCCESS; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
examples/rollbar-struts2-spring/src/main/resources/applicationContext.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "springframework.org/dtd/spring-beans-2.0.dtd"> | ||
|
||
<beans> | ||
<bean id="rollbarFactory" class="com.rollbar.struts.RollbarFactory" scope="singleton" > | ||
<property name="accessToken" value="[ACCESS_TOKEN]" /> | ||
<property name="captureIp" value="true" /> | ||
<property name="environment" value="production" /> | ||
<property name="codeVersion" value="1.1.2" /> | ||
</bean> | ||
</beans> | ||
|
31 changes: 31 additions & 0 deletions
31
examples/rollbar-struts2-spring/src/main/resources/struts.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE struts PUBLIC | ||
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" | ||
"http://struts.apache.org/dtds/struts-2.5.dtd"> | ||
<struts> | ||
<constant name="struts.devMode" value="true" /> | ||
|
||
<package name="basicstruts2" extends="struts-default" namespace="/"> | ||
<interceptors> | ||
<interceptor name="rollbarExceptionInterceptor" | ||
class="com.rollbar.struts.interceptor.RollbarExceptionInterceptor" /> | ||
|
||
<interceptor-stack name="appStack"> | ||
<interceptor-ref name="rollbarExceptionInterceptor" /> | ||
<interceptor-ref name="defaultStack" /> | ||
</interceptor-stack> | ||
</interceptors> | ||
<default-interceptor-ref name="appStack"/> | ||
|
||
<default-action-ref name="index" /> | ||
|
||
<action name="index" class="com.example.rollbar.struts2.action.HelloRollbarAction" method="index"> | ||
<result type="chain">hello</result> | ||
</action> | ||
|
||
<action name="hello" class="com.example.rollbar.struts2.action.HelloRollbarAction" method="hello"> | ||
<result>/WEB-INF/jsp/index.jsp</result> | ||
</action> | ||
|
||
</package> | ||
</struts> |
16 changes: 16 additions & 0 deletions
16
examples/rollbar-struts2-spring/src/main/webapp/WEB-INF/jsp/index.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html PUBLIC | ||
"-//W3C//DTD XHTML 1.1 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<%@taglib prefix="s" uri="/struts-tags" %> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<title>Hello Rollbar struts2 example application</title> | ||
<s:head /> | ||
</head> | ||
<body> | ||
Hello Rollbar! | ||
</body> | ||
</html> | ||
|
29 changes: 29 additions & 0 deletions
29
examples/rollbar-struts2-spring/src/main/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | ||
id="WebApp_ID" version="3.0"> | ||
|
||
<context-param> | ||
<param-name>contextConfigLocation</param-name> | ||
<param-value>classpath*:applicationContext*.xml</param-value> | ||
</context-param> | ||
|
||
<filter> | ||
<filter-name>struts2</filter-name> | ||
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> | ||
</filter> | ||
<filter-mapping> | ||
<filter-name>struts2</filter-name> | ||
<url-pattern>/*</url-pattern> | ||
</filter-mapping> | ||
|
||
<!-- Rollbar listener and filter --> | ||
<listener> | ||
<listener-class>com.rollbar.web.listener.RollbarRequestListener</listener-class> | ||
</listener> | ||
|
||
<listener> | ||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> | ||
</listener> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.bmuschko:gradle-tomcat-plugin:2.3' | ||
} | ||
} | ||
|
||
apply plugin: 'war' | ||
apply plugin: 'com.bmuschko.tomcat' | ||
|
||
dependencies { | ||
implementation project(":rollbar-struts2") | ||
|
||
implementation 'org.apache.struts:struts2-core:2.5.25' | ||
implementation 'javax.servlet:javax.servlet-api:3.1.0' | ||
|
||
def tomcatVersion = '7.0.57' | ||
|
||
tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", | ||
"org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}" | ||
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") | ||
} | ||
|
||
tomcatRun.contextPath = '/' | ||
tomcatRunWar.contextPath = '/' |
23 changes: 23 additions & 0 deletions
23
.../rollbar-struts2/src/main/java/com/example/rollbar/struts2/action/HelloRollbarAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.rollbar.struts2.action; | ||
|
||
import com.opensymphony.xwork2.ActionSupport; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
|
||
/** | ||
* Struts2 action that rises an error every even request number. | ||
*/ | ||
public class HelloRollbarAction extends ActionSupport { | ||
|
||
private static final AtomicInteger counter = new AtomicInteger(1); | ||
|
||
public String execute() { | ||
int current = counter.getAndAdd(1); | ||
if (current % 2 == 0) { | ||
throw new RuntimeException("Fatal error at hello rollbar action. Number: " + current); | ||
} | ||
return SUCCESS; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE struts PUBLIC | ||
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" | ||
"http://struts.apache.org/dtds/struts-2.5.dtd"> | ||
<struts> | ||
<constant name="struts.devMode" value="true" /> | ||
|
||
<package name="basicstruts2" extends="struts-default" namespace="/"> | ||
|
||
<interceptors> | ||
<interceptor name="rollbarExceptionInterceptor" | ||
class="com.rollbar.struts.interceptor.RollbarExceptionInterceptor"> | ||
<param name="accessToken">[ACCESS_TOKEN]</param> | ||
<param name="captureIp">true</param> | ||
<param name="environment">production</param> | ||
<param name="codeVersion">1.1.2</param> | ||
</interceptor> | ||
|
||
<interceptor-stack name="appStack"> | ||
<interceptor-ref name="rollbarExceptionInterceptor" /> | ||
<interceptor-ref name="defaultStack" /> | ||
</interceptor-stack> | ||
</interceptors> | ||
|
||
<default-interceptor-ref name="appStack"/> | ||
|
||
<default-action-ref name="index" /> | ||
|
||
<action name="index" class="com.example.rollbar.struts2.action.HelloRollbarAction" method="execute"> | ||
<result>/WEB-INF/jsp/index.jsp</result> | ||
</action> | ||
|
||
</package> | ||
</struts> |
16 changes: 16 additions & 0 deletions
16
examples/rollbar-struts2/src/main/webapp/WEB-INF/jsp/index.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html PUBLIC | ||
"-//W3C//DTD XHTML 1.1 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
|
||
<%@taglib prefix="s" uri="/struts-tags" %> | ||
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<title>Hello Rollbar struts2 example application</title> | ||
<s:head /> | ||
</head> | ||
<body> | ||
Hello Rollbar! | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | ||
id="WebApp_ID" version="3.0"> | ||
|
||
<!-- Rollbar listener and filter --> | ||
<listener> | ||
<listener-class>com.rollbar.web.listener.RollbarRequestListener</listener-class> | ||
</listener> | ||
|
||
<filter> | ||
<filter-name>struts2</filter-name> | ||
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> | ||
</filter> | ||
<filter-mapping> | ||
<filter-name>struts2</filter-name> | ||
<url-pattern>/*</url-pattern> | ||
</filter-mapping> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ext { | ||
struts2Version = '2.5.25' | ||
} | ||
|
||
dependencies { | ||
api project(":rollbar-web") | ||
implementation 'org.apache.struts:struts2-core:' + struts2Version | ||
} |
Oops, something went wrong.