diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-09 20:15:18 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-09 20:15:18 +0000 |
commit | 2c72506e4074cb6233babb3a3caa7b280b10ffa0 (patch) | |
tree | 89f9ff243ac772b213f0464c352f8a4636990b65 /branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org | |
parent | c89f45844721c95106b300f091956ecdbcd12623 (diff) |
TUSCANY-2938 - Fixing how we calculate request path based on contextPath and ServletPath to make operations working in both embedded and webapp hosted environment
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@763787 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org')
-rw-r--r-- | branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java b/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java index 508731b286..3ee9a5e3dc 100644 --- a/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java +++ b/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java @@ -168,9 +168,11 @@ class AtomBindingListenerServlet extends HttpServlet { // System.out.println( "AtomBindingListener.doGet cache context=" + cacheContext ); // Get the request path - int servletPathLength = request.getContextPath().length() + request.getServletPath().length(); - String path = URLDecoder.decode(request.getRequestURI().substring(servletPathLength), "UTF-8"); + //int servletPathLength = request.getContextPath().length() + request.getServletPath().length(); + //String path = URLDecoder.decode(request.getRequestURI().substring(servletPathLength), "UTF-8"); + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); + logger.fine("get " + request.getRequestURI()); // Handle an Atom request @@ -548,7 +550,7 @@ class AtomBindingListenerServlet extends HttpServlet { } // Get the request path - String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length() + request.getContextPath().length()), "UTF-8"); + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); if (path == null || path.length() == 0 || path.equals("/")) { org.apache.abdera.model.Entry createdFeedEntry = null; @@ -673,7 +675,7 @@ class AtomBindingListenerServlet extends HttpServlet { } // Get the request path - String path = request.getRequestURI().substring(request.getServletPath().length()); + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); if (path != null && path.startsWith("/")) { String id = path.substring(1); @@ -760,7 +762,7 @@ class AtomBindingListenerServlet extends HttpServlet { } // Get the request path - String path = URLDecoder.decode(request.getRequestURI().substring(request.getContextPath().length() + request.getServletPath().length()), "UTF-8"); + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); String id; if (path != null && path.startsWith("/")) { @@ -783,6 +785,26 @@ class AtomBindingListenerServlet extends HttpServlet { } } + + /** + * + * @param request + * @return + */ + private static String getRequestPath(HttpServletRequest request) { + // Get the request path + String contextPath = request.getContextPath(); + String servletPath = request.getServletPath(); + String requestURI = request.getRequestURI(); + + int contextPathLength = request.getContextPath().length(); + int servletPathLenght = servletPath.contains(contextPath) ? servletPath.length() - contextPath.length() : servletPath.length(); + + String requestPath = requestURI.substring(contextPathLength + servletPathLenght); + + return requestPath; + } + /** * Process the authorization header * @@ -851,7 +873,7 @@ class AtomBindingListenerServlet extends HttpServlet { * @param acceptType content-type preference using application/atom-xml as default * @return */ - public static String getContentPreference( String acceptType ) { + private static String getContentPreference( String acceptType ) { if (( acceptType == null ) || ( acceptType.length() < 1 )) { return "application/atom+xml"; } @@ -867,7 +889,7 @@ class AtomBindingListenerServlet extends HttpServlet { * @param response * @param properties */ - public static void addPropertiesToHeader( HttpServletResponse response, String properties ) { + private static void addPropertiesToHeader( HttpServletResponse response, String properties ) { if ( properties == null ) return; StringTokenizer props = new StringTokenizer( properties, ","); while( props.hasMoreTokens()) { @@ -885,4 +907,5 @@ class AtomBindingListenerServlet extends HttpServlet { } } + } |