Skip to content

Commit eaebc76

Browse files
committed
Merged issue 125 from master
1 parent f153adb commit eaebc76

8 files changed

Lines changed: 137 additions & 127 deletions

File tree

‎core/src/main/java/com/ocpsoft/pretty/faces/application/PrettyRedirector.java‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,18 @@ public boolean redirect(final FacesContext context, final String action)
6161

6262
String target = contextPath + url.encode() + query.toQueryString();
6363
log.trace("Refreshing requested page [" + url + "]");
64-
String redirectUrl = externalContext.encodeActionURL(target);
65-
redirectUrl = ((HttpServletResponse) externalContext.getResponse()).encodeRedirectURL(redirectUrl);
66-
externalContext.redirect(redirectUrl);
64+
encodeURL(externalContext, config, target);
6765
return true;
6866
}
6967
else if (isPrettyNavigationCase(prettyContext, action))
7068
{
7169
UrlMapping mapping = config.getMappingById(action);
7270
if (mapping != null)
7371
{
74-
String url = contextPath + builder.buildURL(mapping).encode()
72+
String target = contextPath + builder.buildURL(mapping).encode()
7573
+ builder.buildQueryString(mapping);
76-
log.trace("Redirecting to mappingId [" + mapping.getId() + "], [" + url + "]");
77-
String redirectUrl = externalContext.encodeActionURL(url);
78-
redirectUrl = ((HttpServletResponse) externalContext.getResponse()).encodeRedirectURL(redirectUrl);
79-
externalContext.redirect(redirectUrl);
74+
log.trace("Redirecting to mappingId [" + mapping.getId() + "], [" + target + "]");
75+
encodeURL(externalContext, config, target);
8076
}
8177
else
8278
{
@@ -92,6 +88,20 @@ else if (isPrettyNavigationCase(prettyContext, action))
9288
return false;
9389
}
9490

91+
private void encodeURL(ExternalContext externalContext, PrettyConfig config, String target) throws IOException
92+
{
93+
String redirectUrl = externalContext.encodeActionURL(target);
94+
if (config.isUseEncodeUrlForRedirects())
95+
{
96+
redirectUrl = ((HttpServletResponse) externalContext.getResponse()).encodeURL(redirectUrl);
97+
}
98+
else
99+
{
100+
redirectUrl = ((HttpServletResponse) externalContext.getResponse()).encodeRedirectURL(redirectUrl);
101+
}
102+
externalContext.redirect(redirectUrl);
103+
}
104+
95105
public void send404(final FacesContext facesContext)
96106
{
97107
try

‎core/src/main/java/com/ocpsoft/pretty/faces/config/PrettyConfig.java‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ public class PrettyConfig
3434
private List<UrlMapping> mappings = new ArrayList<UrlMapping>();
3535
private List<RewriteRule> globalRewriteRules = new ArrayList<RewriteRule>();
3636
private String dynaviewId = "";
37-
private Map<String, UrlMapping> cachedMappings = new HashMap<String, UrlMapping>();
37+
private final Map<String, UrlMapping> cachedMappings = new HashMap<String, UrlMapping>();
38+
private boolean useEncodeUrlForRedirects = false;
39+
40+
/**
41+
* Creates an empty {@link PrettyConfig} object
42+
*/
43+
public PrettyConfig()
44+
{
45+
// nothing
46+
}
3847

3948
/**
4049
* Set the current DynaView ID. This is used when calculating dynamic viewIds specified in pretty-config.xml (Do not
@@ -96,7 +105,7 @@ public UrlMapping getMappingForUrl(final URL url)
96105
{
97106
final String mappingKey = url.toURL();
98107
if (cachedMappings.containsKey(mappingKey)) {
99-
return cachedMappings.get(mappingKey);
108+
return cachedMappings.get(mappingKey);
100109
}
101110
for (UrlMapping mapping : getMappings())
102111
{
@@ -148,7 +157,7 @@ public boolean isViewMapped(String viewId)
148157
for (UrlMapping mapping : mappings)
149158
{
150159
if (viewId.equals(mapping.getViewId())
151-
|| (viewId.startsWith("/") && viewId.substring(1).equals(mapping.getViewId())))
160+
|| (viewId.startsWith("/") && viewId.substring(1).equals(mapping.getViewId())))
152161
{
153162
return true;
154163
}
@@ -182,6 +191,16 @@ public UrlMapping getMappingById(String id)
182191
return null;
183192
}
184193

194+
public boolean isUseEncodeUrlForRedirects()
195+
{
196+
return useEncodeUrlForRedirects;
197+
}
198+
199+
public void setUseEncodeUrlForRedirects(boolean useEncodeUrlForRedirects)
200+
{
201+
this.useEncodeUrlForRedirects = useEncodeUrlForRedirects;
202+
}
203+
185204
@Override
186205
public String toString()
187206
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2010 Lincoln Baxter, III
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.ocpsoft.pretty.faces.config.spi;
18+
19+
import javax.servlet.ServletContext;
20+
21+
import com.ocpsoft.pretty.faces.config.PrettyConfig;
22+
import com.ocpsoft.pretty.faces.spi.ConfigurationPostProcessor;
23+
24+
/**
25+
* Set various flags from the ServletContext into the configuration.
26+
*
27+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
28+
*
29+
*/
30+
public class ContextParamsPostProcessor implements ConfigurationPostProcessor
31+
{
32+
public static final String USE_ENCODE_URL_FOR_REDIRECTS = "com.ocpsoft.pretty.USE_ENCODE_URL_FOR_REDIRECTS";
33+
34+
public PrettyConfig processConfiguration(ServletContext context, PrettyConfig config)
35+
{
36+
String useEncodeURL = context.getInitParameter(USE_ENCODE_URL_FOR_REDIRECTS);
37+
if ((useEncodeURL != null) && "true".equalsIgnoreCase(useEncodeURL.trim()))
38+
{
39+
config.setUseEncodeUrlForRedirects(true);
40+
}
41+
42+
return config;
43+
}
44+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.ocpsoft.pretty.faces.config.spi.ContextParamsPostProcessor

‎core/src/test/java/com/ocpsoft/pretty/faces/el/resolver/CDIBeanNameResolverTest.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.easymock.classextension.EasyMock;
3131
import org.junit.Test;
3232

33-
@SuppressWarnings("unchecked")
33+
@SuppressWarnings({ "unchecked", "rawtypes", "static-access" })
3434
public class CDIBeanNameResolverTest
3535
{
3636

@@ -43,7 +43,8 @@ public void testNoCDIEnvironment() throws Exception
4343

4444
// ClassLoader that always throws ClassNotFoundExceptions
4545
ClassLoader classLoader = EasyMock.createNiceMock(ClassLoader.class);
46-
EasyMock.expect(classLoader.loadClass((String) EasyMock.anyObject())).andThrow(new ClassNotFoundException()).once();
46+
EasyMock.expect(classLoader.loadClass((String) EasyMock.anyObject())).andThrow(new ClassNotFoundException())
47+
.once();
4748
EasyMock.replay(classLoader);
4849

4950
// initialize resolver and verify that initialization failed

‎docs/pom.xml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,40 @@
119119
</plugin>
120120

121121
</plugins>
122+
<pluginManagement>
123+
<plugins>
124+
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
125+
<plugin>
126+
<groupId>org.eclipse.m2e</groupId>
127+
<artifactId>lifecycle-mapping</artifactId>
128+
<version>1.0.0</version>
129+
<configuration>
130+
<lifecycleMappingMetadata>
131+
<pluginExecutions>
132+
<pluginExecution>
133+
<pluginExecutionFilter>
134+
<groupId>
135+
org.jboss.maven.plugins
136+
</groupId>
137+
<artifactId>
138+
maven-jdocbook-plugin
139+
</artifactId>
140+
<versionRange>[2.2.3,)</versionRange>
141+
<goals>
142+
<goal>generate</goal>
143+
<goal>resources</goal>
144+
</goals>
145+
</pluginExecutionFilter>
146+
<action>
147+
<ignore></ignore>
148+
</action>
149+
</pluginExecution>
150+
</pluginExecutions>
151+
</lifecycleMappingMetadata>
152+
</configuration>
153+
</plugin>
154+
</plugins>
155+
</pluginManagement>
122156
</build>
123157

124158
<pluginRepositories>

‎docs/src/main/docbook/en-US/FAQ.xml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ log4j.logger.com.ocpsoft=debug</programlisting>
140140
</example>
141141
</step>
142142

143+
<step>
144+
<title>Q. My Orchestra conversationContext parameter is not working with PrettyFaces?</title>
145+
<para>
146+
A. This can happen depending on JSF version and Orchestra version where Orchestra does not properly override encodeRedirectURL.
147+
To solve this problem, enable the following context parameter in your web.xml:
148+
</para>
149+
<example>
150+
<title>web.xml</title>
151+
<programlisting><![CDATA[<context-param>
152+
<param-name>com.ocpsoft.pretty.USE_ENCODE_URL_FOR_REDIRECTS</param-name>
153+
<param-value>true</param-value>
154+
</context-param>]]></programlisting>
155+
</example>
156+
</step>
157+
143158

144159
</procedure>
145160
</chapter>

‎impl-jsf2/src/main/java/com/ocpsoft/pretty/faces/application/PrettyRedirector.java‎

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)