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 di...@apache.org on 2005/07/14 06:12:08 UTC
svn commit: r218983 -
/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
Author: dims
Date: Wed Jul 13 21:12:05 2005
New Revision: 218983
URL: http://svn.apache.org/viewcvs?rev=218983&view=rev
Log:
Don't use a fixed boundary. make up a random string.
Modified:
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java?rev=218983&r1=218982&r2=218983&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java Wed Jul 13 21:12:05 2005
@@ -23,7 +23,12 @@
import javax.xml.stream.XMLStreamWriter;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.LinkedList;
+import java.util.Random;
/**
* For the moment this assumes that transport takes the decision of whether
@@ -36,7 +41,7 @@
private OutputStream outStream;
private LinkedList binaryNodeList;
private ByteArrayOutputStream bufferedSoapOutStream;
- private static String mimeBoundary = "----=_AxIs2_Def_boundary_=42214532";
+ private String mimeBoundary = null;
public OMOutputImpl() {
}
@@ -71,7 +76,7 @@
xmlWriter.flush();
if (doOptimize) {
MIMEOutputUtils.complete(outStream, bufferedSoapOutStream,
- binaryNodeList, mimeBoundary);
+ binaryNodeList, getMimeBoundary());
}
}
@@ -80,7 +85,7 @@
}
public String getOptimizedContentType() {
- return org.apache.axis2.om.impl.MIMEOutputUtils.getContentTypeForMime(mimeBoundary);
+ return org.apache.axis2.om.impl.MIMEOutputUtils.getContentTypeForMime(getMimeBoundary());
}
public void writeOptimized(OMText node) {
@@ -93,5 +98,56 @@
public XMLStreamWriter getXmlStreamWriter() {
return xmlWriter;
+ }
+
+ public String getMimeBoundary() {
+ if(mimeBoundary != null) {
+ mimeBoundary = "--MIMEBoundary" + getRandomStringOf18Characters();
+ }
+ return mimeBoundary;
+ }
+
+ 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
+ */
+ private 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);
+ }
+ 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();
}
}