From ee14a5168606daa06748d32216535f96e8a7416a Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 12 May 2010 06:21:38 +0000 Subject: Adding generated eTag to RPC style invocations git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@943389 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tuscany/sca/common/http/HTTPUtil.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'sca-java-2.x/trunk/modules/common-http') diff --git a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java index 3dc9f5891d..f810970869 100644 --- a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java +++ b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPUtil.java @@ -19,6 +19,9 @@ package org.apache.tuscany.sca.common.http; +import java.math.BigInteger; +import java.security.MessageDigest; + import javax.servlet.http.HttpServletRequest; /** @@ -71,4 +74,20 @@ public class HTTPUtil { return contextRoot; } + + public static String calculateHashETag(byte[] content) { + String eTag = "invalid"; + try { + MessageDigest messageDigest = MessageDigest.getInstance("MD5"); + byte[] digest = messageDigest.digest(content); + BigInteger number = new BigInteger(1, digest); + StringBuffer sb = new StringBuffer('0'); + sb.append(number.toString(16)); + eTag = sb.toString(); + } catch(Exception e) { + //ignore, we will return random etag + eTag = Integer.toString((new java.util.Random()).nextInt(Integer.MAX_VALUE)); + } + return eTag; + } } -- cgit v1.2.3