Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Performance improvement for JSESSIONID handling

  • Loading branch information...
commit 550549400fa3f1a7a963cfb3bf7696c5181b3993 1 parent ae97e85
Christian Kaltepoth authored February 13, 2012
9  core/src/main/java/com/ocpsoft/pretty/PrettyContext.java
@@ -17,6 +17,8 @@
17 17
 
18 18
 import java.io.IOException;
19 19
 import java.io.Serializable;
  20
+import java.util.regex.Matcher;
  21
+import java.util.regex.Pattern;
20 22
 
21 23
 import javax.faces.context.FacesContext;
22 24
 import javax.servlet.ServletRequest;
@@ -46,8 +48,8 @@
46 48
    public static final String PRETTY_PREFIX = "pretty:";
47 49
    private static final String CONTEXT_REQUEST_KEY = "prettyContext";
48 50
 
  51
+   private static final Pattern JSESSIONID_PATTERN = Pattern.compile("(?i)^(.*);jsessionid=[\\w\\.]+(.*)");
49 52
    private static final String JSESSIONID_REPLACEMENT = "$1$2";
50  
-   private static final String JSESSIONID_REGEX = "(?i)^(.*);jsessionid=[\\w\\.]+(.*)";
51 53
 
52 54
    private PrettyConfig config;
53 55
 
@@ -84,9 +86,10 @@ protected PrettyContext(final HttpServletRequest request)
84 86
    public static URL getRequestURL(final HttpServletRequest request)
85 87
    {
86 88
       String url = stripContextPath(request.getContextPath(), request.getRequestURI());
87  
-      if (url.matches(JSESSIONID_REGEX))
  89
+      Matcher sessionIdMatcher = JSESSIONID_PATTERN.matcher(url);
  90
+      if (sessionIdMatcher.matches())
88 91
       {
89  
-         url = url.replaceFirst(JSESSIONID_REGEX, JSESSIONID_REPLACEMENT);
  92
+         url = sessionIdMatcher.replaceFirst(JSESSIONID_REPLACEMENT);
90 93
       }
91 94
 
92 95
       String encoding = request.getCharacterEncoding() == null ? DEFAULT_ENCODING : request.getCharacterEncoding();

0 notes on commit 5505494

Please sign in to comment.
Something went wrong with that request. Please try again.