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 2011/01/02 00:22:25 UTC
svn commit: r1054316 -
/tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java
Author: lresende
Date: Sat Jan 1 23:22:25 2011
New Revision: 1054316
URL: http://svn.apache.org/viewvc?rev=1054316&view=rev
Log:
Adding java doc
Modified:
tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java
Modified: 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=1054316&r1=1054315&r2=1054316&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java Sat Jan 1 23:22:25 2011
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.common.http;
@@ -25,17 +25,17 @@ import java.security.MessageDigest;
import javax.servlet.http.HttpServletRequest;
/**
- *
+ *
* @tuscany.spi.extension.asclient
*
*/
public class HTTPUtil {
/**
- * Calculate the relative request path taking in consideration if
+ * 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
*/
@@ -44,37 +44,42 @@ public class HTTPUtil {
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
+ * 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.
- *
+ * 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;
}
-
+
+ /**
+ * Calculate the ETag using MD5 Hash Algorithm
+ * @param content the content to hash
+ * @return
+ */
public static String calculateHashETag(byte[] content) {
String eTag = "invalid";
try {