mirror of
https://github.com/apache/struts.git
synced 2026-09-01 11:54:31 +00:00
Compare commits
153 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ad95ab30f2 | |||
| 2eecd16888 | |||
| d8c69691ef | |||
| 236ae15c66 | |||
| 4c044f1256 | |||
| f4253ff8ff | |||
| 0ba2d69af9 | |||
| 59e9c18cac | |||
| badb3f4579 | |||
| f0e3cec5cf | |||
| 50b36695e8 | |||
| f70feb11e2 | |||
| 74e5aad4f8 | |||
| 85fe680715 | |||
| a0185f2483 | |||
| 1a88f78a7e | |||
| 20e2110614 | |||
| 03e232344b | |||
| 891598545d | |||
| 32e42b3ecd | |||
| 04e9246389 | |||
| 555a3a37ba | |||
| 6e5a1a07f0 | |||
| 215541146d | |||
| 3b515b1a78 | |||
| c087f2e64c | |||
| 947c6c8a6a | |||
| 35b0a6887f | |||
| 6b13e8ac3a | |||
| 0f068d37ae | |||
| 85e8d819ef | |||
| 12cd92cb62 | |||
| e8614a99dd | |||
| 709434eebc | |||
| e75f8d82b5 | |||
| 0ef086c89b | |||
| 87f80f4738 | |||
| 94a3e6bd95 | |||
| 783063c66f | |||
| 270ec4ad71 | |||
| a228b14a48 | |||
| b0f1ef1f8b | |||
| f31ba637c8 | |||
| 72a5d21332 | |||
| 746c754132 | |||
| e53dd7dd5e | |||
| 4145d1af14 | |||
| 841705cadf | |||
| 393eb8c0f8 | |||
| bb68ce6ae5 | |||
| 4a678f6bbb | |||
| dc43c891da | |||
| 22a6ae9d63 | |||
| 94c1b2a29b | |||
| d70ad5b737 | |||
| 2fa9d60a23 | |||
| 2250639605 | |||
| 6d9bfb6afe | |||
| 2abf8677bf | |||
| 114b6e4f27 | |||
| f4daeb3ea4 | |||
| 2d6fe84301 | |||
| ea124a4757 | |||
| 824801796c | |||
| 21a09493fc | |||
| 9a286c9353 | |||
| ceb4e38b74 | |||
| fb268fff51 | |||
| 1d5f006cf9 | |||
| 2514685266 | |||
| 81ede1181f | |||
| 7c58362e7f | |||
| eb4f53bd53 | |||
| 61856cf59c | |||
| 05cfe51d5f | |||
| 19eb1babaa | |||
| d47538c7db | |||
| 110ef71eb7 | |||
| 7da2def478 | |||
| 9992e39b42 | |||
| cfce5b2e03 | |||
| a650f3bfce | |||
| c452137005 | |||
| 710ec2edb9 | |||
| e8287ddeef | |||
| e1a80789f1 | |||
| 44f0a1bcd3 | |||
| 2e0764f9da | |||
| 433d9c429a | |||
| f58d0f3cc8 | |||
| 9bbf9c5dce | |||
| fc0eae3ef6 | |||
| 2db7c0439e | |||
| 5aa1d076b2 | |||
| 956a956efb | |||
| 3f558a8cfe | |||
| 298eefe8c8 | |||
| 9780e70648 | |||
| ec4dfa3e96 | |||
| 570b38fc86 | |||
| b19ef0c567 | |||
| 0f64675b49 | |||
| de019918fa | |||
| 71e9ee76c1 | |||
| 885c50056c | |||
| c7d88bea6f | |||
| f6737841f8 | |||
| ce4015739a | |||
| 2533d3177c | |||
| bc141267c6 | |||
| bb1a34daae | |||
| 8080d41a1c | |||
| 67a21ffe1b | |||
| 01ccc0bcb3 | |||
| 10203ed89a | |||
| 85f7e8a1a5 | |||
| 129b2c3b08 | |||
| bcaab0c2bf | |||
| 11833fdd51 | |||
| 3685c074c1 | |||
| 24fcc6e5f8 | |||
| 51c68e5cac | |||
| a0da9f2109 | |||
| dbdf72b38b | |||
| 4fa10952ca | |||
| 86be4955d4 | |||
| e6db239aa6 | |||
| b27c9a6bc9 | |||
| b2807827e4 | |||
| 47f7707f6e | |||
| 10355a9ce8 | |||
| c06069cc9c | |||
| 279ef0cd0b | |||
| b48adacec8 | |||
| 040a7c7268 | |||
| 9aed8cd09b | |||
| 66c0b219ce | |||
| 13ac0eced4 | |||
| 486f96468e | |||
| 54b96d2f07 | |||
| aeeaad1237 | |||
| 6ab23d4168 | |||
| c3da93281e | |||
| d2de3f610d | |||
| 2461335576 | |||
| a099c8c1c1 | |||
| 56b4af4a6f | |||
| fa42a20a33 | |||
| 25f79d65b2 | |||
| 6a8cfc8478 | |||
| a23bb60db1 | |||
| 4c926c2f07 | |||
| 62b41ef466 |
@@ -3,8 +3,8 @@ notifications:
|
||||
commits: commits@struts.apache.org
|
||||
# Send all issue emails (new, closed, comments) to issues@
|
||||
issues: issues@struts.apache.org
|
||||
# Send new/closed PR notifications to dev@
|
||||
pullrequests_status: dev@struts.apache.org
|
||||
# Send new/closed PR notifications to commits@
|
||||
pullrequests_status: commits@struts.apache.org
|
||||
# Send individual PR comments/reviews to issues@
|
||||
pullrequests_comment: issues@struts.apache.org
|
||||
# Link opened PRs with JIRA
|
||||
@@ -16,3 +16,5 @@ github:
|
||||
master: { }
|
||||
autolink_jira:
|
||||
- WW
|
||||
dependabot_alerts: true
|
||||
dependabot_updates: true
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
- package-ecosystem: "maven"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
@@ -42,7 +42,7 @@ jobs:
|
||||
language: [ 'java' ]
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
|
||||
@@ -35,9 +35,9 @@ jobs:
|
||||
java: [ '8', '11', '17' ]
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3.0.2
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up cache
|
||||
uses: actions/cache@v3.0.8
|
||||
uses: actions/cache@v3.3.1
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
@@ -49,10 +49,10 @@ jobs:
|
||||
distribution: adopt
|
||||
java-version: ${{ matrix.java }}
|
||||
- name: Build with Maven on Java ${{ matrix.java }}
|
||||
if: matrix.java != '11'
|
||||
run: mvn -B -V -DskipAssembly test --no-transfer-progress
|
||||
if: matrix.java != '17'
|
||||
run: mvn -B -V -DskipAssembly verify --no-transfer-progress
|
||||
- name: Code coverage on Java ${{ matrix.java }}
|
||||
if: matrix.java == '11'
|
||||
if: matrix.java == '17'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
|
||||
|
||||
@@ -40,12 +40,12 @@ jobs:
|
||||
steps:
|
||||
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # 3.1.0
|
||||
uses: actions/checkout@v4 # 3.1.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@99c53751e09b9529366343771cc321ec74e9bd3d # 2.0.6
|
||||
uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # 2.2.0
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
@@ -57,7 +57,7 @@ jobs:
|
||||
publish_results: true
|
||||
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # 3.1.0
|
||||
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # 3.1.3
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# Request PR review from any Apache Struts committer
|
||||
* @apache/struts-committers
|
||||
Vendored
+15
-16
@@ -44,7 +44,7 @@ pipeline {
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh './mvnw -B test'
|
||||
sh './mvnw -B verify -Pcoverage -DskipAssembly'
|
||||
}
|
||||
post {
|
||||
always {
|
||||
@@ -53,6 +53,16 @@ pipeline {
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Code Quality') {
|
||||
when {
|
||||
branch 'master'
|
||||
}
|
||||
steps {
|
||||
withCredentials([string(credentialsId: 'asf-struts-sonarcloud', variable: 'SONARCLOUD_TOKEN')]) {
|
||||
sh './mvnw -B -Pcoverage -DskipAssembly -Dsonar.login=${SONARCLOUD_TOKEN} verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
@@ -79,7 +89,7 @@ pipeline {
|
||||
}
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh './mvnw -B verify -Pcoverage -DskipAssembly'
|
||||
sh './mvnw -B test'
|
||||
}
|
||||
post {
|
||||
always {
|
||||
@@ -88,16 +98,6 @@ pipeline {
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Code Quality') {
|
||||
when {
|
||||
branch 'master'
|
||||
}
|
||||
steps {
|
||||
withCredentials([string(credentialsId: 'asf-struts-sonarcloud', variable: 'SONARCLOUD_TOKEN')]) {
|
||||
sh './mvnw -B -Pcoverage -DskipAssembly -Dsonar.login=${SONARCLOUD_TOKEN} verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
@@ -125,7 +125,6 @@ pipeline {
|
||||
stage('Test') {
|
||||
steps {
|
||||
sh './mvnw -B test'
|
||||
// step([$class: 'JiraIssueUpdater', issueSelector: [$class: 'DefaultIssueSelector'], scm: scm])
|
||||
}
|
||||
post {
|
||||
always {
|
||||
@@ -190,7 +189,7 @@ pipeline {
|
||||
failure {
|
||||
script {
|
||||
emailext(
|
||||
to: "dev@struts.apache.org",
|
||||
to: "commits@struts.apache.org",
|
||||
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
|
||||
from: "Mr. Jenkins <jenkins@builds.apache.org>",
|
||||
subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} failed",
|
||||
@@ -213,7 +212,7 @@ Director of Continuous Integration
|
||||
unstable {
|
||||
script {
|
||||
emailext(
|
||||
to: "dev@struts.apache.org",
|
||||
to: "commits@struts.apache.org",
|
||||
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
|
||||
from: "Mr. Jenkins <jenkins@builds.apache.org>",
|
||||
subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} unstable",
|
||||
@@ -236,7 +235,7 @@ Director of Continuous Integration
|
||||
fixed {
|
||||
script {
|
||||
emailext(
|
||||
to: "dev@struts.apache.org",
|
||||
to: "commits@struts.apache.org",
|
||||
recipientProviders: [[$class: 'DevelopersRecipientProvider']],
|
||||
from: 'Mr. Jenkins <jenkins@builds.apache.org>',
|
||||
subject: "Jenkins job ${env.JOB_NAME}#${env.BUILD_NUMBER} back to normal",
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-rest-showcase</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
<name>Struts 2 Rest Showcase Webapp</name>
|
||||
<description>Struts 2 Rest Showcase Example</description>
|
||||
|
||||
@@ -56,12 +56,10 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
+1
-15
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-apps</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-showcase</artifactId>
|
||||
@@ -68,12 +68,6 @@
|
||||
<artifactId>struts2-json-plugin</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-jsp</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-convention-plugin</artifactId>
|
||||
@@ -114,22 +108,18 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-jcl</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -140,10 +130,6 @@
|
||||
<groupId>org.directwebremoting</groupId>
|
||||
<artifactId>dwr</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
+3
-4
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-assembly</artifactId>
|
||||
@@ -41,9 +41,8 @@
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>dependency-maven-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-war</id>
|
||||
|
||||
+5
-5
@@ -24,12 +24,12 @@
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts-master</artifactId>
|
||||
<version>14</version>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-bom</artifactId>
|
||||
<version>6.2.0</version>
|
||||
<version>6.3.0.2</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Struts 2 Bill of Materials</name>
|
||||
@@ -44,7 +44,7 @@
|
||||
</licenses>
|
||||
|
||||
<properties>
|
||||
<struts-version.version>6.2.0</struts-version.version>
|
||||
<struts-version.version>6.3.0.2</struts-version.version>
|
||||
<maven.site.skip>true</maven.site.skip>
|
||||
<maven.site.deploy.skip>true</maven.site.deploy.skip>
|
||||
</properties>
|
||||
@@ -190,7 +190,7 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<scm>
|
||||
<tag>STRUTS_6_2_0</tag>
|
||||
<tag>STRUTS_6_3_0_2</tag>
|
||||
<connection>scm:git:https://gitbox.apache.org/repos/asf/struts.git</connection>
|
||||
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/struts.git</developerConnection>
|
||||
<url>https://github.com/apache/struts/</url>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-admin-bundle</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-demo-bundle</artifactId>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-bundles</artifactId>
|
||||
|
||||
+1
-2
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
<artifactId>struts2-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
@@ -260,7 +260,6 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -22,14 +22,17 @@ import com.opensymphony.xwork2.config.Configuration;
|
||||
import com.opensymphony.xwork2.config.ConfigurationException;
|
||||
import com.opensymphony.xwork2.config.ConfigurationManager;
|
||||
import com.opensymphony.xwork2.config.ConfigurationProvider;
|
||||
import com.opensymphony.xwork2.inject.*;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.ContainerBuilder;
|
||||
import com.opensymphony.xwork2.inject.Context;
|
||||
import com.opensymphony.xwork2.inject.Factory;
|
||||
import com.opensymphony.xwork2.inject.Scope;
|
||||
import com.opensymphony.xwork2.test.StubConfigurationProvider;
|
||||
import com.opensymphony.xwork2.util.XWorkTestCaseHelper;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -217,8 +217,8 @@ public class ParametersInterceptor extends MethodFilterInterceptor {
|
||||
//block or allow access to properties
|
||||
//see WW-2761 for more details
|
||||
MemberAccessValueStack accessValueStack = (MemberAccessValueStack) newStack;
|
||||
accessValueStack.setAcceptProperties(acceptedPatterns.getAcceptedPatterns());
|
||||
accessValueStack.setExcludeProperties(excludedPatterns.getExcludedPatterns());
|
||||
accessValueStack.useAcceptProperties(acceptedPatterns.getAcceptedPatterns());
|
||||
accessValueStack.useExcludeProperties(excludedPatterns.getExcludedPatterns());
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Parameter> entry : acceptableParameters.entrySet()) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
|
||||
import com.opensymphony.xwork2.util.CompoundRoot;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionException;
|
||||
import ognl.ClassResolver;
|
||||
import ognl.Ognl;
|
||||
@@ -51,6 +50,11 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import static com.opensymphony.xwork2.util.TextParseUtil.commaDelimitedStringToSet;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static org.apache.commons.lang3.StringUtils.strip;
|
||||
|
||||
|
||||
/**
|
||||
@@ -96,8 +100,8 @@ public class OgnlUtil {
|
||||
@Deprecated
|
||||
public OgnlUtil() {
|
||||
// Instantiate default Expression and BeanInfo caches (factories must be non-null).
|
||||
this(new DefaultOgnlExpressionCacheFactory<String, Object>(),
|
||||
new DefaultOgnlBeanInfoCacheFactory<Class<?>, BeanInfo>());
|
||||
this(new DefaultOgnlExpressionCacheFactory<>(),
|
||||
new DefaultOgnlBeanInfoCacheFactory<>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,9 +191,8 @@ public class OgnlUtil {
|
||||
}
|
||||
|
||||
private Set<Class<?>> parseClasses(String commaDelimitedClasses) {
|
||||
Set<String> classNames = TextParseUtil.commaDelimitedStringToSet(commaDelimitedClasses);
|
||||
Set<String> classNames = commaDelimitedStringToSet(commaDelimitedClasses);
|
||||
Set<Class<?>> classes = new HashSet<>();
|
||||
|
||||
for (String className : classNames) {
|
||||
try {
|
||||
classes.add(Class.forName(className));
|
||||
@@ -197,7 +200,6 @@ public class OgnlUtil {
|
||||
throw new ConfigurationException("Cannot load class for exclusion/exemption configuration: " + className, e);
|
||||
}
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
@@ -218,14 +220,13 @@ public class OgnlUtil {
|
||||
}
|
||||
|
||||
private Set<Pattern> parseExcludedPackageNamePatterns(String commaDelimitedPackagePatterns) {
|
||||
Set<String> packagePatterns = TextParseUtil.commaDelimitedStringToSet(commaDelimitedPackagePatterns);
|
||||
Set<Pattern> packageNamePatterns = new HashSet<>();
|
||||
|
||||
for (String pattern : packagePatterns) {
|
||||
packageNamePatterns.add(Pattern.compile(pattern));
|
||||
try {
|
||||
return commaDelimitedStringToSet(commaDelimitedPackagePatterns)
|
||||
.stream().map(Pattern::compile).collect(toSet());
|
||||
} catch (PatternSyntaxException e) {
|
||||
throw new ConfigurationException(
|
||||
"Excluded package name patterns could not be parsed due to invalid regex: " + commaDelimitedPackagePatterns, e);
|
||||
}
|
||||
|
||||
return packageNamePatterns;
|
||||
}
|
||||
|
||||
@Inject(value = StrutsConstants.STRUTS_EXCLUDED_PACKAGE_NAMES, required = false)
|
||||
@@ -261,7 +262,12 @@ public class OgnlUtil {
|
||||
}
|
||||
|
||||
private Set<String> parseExcludedPackageNames(String commaDelimitedPackageNames) {
|
||||
return TextParseUtil.commaDelimitedStringToSet(commaDelimitedPackageNames);
|
||||
Set<String> parsedSet = commaDelimitedStringToSet(commaDelimitedPackageNames)
|
||||
.stream().map(s -> strip(s, ".")).collect(toSet());
|
||||
if (parsedSet.stream().anyMatch(s -> s.matches("(.*?)\\s(.*?)"))) {
|
||||
throw new ConfigurationException("Excluded package names could not be parsed due to erroneous whitespace characters: " + commaDelimitedPackageNames);
|
||||
}
|
||||
return parsedSet;
|
||||
}
|
||||
|
||||
public Set<Class<?>> getExcludedClasses() {
|
||||
@@ -872,22 +878,22 @@ public class OgnlUtil {
|
||||
}
|
||||
|
||||
SecurityMemberAccess memberAccess = new SecurityMemberAccess(allowStaticFieldAccess);
|
||||
memberAccess.setDisallowProxyMemberAccess(disallowProxyMemberAccess);
|
||||
memberAccess.disallowProxyMemberAccess(disallowProxyMemberAccess);
|
||||
|
||||
if (devMode) {
|
||||
if (!warnReported.get()) {
|
||||
warnReported.set(true);
|
||||
LOG.warn("Working in devMode, using devMode excluded classes and packages!");
|
||||
}
|
||||
memberAccess.setExcludedClasses(devModeExcludedClasses);
|
||||
memberAccess.setExcludedPackageNamePatterns(devModeExcludedPackageNamePatterns);
|
||||
memberAccess.setExcludedPackageNames(devModeExcludedPackageNames);
|
||||
memberAccess.setExcludedPackageExemptClasses(devModeExcludedPackageExemptClasses);
|
||||
memberAccess.useExcludedClasses(devModeExcludedClasses);
|
||||
memberAccess.useExcludedPackageNamePatterns(devModeExcludedPackageNamePatterns);
|
||||
memberAccess.useExcludedPackageNames(devModeExcludedPackageNames);
|
||||
memberAccess.useExcludedPackageExemptClasses(devModeExcludedPackageExemptClasses);
|
||||
} else {
|
||||
memberAccess.setExcludedClasses(excludedClasses);
|
||||
memberAccess.setExcludedPackageNamePatterns(excludedPackageNamePatterns);
|
||||
memberAccess.setExcludedPackageNames(excludedPackageNames);
|
||||
memberAccess.setExcludedPackageExemptClasses(excludedPackageExemptClasses);
|
||||
memberAccess.useExcludedClasses(excludedClasses);
|
||||
memberAccess.useExcludedPackageNamePatterns(excludedPackageNamePatterns);
|
||||
memberAccess.useExcludedPackageNames(excludedPackageNames);
|
||||
memberAccess.useExcludedPackageExemptClasses(excludedPackageExemptClasses);
|
||||
}
|
||||
|
||||
return Ognl.createDefaultContext(root, memberAccess, resolver, defaultConverter);
|
||||
|
||||
@@ -89,11 +89,11 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
@Inject
|
||||
protected void setOgnlUtil(OgnlUtil ognlUtil) {
|
||||
this.ognlUtil = ognlUtil;
|
||||
securityMemberAccess.setExcludedClasses(ognlUtil.getExcludedClasses());
|
||||
securityMemberAccess.setExcludedPackageNamePatterns(ognlUtil.getExcludedPackageNamePatterns());
|
||||
securityMemberAccess.setExcludedPackageNames(ognlUtil.getExcludedPackageNames());
|
||||
securityMemberAccess.setExcludedPackageExemptClasses(ognlUtil.getExcludedPackageExemptClasses());
|
||||
securityMemberAccess.setDisallowProxyMemberAccess(ognlUtil.isDisallowProxyMemberAccess());
|
||||
securityMemberAccess.useExcludedClasses(ognlUtil.getExcludedClasses());
|
||||
securityMemberAccess.useExcludedPackageNamePatterns(ognlUtil.getExcludedPackageNamePatterns());
|
||||
securityMemberAccess.useExcludedPackageNames(ognlUtil.getExcludedPackageNames());
|
||||
securityMemberAccess.useExcludedPackageExemptClasses(ognlUtil.getExcludedPackageExemptClasses());
|
||||
securityMemberAccess.disallowProxyMemberAccess(ognlUtil.isDisallowProxyMemberAccess());
|
||||
}
|
||||
|
||||
protected void setRoot(XWorkConverter xworkConverter, CompoundRootAccessor accessor, CompoundRoot compoundRoot, boolean allowStaticFieldAccess) {
|
||||
@@ -482,12 +482,22 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
((OgnlContext) context).getValues().clear();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setAcceptProperties(Set<Pattern> acceptedProperties) {
|
||||
securityMemberAccess.setAcceptProperties(acceptedProperties);
|
||||
securityMemberAccess.useAcceptProperties(acceptedProperties);
|
||||
}
|
||||
|
||||
public void useAcceptProperties(Set<Pattern> acceptedProperties) {
|
||||
securityMemberAccess.useAcceptProperties(acceptedProperties);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setExcludeProperties(Set<Pattern> excludeProperties) {
|
||||
securityMemberAccess.setExcludeProperties(excludeProperties);
|
||||
securityMemberAccess.useExcludeProperties(excludeProperties);
|
||||
}
|
||||
|
||||
public void useExcludeProperties(Set<Pattern> excludeProperties) {
|
||||
securityMemberAccess.useExcludeProperties(excludeProperties);
|
||||
}
|
||||
|
||||
@Inject
|
||||
|
||||
@@ -27,13 +27,17 @@ import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Collections;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
import static java.util.Collections.unmodifiableSet;
|
||||
|
||||
/**
|
||||
* Allows access decisions to be made on the basis of whether a member is static or not.
|
||||
* Also blocks or allows access to properties.
|
||||
@@ -43,12 +47,12 @@ public class SecurityMemberAccess implements MemberAccess {
|
||||
private static final Logger LOG = LogManager.getLogger(SecurityMemberAccess.class);
|
||||
|
||||
private final boolean allowStaticFieldAccess;
|
||||
private Set<Pattern> excludeProperties = Collections.emptySet();
|
||||
private Set<Pattern> acceptProperties = Collections.emptySet();
|
||||
private Set<Class<?>> excludedClasses = Collections.emptySet();
|
||||
private Set<Pattern> excludedPackageNamePatterns = Collections.emptySet();
|
||||
private Set<String> excludedPackageNames = Collections.emptySet();
|
||||
private Set<Class<?>> excludedPackageExemptClasses = Collections.emptySet();
|
||||
private Set<Pattern> excludeProperties = emptySet();
|
||||
private Set<Pattern> acceptProperties = emptySet();
|
||||
private Set<Class<?>> excludedClasses = emptySet();
|
||||
private Set<Pattern> excludedPackageNamePatterns = emptySet();
|
||||
private Set<String> excludedPackageNames = emptySet();
|
||||
private Set<Class<?>> excludedPackageExemptClasses = emptySet();
|
||||
private boolean disallowProxyMemberAccess;
|
||||
|
||||
/**
|
||||
@@ -60,6 +64,7 @@ public class SecurityMemberAccess implements MemberAccess {
|
||||
*/
|
||||
public SecurityMemberAccess(boolean allowStaticFieldAccess) {
|
||||
this.allowStaticFieldAccess = allowStaticFieldAccess;
|
||||
useExcludedClasses(excludedClasses); // Initialise default exclusions
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,18 +242,15 @@ public class SecurityMemberAccess implements MemberAccess {
|
||||
|
||||
protected boolean isExcludedPackageNamePatterns(Class<?> clazz) {
|
||||
String packageName = toPackageName(clazz);
|
||||
for (Pattern pattern : excludedPackageNamePatterns) {
|
||||
if (pattern.matcher(packageName).matches()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return excludedPackageNamePatterns.stream().anyMatch(pattern -> pattern.matcher(packageName).matches());
|
||||
}
|
||||
|
||||
protected boolean isExcludedPackageNames(Class<?> clazz) {
|
||||
String suffixedPackageName = toPackageName(clazz) + ".";
|
||||
for (String excludedPackageName : excludedPackageNames) {
|
||||
if (suffixedPackageName.startsWith(excludedPackageName)) {
|
||||
String packageName = toPackageName(clazz);
|
||||
List<String> packageParts = Arrays.asList(packageName.split("\\."));
|
||||
for (int i = 0; i < packageParts.size(); i++) {
|
||||
String parentPackage = String.join(".", packageParts.subList(0, i + 1));
|
||||
if (excludedPackageNames.contains(parentPackage)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -256,14 +258,11 @@ public class SecurityMemberAccess implements MemberAccess {
|
||||
}
|
||||
|
||||
protected boolean isClassExcluded(Class<?> clazz) {
|
||||
if (clazz == Object.class || (clazz == Class.class && !allowStaticFieldAccess)) {
|
||||
return true;
|
||||
}
|
||||
return excludedClasses.stream().anyMatch(clazz::isAssignableFrom);
|
||||
return excludedClasses.contains(clazz);
|
||||
}
|
||||
|
||||
protected boolean isExcludedPackageExempt(Class<?> clazz) {
|
||||
return excludedPackageExemptClasses.stream().anyMatch(clazz::equals);
|
||||
return excludedPackageExemptClasses.contains(clazz);
|
||||
}
|
||||
|
||||
protected boolean isAcceptableProperty(String name) {
|
||||
@@ -299,31 +298,92 @@ public class SecurityMemberAccess implements MemberAccess {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #useExcludeProperties(Set)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setExcludeProperties(Set<Pattern> excludeProperties) {
|
||||
this.excludeProperties = excludeProperties;
|
||||
}
|
||||
|
||||
public void useExcludeProperties(Set<Pattern> excludeProperties) {
|
||||
this.excludeProperties = excludeProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #useAcceptProperties(Set)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setAcceptProperties(Set<Pattern> acceptedProperties) {
|
||||
this.acceptProperties = acceptedProperties;
|
||||
}
|
||||
|
||||
public void setExcludedClasses(Set<Class<?>> excludedClasses) {
|
||||
this.excludedClasses = excludedClasses;
|
||||
public void useAcceptProperties(Set<Pattern> acceptedProperties) {
|
||||
this.acceptProperties = acceptedProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #useExcludedClasses(Set)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setExcludedClasses(Set<Class<?>> excludedClasses) {
|
||||
useExcludedClasses(excludedClasses);
|
||||
}
|
||||
|
||||
public void useExcludedClasses(Set<Class<?>> excludedClasses) {
|
||||
Set<Class<?>> newExcludedClasses = new HashSet<>(excludedClasses);
|
||||
newExcludedClasses.add(Object.class);
|
||||
if (!allowStaticFieldAccess) {
|
||||
newExcludedClasses.add(Class.class);
|
||||
}
|
||||
this.excludedClasses = unmodifiableSet(newExcludedClasses);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #useExcludedPackageNamePatterns(Set)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setExcludedPackageNamePatterns(Set<Pattern> excludedPackageNamePatterns) {
|
||||
this.excludedPackageNamePatterns = excludedPackageNamePatterns;
|
||||
}
|
||||
|
||||
public void useExcludedPackageNamePatterns(Set<Pattern> excludedPackageNamePatterns) {
|
||||
this.excludedPackageNamePatterns = excludedPackageNamePatterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #useExcludedPackageNames(Set)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setExcludedPackageNames(Set<String> excludedPackageNames) {
|
||||
this.excludedPackageNames = excludedPackageNames;
|
||||
}
|
||||
|
||||
public void useExcludedPackageNames(Set<String> excludedPackageNames) {
|
||||
this.excludedPackageNames = excludedPackageNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #useExcludedPackageExemptClasses(Set)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setExcludedPackageExemptClasses(Set<Class<?>> excludedPackageExemptClasses) {
|
||||
this.excludedPackageExemptClasses = excludedPackageExemptClasses;
|
||||
}
|
||||
|
||||
public void useExcludedPackageExemptClasses(Set<Class<?>> excludedPackageExemptClasses) {
|
||||
this.excludedPackageExemptClasses = excludedPackageExemptClasses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #disallowProxyMemberAccess(boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDisallowProxyMemberAccess(boolean disallowProxyMemberAccess) {
|
||||
this.disallowProxyMemberAccess = disallowProxyMemberAccess;
|
||||
}
|
||||
|
||||
public void disallowProxyMemberAccess(boolean disallowProxyMemberAccess) {
|
||||
this.disallowProxyMemberAccess = disallowProxyMemberAccess;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,20 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public interface MemberAccessValueStack {
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #useExcludeProperties(Set)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setExcludeProperties(Set<Pattern> excludeProperties);
|
||||
|
||||
void useExcludeProperties(Set<Pattern> excludeProperties);
|
||||
|
||||
/**
|
||||
* @deprecated please use {@link #useAcceptProperties(Set)}
|
||||
*/
|
||||
@Deprecated
|
||||
void setAcceptProperties(Set<Pattern> acceptedProperties);
|
||||
|
||||
void useAcceptProperties(Set<Pattern> acceptedProperties);
|
||||
|
||||
}
|
||||
|
||||
@@ -20,9 +20,12 @@ package com.opensymphony.xwork2.util;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
|
||||
import com.opensymphony.xwork2.inject.Container;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -241,13 +244,13 @@ public class TextParseUtil {
|
||||
/**
|
||||
* Tests if given string is not null and not empty when excluding of empty
|
||||
* elements is requested.
|
||||
*
|
||||
*
|
||||
* @param str String to check.
|
||||
* @param excludeEmptyElements Whether empty elements shall be excluded.
|
||||
* @return True if given string can be included in collection.
|
||||
*/
|
||||
private static boolean shallBeIncluded(String str, boolean excludeEmptyElements) {
|
||||
return !excludeEmptyElements || ((str != null) && (str.length() > 0));
|
||||
return !excludeEmptyElements || str != null && !str.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,14 +259,7 @@ public class TextParseUtil {
|
||||
* @return A set from comma delimited Strings.
|
||||
*/
|
||||
public static Set<String> commaDelimitedStringToSet(String s) {
|
||||
Set<String> set = new HashSet<>();
|
||||
String[] split = s.split(",");
|
||||
for (String aSplit : split) {
|
||||
String trimmed = aSplit.trim();
|
||||
if (trimmed.length() > 0)
|
||||
set.add(trimmed);
|
||||
}
|
||||
return set;
|
||||
return Arrays.stream(s.split(",")).map(String::trim).filter(s1 -> !s1.isEmpty()).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
||||
@@ -287,7 +283,7 @@ public class TextParseUtil {
|
||||
*
|
||||
* @author tm_jee
|
||||
*/
|
||||
public static interface ParsedValueEvaluator {
|
||||
public interface ParsedValueEvaluator {
|
||||
|
||||
/**
|
||||
* Evaluated the value parsed by Ognl value stack.
|
||||
|
||||
@@ -36,10 +36,9 @@ public class ApplicationMap extends AbstractMap<String, Object> implements Seria
|
||||
|
||||
private static final long serialVersionUID = 9136809763083228202L;
|
||||
|
||||
private ServletContext context;
|
||||
private final ServletContext context;
|
||||
private Set<Entry<String, Object>> entries;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new map object given the servlet context.
|
||||
*
|
||||
@@ -117,12 +116,16 @@ public class ApplicationMap extends AbstractMap<String, Object> implements Seria
|
||||
* @param key the entry key.
|
||||
* @return the servlet context attribute or init parameter or <tt>null</tt> if the entry is not found.
|
||||
*/
|
||||
public Object get(final String key) {
|
||||
@Override
|
||||
public Object get(final Object key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
// Try context attributes first, then init params
|
||||
// This gives the proper shadowing effects
|
||||
Object value = context.getAttribute(key);
|
||||
Object value = context.getAttribute(key.toString());
|
||||
|
||||
return (value == null) ? context.getInitParameter(key) : value;
|
||||
return (value == null) ? context.getInitParameter(key.toString()) : value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
public class HttpParameters implements Map<String, Parameter> {
|
||||
|
||||
final private Map<String, Parameter> parameters;
|
||||
|
||||
@@ -37,6 +37,7 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Builder create(Map requestParameterMap) {
|
||||
return new Builder(requestParameterMap);
|
||||
}
|
||||
@@ -47,7 +48,7 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
|
||||
public HttpParameters remove(Set<String> paramsToRemove) {
|
||||
for (String paramName : paramsToRemove) {
|
||||
parameters.remove(paramName);
|
||||
parameters.entrySet().removeIf(p -> p.getKey().equalsIgnoreCase(paramName));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -59,12 +60,15 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
}
|
||||
|
||||
public boolean contains(String name) {
|
||||
return parameters.containsKey(name);
|
||||
return parameters.keySet().stream().anyMatch(p -> p.equalsIgnoreCase(name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Access to this method can be potentially dangerous as it allows access to raw parameter values.
|
||||
*
|
||||
* @deprecated since 6.4.0, it will be removed with a new major release
|
||||
*/
|
||||
@Deprecated
|
||||
private Map<String, String[]> toMap() {
|
||||
final Map<String, String[]> result = new HashMap<>(parameters.size());
|
||||
for (Map.Entry<String, Parameter> entry : parameters.entrySet()) {
|
||||
@@ -73,7 +77,14 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all the parameters by overriding any existing params in a case-insensitive manner
|
||||
*
|
||||
* @param newParams A new params to append
|
||||
* @return a current instance of {@link HttpParameters}
|
||||
*/
|
||||
public HttpParameters appendAll(Map<String, Parameter> newParams) {
|
||||
remove(newParams.keySet());
|
||||
parameters.putAll(newParams);
|
||||
return this;
|
||||
}
|
||||
@@ -100,8 +111,11 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
|
||||
@Override
|
||||
public Parameter get(Object key) {
|
||||
if (parameters.containsKey(key)) {
|
||||
return parameters.get(key);
|
||||
if (key != null && contains(String.valueOf(key))) {
|
||||
return parameters.entrySet().stream()
|
||||
.filter(p -> p.getKey().equalsIgnoreCase(String.valueOf(key)))
|
||||
.findFirst().map(Entry::getValue)
|
||||
.orElse(new Parameter.Empty(String.valueOf(key)));
|
||||
} else {
|
||||
return new Parameter.Empty(String.valueOf(key));
|
||||
}
|
||||
@@ -177,8 +191,8 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
|
||||
public HttpParameters build() {
|
||||
Map<String, Parameter> parameters = (parent == null)
|
||||
? new HashMap<>()
|
||||
: new HashMap<>(parent.parameters);
|
||||
? new HashMap<>()
|
||||
: new HashMap<>(parent.parameters);
|
||||
|
||||
for (Map.Entry<String, Object> entry : requestParameterMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
@@ -197,8 +211,9 @@ public class HttpParameters implements Map<String, Parameter>, Cloneable {
|
||||
* Alternate Builder method which avoids wrapping any parameters that are already
|
||||
* a {@link Parameter} element within another {@link Parameter} wrapper.
|
||||
*
|
||||
* @return
|
||||
* @deprecated since 6.4.0, use {@link #build()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public HttpParameters buildNoNestedWrapping() {
|
||||
Map<String, Parameter> parameters = (parent == null)
|
||||
? new HashMap<>()
|
||||
|
||||
@@ -94,8 +94,12 @@ public class RequestMap extends AbstractMap<String, Object> implements Serializa
|
||||
* @param key the name of the request attribute.
|
||||
* @return the request attribute or <tt>null</tt> if it doesn't exist.
|
||||
*/
|
||||
public Object get(final String key) {
|
||||
return request.getAttribute(key);
|
||||
@Override
|
||||
public Object get(final Object key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
return request.getAttribute(key.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,7 @@ import java.io.OutputStream;
|
||||
* <li><b>bufferSize</b> - the size of the buffer to copy from input to output
|
||||
* (default = <code>1024</code>).</li>
|
||||
* <li><b>allowCaching</b> if set to 'false' it will set the headers 'Pragma' and 'Cache-Control'
|
||||
* to 'no-cahce', and prevent client from caching the content. (default = <code>true</code>)
|
||||
* to 'no-cache', and prevent client from caching the content. (default = <code>true</code>)
|
||||
* <li><b>contentCharSet</b> if set to a string, ';charset=value' will be added to the
|
||||
* content-type header, where value is the string set. If set to an expression, the result
|
||||
* of evaluating the expression will be used. If not set, then no charset will be set on
|
||||
|
||||
@@ -18,14 +18,16 @@
|
||||
*/
|
||||
package org.apache.struts2.util;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ObjectFactory;
|
||||
import com.opensymphony.xwork2.ognl.OgnlUtil;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import ognl.OgnlException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.views.jsp.ui.OgnlTool;
|
||||
import org.apache.struts2.views.util.UrlHelper;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
@@ -39,7 +41,16 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.text.MessageFormat.format;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
/**
|
||||
* Struts base utility class, for use in Velocity and Freemarker templates
|
||||
@@ -50,32 +61,30 @@ public class StrutsUtil {
|
||||
|
||||
protected HttpServletRequest request;
|
||||
protected HttpServletResponse response;
|
||||
protected Map<String, Class> classes = new Hashtable<>();
|
||||
protected OgnlTool ognl;
|
||||
protected Map<String, Class<?>> classes = new HashMap<>();
|
||||
protected OgnlUtil ognl;
|
||||
protected ValueStack stack;
|
||||
|
||||
private UrlHelper urlHelper;
|
||||
private ObjectFactory objectFactory;
|
||||
private final UrlHelper urlHelper;
|
||||
private final ObjectFactory objectFactory;
|
||||
|
||||
public StrutsUtil(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
|
||||
this.stack = stack;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.ognl = stack.getActionContext().getContainer().getInstance(OgnlTool.class);
|
||||
this.ognl = stack.getActionContext().getContainer().getInstance(OgnlUtil.class);
|
||||
this.urlHelper = stack.getActionContext().getContainer().getInstance(UrlHelper.class);
|
||||
this.objectFactory = stack.getActionContext().getContainer().getInstance(ObjectFactory.class);
|
||||
}
|
||||
|
||||
public Object bean(Object aName) throws Exception {
|
||||
String name = aName.toString();
|
||||
Class c = classes.get(name);
|
||||
|
||||
if (c == null) {
|
||||
c = ClassLoaderUtil.loadClass(name, StrutsUtil.class);
|
||||
classes.put(name, c);
|
||||
public Object bean(Object name) throws Exception {
|
||||
String className = name.toString();
|
||||
Class<?> clazz = classes.get(className);
|
||||
if (clazz == null) {
|
||||
clazz = ClassLoaderUtil.loadClass(className, StrutsUtil.class);
|
||||
classes.put(className, clazz);
|
||||
}
|
||||
|
||||
return objectFactory.buildBean(c, stack.getContext());
|
||||
return objectFactory.buildBean(clazz, stack.getContext());
|
||||
}
|
||||
|
||||
public boolean isTrue(String expression) {
|
||||
@@ -88,30 +97,20 @@ public class StrutsUtil {
|
||||
}
|
||||
|
||||
public String include(Object aName) throws Exception {
|
||||
try {
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher(aName.toString());
|
||||
|
||||
if (dispatcher == null) {
|
||||
throw new IllegalArgumentException("Cannot find included file " + aName);
|
||||
}
|
||||
|
||||
ResponseWrapper responseWrapper = new ResponseWrapper(response);
|
||||
|
||||
dispatcher.include(request, responseWrapper);
|
||||
|
||||
return responseWrapper.getData();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.debug("Cannot include {}", aName, e);
|
||||
throw e;
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher(aName.toString());
|
||||
if (dispatcher == null) {
|
||||
throw new IllegalArgumentException("Cannot find included file " + aName);
|
||||
}
|
||||
ResponseWrapper responseWrapper = new ResponseWrapper(response);
|
||||
dispatcher.include(request, responseWrapper);
|
||||
return responseWrapper.getData();
|
||||
}
|
||||
|
||||
public String urlEncode(String s) {
|
||||
try {
|
||||
return URLEncoder.encode(s, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOG.debug("Cannot encode URL [{}]", s, e);
|
||||
LOG.debug(format("Cannot encode URL [{0}]", s), e);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -124,6 +123,17 @@ public class StrutsUtil {
|
||||
return stack.findValue(expression, Class.forName(className));
|
||||
}
|
||||
|
||||
public Object findValue(String expr, Object context) {
|
||||
try {
|
||||
return ognl.getValue(expr, ActionContext.getContext().getContextMap(), context);
|
||||
} catch (OgnlException e) {
|
||||
if (e.getReason() instanceof SecurityException) {
|
||||
LOG.error(format("Could not evaluate this expression due to security constraints: [{0}]", expr), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getText(String text) {
|
||||
return (String) stack.findValue("getText('" + text.replace('\'', '"') + "')");
|
||||
}
|
||||
@@ -132,7 +142,7 @@ public class StrutsUtil {
|
||||
* @return the url ContextPath. An empty string if one does not exist.
|
||||
*/
|
||||
public String getContext() {
|
||||
return (request == null)? "" : request.getContextPath();
|
||||
return request == null ? "" : request.getContextPath();
|
||||
}
|
||||
|
||||
public String translateVariables(String expression) {
|
||||
@@ -156,71 +166,64 @@ public class StrutsUtil {
|
||||
* to use as the value of the ListEntry
|
||||
* @return a List of ListEntry
|
||||
*/
|
||||
public List makeSelectList(String selectedList, String list, String listKey, String listValue) {
|
||||
List selectList = new ArrayList();
|
||||
|
||||
Collection selectedItems = null;
|
||||
|
||||
Object i = stack.findValue(selectedList);
|
||||
|
||||
if (i != null) {
|
||||
if (i.getClass().isArray()) {
|
||||
selectedItems = Arrays.asList((Object[]) i);
|
||||
} else if (i instanceof Collection) {
|
||||
selectedItems = (Collection) i;
|
||||
} else {
|
||||
// treat it is a single item
|
||||
selectedItems = new ArrayList();
|
||||
selectedItems.add(i);
|
||||
}
|
||||
}
|
||||
public List<ListEntry> makeSelectList(String selectedList, String list, String listKey, String listValue) {
|
||||
List<ListEntry> selectList = new ArrayList<>();
|
||||
|
||||
Collection items = (Collection) stack.findValue(list);
|
||||
if (items == null) {
|
||||
return selectList;
|
||||
}
|
||||
|
||||
if (items != null) {
|
||||
for (Object element : items) {
|
||||
Object key;
|
||||
|
||||
if ((listKey == null) || (listKey.length() == 0)) {
|
||||
key = element;
|
||||
} else {
|
||||
key = ognl.findValue(listKey, element);
|
||||
}
|
||||
|
||||
Object value = null;
|
||||
|
||||
if ((listValue == null) || (listValue.length() == 0)) {
|
||||
value = element;
|
||||
} else {
|
||||
value = ognl.findValue(listValue, element);
|
||||
}
|
||||
|
||||
boolean isSelected = false;
|
||||
|
||||
if ((value != null) && (selectedItems != null) && selectedItems.contains(value)) {
|
||||
isSelected = true;
|
||||
}
|
||||
|
||||
selectList.add(new ListEntry(key, value, isSelected));
|
||||
}
|
||||
Collection selectedItems = getSelectedItems(selectedList);
|
||||
for (Object element : items) {
|
||||
Object key = computeKey(listKey, element);
|
||||
Object value = computeValue(listValue, element);
|
||||
boolean isSelected = value != null && selectedItems.contains(value);
|
||||
selectList.add(new ListEntry(key, value, isSelected));
|
||||
}
|
||||
|
||||
return selectList;
|
||||
}
|
||||
|
||||
private Collection getSelectedItems(String selectedListName) {
|
||||
Object i = stack.findValue(selectedListName);
|
||||
if (i == null) {
|
||||
return emptyList();
|
||||
}
|
||||
if (i.getClass().isArray()) {
|
||||
return Arrays.asList((Object[]) i);
|
||||
} else if (i instanceof Collection) {
|
||||
return (Collection) i;
|
||||
}
|
||||
return singletonList(i);
|
||||
}
|
||||
|
||||
private Object computeKey(String listKey, Object element) {
|
||||
if (listKey == null || listKey.isEmpty()) {
|
||||
return element;
|
||||
}
|
||||
return findValue(listKey, element);
|
||||
}
|
||||
|
||||
private Object computeValue(String listValue, Object element) {
|
||||
if (listValue == null || listValue.isEmpty()) {
|
||||
return element;
|
||||
}
|
||||
return findValue(listValue, element);
|
||||
}
|
||||
|
||||
public int toInt(long aLong) {
|
||||
return (int) aLong;
|
||||
}
|
||||
|
||||
public long toLong(int anInt) {
|
||||
return (long) anInt;
|
||||
return anInt;
|
||||
}
|
||||
|
||||
public long toLong(String aLong) {
|
||||
if (aLong == null) {
|
||||
if (aLong == null || aLong.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Long.parseLong(aLong);
|
||||
}
|
||||
|
||||
@@ -233,14 +236,7 @@ public class StrutsUtil {
|
||||
}
|
||||
|
||||
public String toStringSafe(Object obj) {
|
||||
try {
|
||||
if (obj != null) {
|
||||
return String.valueOf(obj);
|
||||
}
|
||||
return "";
|
||||
} catch (Exception e) {
|
||||
return "Exception thrown: " + e;
|
||||
}
|
||||
return obj == null ? "" : obj.toString();
|
||||
}
|
||||
|
||||
static class ResponseWrapper extends HttpServletResponseWrapper {
|
||||
@@ -257,7 +253,6 @@ public class StrutsUtil {
|
||||
|
||||
public String getData() {
|
||||
writer.flush();
|
||||
|
||||
return strout.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,16 +24,24 @@ import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import freemarker.cache.*;
|
||||
import freemarker.cache.ClassTemplateLoader;
|
||||
import freemarker.cache.FileTemplateLoader;
|
||||
import freemarker.cache.MultiTemplateLoader;
|
||||
import freemarker.cache.TemplateLoader;
|
||||
import freemarker.cache.WebappTemplateLoader;
|
||||
import freemarker.core.HTMLOutputFormat;
|
||||
import freemarker.core.OutputFormat;
|
||||
import freemarker.core.TemplateClassResolver;
|
||||
import freemarker.ext.jsp.TaglibFactory;
|
||||
import freemarker.ext.servlet.HttpRequestHashModel;
|
||||
import freemarker.ext.servlet.HttpRequestParametersHashModel;
|
||||
import freemarker.ext.servlet.HttpSessionHashModel;
|
||||
import freemarker.ext.servlet.ServletContextHashModel;
|
||||
import freemarker.template.*;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.ObjectWrapper;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateExceptionHandler;
|
||||
import freemarker.template.TemplateModel;
|
||||
import freemarker.template.Version;
|
||||
import freemarker.template.utility.StringUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -51,7 +59,13 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -176,27 +190,27 @@ public class FreemarkerManager {
|
||||
public void setEncoding(String encoding) {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
|
||||
@Inject(StrutsConstants.STRUTS_FREEMARKER_WRAPPER_ALT_MAP)
|
||||
public void setWrapperAltMap(String val) {
|
||||
altMapWrapper = "true".equals(val);
|
||||
}
|
||||
|
||||
|
||||
@Inject(StrutsConstants.STRUTS_FREEMARKER_BEANWRAPPER_CACHE)
|
||||
public void setCacheBeanWrapper(String val) {
|
||||
cacheBeanWrapper = "true".equals(val);
|
||||
}
|
||||
|
||||
|
||||
@Inject(StrutsConstants.STRUTS_FREEMARKER_MRU_MAX_STRONG_SIZE)
|
||||
public void setMruMaxStrongSize(String size) {
|
||||
mruMaxStrongSize = Integer.parseInt(size);
|
||||
}
|
||||
|
||||
|
||||
@Inject(value = StrutsConstants.STRUTS_FREEMARKER_TEMPLATES_CACHE_UPDATE_DELAY, required = false)
|
||||
public void setTemplateUpdateDelay(String delay) {
|
||||
templateUpdateDelay = delay;
|
||||
}
|
||||
|
||||
|
||||
@Inject
|
||||
public void setContainer(Container container) {
|
||||
Map<String, TagLibraryModelProvider> map = new HashMap<>();
|
||||
@@ -281,8 +295,8 @@ public class FreemarkerManager {
|
||||
loadSettings(servletContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Freemarker Configuration's template loader with the FreemarkerThemeTemplateLoader
|
||||
/**
|
||||
* Sets the Freemarker Configuration's template loader with the FreemarkerThemeTemplateLoader
|
||||
* at the top.
|
||||
*
|
||||
* @param templateLoader the template loader
|
||||
@@ -293,7 +307,7 @@ public class FreemarkerManager {
|
||||
themeTemplateLoader.init(templateLoader);
|
||||
config.setTemplateLoader(themeTemplateLoader);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the instance of the freemarker Configuration object.
|
||||
* <p>
|
||||
@@ -543,7 +557,7 @@ public class FreemarkerManager {
|
||||
|
||||
protected void populateContext(ScopesHashModel model, ValueStack stack, Object action, HttpServletRequest request, HttpServletResponse response) {
|
||||
// put the same objects into the context that the velocity result uses
|
||||
Map standard = ContextUtil.getStandardContext(stack, request, response);
|
||||
Map<String, Object> standard = ContextUtil.getStandardContext(stack, request, response);
|
||||
model.putAll(standard);
|
||||
|
||||
// support for JSP exception pages, exposing the servlet or JSP exception
|
||||
|
||||
@@ -45,11 +45,9 @@ public class TagUtils {
|
||||
"Please read https://struts.apache.org/security/#never-expose-jsp-files-directly");
|
||||
} else {
|
||||
LOG.trace("Adds the current PageContext to ActionContext");
|
||||
AttributeMap attrMap = new AttributeMap(stack.getContext());
|
||||
|
||||
stack.getActionContext()
|
||||
.withPageContext(pageContext)
|
||||
.with("attr", attrMap);
|
||||
.with("attr", new AttributeMap(stack.getContext()));
|
||||
}
|
||||
|
||||
return stack;
|
||||
|
||||
@@ -19,16 +19,16 @@
|
||||
package org.apache.struts2.views.jsp.ui;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import ognl.OgnlException;
|
||||
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.ognl.OgnlUtil;
|
||||
import ognl.OgnlException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* FIXME: remove?
|
||||
* @deprecated since 6.3.0. Use {@link org.apache.struts2.util.StrutsUtil} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class OgnlTool {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(OgnlTool.class);
|
||||
@@ -43,6 +43,10 @@ public class OgnlTool {
|
||||
this.ognlUtil = ognlUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 6.3.0. Use {@link org.apache.struts2.util.StrutsUtil#findValue(String, Object)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Object findValue(String expr, Object context) {
|
||||
try {
|
||||
return ognlUtil.getValue(expr, ActionContext.getContext().getContextMap(), context);
|
||||
|
||||
@@ -18,12 +18,9 @@
|
||||
*/
|
||||
package org.apache.struts2.views.util;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.util.StrutsUtil;
|
||||
import org.apache.struts2.views.jsp.ui.OgnlTool;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -50,8 +47,9 @@ public class ContextUtil {
|
||||
map.put(SESSION, req.getSession(false));
|
||||
map.put(BASE, req.getContextPath());
|
||||
map.put(STACK, stack);
|
||||
map.put(OGNL, stack.getActionContext().getContainer().getInstance(OgnlTool.class));
|
||||
map.put(STRUTS, new StrutsUtil(stack, req, res));
|
||||
StrutsUtil util = new StrutsUtil(stack, req, res);
|
||||
map.put(STRUTS, util);
|
||||
map.put(OGNL, util); // Deprecated since 6.3.0
|
||||
|
||||
ActionInvocation invocation = stack.getActionContext().getActionInvocation();
|
||||
if (invocation != null) {
|
||||
|
||||
@@ -198,6 +198,7 @@
|
||||
<bean type="ognl.MethodAccessor" name="com.opensymphony.xwork2.util.CompoundRoot"
|
||||
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/>
|
||||
|
||||
<!-- Deprecated since 6.3.0, inject OgnlUtil directly instead, or use StrutsUtil -->
|
||||
<bean class="org.apache.struts2.views.jsp.ui.OgnlTool"/>
|
||||
|
||||
<bean type="org.apache.struts2.dispatcher.StaticContentLoader"
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
@@ -55,52 +55,52 @@
|
||||
<!-- constant name="struts.excludedPackageNamePatterns" value="^java\.lang\..*,^ognl.*,^(?!javax\.servlet\..+)(javax\..+)" / -->
|
||||
<!-- constant name="struts.devMode.excludedPackageNamePatterns" value="^java\.lang\..*,^ognl.*,^(?!javax\.servlet\..+)(javax\..+)" / -->
|
||||
|
||||
<!-- this is simpler version of the above used with string comparison -->
|
||||
<!-- All classes within the following packages and their sub-packages are excluded -->
|
||||
<constant name="struts.excludedPackageNames"
|
||||
value="
|
||||
ognl.,
|
||||
java.io.,
|
||||
java.net.,
|
||||
java.nio.,
|
||||
javax.,
|
||||
freemarker.core.,
|
||||
freemarker.template.,
|
||||
freemarker.ext.jsp.,
|
||||
freemarker.ext.rhino.,
|
||||
sun.misc.,
|
||||
sun.reflect.,
|
||||
javassist.,
|
||||
org.apache.velocity.,
|
||||
org.objectweb.asm.,
|
||||
org.springframework.context.,
|
||||
com.opensymphony.xwork2.inject.,
|
||||
com.opensymphony.xwork2.ognl.,
|
||||
com.opensymphony.xwork2.security.,
|
||||
com.opensymphony.xwork2.util.,
|
||||
org.apache.tomcat.,
|
||||
org.apache.catalina.core.,
|
||||
org.wildfly.extension.undertow.deployment."/>
|
||||
ognl,
|
||||
java.io,
|
||||
java.net,
|
||||
java.nio,
|
||||
javax,
|
||||
freemarker.core,
|
||||
freemarker.template,
|
||||
freemarker.ext.jsp,
|
||||
freemarker.ext.rhino,
|
||||
sun.misc,
|
||||
sun.reflect,
|
||||
javassist,
|
||||
org.apache.velocity,
|
||||
org.objectweb.asm,
|
||||
org.springframework.context,
|
||||
com.opensymphony.xwork2.inject,
|
||||
com.opensymphony.xwork2.ognl,
|
||||
com.opensymphony.xwork2.security,
|
||||
com.opensymphony.xwork2.util,
|
||||
org.apache.tomcat,
|
||||
org.apache.catalina.core,
|
||||
org.wildfly.extension.undertow.deployment"/>
|
||||
|
||||
<constant name="struts.devMode.excludedPackageNames"
|
||||
value="
|
||||
ognl.,
|
||||
java.io.,
|
||||
java.net.,
|
||||
java.nio.,
|
||||
javax.,
|
||||
freemarker.core.,
|
||||
freemarker.template.,
|
||||
freemarker.ext.jsp.,
|
||||
freemarker.ext.rhino.,
|
||||
sun.misc.,
|
||||
sun.reflect.,
|
||||
javassist.,
|
||||
org.apache.velocity.,
|
||||
org.objectweb.asm.,
|
||||
org.springframework.context.,
|
||||
com.opensymphony.xwork2.inject.,
|
||||
com.opensymphony.xwork2.ognl.,
|
||||
com.opensymphony.xwork2.security.,
|
||||
com.opensymphony.xwork2.util."/>
|
||||
ognl,
|
||||
java.io,
|
||||
java.net,
|
||||
java.nio,
|
||||
javax,
|
||||
freemarker.core,
|
||||
freemarker.template,
|
||||
freemarker.ext.jsp,
|
||||
freemarker.ext.rhino,
|
||||
sun.misc,
|
||||
sun.reflect,
|
||||
javassist,
|
||||
org.apache.velocity,
|
||||
org.objectweb.asm,
|
||||
org.springframework.context,
|
||||
com.opensymphony.xwork2.inject,
|
||||
com.opensymphony.xwork2.ognl,
|
||||
com.opensymphony.xwork2.security,
|
||||
com.opensymphony.xwork2.util"/>
|
||||
|
||||
</struts>
|
||||
|
||||
@@ -33,5 +33,5 @@
|
||||
#end
|
||||
|
||||
#macro(property $object $property)
|
||||
$!{ognl.findValue($property, $object)}
|
||||
$!{struts.findValue($property, $object)}
|
||||
#end
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.opensymphony.xwork2.util.Owner;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.location.LocatableProperties;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
|
||||
import java.beans.BeanInfo;
|
||||
import ognl.InappropriateExpressionException;
|
||||
import ognl.MethodFailedException;
|
||||
import ognl.NoSuchPropertyException;
|
||||
@@ -48,6 +47,7 @@ import ognl.SimpleNode;
|
||||
import org.apache.struts2.StrutsConstants;
|
||||
import org.apache.struts2.StrutsException;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DateFormat;
|
||||
@@ -64,6 +64,8 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class OgnlUtilTest extends XWorkTestCase {
|
||||
|
||||
// Fields for static field access test
|
||||
@@ -877,6 +879,33 @@ public class OgnlUtilTest extends XWorkTestCase {
|
||||
assertEquals(123, foo.getALong());
|
||||
}
|
||||
|
||||
public void testBeanMapExpressions() throws OgnlException, NoSuchMethodException {
|
||||
Foo foo = new Foo();
|
||||
ognlUtil.setExcludedPackageNames(
|
||||
"com.opensymphony.xwork2.ognl."
|
||||
);
|
||||
|
||||
Map<String, Object> context = ognlUtil.createDefaultContext(foo);
|
||||
|
||||
String expression = "%{\n" +
|
||||
"(#request.a=#@org.apache.commons.collections.BeanMap@{}) +\n" +
|
||||
"(#request.a.setBean(#request.get('struts.valueStack')) == true) +\n" +
|
||||
"(#request.b=#@org.apache.commons.collections.BeanMap@{}) +\n" +
|
||||
"(#request.b.setBean(#request.get('a').get('context'))) +\n" +
|
||||
"(#request.c=#@org.apache.commons.collections.BeanMap@{}) +\n" +
|
||||
"(#request.c.setBean(#request.get('b').get('memberAccess'))) +\n" +
|
||||
"(#request.get('c').put('excluded'+'PackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet())) +\n" +
|
||||
"(#request.get('c').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()))\n" +
|
||||
"}";
|
||||
|
||||
ognlUtil.setValue("title", context, foo, expression);
|
||||
|
||||
assertEquals(foo.getTitle(), expression);
|
||||
|
||||
SecurityMemberAccess sma = (SecurityMemberAccess) ((OgnlContext) context).getMemberAccess();
|
||||
assertFalse(sma.isAccessible(context, sma, sma.getClass().getDeclaredMethod("setExcludedClasses", Set.class), "excludedClasses"));
|
||||
}
|
||||
|
||||
public void testNullProperties() {
|
||||
Foo foo = new Foo();
|
||||
foo.setALong(88);
|
||||
@@ -1685,6 +1714,13 @@ public class OgnlUtilTest extends XWorkTestCase {
|
||||
assertSame(that, root);
|
||||
}
|
||||
|
||||
public void testSetExcludedPackageNames() {
|
||||
assertThrows(ConfigurationException.class, () -> ognlUtil.setExcludedPackageNames("java.lang\njava.awt"));
|
||||
assertThrows(ConfigurationException.class, () -> ognlUtil.setExcludedPackageNames("java.lang\tjava.awt"));
|
||||
ConfigurationException e = assertThrows(ConfigurationException.class, () -> ognlUtil.setExcludedPackageNames("java.lang java.awt"));
|
||||
assertTrue(e.getMessage().contains("erroneous whitespace characters"));
|
||||
}
|
||||
|
||||
public void testGetExcludedPackageNames() {
|
||||
// Getter should return an immutable collection
|
||||
OgnlUtil util = new OgnlUtil();
|
||||
@@ -1701,7 +1737,7 @@ public class OgnlUtilTest extends XWorkTestCase {
|
||||
|
||||
public void testGetExcludedPackageNamesAlternateConstructorPopulated() {
|
||||
// Getter should return an immutable collection
|
||||
OgnlUtil util = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<String, Object>(), new DefaultOgnlBeanInfoCacheFactory<Class<?>, BeanInfo>());
|
||||
OgnlUtil util = new OgnlUtil(new DefaultOgnlExpressionCacheFactory<>(), new DefaultOgnlBeanInfoCacheFactory<>());
|
||||
util.setExcludedPackageNames("java.lang,java.awt");
|
||||
assertEquals(util.getExcludedPackageNames().size(), 2);
|
||||
try {
|
||||
@@ -1834,19 +1870,19 @@ public class OgnlUtilTest extends XWorkTestCase {
|
||||
defaultOgnlCacheFactory.setUseLRUCache("false");
|
||||
ognlCache = defaultOgnlCacheFactory.buildOgnlCache();
|
||||
assertNotNull("No param build method result null ?", ognlCache);
|
||||
assertEquals("Eviction limit for cache mismatches limit for factory ?", 12, ognlCache.getEvictionLimit() );
|
||||
assertEquals("Eviction limit for cache mismatches limit for factory ?", 12, ognlCache.getEvictionLimit());
|
||||
ognlCache = defaultOgnlCacheFactory.buildOgnlCache(6, 6, 0.75f, false);
|
||||
assertNotNull("No param build method result null ?", ognlCache);
|
||||
assertEquals("Eviction limit for cache mismatches limit for factory ?", 6, ognlCache.getEvictionLimit() );
|
||||
assertEquals("Eviction limit for cache mismatches limit for factory ?", 6, ognlCache.getEvictionLimit());
|
||||
// LRU cache
|
||||
defaultOgnlCacheFactory.setCacheMaxSize("30");
|
||||
defaultOgnlCacheFactory.setUseLRUCache("true");
|
||||
ognlCache = defaultOgnlCacheFactory.buildOgnlCache();
|
||||
assertNotNull("No param build method result null ?", ognlCache);
|
||||
assertEquals("Eviction limit for cache mismatches limit for factory ?", 30, ognlCache.getEvictionLimit() );
|
||||
assertEquals("Eviction limit for cache mismatches limit for factory ?", 30, ognlCache.getEvictionLimit());
|
||||
ognlCache = defaultOgnlCacheFactory.buildOgnlCache(15, 15, 0.75f, false);
|
||||
assertNotNull("No param build method result null ?", ognlCache);
|
||||
assertEquals("Eviction limit for cache mismatches limit for factory ?", 15, ognlCache.getEvictionLimit() );
|
||||
assertEquals("Eviction limit for cache mismatches limit for factory ?", 15, ognlCache.getEvictionLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,7 +75,7 @@ public class SecurityMemberAccessTest {
|
||||
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
excluded.add(FooBar.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
sma.useExcludedClasses(excluded);
|
||||
|
||||
// when
|
||||
boolean accessible = sma.isAccessible(context, target, member, propertyName);
|
||||
@@ -118,7 +118,7 @@ public class SecurityMemberAccessTest {
|
||||
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
excluded.add(BarInterface.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
sma.useExcludedClasses(excluded);
|
||||
|
||||
// when
|
||||
boolean accessible = sma.isAccessible(context, target, member, propertyName);
|
||||
@@ -135,7 +135,7 @@ public class SecurityMemberAccessTest {
|
||||
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
excluded.add(BarInterface.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
sma.useExcludedClasses(excluded);
|
||||
|
||||
// when
|
||||
boolean accessible = sma.isAccessible(context, target, member, propertyName);
|
||||
@@ -152,7 +152,7 @@ public class SecurityMemberAccessTest {
|
||||
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
excluded.add(BarInterface.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
sma.useExcludedClasses(excluded);
|
||||
|
||||
// when
|
||||
boolean accessible = sma.isAccessible(context, target, member, propertyName);
|
||||
@@ -169,7 +169,7 @@ public class SecurityMemberAccessTest {
|
||||
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
excluded.add(FooInterface.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
sma.useExcludedClasses(excluded);
|
||||
|
||||
// when
|
||||
boolean accessible = sma.isAccessible(context, target, member, propertyName);
|
||||
@@ -178,29 +178,12 @@ public class SecurityMemberAccessTest {
|
||||
assertTrue("barLogic() from BarInterface isn't accessible!!!", accessible);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMiddleOfInheritanceExclusion4() throws Exception {
|
||||
// given
|
||||
String propertyName = "barLogic";
|
||||
Member member = BarInterface.class.getMethod(propertyName);
|
||||
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
excluded.add(FooBarInterface.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
|
||||
// when
|
||||
boolean accessible = sma.isAccessible(context, target, member, propertyName);
|
||||
|
||||
// then
|
||||
assertFalse("barLogic() from BarInterface is accessible!!!", accessible);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageExclusion() throws Exception {
|
||||
// given
|
||||
Set<Pattern> excluded = new HashSet<>();
|
||||
excluded.add(Pattern.compile("^" + FooBar.class.getPackage().getName().replaceAll("\\.", "\\\\.") + ".*"));
|
||||
sma.setExcludedPackageNamePatterns(excluded);
|
||||
sma.useExcludedPackageNamePatterns(excluded);
|
||||
|
||||
String propertyName = "stringField";
|
||||
Member member = FooBar.class.getMethod(formGetterName(propertyName));
|
||||
@@ -217,11 +200,11 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<Pattern> excluded = new HashSet<>();
|
||||
excluded.add(Pattern.compile("^" + FooBar.class.getPackage().getName().replaceAll("\\.", "\\\\.") + ".*"));
|
||||
sma.setExcludedPackageNamePatterns(excluded);
|
||||
sma.useExcludedPackageNamePatterns(excluded);
|
||||
|
||||
Set<Class<?>> allowed = new HashSet<>();
|
||||
allowed.add(FooBar.class);
|
||||
sma.setExcludedPackageExemptClasses(allowed);
|
||||
sma.useExcludedPackageExemptClasses(allowed);
|
||||
|
||||
String propertyName = "stringField";
|
||||
Member member = FooBar.class.getMethod(formGetterName(propertyName));
|
||||
@@ -238,7 +221,7 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<String> excluded = new HashSet<>();
|
||||
excluded.add(FooBar.class.getPackage().getName());
|
||||
sma.setExcludedPackageNames(excluded);
|
||||
sma.useExcludedPackageNames(excluded);
|
||||
|
||||
String propertyName = "stringField";
|
||||
Member member = FooBar.class.getMethod(formGetterName(propertyName));
|
||||
@@ -255,11 +238,11 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<String> excluded = new HashSet<>();
|
||||
excluded.add(FooBar.class.getPackage().getName());
|
||||
sma.setExcludedPackageNames(excluded);
|
||||
sma.useExcludedPackageNames(excluded);
|
||||
|
||||
Set<Class<?>> allowed = new HashSet<>();
|
||||
allowed.add(FooBar.class);
|
||||
sma.setExcludedPackageExemptClasses(allowed);
|
||||
sma.useExcludedPackageExemptClasses(allowed);
|
||||
|
||||
String propertyName = "stringField";
|
||||
Member member = FooBar.class.getMethod(formGetterName(propertyName));
|
||||
@@ -276,12 +259,12 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<String> excluded = new HashSet<>();
|
||||
excluded.add(FooBar.class.getPackage().getName());
|
||||
sma.setExcludedPackageNames(excluded);
|
||||
sma.useExcludedPackageNames(excluded);
|
||||
|
||||
// Exemption must exist for both classes (target and member) if they both match a banned package
|
||||
Set<Class<?>> allowed = new HashSet<>();
|
||||
allowed.add(BarInterface.class);
|
||||
sma.setExcludedPackageExemptClasses(allowed);
|
||||
sma.useExcludedPackageExemptClasses(allowed);
|
||||
|
||||
String propertyName = "barLogic";
|
||||
Member member = BarInterface.class.getMethod(propertyName);
|
||||
@@ -298,13 +281,13 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<String> excluded = new HashSet<>();
|
||||
excluded.add(FooBar.class.getPackage().getName());
|
||||
sma.setExcludedPackageNames(excluded);
|
||||
sma.useExcludedPackageNames(excluded);
|
||||
|
||||
// Exemption must exist for both classes (target and member) if they both match a banned package
|
||||
Set<Class<?>> allowed = new HashSet<>();
|
||||
allowed.add(BarInterface.class);
|
||||
allowed.add(FooBar.class);
|
||||
sma.setExcludedPackageExemptClasses(allowed);
|
||||
sma.useExcludedPackageExemptClasses(allowed);
|
||||
|
||||
String propertyName = "barLogic";
|
||||
Member member = BarInterface.class.getMethod(propertyName);
|
||||
@@ -321,7 +304,7 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<Pattern> excluded = new HashSet<>();
|
||||
excluded.add(Pattern.compile("^" + FooBar.class.getPackage().getName().replaceAll("\\.", "\\\\.") + ".*"));
|
||||
sma.setExcludedPackageNamePatterns(excluded);
|
||||
sma.useExcludedPackageNamePatterns(excluded);
|
||||
|
||||
Class<?> clazz = Class.forName("PackagelessAction");
|
||||
|
||||
@@ -337,7 +320,7 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<Pattern> excluded = new HashSet<>();
|
||||
excluded.add(Pattern.compile("^$"));
|
||||
sma.setExcludedPackageNamePatterns(excluded);
|
||||
sma.useExcludedPackageNamePatterns(excluded);
|
||||
|
||||
Class<?> clazz = Class.forName("PackagelessAction");
|
||||
|
||||
@@ -361,7 +344,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testAccessStaticMethod() throws Exception {
|
||||
// given
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
Member method = StaticTester.class.getMethod("sayHello");
|
||||
@@ -374,7 +357,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testAccessStaticField() throws Exception {
|
||||
// given
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
Member method = StaticTester.class.getField("MAX_VALUE");
|
||||
@@ -388,7 +371,7 @@ public class SecurityMemberAccessTest {
|
||||
public void testBlockedStaticFieldWhenFlagIsTrue() throws Exception {
|
||||
// given
|
||||
assignNewSma(true);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
Member method = StaticTester.class.getField("MAX_VALUE");
|
||||
@@ -400,7 +383,7 @@ public class SecurityMemberAccessTest {
|
||||
// public static final test
|
||||
// given
|
||||
assignNewSma(true);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.class.getField("MIN_VALUE");
|
||||
@@ -412,7 +395,7 @@ public class SecurityMemberAccessTest {
|
||||
// package static test
|
||||
// given
|
||||
assignNewSma(true);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("PACKAGE_STRING");
|
||||
@@ -424,7 +407,7 @@ public class SecurityMemberAccessTest {
|
||||
// package final static test
|
||||
// given
|
||||
assignNewSma(true);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("FINAL_PACKAGE_STRING");
|
||||
@@ -436,7 +419,7 @@ public class SecurityMemberAccessTest {
|
||||
// protected static test
|
||||
// given
|
||||
assignNewSma(true);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("PROTECTED_STRING");
|
||||
@@ -448,7 +431,7 @@ public class SecurityMemberAccessTest {
|
||||
// protected final static test
|
||||
// given
|
||||
assignNewSma(true);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("FINAL_PROTECTED_STRING");
|
||||
@@ -460,7 +443,7 @@ public class SecurityMemberAccessTest {
|
||||
// private static test
|
||||
// given
|
||||
assignNewSma(true);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("PRIVATE_STRING");
|
||||
@@ -472,7 +455,7 @@ public class SecurityMemberAccessTest {
|
||||
// private final static test
|
||||
// given
|
||||
assignNewSma(true);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("FINAL_PRIVATE_STRING");
|
||||
@@ -486,7 +469,7 @@ public class SecurityMemberAccessTest {
|
||||
public void testBlockedStaticFieldWhenFlagIsFalse() throws Exception {
|
||||
// given
|
||||
assignNewSma(false);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
Member method = StaticTester.class.getField("MAX_VALUE");
|
||||
@@ -498,7 +481,7 @@ public class SecurityMemberAccessTest {
|
||||
// public static final test
|
||||
// given
|
||||
assignNewSma(false);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.class.getField("MIN_VALUE");
|
||||
@@ -510,7 +493,7 @@ public class SecurityMemberAccessTest {
|
||||
// package static test
|
||||
// given
|
||||
assignNewSma(false);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("PACKAGE_STRING");
|
||||
@@ -522,7 +505,7 @@ public class SecurityMemberAccessTest {
|
||||
// package final static test
|
||||
// given
|
||||
assignNewSma(false);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("FINAL_PACKAGE_STRING");
|
||||
@@ -534,7 +517,7 @@ public class SecurityMemberAccessTest {
|
||||
// protected static test
|
||||
// given
|
||||
assignNewSma(false);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("PROTECTED_STRING");
|
||||
@@ -546,7 +529,7 @@ public class SecurityMemberAccessTest {
|
||||
// protected final static test
|
||||
// given
|
||||
assignNewSma(false);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("FINAL_PROTECTED_STRING");
|
||||
@@ -558,7 +541,7 @@ public class SecurityMemberAccessTest {
|
||||
// private static test
|
||||
// given
|
||||
assignNewSma(false);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("PRIVATE_STRING");
|
||||
@@ -570,7 +553,7 @@ public class SecurityMemberAccessTest {
|
||||
// private final static test
|
||||
// given
|
||||
assignNewSma(false);
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
method = StaticTester.getFieldByName("FINAL_PRIVATE_STRING");
|
||||
@@ -583,7 +566,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testBlockedStaticFieldWhenClassIsExcluded() throws Exception {
|
||||
// given
|
||||
sma.setExcludedClasses(new HashSet<>(Arrays.asList(Class.class, StaticTester.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Arrays.asList(Class.class, StaticTester.class)));
|
||||
|
||||
// when
|
||||
Member method = StaticTester.class.getField("MAX_VALUE");
|
||||
@@ -596,7 +579,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testBlockStaticMethodAccess() throws Exception {
|
||||
// given
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
Member method = StaticTester.class.getMethod("sayHello");
|
||||
@@ -609,7 +592,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testBlockAccessIfClassIsExcluded() throws Exception {
|
||||
// given
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
Member method = Class.class.getMethod("getClassLoader");
|
||||
@@ -622,7 +605,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testBlockAccessIfClassIsExcluded_2() throws Exception {
|
||||
// given
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(ClassLoader.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(ClassLoader.class)));
|
||||
|
||||
// when
|
||||
Member method = ClassLoader.class.getMethod("loadClass", String.class);
|
||||
@@ -636,7 +619,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testAllowAccessIfClassIsNotExcluded() throws Exception {
|
||||
// given
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(ClassLoader.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(ClassLoader.class)));
|
||||
|
||||
// when
|
||||
Member method = Class.class.getMethod("getClassLoader");
|
||||
@@ -649,7 +632,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testIllegalArgumentExceptionExpectedForTargetMemberMismatch() throws Exception {
|
||||
// given
|
||||
sma.setExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
sma.useExcludedClasses(new HashSet<>(Collections.singletonList(Class.class)));
|
||||
|
||||
// when
|
||||
Member method = ClassLoader.class.getMethod("loadClass", String.class);
|
||||
@@ -668,7 +651,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testAccessPrimitiveInt() throws Exception {
|
||||
// given
|
||||
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang.,ognl,javax"));
|
||||
sma.useExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang.,ognl,javax"));
|
||||
|
||||
String propertyName = "intField";
|
||||
Member member = FooBar.class.getMethod(formGetterName(propertyName));
|
||||
@@ -683,7 +666,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testAccessPrimitiveDoubleWithNames() throws Exception {
|
||||
// given
|
||||
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("ognl.,javax."));
|
||||
sma.useExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("ognl.,javax."));
|
||||
|
||||
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
@@ -692,7 +675,7 @@ public class SecurityMemberAccessTest {
|
||||
excluded.add(System.class);
|
||||
excluded.add(Class.class);
|
||||
excluded.add(ClassLoader.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
sma.useExcludedClasses(excluded);
|
||||
|
||||
String propertyName = "doubleValue";
|
||||
double myDouble = 1;
|
||||
@@ -738,7 +721,7 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<Pattern> patterns = new HashSet<>();
|
||||
patterns.add(Pattern.compile("^java\\.lang\\..*"));
|
||||
sma.setExcludedPackageNamePatterns(patterns);
|
||||
sma.useExcludedPackageNamePatterns(patterns);
|
||||
|
||||
String propertyName = "doubleValue";
|
||||
double myDouble = 1;
|
||||
@@ -756,7 +739,7 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
excluded.add(ognl.MemberAccess.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
sma.useExcludedClasses(excluded);
|
||||
|
||||
String propertyName = "excludedClasses";
|
||||
String setter = "setExcludedClasses";
|
||||
@@ -774,7 +757,7 @@ public class SecurityMemberAccessTest {
|
||||
// given
|
||||
Set<Class<?>> excluded = new HashSet<>();
|
||||
excluded.add(SecurityMemberAccess.class);
|
||||
sma.setExcludedClasses(excluded);
|
||||
sma.useExcludedClasses(excluded);
|
||||
|
||||
String propertyName = "excludedClasses";
|
||||
String setter = "setExcludedClasses";
|
||||
@@ -790,7 +773,7 @@ public class SecurityMemberAccessTest {
|
||||
@Test
|
||||
public void testPackageNameExclusionAsCommaDelimited() {
|
||||
// given
|
||||
sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang."));
|
||||
sma.useExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang"));
|
||||
|
||||
// when
|
||||
boolean actual = sma.isPackageExcluded(String.class, String.class);
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.dispatcher;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class ApplicationMapTest {
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveAttribute() {
|
||||
// given
|
||||
ServletContext context = new MockServletContext();
|
||||
context.setAttribute("attr", "value");
|
||||
|
||||
// when
|
||||
ApplicationMap am = new ApplicationMap(context);
|
||||
Object value = am.get("attr");
|
||||
|
||||
// then
|
||||
assertEquals("value", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullIfKeyIsNull() {
|
||||
// given
|
||||
ServletContext context = new MockServletContext();
|
||||
|
||||
// when
|
||||
ApplicationMap am = new ApplicationMap(context);
|
||||
Object value = am.get(null);
|
||||
|
||||
// then
|
||||
assertNull(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveAttributeFromServletContext() {
|
||||
// given
|
||||
ServletContext context = new MockServletContext();
|
||||
context.setAttribute("attr", "value");
|
||||
|
||||
// when
|
||||
ApplicationMap am = new ApplicationMap(context);
|
||||
Object value = am.remove("attr");
|
||||
|
||||
// then
|
||||
assertEquals("value", value);
|
||||
assertNull(context.getAttribute("attr"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldClearAttributes() {
|
||||
// given
|
||||
ServletContext context = new MockServletContext();
|
||||
context.setAttribute("attr", "value");
|
||||
|
||||
// when
|
||||
ApplicationMap am = new ApplicationMap(context);
|
||||
Object value = am.get("attr");
|
||||
|
||||
// then
|
||||
assertEquals("value", value);
|
||||
|
||||
// when
|
||||
am.clear();
|
||||
|
||||
// then
|
||||
assertNull(context.getAttribute("attr"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.dispatcher;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class HttpParametersTest {
|
||||
|
||||
@Test
|
||||
public void shouldGetBeCaseInsensitive() {
|
||||
// given
|
||||
HttpParameters params = HttpParameters.create(new HashMap<String, Object>() {{
|
||||
put("param1", "value1");
|
||||
}}).build();
|
||||
|
||||
// then
|
||||
assertEquals("value1", params.get("Param1").getValue());
|
||||
assertEquals("value1", params.get("paraM1").getValue());
|
||||
assertEquals("value1", params.get("pAraM1").getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAppendSameParamsIgnoringCase() {
|
||||
// given
|
||||
HttpParameters params = HttpParameters.create(new HashMap<String, Object>() {{
|
||||
put("param1", "value1");
|
||||
}}).build();
|
||||
|
||||
// when
|
||||
assertEquals("value1", params.get("param1").getValue());
|
||||
|
||||
params = params.appendAll(HttpParameters.create(new HashMap<String, String>() {{
|
||||
put("Param1", "Value1");
|
||||
}}).build());
|
||||
|
||||
// then
|
||||
assertTrue(params.contains("param1"));
|
||||
assertTrue(params.contains("Param1"));
|
||||
|
||||
assertEquals("Value1", params.get("param1").getValue());
|
||||
assertEquals("Value1", params.get("Param1").getValue());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.dispatcher;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class RequestMapTest {
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveRequestAttribute() {
|
||||
// given
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setAttribute("attr", "value");
|
||||
|
||||
// when
|
||||
RequestMap rm = new RequestMap(request);
|
||||
Object value = rm.get("attr");
|
||||
|
||||
// then
|
||||
assertEquals("value", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullIfKeyIsNull() {
|
||||
// given
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
// when
|
||||
RequestMap rm = new RequestMap(request);
|
||||
Object value = rm.get(null);
|
||||
|
||||
// then
|
||||
assertNull(value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveAttributeFromRequest() {
|
||||
// given
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setAttribute("attr", "value");
|
||||
|
||||
// when
|
||||
RequestMap rm = new RequestMap(request);
|
||||
Object value = rm.remove("attr");
|
||||
|
||||
// then
|
||||
assertEquals("value", value);
|
||||
assertNull(request.getAttribute("attr"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldClearAttributes() {
|
||||
// given
|
||||
HttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setAttribute("attr", "value");
|
||||
|
||||
// when
|
||||
RequestMap rm = new RequestMap(request);
|
||||
Object value = rm.get("attr");
|
||||
|
||||
// then
|
||||
assertEquals("value", value);
|
||||
|
||||
// when
|
||||
rm.clear();
|
||||
|
||||
// then
|
||||
assertNull(request.getAttribute("attr"));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class StrutsBackgroundProcessTest extends StrutsInternalTestCase {
|
||||
executor.execute(bp);
|
||||
}
|
||||
|
||||
Thread.sleep(400);
|
||||
Thread.sleep(500);
|
||||
|
||||
for (BackgroundProcess bp : bps) {
|
||||
assertTrue("Process is still active: " + bp, bp.isDone());
|
||||
|
||||
@@ -45,7 +45,7 @@ public class SecurityMemberAccessInServletsTest extends StrutsInternalTestCase {
|
||||
|
||||
Set<Pattern> excluded = new HashSet<Pattern>();
|
||||
excluded.add(Pattern.compile("^(?!javax\\.servlet\\..+)(javax\\..+)"));
|
||||
sma.setExcludedPackageNamePatterns(excluded);
|
||||
sma.useExcludedPackageNamePatterns(excluded);
|
||||
|
||||
String propertyName = "value";
|
||||
Member member = TagSupport.class.getMethod("doStartTag");
|
||||
@@ -63,7 +63,7 @@ public class SecurityMemberAccessInServletsTest extends StrutsInternalTestCase {
|
||||
|
||||
Set<Pattern> excluded = new HashSet<>();
|
||||
excluded.add(Pattern.compile("^javax\\..+"));
|
||||
sma.setExcludedPackageNamePatterns(excluded);
|
||||
sma.useExcludedPackageNamePatterns(excluded);
|
||||
|
||||
String propertyName = "value";
|
||||
Member member = TagSupport.class.getMethod("doStartTag");
|
||||
|
||||
@@ -29,9 +29,12 @@ import org.springframework.mock.web.MockRequestDispatcher;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test case for StrutsUtil.
|
||||
*
|
||||
@@ -145,28 +148,63 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
|
||||
public void testMakeSelectListMethod() {
|
||||
String[] selectedList = new String[] { "Car", "Airplane", "Bus" };
|
||||
List list = new ArrayList();
|
||||
list.add("Lorry");
|
||||
list.add("Car");
|
||||
list.add("Helicopter");
|
||||
public void testMakeSelectList() {
|
||||
String[] selectedList = new String[]{"Car", "Airplane", "Bus"}; // Array
|
||||
List<String> list = Arrays.asList("Lorry", "Car", "Helicopter");
|
||||
|
||||
stack.getContext().put("mySelectedList", selectedList);
|
||||
stack.getContext().put("myList", list);
|
||||
|
||||
List listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
|
||||
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
|
||||
|
||||
assertEquals(listMade.size(), 3);
|
||||
assertEquals(((ListEntry)listMade.get(0)).getKey(), "Lorry");
|
||||
assertEquals(((ListEntry)listMade.get(0)).getValue(), "Lorry");
|
||||
assertFalse(((ListEntry) listMade.get(0)).getIsSelected());
|
||||
assertEquals(((ListEntry)listMade.get(1)).getKey(), "Car");
|
||||
assertEquals(((ListEntry)listMade.get(1)).getValue(), "Car");
|
||||
assertTrue(((ListEntry) listMade.get(1)).getIsSelected());
|
||||
assertEquals(((ListEntry)listMade.get(2)).getKey(), "Helicopter");
|
||||
assertEquals(((ListEntry)listMade.get(2)).getValue(), "Helicopter");
|
||||
assertFalse(((ListEntry) listMade.get(2)).getIsSelected());
|
||||
LinkedHashMap<String, Boolean> expectedItems = new LinkedHashMap<>();
|
||||
expectedItems.put("Lorry", false);
|
||||
expectedItems.put("Car", true);
|
||||
expectedItems.put("Helicopter", false);
|
||||
makeSelectListCommonAssertions(listMade, expectedItems);
|
||||
}
|
||||
|
||||
public void testMakeSelectListCollection() {
|
||||
List<String> selectedList = Arrays.asList("Airplane", "Helicopter", "Bus"); // Collection
|
||||
List<String> list = Arrays.asList("Lorry", "Car", "Helicopter");
|
||||
|
||||
stack.getContext().put("mySelectedList", selectedList);
|
||||
stack.getContext().put("myList", list);
|
||||
|
||||
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
|
||||
|
||||
LinkedHashMap<String, Boolean> expectedItems = new LinkedHashMap<>();
|
||||
expectedItems.put("Lorry", false);
|
||||
expectedItems.put("Car", false);
|
||||
expectedItems.put("Helicopter", true);
|
||||
makeSelectListCommonAssertions(listMade, expectedItems);
|
||||
}
|
||||
|
||||
public void testMakeSelectListSingleton() {
|
||||
String selectedItem = "Lorry"; // Singleton
|
||||
List<String> list = Arrays.asList("Lorry", "Car", "Helicopter");
|
||||
|
||||
stack.getContext().put("mySelectedList", selectedItem);
|
||||
stack.getContext().put("myList", list);
|
||||
|
||||
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null);
|
||||
|
||||
LinkedHashMap<String, Boolean> expectedItems = new LinkedHashMap<>();
|
||||
expectedItems.put("Lorry", true);
|
||||
expectedItems.put("Car", false);
|
||||
expectedItems.put("Helicopter", false);
|
||||
makeSelectListCommonAssertions(listMade, expectedItems);
|
||||
}
|
||||
|
||||
private void makeSelectListCommonAssertions(List<ListEntry> listMade, LinkedHashMap<String, Boolean> expectedItems) {
|
||||
assertThat(listMade).extracting("key").containsExactly(expectedItems.keySet().toArray());
|
||||
assertThat(listMade).extracting("value").containsExactly(expectedItems.keySet().toArray());
|
||||
assertThat(listMade).extracting("isSelected").containsExactly(expectedItems.values().toArray());
|
||||
}
|
||||
|
||||
public void testMakeSelectListNonExistent() {
|
||||
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#nonexistent", null, null);
|
||||
assertThat(listMade).isEmpty();
|
||||
}
|
||||
|
||||
public void testToInt() {
|
||||
@@ -178,12 +216,22 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
|
||||
assertEquals(strutsUtil.toLong(11), 11L);
|
||||
}
|
||||
|
||||
public void testStringToLong() {
|
||||
assertEquals(11L, strutsUtil.toLong("11"));
|
||||
assertEquals(0L, strutsUtil.toLong(null));
|
||||
assertEquals(0L, strutsUtil.toLong(""));
|
||||
}
|
||||
|
||||
public void testToString() {
|
||||
assertEquals(strutsUtil.toString(1), "1");
|
||||
assertEquals(strutsUtil.toString(11L), "11");
|
||||
}
|
||||
|
||||
public void testToStringSafe() {
|
||||
assertEquals("1", strutsUtil.toStringSafe(1));
|
||||
assertEquals("", strutsUtil.toStringSafe(null));
|
||||
}
|
||||
|
||||
public void testTranslateVariables() {
|
||||
stack.push(new Object() {
|
||||
public String getFoo() {
|
||||
@@ -233,7 +281,7 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
|
||||
|
||||
// === internal class to assist in testing
|
||||
|
||||
static class InternalMockHttpServletRequest extends MockHttpServletRequest {
|
||||
protected static class InternalMockHttpServletRequest extends MockHttpServletRequest {
|
||||
InternalMockRequestDispatcher dispatcher = null;
|
||||
public RequestDispatcher getRequestDispatcher(String path) {
|
||||
dispatcher = new InternalMockRequestDispatcher(path);
|
||||
@@ -245,8 +293,8 @@ public class StrutsUtilTest extends StrutsInternalTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
static class InternalMockRequestDispatcher extends MockRequestDispatcher {
|
||||
private String url;
|
||||
protected static class InternalMockRequestDispatcher extends MockRequestDispatcher {
|
||||
private final String url;
|
||||
boolean included = false;
|
||||
public InternalMockRequestDispatcher(String url) {
|
||||
super(url);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-async-plugin</artifactId>
|
||||
@@ -36,13 +36,6 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mockobjects</groupId>
|
||||
<artifactId>mockobjects-core</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -55,17 +55,6 @@
|
||||
<artifactId>javax.el</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- this library is excluded in the parent pom as it clashes with Easymock dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.objenesis</groupId>
|
||||
<artifactId>objenesis</artifactId>
|
||||
<version>3.2</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
The Java EE API modules listed below are all marked @Deprecated(forRemoval=true), because they are scheduled
|
||||
@@ -88,7 +77,7 @@
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-impl</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<version>2.3.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
+1
-8
@@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-cdi-plugin</artifactId>
|
||||
@@ -58,13 +58,6 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-config-browser-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-convention-plugin</artifactId>
|
||||
@@ -49,10 +49,6 @@
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
@@ -63,15 +59,25 @@
|
||||
</dependency>
|
||||
|
||||
<!-- testing -->
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-junit-plugin</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
+3
-2
@@ -21,9 +21,10 @@ package actions;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
* Example action, which is called by the convention plugin test case
|
||||
* Example action, called by {@link org.apache.struts2.convention.ConventionJUnit4Test}.
|
||||
* Result defined by message-success.ftl.
|
||||
*/
|
||||
public class ViewAction extends ActionSupport {
|
||||
public class MessageAction extends ActionSupport {
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
+5
-6
@@ -16,9 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.junit.convention;
|
||||
package org.apache.struts2.convention;
|
||||
|
||||
import actions.ViewAction;
|
||||
import actions.MessageAction;
|
||||
import org.apache.struts2.junit.StrutsJUnit4TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -28,17 +28,17 @@ import static org.junit.Assert.assertTrue;
|
||||
/**
|
||||
* Uses the convention plugin to execute actions
|
||||
*/
|
||||
public class StrutsJUnit4ConventionTestCaseTest extends StrutsJUnit4TestCase<ViewAction> {
|
||||
public class ConventionJUnit4Test extends StrutsJUnit4TestCase<MessageAction> {
|
||||
|
||||
@Test
|
||||
public void testConventionUrl() throws Exception {
|
||||
// Output is filled out only for FreeMarker and Velocity templates
|
||||
// If you wanna use JSP check response.getForwardedUrl()
|
||||
String output = executeAction("/view.action");
|
||||
String output = executeAction("/message.action");
|
||||
|
||||
assertTrue(output.contains("This is the view Hello World"));
|
||||
|
||||
ViewAction action = this.getAction();
|
||||
MessageAction action = this.getAction();
|
||||
assertEquals("Hello World", action.getMessage());
|
||||
}
|
||||
|
||||
@@ -48,6 +48,5 @@ public class StrutsJUnit4ConventionTestCaseTest extends StrutsJUnit4TestCase<Vie
|
||||
// struts-convention-configuration.xml overrides some settings from plugin to allow work in limited environment
|
||||
return "struts-plugin.xml,struts-convention-configuration.xml";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-8
@@ -25,14 +25,7 @@
|
||||
"https://struts.apache.org/dtds/struts-6.0.dtd">
|
||||
|
||||
<struts>
|
||||
|
||||
<!-- result is defined in test/resources -->
|
||||
<constant name="struts.convention.result.path" value="/"/>
|
||||
|
||||
<!-- This is needed as there is struts2-spring-plugin on classpath -->
|
||||
<constant name="struts.objectFactory" value="struts"/>
|
||||
|
||||
<package name="convention-default" extends="struts-default">
|
||||
</package>
|
||||
|
||||
<package name="convention-default" extends="struts-default"/>
|
||||
</struts>
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-dwr-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-embeddedjsp-plugin</artifactId>
|
||||
@@ -32,10 +32,6 @@
|
||||
<name>DEPRECATED: Struts 2 Embedded JSP Plugin, since 6.0.0</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-velocity-plugin</artifactId>
|
||||
@@ -65,11 +61,6 @@
|
||||
<artifactId>request</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-juli</artifactId>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-gxp-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-jasperreports-plugin</artifactId>
|
||||
@@ -32,14 +32,10 @@
|
||||
<name>Struts 2 Jasper Reports Plugin</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.jasperreports</groupId>
|
||||
<artifactId>jasperreports</artifactId>
|
||||
<version>6.19.1</version>
|
||||
<version>6.20.5</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<!-- not necessary to compile and it force dependency convergence issues -->
|
||||
@@ -62,11 +58,6 @@
|
||||
<artifactId>struts2-junit-plugin</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-javatemplates-plugin</artifactId>
|
||||
@@ -33,14 +33,6 @@
|
||||
<name>Struts 2 Java Templates Plugin</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-jfreechart-plugin</artifactId>
|
||||
@@ -61,11 +61,6 @@
|
||||
<artifactId>struts2-junit-plugin</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
|
||||
+1
-23
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-json-plugin</artifactId>
|
||||
@@ -54,22 +54,6 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
@@ -99,12 +83,6 @@
|
||||
<artifactId>spring-web</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
# Struts 2 JFreeChart plugin
|
||||
# Struts 2 JUnit plugin
|
||||
The JUnit Plugin supports testing actions within a Struts invocation, meaning that a full request is simulated,
|
||||
and the output of the action can be tested.
|
||||
You will find more details in [documentation](https://struts.apache.org/plugins/junit/).
|
||||
|
||||
## Installation
|
||||
Just drop this plugin JAR into `WEB-INF/lib` folder or add it as a Maven dependency.
|
||||
|
||||
+1
-33
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-junit-plugin</artifactId>
|
||||
@@ -49,42 +49,10 @@
|
||||
<artifactId>struts2-spring-plugin</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Convention Plugin tests -->
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-convention-plugin</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Portlet -->
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-mocks-plugin</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -19,13 +19,9 @@
|
||||
package org.apache.struts2.junit;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
@@ -64,38 +60,4 @@ public class StrutsTestCaseTest extends StrutsSpringTestCase {
|
||||
String name = (String) findValueAfterExecute("name");
|
||||
assertEquals("FD", name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPortletContextBeAvailable() throws Exception {
|
||||
// given
|
||||
assertNull(ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT));
|
||||
|
||||
// when
|
||||
String output = executeAction("/test/testAction.action");
|
||||
assertEquals("Hello", output);
|
||||
|
||||
// then
|
||||
Object portletContext = ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
|
||||
assertNotNull(portletContext);
|
||||
assertTrue(portletContext instanceof PortletContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAdditionalContextParamsBeAvailable() throws Exception {
|
||||
// given
|
||||
String key = "my-param";
|
||||
assertNull(ActionContext.getContext().get(key));
|
||||
|
||||
// when
|
||||
String output = executeAction("/test/testAction.action");
|
||||
assertEquals("Hello", output);
|
||||
|
||||
// then
|
||||
assertNotNull(ActionContext.getContext().get(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyAdditionalParams(ActionContext context) {
|
||||
context.put("my-param", new Object());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-15
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-osgi-plugin</artifactId>
|
||||
@@ -38,7 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>osgi.core</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<version>8.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -84,11 +84,6 @@
|
||||
<artifactId>struts2-velocity-plugin</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-digester</groupId>
|
||||
<artifactId>commons-digester</artifactId>
|
||||
@@ -105,14 +100,6 @@
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j2.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-oval-plugin</artifactId>
|
||||
@@ -49,11 +49,6 @@
|
||||
<artifactId>xstream</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>persistence-api</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-pell-multipart-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-plexus-plugin</artifactId>
|
||||
|
||||
+24
-1
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-parent</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
@@ -50,6 +50,7 @@
|
||||
<module>pell-multipart</module>
|
||||
<module>plexus</module>
|
||||
<module>portlet</module>
|
||||
<module>portlet-junit</module>
|
||||
<module>portlet-mocks</module>
|
||||
<module>portlet-tiles</module>
|
||||
<module>rest</module>
|
||||
@@ -66,6 +67,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Test dependencies -->
|
||||
@@ -74,7 +76,28 @@
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# Struts 2 Portlet JUnit plugin
|
||||
The Portlet JUnit Plugin supports testing applications that use the Portlet Plugin.
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-junit-plugin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>DEPRECATED: Struts 2 Portlet JUnit Plugin - since 6.3.0</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-junit-plugin</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-mocks-plugin</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
+1
-14
@@ -35,19 +35,6 @@ import javax.portlet.PortletMode;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
* Changes: This is a copy of org.apache.struts2.StrutsPortletTestCase from the Struts 2 portlet-plugin, moved
|
||||
* into the junit-plugin (same package org.apache.struts2).
|
||||
* The import order above was changed to alphabetical.
|
||||
*
|
||||
* Note: The assumption is that anyone utilizing StrutsPortletTestCase currently from the portlet-plugin will almost
|
||||
* certainly be using the junit-plugin. Under that assumption, the refactored-move of StrutsPortletTestCase
|
||||
* should not cause issues for pre-existing usage of StrutsPortletTestCase.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base class used to test action in portlet environment
|
||||
*/
|
||||
public abstract class StrutsPortletTestCase extends StrutsTestCase {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(StrutsPortletTestCase.class);
|
||||
@@ -95,7 +82,7 @@ public abstract class StrutsPortletTestCase extends StrutsTestCase {
|
||||
* @return Map with session parameters
|
||||
*/
|
||||
private Map<String, Object> createSession() {
|
||||
return new HashMap<String, Object>(portletRequest.getPortletSession().getAttributeMap());
|
||||
return new HashMap<>(portletRequest.getPortletSession().getAttributeMap());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
-->
|
||||
<project name="Apache Struts">
|
||||
<skin>
|
||||
<groupId>org.apache.maven.skins</groupId>
|
||||
<artifactId>maven-fluido-skin</artifactId>
|
||||
<version>${fluido-skin.version}</version>
|
||||
</skin>
|
||||
<bannerLeft>
|
||||
<name>Apache Software Foundation</name>
|
||||
<src>http://www.apache.org/images/asf-logo.gif</src>
|
||||
<href>http://www.apache.org/</href>
|
||||
</bannerLeft>
|
||||
<bannerRight>
|
||||
<name>Apache Struts</name>
|
||||
<src>http://struts.apache.org/img/struts-logo.svg</src>
|
||||
<href>http://struts.apache.org/</href>
|
||||
</bannerRight>
|
||||
<publishDate position="left"/>
|
||||
<version position="right"/>
|
||||
<body>
|
||||
<links>
|
||||
<item name="Apache" href="http://www.apache.org/"/>
|
||||
<item name="Struts" href="http://struts.apache.org/"/>
|
||||
</links>
|
||||
|
||||
<menu ref="parent"/>
|
||||
<menu ref="reports"/>
|
||||
|
||||
<footer>
|
||||
<![CDATA[<div class="row span12">
|
||||
Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project
|
||||
logos are trademarks of The Apache Software Foundation.
|
||||
</div>]]>
|
||||
</footer>
|
||||
</body>
|
||||
</project>
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.junit;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
|
||||
public class StrutsPortletTestCaseTest extends StrutsPortletTestCase {
|
||||
|
||||
String KEY = "my-param";
|
||||
|
||||
public void testShouldPortletContextBeAvailable() throws Exception {
|
||||
// given
|
||||
assertNull(ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT));
|
||||
|
||||
// when
|
||||
ActionProxy proxy = getActionProxy("/test/testAction.action");
|
||||
String result = proxy.execute();
|
||||
|
||||
// then
|
||||
assertEquals(Action.SUCCESS, result);
|
||||
Object portletContext = ActionContext.getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
|
||||
assertNotNull(portletContext);
|
||||
assertTrue(portletContext instanceof PortletContext);
|
||||
}
|
||||
|
||||
public void testShouldAdditionalContextParamsBeAvailable() throws Exception {
|
||||
// given
|
||||
assertNull(ActionContext.getContext().get(KEY));
|
||||
|
||||
// when
|
||||
ActionProxy proxy = getActionProxy("/test/testAction.action");
|
||||
String result = proxy.execute();
|
||||
|
||||
// then
|
||||
assertEquals(Action.SUCCESS, result);
|
||||
assertNotNull(ActionContext.getContext().get(KEY));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyAdditionalParams(ActionContext context) {
|
||||
context.put(KEY, new Object());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!--
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
-->
|
||||
<!DOCTYPE struts PUBLIC
|
||||
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
|
||||
"https://struts.apache.org/dtds/struts-2.1.dtd">
|
||||
|
||||
<struts>
|
||||
<package name="test" namespace="/test" extends="struts-default">
|
||||
<action name="testAction" class="com.opensymphony.xwork2.ActionSupport">
|
||||
<result name="success" type="httpheader">
|
||||
<param name="status">200</param>
|
||||
</result>
|
||||
</action>
|
||||
</package>
|
||||
</struts>
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-mocks-plugin</artifactId>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<parent>
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-plugins</artifactId>
|
||||
<version>6.2.0-SNAPSHOT</version>
|
||||
<version>6.3.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>struts2-portlet-tiles-plugin</artifactId>
|
||||
@@ -40,24 +40,15 @@
|
||||
<groupId>org.apache.struts</groupId>
|
||||
<artifactId>struts2-portlet-plugin</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-request-portlet</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet.jsp</groupId>
|
||||
<artifactId>jsp-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.portlet</groupId>
|
||||
<artifactId>portlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tiles</groupId>
|
||||
<artifactId>tiles-jsp</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
|
||||
+3
-3
@@ -22,9 +22,9 @@ import com.opensymphony.xwork2.ActionInvocation;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.portlet.context.PortletActionContext;
|
||||
import org.apache.struts2.result.ServletDispatcherResult;
|
||||
import org.apache.tiles.TilesContainer;
|
||||
import org.apache.tiles.TilesException;
|
||||
import org.apache.tiles.access.TilesAccess;
|
||||
import org.apache.tiles.api.TilesContainer;
|
||||
import org.apache.tiles.api.TilesException;
|
||||
import org.apache.tiles.api.access.TilesAccess;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.portlet.RenderPortletRequest;
|
||||
|
||||
+344
@@ -0,0 +1,344 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet;
|
||||
|
||||
import org.apache.tiles.request.AbstractClientRequest;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.attribute.Addable;
|
||||
import org.apache.tiles.request.collection.HeaderValuesMap;
|
||||
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
|
||||
import org.apache.tiles.request.collection.ScopeMap;
|
||||
import org.apache.tiles.request.portlet.delegate.RequestDelegate;
|
||||
import org.apache.tiles.request.portlet.delegate.ResponseDelegate;
|
||||
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
|
||||
import org.apache.tiles.request.portlet.extractor.RequestScopeExtractor;
|
||||
import org.apache.tiles.request.portlet.extractor.SessionScopeExtractor;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletRequestDispatcher;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.PortletSession;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Portlet-based TilesApplicationContext implementation.
|
||||
*/
|
||||
public class PortletRequest extends AbstractClientRequest {
|
||||
|
||||
/**
|
||||
* The native available scopes.
|
||||
*/
|
||||
private static final List<String> SCOPES = Collections.unmodifiableList(Arrays.asList(REQUEST_SCOPE, "portletSession", "session", APPLICATION_SCOPE));
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of header name-value
|
||||
* combinations (immutable).</p>
|
||||
*/
|
||||
private Map<String, String> header = null;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of header name-value
|
||||
* combinations (write-only).</p>
|
||||
*/
|
||||
private Addable<String> responseHeaders = null;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of header name-values
|
||||
* combinations (immutable).</p>
|
||||
*/
|
||||
private Map<String, String[]> headerValues = null;
|
||||
|
||||
/**
|
||||
* The <code>PortletContext</code> for this application.
|
||||
*/
|
||||
protected PortletContext context;
|
||||
|
||||
/**
|
||||
* <p>The <code>PortletRequest</code> for this request.</p>
|
||||
*/
|
||||
protected javax.portlet.PortletRequest request;
|
||||
|
||||
/**
|
||||
* The delegate to get information about parameters.
|
||||
*/
|
||||
protected RequestDelegate requestDelegate;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of request scope
|
||||
* attributes.</p>
|
||||
*/
|
||||
private Map<String, Object> requestScope = null;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The <code>PortletResponse</code> for this request.</p>
|
||||
*/
|
||||
protected PortletResponse response;
|
||||
|
||||
/**
|
||||
* The delegate to get information from a response (output stream, writer, etc.).
|
||||
*/
|
||||
protected ResponseDelegate responseDelegate;
|
||||
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of session scope
|
||||
* attributes.</p>
|
||||
*/
|
||||
private Map<String, Object> sessionScope = null;
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of portlet session scope
|
||||
* attributes.</p>
|
||||
*/
|
||||
private Map<String, Object> portletSessionScope = null;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of PortletTilesRequestContext.
|
||||
*
|
||||
* @param applicationContext The Tiles application context.
|
||||
* @param context The portlet context to use.
|
||||
* @param request The request object to use.
|
||||
* @param response The response object to use.
|
||||
* @param requestDelegate The request delegate.
|
||||
* @param responseDelegate The response delegate.
|
||||
*/
|
||||
public PortletRequest(ApplicationContext applicationContext,
|
||||
PortletContext context, javax.portlet.PortletRequest request,
|
||||
PortletResponse response, RequestDelegate requestDelegate, ResponseDelegate responseDelegate) {
|
||||
super(applicationContext);
|
||||
|
||||
// Save the specified Portlet API object references
|
||||
this.context = context;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.requestDelegate = requestDelegate;
|
||||
this.responseDelegate = responseDelegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Return the {@link PortletRequest} for this context.</p>
|
||||
*
|
||||
* @return The used portlet request.
|
||||
*/
|
||||
public javax.portlet.PortletRequest getRequest() {
|
||||
return (this.request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the portlet context.
|
||||
*
|
||||
* @return The portlet context.
|
||||
*/
|
||||
public PortletContext getPortletContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, String> getHeader() {
|
||||
if ((header == null) && (request != null)) {
|
||||
header = new ReadOnlyEnumerationMap<>(new HeaderExtractor(request, null));
|
||||
}
|
||||
return (header);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Addable<String> getResponseHeaders() {
|
||||
if ((responseHeaders == null) && (request != null)) {
|
||||
responseHeaders = new HeaderExtractor(null, response);
|
||||
}
|
||||
return (responseHeaders);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, String[]> getHeaderValues() {
|
||||
if ((headerValues == null) && (request != null)) {
|
||||
headerValues = new HeaderValuesMap(new HeaderExtractor(request, response));
|
||||
}
|
||||
return (headerValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, Object> getRequestScope() {
|
||||
if ((requestScope == null) && (request != null)) {
|
||||
requestScope = new ScopeMap(new RequestScopeExtractor(request));
|
||||
}
|
||||
return (requestScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, Object> getSessionScope() {
|
||||
if ((sessionScope == null) && (request != null)) {
|
||||
sessionScope = new ScopeMap(new SessionScopeExtractor(request,
|
||||
PortletSession.APPLICATION_SCOPE));
|
||||
}
|
||||
return (sessionScope);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, Object> getPortletSessionScope() {
|
||||
if ((portletSessionScope == null) && (request != null)) {
|
||||
portletSessionScope = new ScopeMap(new SessionScopeExtractor(
|
||||
request, PortletSession.APPLICATION_SCOPE));
|
||||
}
|
||||
return (portletSessionScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAvailableScopes() {
|
||||
return SCOPES;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Locale getRequestLocale() {
|
||||
return request.getLocale();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getParam() {
|
||||
return requestDelegate.getParam();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String[]> getParamValues() {
|
||||
return requestDelegate.getParamValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public boolean isUserInRole(String role) {
|
||||
return request.isUserInRole(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return responseDelegate.getOutputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintWriter getPrintWriter() throws IOException {
|
||||
return responseDelegate.getPrintWriter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Writer getWriter() throws IOException {
|
||||
return responseDelegate.getWriter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isResponseCommitted() {
|
||||
return responseDelegate.isResponseCommitted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String contentType) {
|
||||
responseDelegate.setContentType(contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void doForward(String path) throws IOException {
|
||||
if (responseDelegate.isResponseCommitted()) {
|
||||
doInclude(path);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
PortletRequestDispatcher rd = getPortletContext()
|
||||
.getRequestDispatcher(path);
|
||||
|
||||
if (rd == null) {
|
||||
throw new IOException(
|
||||
"No portlet request dispatcher returned for path '"
|
||||
+ path + "'");
|
||||
}
|
||||
|
||||
rd.forward(request, response);
|
||||
} catch (PortletException e) {
|
||||
throw new IOException("PortletException while including path '"
|
||||
+ path + "'.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void doInclude(String path) throws IOException {
|
||||
try {
|
||||
PortletRequestDispatcher rd = getPortletContext()
|
||||
.getRequestDispatcher(path);
|
||||
|
||||
if (rd == null) {
|
||||
throw new IOException(
|
||||
"No portlet request dispatcher returned for path '"
|
||||
+ path + "'");
|
||||
}
|
||||
|
||||
rd.include(request, response);
|
||||
} catch (PortletException e) {
|
||||
throw new IOException("PortletException while including path '"
|
||||
+ path + "'.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getContext(String scope) {
|
||||
if (REQUEST_SCOPE.equals(scope)) {
|
||||
return getRequestScope();
|
||||
} else if ("session".equals(scope)) {
|
||||
return getSessionScope();
|
||||
} else if ("portletSession".equals(scope)) {
|
||||
return getPortletSessionScope();
|
||||
} else if (APPLICATION_SCOPE.equals(scope)) {
|
||||
return getApplicationScope();
|
||||
}
|
||||
throw new IllegalArgumentException(scope + " does not exist. Call getAvailableScopes() first to check.");
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet;
|
||||
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.portlet.delegate.MimeResponseDelegate;
|
||||
import org.apache.tiles.request.portlet.delegate.PortletRequestDelegate;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
|
||||
/**
|
||||
* Portlet request for a {@link RenderRequest}.
|
||||
*/
|
||||
public class RenderPortletRequest extends PortletRequest {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param applicationContext The application context.
|
||||
* @param context The portlet context.
|
||||
* @param request The portlet request.
|
||||
* @param response The portlet response.
|
||||
*/
|
||||
public RenderPortletRequest(ApplicationContext applicationContext, PortletContext context, RenderRequest request, RenderResponse response) {
|
||||
super(applicationContext, context, request, response, new PortletRequestDelegate(request), new MimeResponseDelegate(response));
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import javax.portlet.MimeResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Response delegate in case of {@link MimeResponse}.
|
||||
*/
|
||||
public class MimeResponseDelegate implements ResponseDelegate {
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private final MimeResponse response;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param response The response.
|
||||
*/
|
||||
public MimeResponseDelegate(MimeResponse response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
return response.getPortletOutputStream();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public PrintWriter getPrintWriter() throws IOException {
|
||||
return response.getWriter();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public Writer getWriter() throws IOException {
|
||||
return response.getWriter();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public boolean isResponseCommitted() {
|
||||
return response.isCommitted();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void setContentType(String contentType) {
|
||||
response.setContentType(contentType);
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
|
||||
import org.apache.tiles.request.portlet.extractor.ParameterExtractor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Request delegate in case of simple Portlet request.
|
||||
*/
|
||||
public class PortletRequestDelegate implements RequestDelegate {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of request
|
||||
* parameter name-value.</p>
|
||||
*/
|
||||
private Map<String, String> param = null;
|
||||
|
||||
/**
|
||||
* <p>The lazily instantiated <code>Map</code> of request
|
||||
* parameter name-values.</p>
|
||||
*/
|
||||
private Map<String, String[]> paramValues = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The request.
|
||||
*/
|
||||
public PortletRequestDelegate(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, String> getParam() {
|
||||
if ((param == null) && (request != null)) {
|
||||
param = new ReadOnlyEnumerationMap<>(new ParameterExtractor(request));
|
||||
}
|
||||
return (param);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public Map<String, String[]> getParamValues() {
|
||||
if ((paramValues == null) && (request != null)) {
|
||||
paramValues = request.getParameterMap();
|
||||
}
|
||||
return (paramValues);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Exposes the parameters of a portlet request, if available.
|
||||
*/
|
||||
public interface RequestDelegate {
|
||||
|
||||
/**
|
||||
* The parameters, as single values.
|
||||
*
|
||||
* @return The parameters.
|
||||
*/
|
||||
Map<String, String> getParam();
|
||||
|
||||
/**
|
||||
* The parameters, with values as array of strings.
|
||||
*
|
||||
* @return The parameters.
|
||||
*/
|
||||
Map<String, String[]> getParamValues();
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Exposes features of a response, if they are available.
|
||||
*/
|
||||
public interface ResponseDelegate {
|
||||
|
||||
/**
|
||||
* Returns the output stream.
|
||||
*
|
||||
* @return The output stream.
|
||||
* @throws IOException If the underlying response causes a problem.
|
||||
*/
|
||||
OutputStream getOutputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the print writer.
|
||||
*
|
||||
* @return The print writer.
|
||||
* @throws IOException If the underlying response causes a problem.
|
||||
*/
|
||||
PrintWriter getPrintWriter() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the writer.
|
||||
*
|
||||
* @return The writer.
|
||||
* @throws IOException If the underlying response causes a problem.
|
||||
*/
|
||||
Writer getWriter() throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the content type of the response.
|
||||
*
|
||||
* @param contentType The content type.
|
||||
*/
|
||||
void setContentType(String contentType);
|
||||
|
||||
/**
|
||||
* Checks if the response is committed.
|
||||
*
|
||||
* @return <code>true</code> if the response is committed.
|
||||
*/
|
||||
boolean isResponseCommitted();
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
/**
|
||||
* Delegations to map all the different types of request and responses.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.delegate;
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.AttributeExtractor;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts attributes from portlet application scope.
|
||||
*/
|
||||
public class ApplicationScopeExtractor implements AttributeExtractor {
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private final PortletContext context;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param context The portlet context.
|
||||
*/
|
||||
public ApplicationScopeExtractor(PortletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String name, Object value) {
|
||||
context.setAttribute(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String name) {
|
||||
context.removeAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return context.getAttributeNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String key) {
|
||||
return context.getAttribute(key);
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.EnumeratedValuesExtractor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts and puts headers in portlet requests and responses.
|
||||
*/
|
||||
public class HeaderExtractor implements EnumeratedValuesExtractor {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private final PortletResponse response;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The request.
|
||||
* @param response The response.
|
||||
*/
|
||||
public HeaderExtractor(PortletRequest request, PortletResponse response) {
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return request.getPropertyNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String key) {
|
||||
return request.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getValues(String key) {
|
||||
return request.getProperties(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String key, String value) {
|
||||
response.setProperty(key, value);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.HasKeys;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts init parameters from a portlet context.
|
||||
*/
|
||||
public class InitParameterExtractor implements HasKeys<String> {
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private final PortletContext context;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param context The portlet context.
|
||||
*/
|
||||
public InitParameterExtractor(PortletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return context.getInitParameterNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String key) {
|
||||
return context.getInitParameter(key);
|
||||
}
|
||||
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.HasKeys;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts parameters from a portlet request.
|
||||
*/
|
||||
public class ParameterExtractor implements HasKeys<String> {
|
||||
|
||||
/**
|
||||
* The portlet request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The portlet request.
|
||||
*/
|
||||
public ParameterExtractor(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return request.getParameterNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(String key) {
|
||||
return request.getParameter(key);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.AttributeExtractor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts attributes from request scope of a portlet request.
|
||||
*/
|
||||
public class RequestScopeExtractor implements AttributeExtractor {
|
||||
|
||||
/**
|
||||
* The portlet request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The portlet request.
|
||||
*/
|
||||
public RequestScopeExtractor(PortletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String name, Object value) {
|
||||
request.setAttribute(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String name) {
|
||||
request.removeAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
return request.getAttributeNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String key) {
|
||||
return request.getAttribute(key);
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.AttributeExtractor;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletSession;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* Extracts attributes from the session scope of a portlet request.
|
||||
*/
|
||||
public class SessionScopeExtractor implements AttributeExtractor {
|
||||
|
||||
/**
|
||||
* The portlet request.
|
||||
*/
|
||||
private final PortletRequest request;
|
||||
|
||||
/**
|
||||
* The subscope (application or portlet).
|
||||
*/
|
||||
private final int scope;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The request.
|
||||
* @param scope The subscope (application or portlet).
|
||||
*/
|
||||
public SessionScopeExtractor(PortletRequest request, int scope) {
|
||||
this.request = request;
|
||||
if (scope != PortletSession.APPLICATION_SCOPE && scope != PortletSession.PORTLET_SCOPE) {
|
||||
throw new IllegalArgumentException("The scope must be either APPLICATION_SCOPE or PORTLET_SCOPE");
|
||||
}
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String name, Object value) {
|
||||
request.getPortletSession().setAttribute(name, value, scope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeValue(String name) {
|
||||
PortletSession session = request.getPortletSession(false);
|
||||
if (session != null) {
|
||||
session.removeAttribute(name, scope);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enumeration<String> getKeys() {
|
||||
PortletSession session = request.getPortletSession(false);
|
||||
if (session != null) {
|
||||
return session.getAttributeNames(scope);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String key) {
|
||||
PortletSession session = request.getPortletSession(false);
|
||||
if (session != null) {
|
||||
return session.getAttribute(key, scope);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.attribute.HasAddableKeys;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.StateAwareResponse;
|
||||
|
||||
/**
|
||||
* Extracts parameters from a request and allows putting render parameters in a state aware response.
|
||||
*/
|
||||
public class StateAwareParameterExtractor extends ParameterExtractor implements HasAddableKeys<String> {
|
||||
|
||||
/**
|
||||
* The portlet response.
|
||||
*/
|
||||
private final StateAwareResponse response;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param request The portlet request.
|
||||
* @param response The portlet response.
|
||||
*/
|
||||
public StateAwareParameterExtractor(PortletRequest request, StateAwareResponse response) {
|
||||
super(request);
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String key, String value) {
|
||||
response.setRenderParameter(key, value);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
/**
|
||||
* Extractors to get scopes from Portlet requests.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* $Id: package-info.java 1049711 2010-12-15 21:12:00Z apetrelli $
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
/**
|
||||
* Support of Tiles requests to portlets.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet;
|
||||
+424
@@ -0,0 +1,424 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet;
|
||||
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.collection.HeaderValuesMap;
|
||||
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
|
||||
import org.apache.tiles.request.collection.ScopeMap;
|
||||
import org.apache.tiles.request.portlet.delegate.RequestDelegate;
|
||||
import org.apache.tiles.request.portlet.delegate.ResponseDelegate;
|
||||
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.PortletRequestDispatcher;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests {@link PortletRequest}.
|
||||
*/
|
||||
public class PortletRequestTest {
|
||||
|
||||
/**
|
||||
* The application context.
|
||||
*/
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private PortletContext portletContext;
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private javax.portlet.PortletRequest request;
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private PortletResponse response;
|
||||
|
||||
/**
|
||||
* The request to test.
|
||||
*/
|
||||
private PortletRequest req;
|
||||
|
||||
/**
|
||||
* The request delegate.
|
||||
*/
|
||||
private RequestDelegate requestDelegate;
|
||||
|
||||
/**
|
||||
* The response delegate.
|
||||
*/
|
||||
private ResponseDelegate responseDelegate;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
applicationContext = createMock(ApplicationContext.class);
|
||||
portletContext = createMock(PortletContext.class);
|
||||
request = createMock(javax.portlet.PortletRequest.class);
|
||||
response = createMock(PortletResponse.class);
|
||||
requestDelegate = createMock(RequestDelegate.class);
|
||||
responseDelegate = createMock(ResponseDelegate.class);
|
||||
req = new PortletRequest(applicationContext, portletContext, request,
|
||||
response, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doForward(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testDoForward() throws PortletException, IOException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(false);
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.forward(request, response);
|
||||
|
||||
replay(applicationContext, portletContext, request, response, rd);
|
||||
req.doForward("/my/path");
|
||||
verify(applicationContext, portletContext, request, response, rd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doForward(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testDoForwardNoDispatcher() throws IOException {
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(false);
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(null);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
try {
|
||||
req.doForward("/my/path");
|
||||
} finally {
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doForward(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testDoForwardPortletException() throws PortletException, IOException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(false);
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.forward(request, response);
|
||||
expectLastCall().andThrow(new PortletException());
|
||||
|
||||
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
try {
|
||||
req.doForward("/my/path");
|
||||
} finally {
|
||||
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doForward(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testDoForwardInclude() throws PortletException, IOException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(true);
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.include(request, response);
|
||||
|
||||
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
req.doForward("/my/path");
|
||||
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doInclude(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testDoInclude() throws IOException, PortletException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.include(request, response);
|
||||
|
||||
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
req.doInclude("/my/path");
|
||||
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doInclude(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testDoIncludeNoDispatcher() throws IOException {
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(null);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
try {
|
||||
req.doInclude("/my/path");
|
||||
} finally {
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#doInclude(String)}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
* @throws PortletException If something goes wrong.
|
||||
*/
|
||||
@Test(expected = IOException.class)
|
||||
public void testDoIncludePortletException() throws IOException, PortletException {
|
||||
PortletRequestDispatcher rd = createMock(PortletRequestDispatcher.class);
|
||||
|
||||
expect(portletContext.getRequestDispatcher("/my/path")).andReturn(rd);
|
||||
rd.include(request, response);
|
||||
expectLastCall().andThrow(new PortletException());
|
||||
|
||||
replay(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
try {
|
||||
req.doInclude("/my/path");
|
||||
} finally {
|
||||
verify(applicationContext, request, response, rd, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getHeader()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetHeader() {
|
||||
assertTrue(req.getHeader() instanceof ReadOnlyEnumerationMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getResponseHeaders()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetResponseHeaders() {
|
||||
assertTrue(req.getResponseHeaders() instanceof HeaderExtractor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getHeaderValues()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetHeaderValues() {
|
||||
assertTrue(req.getHeaderValues() instanceof HeaderValuesMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getParam()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetParam() {
|
||||
Map<String, String> map = createMock(Map.class);
|
||||
|
||||
expect(requestDelegate.getParam()).andReturn(map);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(map, req.getParam());
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getParamValues()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetParamValues() {
|
||||
Map<String, String[]> paramMap = createMock(Map.class);
|
||||
|
||||
expect(requestDelegate.getParamValues()).andReturn(paramMap);
|
||||
|
||||
replay(applicationContext, request, response, paramMap, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(paramMap, req.getParamValues());
|
||||
verify(applicationContext, request, response, paramMap, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getRequestScope()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRequestScope() {
|
||||
assertTrue(req.getRequestScope() instanceof ScopeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getSessionScope()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetSessionScope() {
|
||||
assertTrue(req.getSessionScope() instanceof ScopeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getPortletSessionScope()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPortletSessionScope() {
|
||||
assertTrue(req.getPortletSessionScope() instanceof ScopeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getOutputStream()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetOutputStream() throws IOException {
|
||||
ServletOutputStream os = createMock(ServletOutputStream.class);
|
||||
|
||||
expect(responseDelegate.getOutputStream()).andReturn(os);
|
||||
|
||||
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(req.getOutputStream(), os);
|
||||
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getWriter()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetWriter() throws IOException {
|
||||
PrintWriter os = createMock(PrintWriter.class);
|
||||
|
||||
expect(responseDelegate.getWriter()).andReturn(os);
|
||||
|
||||
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(req.getWriter(), os);
|
||||
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getPrintWriter()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPrintWriter() throws IOException {
|
||||
PrintWriter os = createMock(PrintWriter.class);
|
||||
|
||||
expect(responseDelegate.getPrintWriter()).andReturn(os);
|
||||
|
||||
replay(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(req.getPrintWriter(), os);
|
||||
verify(applicationContext, request, response, os, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#isResponseCommitted()}.
|
||||
*/
|
||||
@Test
|
||||
public void testIsResponseCommitted() {
|
||||
expect(responseDelegate.isResponseCommitted()).andReturn(true);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertTrue(req.isResponseCommitted());
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#setContentType(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetContentType() {
|
||||
responseDelegate.setContentType("text/html");
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
req.setContentType("text/html");
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getRequestLocale()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRequestLocale() {
|
||||
Locale locale = Locale.ITALY;
|
||||
|
||||
expect(request.getLocale()).andReturn(locale);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(locale, req.getRequestLocale());
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#getRequest()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetRequest() {
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertEquals(request, req.getRequest());
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequest#isUserInRole(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testIsUserInRole() {
|
||||
expect(request.isUserInRole("myrole")).andReturn(true);
|
||||
|
||||
replay(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
assertTrue(req.isUserInRole("myrole"));
|
||||
verify(applicationContext, request, response, portletContext, requestDelegate, responseDelegate);
|
||||
}
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet;
|
||||
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.portlet.delegate.MimeResponseDelegate;
|
||||
import org.apache.tiles.request.portlet.delegate.PortletRequestDelegate;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests {@link RenderPortletRequest}.
|
||||
*/
|
||||
public class RenderPortletRequestTest {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link RenderPortletRequest#RenderPortletRequest(ApplicationContext, PortletContext,
|
||||
* RenderRequest, RenderResponse)}.
|
||||
*
|
||||
* @throws NoSuchFieldException If something goes wrong.
|
||||
* @throws SecurityException If something goes wrong.
|
||||
* @throws IllegalAccessException If something goes wrong.
|
||||
* @throws IllegalArgumentException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testRenderPortletRequest() throws NoSuchFieldException, IllegalAccessException {
|
||||
ApplicationContext applicationContext = createMock(ApplicationContext.class);
|
||||
PortletContext portletContext = createMock(PortletContext.class);
|
||||
RenderRequest request = createMock(RenderRequest.class);
|
||||
RenderResponse response = createMock(RenderResponse.class);
|
||||
|
||||
replay(applicationContext, portletContext, request, response);
|
||||
RenderPortletRequest req = new RenderPortletRequest(applicationContext,
|
||||
portletContext, request, response);
|
||||
Class<? extends RenderPortletRequest> clazz = req.getClass();
|
||||
Field field = clazz.getSuperclass().getDeclaredField("requestDelegate");
|
||||
assertTrue(field.get(req) instanceof PortletRequestDelegate);
|
||||
field = clazz.getSuperclass().getDeclaredField("responseDelegate");
|
||||
assertTrue(field.get(req) instanceof MimeResponseDelegate);
|
||||
verify(applicationContext, portletContext, request, response);
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.MimeResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests {@link MimeResponseDelegate}.
|
||||
*/
|
||||
public class MimeResponseDelegateTest {
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private MimeResponse response;
|
||||
|
||||
/**
|
||||
* The delegate to test.
|
||||
*/
|
||||
private MimeResponseDelegate delegate;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
response = createMock(MimeResponse.class);
|
||||
delegate = new MimeResponseDelegate(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#getOutputStream()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetOutputStream() throws IOException {
|
||||
OutputStream os = createMock(OutputStream.class);
|
||||
|
||||
expect(response.getPortletOutputStream()).andReturn(os);
|
||||
|
||||
replay(response, os);
|
||||
assertEquals(os, delegate.getOutputStream());
|
||||
verify(response, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#getPrintWriter()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPrintWriter() throws IOException {
|
||||
PrintWriter os = createMock(PrintWriter.class);
|
||||
|
||||
expect(response.getWriter()).andReturn(os);
|
||||
|
||||
replay(response, os);
|
||||
assertEquals(os, delegate.getPrintWriter());
|
||||
verify(response, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#getWriter()}.
|
||||
*
|
||||
* @throws IOException If something goes wrong.
|
||||
*/
|
||||
@Test
|
||||
public void testGetWriter() throws IOException {
|
||||
PrintWriter os = createMock(PrintWriter.class);
|
||||
|
||||
expect(response.getWriter()).andReturn(os);
|
||||
|
||||
replay(response, os);
|
||||
assertEquals(os, delegate.getWriter());
|
||||
verify(response, os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#isResponseCommitted()}.
|
||||
*/
|
||||
@Test
|
||||
public void testIsResponseCommitted() {
|
||||
expect(response.isCommitted()).andReturn(true);
|
||||
|
||||
replay(response);
|
||||
assertTrue(delegate.isResponseCommitted());
|
||||
verify(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link MimeResponseDelegate#setContentType(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetContentType() {
|
||||
response.setContentType("text/html");
|
||||
|
||||
replay(response);
|
||||
delegate.setContentType("text/html");
|
||||
verify(response);
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.delegate;
|
||||
|
||||
import org.apache.tiles.request.collection.ReadOnlyEnumerationMap;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests {@link PortletRequestDelegate}.
|
||||
*/
|
||||
public class PortletRequestDelegateTest {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The delegate to test.
|
||||
*/
|
||||
private PortletRequestDelegate delegate;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = createMock(PortletRequest.class);
|
||||
delegate = new PortletRequestDelegate(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequestDelegate#getParam()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetParam() {
|
||||
replay(request);
|
||||
assertTrue(delegate.getParam() instanceof ReadOnlyEnumerationMap);
|
||||
verify(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link PortletRequestDelegate#getParamValues()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetParamValues() {
|
||||
Map<String, String[]> params = createMock(Map.class);
|
||||
|
||||
expect(request.getParameterMap()).andReturn(params);
|
||||
|
||||
replay(request, params);
|
||||
assertEquals(params, delegate.getParamValues());
|
||||
verify(request, params);
|
||||
}
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.ApplicationScopeExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link ApplicationScopeExtractor}.
|
||||
*/
|
||||
public class ApplicationScopeExtractorTest {
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private PortletContext context;
|
||||
|
||||
/**
|
||||
* The extractot to test.
|
||||
*/
|
||||
private ApplicationScopeExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
context = createMock(PortletContext.class);
|
||||
extractor = new ApplicationScopeExtractor(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ApplicationScopeExtractor#setValue(String, Object)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
context.setAttribute("attribute", "value");
|
||||
|
||||
replay(context);
|
||||
extractor.setValue("attribute", "value");
|
||||
verify(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ApplicationScopeExtractor#removeValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveValue() {
|
||||
context.removeAttribute("attribute");
|
||||
|
||||
replay(context);
|
||||
extractor.removeValue("attribute");
|
||||
verify(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ApplicationScopeExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
expect(context.getAttributeNames()).andReturn(keys);
|
||||
|
||||
replay(context, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(context, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ApplicationScopeExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(context.getAttribute("attribute")).andReturn("value");
|
||||
|
||||
replay(context);
|
||||
assertEquals("value", extractor.getValue("attribute"));
|
||||
verify(context);
|
||||
}
|
||||
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.HeaderExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link HeaderExtractor}.
|
||||
*/
|
||||
public class HeaderExtractorTest {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The response.
|
||||
*/
|
||||
private PortletResponse response;
|
||||
|
||||
/**
|
||||
* The extractor to test.
|
||||
*/
|
||||
private HeaderExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = createMock(PortletRequest.class);
|
||||
response = createMock(PortletResponse.class);
|
||||
extractor = new HeaderExtractor(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link HeaderExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(request.getPropertyNames()).andReturn(keys);
|
||||
|
||||
replay(request, response, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(request, response, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link HeaderExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(request.getProperty("name")).andReturn("value");
|
||||
|
||||
replay(request, response);
|
||||
assertEquals("value", extractor.getValue("name"));
|
||||
verify(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link HeaderExtractor#getValues(String)}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetValues() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(request.getProperties("name")).andReturn(keys);
|
||||
|
||||
replay(request, response, keys);
|
||||
assertEquals(keys, extractor.getValues("name"));
|
||||
verify(request, response, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link HeaderExtractor#setValue(String, String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetValue() {
|
||||
response.setProperty("name", "value");
|
||||
|
||||
replay(request, response);
|
||||
extractor.setValue("name", "value");
|
||||
verify(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.InitParameterExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link InitParameterExtractor}.
|
||||
*/
|
||||
public class InitParameterExtractorTest {
|
||||
|
||||
/**
|
||||
* The portlet context.
|
||||
*/
|
||||
private PortletContext context;
|
||||
|
||||
/**
|
||||
* The extractor to test.
|
||||
*/
|
||||
private InitParameterExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
context = createMock(PortletContext.class);
|
||||
extractor = new InitParameterExtractor(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link InitParameterExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(context.getInitParameterNames()).andReturn(keys);
|
||||
|
||||
replay(context, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(context, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link InitParameterExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(context.getInitParameter("name")).andReturn("value");
|
||||
|
||||
replay(context);
|
||||
assertEquals("value", extractor.getValue("name"));
|
||||
verify(context);
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.tiles.request.portlet.extractor;
|
||||
|
||||
import org.apache.tiles.request.portlet.extractor.ParameterExtractor;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.portlet.PortletRequest;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@link ParameterExtractor}.
|
||||
*/
|
||||
public class ParameterExtractorTest {
|
||||
|
||||
/**
|
||||
* The request.
|
||||
*/
|
||||
private PortletRequest request;
|
||||
|
||||
/**
|
||||
* The extractor to test.
|
||||
*/
|
||||
private ParameterExtractor extractor;
|
||||
|
||||
/**
|
||||
* Sets up the test.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
request = createMock(PortletRequest.class);
|
||||
extractor = new ParameterExtractor(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ParameterExtractor#getKeys()}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGetKeys() {
|
||||
Enumeration<String> keys = createMock(Enumeration.class);
|
||||
|
||||
expect(request.getParameterNames()).andReturn(keys);
|
||||
|
||||
replay(request, keys);
|
||||
assertEquals(keys, extractor.getKeys());
|
||||
verify(request, keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ParameterExtractor#getValue(String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetValue() {
|
||||
expect(request.getParameter("name")).andReturn("value");
|
||||
|
||||
replay(request);
|
||||
assertEquals("value", extractor.getValue("name"));
|
||||
verify(request);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user