Author: lresende
Date: Thu Apr 9 20:15:18 2009
New Revision: 763787
URL: http://svn.apache.org/viewvc?rev=763787&view=rev
Log:
TUSCANY-2938 - Fixing how we calculate request path based on contextPath and
ServletPath to make operations working in both embedded and webapp hosted
environment
Modified:
tuscany/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
Modified:
tuscany/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
URL:
http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java?rev=763787&r1=763786&r2=763787&view=diff
==============================================================================
---
tuscany/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
(original)
+++
tuscany/branches/sca-java-1.x/modules/binding-atom-abdera/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
Thu Apr 9 20:15:18 2009
@@ -168,9 +168,11 @@
// 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 @@
}
// 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 @@
}
// 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 @@
}
// 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 @@
}
}
+
+ /**
+ *
+ * @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 @@
* @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 @@
* @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 @@
}
}
+
}