Author: dkulp Date: Tue Nov 18 06:50:01 2008 New Revision: 718623 URL: http://svn.apache.org/viewvc?rev=718623&view=rev Log: Merged revisions 718622 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.1.x-fixes
................ r718622 | dkulp | 2008-11-18 09:48:31 -0500 (Tue, 18 Nov 2008) | 9 lines Merged revisions 718620 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r718620 | dkulp | 2008-11-18 09:37:41 -0500 (Tue, 18 Nov 2008) | 2 lines [CXF-1918, CXF-1916] Performance enhancments for mime attachments ........ ................ Modified: cxf/branches/2.0.x-fixes/ (props changed) cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/wsdl/CrossSchemaImportsTests.java (props changed) Propchange: cxf/branches/2.0.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Nov 18 06:50:01 2008 @@ -1,3 +1,3 @@ -/cxf/branches/2.1.x-fixes:673548,674485,674547,674551,674562,674601,674649,674764,674887,675644,675653,677048,677385,678004,678009,678559,678629,678808,678852,678891,678893,679248,679597,680435,681060,681165,681813,681816,682902,682951,683089,683290,683318,684099,684790-684793,684842,684862,684895-684918,685205,685253,686237,686283,686299,686333-686364,686765,686827,687097,687464-687465,689109,689112,689122,691316,691357,691491,691711,691715,691745,692162-692163,692468,692500,694466-694469,694472,694717,694748-694749,694870,695503,695509,695553,695555,695563,695875-695877,695940,695980,696436,696455,696721,697086,698129,701526,701634,702275,702443,702527,702582,702604,702610,702642-702643,702649,702760,702870,702873,702959,703193,703242,703523,704303,704587,704738,704998,705153,705280-705449,705455,709357,709641,709644,710177,710184,711736,712199,712225,712275,712600,712896,713083,713410,713413,713594,713599,713808,713901,714169-714171 -/cxf/trunk:651669-686342,686344-686363,686764,686820,687096,687387,687463,688086,688102,688735,691271,691355,691488,691602,691706,691728,692116,692157,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694869,695396,695484,695537,695552,695561,695619,695684,695835,695935,695977,696094,696433,696720,697085,698128,700261,700602,701783,701830,701862,702267,702580,702602,702609,702616,702656,702957,703191,703239,703501,704584,704997,705150,705274,705340,705446,708550,708554,709353-709354,709425,710150,712194,712198,712272,712312,712670,712893,713082,713584,713597,713804,713899,714167-714168 +/cxf/branches/2.1.x-fixes:673548,674485,674547,674551,674562,674601,674649,674764,674887,675644,675653,677048,677385,678004,678009,678559,678629,678808,678852,678891,678893,679248,679597,680435,681060,681165,681813,681816,682902,682951,683089,683290,683318,684099,684790-684793,684842,684862,684895-684918,685205,685253,686237,686283,686299,686333-686364,686765,686827,687097,687464-687465,689109,689112,689122,691316,691357,691491,691711,691715,691745,692162-692163,692468,692500,694466-694469,694472,694717,694748-694749,694870,695503,695509,695553,695555,695563,695875-695877,695940,695980,696436,696455,696721,697086,698129,701526,701634,702275,702443,702527,702582,702604,702610,702642-702643,702649,702760,702870,702873,702959,703193,703242,703523,704303,704587,704738,704998,705153,705280-705449,705455,709357,709641,709644,710177,710184,711736,712199,712225,712275,712600,712896,713083,713410,713413,713594,713599,713808,713901,714169-714171,718622 +/cxf/trunk:651669-686342,686344-686363,686764,686820,687096,687387,687463,688086,688102,688735,691271,691355,691488,691602,691706,691728,692116,692157,692466,692499,693653,693819,694179,694263,694417,694716,694744,694747,694869,695396,695484,695537,695552,695561,695619,695684,695835,695935,695977,696094,696433,696720,697085,698128,700261,700602,701783,701830,701862,702267,702580,702602,702609,702616,702656,702957,703191,703239,703501,704584,704997,705150,705274,705340,705446,708550,708554,709353-709354,709425,710150,712194,712198,712272,712312,712670,712893,713082,713584,713597,713804,713899,714167-714168,718620 /incubator/cxf/trunk:434594-651668 Propchange: cxf/branches/2.0.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=718623&r1=718622&r2=718623&view=diff ============================================================================== --- cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java (original) +++ cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java Tue Nov 18 06:50:01 2008 @@ -58,6 +58,7 @@ private boolean lazyLoading = true; + private int pbAmount = 2048; private PushbackInputStream stream; private byte boundary[]; @@ -106,7 +107,7 @@ boundary = boundaryString.getBytes(); stream = new PushbackInputStream(message.getContent(InputStream.class), - boundary.length * 2); + pbAmount); if (!readTillFirstBoundary(stream, boundary)) { throw new IOException("Couldn't find MIME boundary: " + new String(boundary)); } @@ -118,7 +119,7 @@ throw new RuntimeException(e); } - body = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary)); + body = new DelegatingInputStream(new MimeBodyPartInputStream(stream, boundary, pbAmount)); message.setContent(InputStream.class, body); } } @@ -286,7 +287,7 @@ * @throws IOException */ private void setupAttachment(AttachmentImpl att, InternetHeaders headers) throws IOException { - MimeBodyPartInputStream partStream = new MimeBodyPartInputStream(stream, boundary); + MimeBodyPartInputStream partStream = new MimeBodyPartInputStream(stream, boundary, pbAmount); final String ct = headers.getHeader("Content-Type", null); DataSource source = new AttachmentDataSource(ct, new DelegatingInputStream(partStream)); Modified: cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=718623&r1=718622&r2=718623&view=diff ============================================================================== --- cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java (original) +++ cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java Tue Nov 18 06:50:01 2008 @@ -30,7 +30,9 @@ import org.apache.cxf.message.Attachment; public final class AttachmentUtil { - + private static volatile int counter; + private static final String ATT_UUID = UUID.randomUUID().toString(); + private AttachmentUtil() { } @@ -42,7 +44,8 @@ public static String createContentID(String ns) throws UnsupportedEncodingException { // tend to change String cid = "http://cxf.apache.org/"; - String name = UUID.randomUUID().toString(); + //String name = UUID.randomUUID().toString(); + String name = ATT_UUID + String.valueOf(++counter); if (ns != null && (ns.length() > 0)) { try { URI uri = new URI(ns); Modified: cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java?rev=718623&r1=718622&r2=718623&view=diff ============================================================================== --- cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java (original) +++ cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java Tue Nov 18 06:50:01 2008 @@ -28,13 +28,157 @@ PushbackInputStream inStream; boolean boundaryFound; - + int pbAmount; byte[] boundary; + byte[] boundaryBuffer; - public MimeBodyPartInputStream(PushbackInputStream inStreamParam, byte[] boundaryParam) { + public MimeBodyPartInputStream(PushbackInputStream inStreamParam, + byte[] boundaryParam, + int pbsize) { super(); this.inStream = inStreamParam; this.boundary = boundaryParam; + this.pbAmount = pbsize; + } + + public int read(byte buf[], int origOff, int origLen) throws IOException { + byte b[] = buf; + int off = origOff; + int len = origLen; + if (boundaryFound) { + return -1; + } + if ((off < 0) || (off > b.length) || (len < 0) + || ((off + len) > b.length) || ((off + len) < 0)) { + + throw new IndexOutOfBoundsException(); + } + if (len == 0) { + return 0; + } + boolean bufferCreated = false; + if (len < boundary.length * 2) { + //buffer is too short to detect boundaries with it. We'll need to create a larger buffer + bufferCreated = true; + if (boundaryBuffer == null) { + boundaryBuffer = new byte[boundary.length * 2]; + } + b = boundaryBuffer; + off = 0; + len = boundaryBuffer.length; + } + if (len > pbAmount) { + len = pbAmount; //can only pushback that much so make sure we can + } + if (len > 0) { + len = inStream.read(b, off, len); + } + int i = processBuffer(b, off, len); + if (bufferCreated && i > 0) { + // read more than we need, push it back + if (origLen >= i) { + System.arraycopy(b, 0, buf, origOff, i); + } else { + System.arraycopy(b, 0, buf, origOff, origLen); + inStream.unread(b, origLen, i - origLen); + i = origLen; + } + } else if (i == 0 && boundaryFound) { + return -1; + } + return i; + } + + //Has Data after encountering CRLF + private boolean hasData(byte[] b, int initialPointer, int pointer, int off, int len) + throws IOException { + if (pointer < (off + len)) { + return true; + } else { + inStream.unread(b, initialPointer, (off + len) - initialPointer); + return false; + } + } + + protected int processBuffer(byte[] buffer, int off, int len) throws IOException { + for (int i = off; i < (off + len); i++) { + boolean needUnread0d0a = false; + int value = buffer[i]; + int initialI = i; + if (value == 13) { + if (!hasData(buffer, initialI, initialI + 1, off, len)) { + return initialI - off; + } + value = buffer[initialI + 1]; + if (value != 10) { + continue; + } else { //if it comes here then 13, 10 are values and will try to match boundaries + if (!hasData(buffer, initialI, initialI + 2, off, len)) { + return initialI - off; + } + value = buffer[initialI + 2]; + if ((byte) value != boundary[0]) { + i++; + continue; + } else { //13, 10, boundaries first value matched + needUnread0d0a = true; + i += 2; //i after this points to boundary[0] element + } + } + } else if (value != boundary[0]) { + continue; + } + + int boundaryIndex = 0; + while ((boundaryIndex < boundary.length) && (value == boundary[boundaryIndex])) { + if (!hasData(buffer, initialI, i + 1, off, len)) { + return initialI - off; + } + value = buffer[++i]; + boundaryIndex++; + } + if (boundaryIndex == boundary.length) { + // read the end of line character + if (initialI != off) { + i = 1000000000; + } + if (!hasData(buffer, initialI, i + 1, off, len)) { + return initialI - off; + } + boundaryFound = true; + int j = i + 1; + if (j < len && buffer[j] == 45 && value == 45) { + // Last mime boundary should have a succeeding "--" + // as we are on it, read the terminating CRLF + i += 2; + //last mime boundary + } + + //boundary matched (may or may not be last mime boundary) + int processed = initialI - off; + if ((len - (i + 2)) > 0) { + inStream.unread(buffer, i + 2, len - (i + 2)); + } + return processed; + } + + // Boundary not found. Restoring bytes skipped. + // write first skipped byte, push back the rest + if (value != -1) { //pushing back first byte of boundary + // Stream might have ended + i--; + } + if (needUnread0d0a) { //Pushing all, returning 13 + i = i - boundaryIndex; + i--; //for 10 + value = 13; + } else { + i = i - boundaryIndex; + i++; + value = boundary[0]; + } + } + return len; } public int read() throws IOException { Propchange: cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/wsdl/CrossSchemaImportsTests.java ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Nov 18 06:50:01 2008 @@ -1 +1 @@ -/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/wsdl/CrossSchemaImportsTests.java:712600,713083,713410,713413,713594,713599,713808,713901,714169-714171 +/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/wsdl/CrossSchemaImportsTests.java:712600,713083,713410,713413,713594,713599,713808,713901,714169-714171,718622
