You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2010/02/26 01:57:55 UTC
svn commit: r916511 - in /tuscany/sca-java-2.x/trunk/modules:
binding-atom-runtime/ binding-atom-runtime/META-INF/
binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/
common-http/ common-http/src/main/java/org/apache/tuscan...
Author: lresende
Date: Fri Feb 26 00:57:54 2010
New Revision: 916511
URL: http://svn.apache.org/viewvc?rev=916511&view=rev
Log:
Moving getRequestPath utility to common-http utility class
Added:
tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java (with props)
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/META-INF/MANIFEST.MF
tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/pom.xml
tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
tuscany/sca-java-2.x/trunk/modules/common-http/pom.xml
Modified: tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/META-INF/MANIFEST.MF?rev=916511&r1=916510&r2=916511&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/META-INF/MANIFEST.MF (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/META-INF/MANIFEST.MF Fri Feb 26 00:57:54 2010
@@ -28,6 +28,7 @@
org.apache.tuscany.sca.assembly;version="2.0.0",
org.apache.tuscany.sca.binding.atom;version="2.0.0",
org.apache.tuscany.sca.binding.http;version="2.0.0",
+ org.apache.tuscany.sca.common.http;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
org.apache.tuscany.sca.data.collection;version="2.0.0",
org.apache.tuscany.sca.databinding;version="2.0.0",
Modified: tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/pom.xml?rev=916511&r1=916510&r2=916511&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/pom.xml Fri Feb 26 00:57:54 2010
@@ -74,6 +74,12 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-common-http</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-http</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
Modified: tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java?rev=916511&r1=916510&r2=916511&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java Fri Feb 26 00:57:54 2010
@@ -52,6 +52,7 @@
import org.apache.abdera.writer.WriterFactory;
import org.apache.commons.codec.binary.Base64;
import org.apache.tuscany.sca.binding.http.HTTPCacheContext;
+import org.apache.tuscany.sca.common.http.HTTPUtil;
import org.apache.tuscany.sca.data.collection.Entry;
import org.apache.tuscany.sca.databinding.Mediator;
import org.apache.tuscany.sca.interfacedef.DataType;
@@ -171,7 +172,7 @@
//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");
+ String path = URLDecoder.decode(HTTPUtil.getRequestPath(request), "UTF-8");
logger.fine("get " + request.getRequestURI());
@@ -553,7 +554,7 @@
}
// Get the request path
- String path = URLDecoder.decode(getRequestPath(request), "UTF-8");
+ String path = URLDecoder.decode(HTTPUtil.getRequestPath(request), "UTF-8");
if (path == null || path.length() == 0 || path.equals("/")) {
org.apache.abdera.model.Entry createdFeedEntry = null;
@@ -678,7 +679,7 @@
}
// Get the request path
- String path = URLDecoder.decode(getRequestPath(request), "UTF-8");
+ String path = URLDecoder.decode(HTTPUtil.getRequestPath(request), "UTF-8");
if (path != null && path.startsWith("/")) {
String id = path.substring(1);
@@ -765,7 +766,7 @@
}
// Get the request path
- String path = URLDecoder.decode(getRequestPath(request), "UTF-8");
+ String path = URLDecoder.decode(HTTPUtil.getRequestPath(request), "UTF-8");
String id;
if (path != null && path.startsWith("/")) {
@@ -787,26 +788,6 @@
}
}
}
-
-
- /**
- *
- * @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
Modified: tuscany/sca-java-2.x/trunk/modules/common-http/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/common-http/pom.xml?rev=916511&r1=916510&r2=916511&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/common-http/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/common-http/pom.xml Fri Feb 26 00:57:54 2010
@@ -28,4 +28,20 @@
<artifactId>tuscany-common-http</artifactId>
<name>Apache Tuscany SCA Common HTTP</name>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version> <!-- to keep compatible with older servlet containers -->
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
</project>
Added: tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java?rev=916511&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java Fri Feb 26 00:57:54 2010
@@ -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.tuscany.sca.common.http;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class HTTPUtil {
+
+ /**
+ * Calculate the relative request path taking in consideration if
+ * the application is running in a embedded webContatiner or from
+ * within a web application server host environment
+ *
+ * @param request The http request
+ * @return the relative path
+ */
+ public static String getRequestPath(HttpServletRequest request) {
+ // Get the request path
+ String contextPath = request.getContextPath();
+ String servletPath = request.getServletPath();
+ String requestURI = request.getRequestURI();
+
+ int contextPathLength = contextPath.length();
+ int servletPathLenght = servletPath.contains(contextPath) ? servletPath.length() - contextPath.length() : servletPath.length();
+
+ String requestPath = requestURI.substring(contextPathLength + servletPathLenght);
+
+ return requestPath;
+ }
+
+ /**
+ * Calculate the context root for an application taking in consideration if
+ * the application is running in a embedded webContatiner or from
+ * within a web application server host environment.
+ *
+ * In the case of webContainer the contextRoot will always be a empty string.
+ *
+ * @param request The http request
+ * @return the contextRoot
+ */
+ public static String getContextRoot(HttpServletRequest request) {
+ // Get the request path
+ String contextPath = request.getContextPath();
+ String requestURI = request.getRequestURI();
+
+ int contextPathLength = contextPath.length();
+
+ String contextRoot = requestURI.substring(0, contextPathLength);
+
+ return contextRoot;
+ }
+}
Propchange: tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java
------------------------------------------------------------------------------
svn:keywords = Rev Date