You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2005/09/08 10:31:03 UTC

svn commit: r279536 - in /webservices/axis2/trunk/java/modules: common/src/org/apache/axis2/util/ samples/src/sample/om/binary/ xml/src/org/apache/axis2/om/impl/ xml/src/org/apache/axis2/om/impl/llom/

Author: chinthaka
Date: Thu Sep  8 01:30:35 2005
New Revision: 279536

URL: http://svn.apache.org/viewcvs?rev=279536&view=rev
Log:
Fixing Axis2-210 - Refactoring UUID generation from MIMEUtils to commons package.

Added:
    webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/
    webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java
Modified:
    webservices/axis2/trunk/java/modules/samples/src/sample/om/binary/FIUtil.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java

Added: webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java?rev=279536&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java (added)
+++ webservices/axis2/trunk/java/modules/common/src/org/apache/axis2/util/UUIDGenerator.java Thu Sep  8 01:30:35 2005
@@ -0,0 +1,76 @@
+package org.apache.axis2.util;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Random;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * @author : Eran Chinthaka (chinthaka@apache.org)
+ */
+
+public class UUIDGenerator {
+    /**
+     * This class will give UUIDs for axis2.
+     */
+
+    private static Random myRand = null;
+
+    /**
+     * MD5 a random string with localhost/date etc will return 128 bits
+     * construct a string of 18 characters from those bits.
+     * @return string
+     */
+    public static String getUUID() {
+        if (myRand == null) {
+            myRand = new Random();
+        }
+        long rand = myRand.nextLong();
+        String sid;
+        try {
+            sid = InetAddress.getLocalHost().toString();
+        } catch (UnknownHostException e) {
+            sid = Thread.currentThread().getName();
+        }
+        long time = System.currentTimeMillis();
+        StringBuffer sb = new StringBuffer();
+        sb.append(sid);
+        sb.append(":");
+        sb.append(Long.toString(time));
+        sb.append(":");
+        sb.append(Long.toString(rand));
+        MessageDigest md5 = null;
+        try {
+            md5 = MessageDigest.getInstance("MD5");
+        } catch (NoSuchAlgorithmException e) {
+            //System.out.println("Error: " + e);
+            //todo heve to be properly handle
+        }
+        md5.update(sb.toString().getBytes());
+        byte[] array = md5.digest();
+        StringBuffer sb2 = new StringBuffer();
+        for (int j = 0; j < array.length; ++j) {
+            int b = array[j] & 0xFF;
+            sb2.append(Integer.toHexString(b));
+        }
+        int begin = myRand.nextInt();
+        if(begin < 0) begin = begin * -1;
+        begin = begin % 8;
+        return new String(sb2.toString().substring(begin, begin + 18)).toUpperCase();
+    }
+}

Modified: webservices/axis2/trunk/java/modules/samples/src/sample/om/binary/FIUtil.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/samples/src/sample/om/binary/FIUtil.java?rev=279536&r1=279535&r2=279536&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/samples/src/sample/om/binary/FIUtil.java (original)
+++ webservices/axis2/trunk/java/modules/samples/src/sample/om/binary/FIUtil.java Thu Sep  8 01:30:35 2005
@@ -106,6 +106,7 @@
         } catch (XMLStreamException e) {
             throw new UnsupportedOperationException();
         } catch (FileNotFoundException e) {
+            e.printStackTrace();
             throw new UnsupportedOperationException();
         } catch (IOException e) {
             throw new UnsupportedOperationException();

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java?rev=279536&r1=279535&r2=279536&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java Thu Sep  8 01:30:35 2005
@@ -25,18 +25,12 @@
 import javax.mail.internet.MimeBodyPart;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
 import java.util.Iterator;
 import java.util.LinkedList;
-import java.util.Random;
 
 public class MIMEOutputUtils {
 
     private static byte[] CRLF = {13, 10};
-    private static Random myRand = null;
     private Log log = LogFactory.getLog(getClass());
 
     public static void complete(OutputStream outStream,
@@ -142,46 +136,4 @@
         return sb.toString();
     }
 
-    /**
-     * MD5 a random string with localhost/date etc will return 128 bits
-     * construct a string of 18 characters from those bits.
-     * @return string
-     */
-    public static String getRandomStringOf18Characters() {
-        if (myRand == null) {
-            myRand = new Random();
-        }
-        long rand = myRand.nextLong();
-        String sid;
-        try {
-            sid = InetAddress.getLocalHost().toString();
-        } catch (UnknownHostException e) {
-            sid = Thread.currentThread().getName();
-        }
-        long time = System.currentTimeMillis();
-        StringBuffer sb = new StringBuffer();
-        sb.append(sid);
-        sb.append(":");
-        sb.append(Long.toString(time));
-        sb.append(":");
-        sb.append(Long.toString(rand));
-        MessageDigest md5 = null;
-        try {
-            md5 = MessageDigest.getInstance("MD5");
-        } catch (NoSuchAlgorithmException e) {
-            //System.out.println("Error: " + e);
-            //todo heve to be properly handle
-        }
-        md5.update(sb.toString().getBytes());
-        byte[] array = md5.digest();
-        StringBuffer sb2 = new StringBuffer();
-        for (int j = 0; j < array.length; ++j) {
-            int b = array[j] & 0xFF;
-            sb2.append(Integer.toHexString(b));
-        }
-        int begin = myRand.nextInt();
-        if(begin < 0) begin = begin * -1;
-        begin = begin % 8;
-        return new String(sb2.toString().substring(begin, begin + 18)).toUpperCase();
-    }
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java?rev=279536&r1=279535&r2=279536&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java Thu Sep  8 01:30:35 2005
@@ -18,6 +18,7 @@
     import org.apache.axis2.om.OMText;
     import org.apache.axis2.soap.SOAP11Constants;
     import org.apache.axis2.soap.SOAP12Constants;
+    import org.apache.axis2.util.UUIDGenerator;
 
     import javax.xml.stream.FactoryConfigurationError;
     import javax.xml.stream.XMLOutputFactory;
@@ -169,7 +170,7 @@
         if (mimeBoundary == null) {
             mimeBoundary =
                 "MIMEBoundary"
-                    + MIMEOutputUtils.getRandomStringOf18Characters();
+                    + UUIDGenerator.getUUID();
         }
         return mimeBoundary;
     }
@@ -178,7 +179,7 @@
         if (rootContentId == null) {
             rootContentId =
                 "0."
-                    + MIMEOutputUtils.getRandomStringOf18Characters()
+                    + UUIDGenerator.getUUID()
                     + "@apache.org";
         }
         return rootContentId;
@@ -188,7 +189,7 @@
         nextid++;
         return nextid
             + "."
-            + MIMEOutputUtils.getRandomStringOf18Characters()
+            + UUIDGenerator.getUUID()
             + "@apache.org";
     }
 

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java?rev=279536&r1=279535&r2=279536&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java Thu Sep  8 01:30:35 2005
@@ -19,9 +19,9 @@
 import org.apache.axis2.attachments.ByteArrayDataSource;
 import org.apache.axis2.attachments.utils.IOUtils;
 import org.apache.axis2.om.*;
-import org.apache.axis2.om.impl.MIMEOutputUtils;
 import org.apache.axis2.om.impl.OMOutputImpl;
 import org.apache.axis2.om.impl.llom.mtom.MTOMStAXSOAPModelBuilder;
+import org.apache.axis2.util.UUIDGenerator;
 
 import javax.activation.DataHandler;
 import javax.xml.stream.XMLStreamException;
@@ -286,7 +286,7 @@
 
     public String getContentID() {
         if (contentID == null) {
-            contentID = MIMEOutputUtils.getRandomStringOf18Characters()
+            contentID = UUIDGenerator.getUUID()
                     + "@apache.org";
         }
         return this.contentID;