Author: dkulp
Date: Thu Jan 22 15:35:26 2009
New Revision: 736852
URL: http://svn.apache.org/viewvc?rev=736852&view=rev
Log:
[CXF-1819, CXF-1847] Apply couple of easy fixes
Added:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/QuotedPrintableDecoderStream.java
(with props)
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?rev=736852&r1=736851&r2=736852&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
Thu Jan 22 15:35:26 2009
@@ -338,7 +338,11 @@
if (isFineLogging) {
LOG.fine("Invoking handleFault on interceptor " +
currentInterceptor);
}
- currentInterceptor.handleFault(message);
+ try {
+ currentInterceptor.handleFault(message);
+ } catch (Exception e) {
+ LOG.log(Level.WARNING, "Exception in handleFault on
interceptor " + currentInterceptor, e);
+ }
}
}
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=736852&r1=736851&r2=736852&view=diff
==============================================================================
---
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
(original)
+++
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
Thu Jan 22 15:35:26 2009
@@ -290,17 +290,29 @@
MimeBodyPartInputStream partStream = new
MimeBodyPartInputStream(stream, boundary, pbAmount);
final String ct = headers.getHeader("Content-Type", null);
- DataSource source = new AttachmentDataSource(ct, new
DelegatingInputStream(partStream));
- att.setDataHandler(new DataHandler(source));
-
+
+ boolean quotedPrintable = false;
+
for (Enumeration<?> e = headers.getAllHeaders(); e.hasMoreElements();)
{
Header header = (Header) e.nextElement();
- if (header.getName().equalsIgnoreCase("Content-Transfer-Encoding")
- && header.getValue().equalsIgnoreCase("binary")) {
- att.setXOP(true);
+ if
(header.getName().equalsIgnoreCase("Content-Transfer-Encoding")) {
+ if (header.getValue().equalsIgnoreCase("binary")) {
+ att.setXOP(true);
+ } else if
(header.getValue().equalsIgnoreCase("quoted-printable")) {
+ quotedPrintable = true;
+ }
}
att.setHeader(header.getName(), header.getValue());
}
+
+ DelegatingInputStream is = new DelegatingInputStream(partStream);
+ if (quotedPrintable) {
+ DataSource source = new AttachmentDataSource(ct, new
QuotedPrintableDecoderStream(is));
+ att.setDataHandler(new DataHandler(source));
+ } else {
+ DataSource source = new AttachmentDataSource(ct, is);
+ att.setDataHandler(new DataHandler(source));
+ }
}
public boolean isLazyLoading() {
Added:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/QuotedPrintableDecoderStream.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/QuotedPrintableDecoderStream.java?rev=736852&view=auto
==============================================================================
---
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/QuotedPrintableDecoderStream.java
(added)
+++
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/QuotedPrintableDecoderStream.java
Thu Jan 22 15:35:26 2009
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * 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.
+ */
+package org.apache.cxf.attachment;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class QuotedPrintableDecoderStream extends InputStream {
+ private static final byte[] ENCODING_TABLE = {
+ (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5',
(byte)'6', (byte)'7', (byte)'8',
+ (byte)'9', (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E',
(byte)'F'
+ };
+
+ /*
+ * set up the decoding table.
+ */
+ private static final byte[] DECODING_TABLE = new byte[128];
+
+ static {
+ // initialize the decoding table
+ for (int i = 0; i < ENCODING_TABLE.length; i++) {
+ DECODING_TABLE[ENCODING_TABLE[i]] = (byte)i;
+ }
+ }
+
+ private int deferredWhitespace;
+ private int cachedCharacter = -1;
+ private final InputStream in;
+
+ public QuotedPrintableDecoderStream(InputStream is) {
+ this.in = is;
+ }
+
+ private int decodeNonspaceChar(int ch) throws IOException {
+ if (ch != '=') {
+ return ch;
+ }
+ // we need to get two characters after the quotation marker
+ byte[] b = new byte[2];
+ if (in.read(b) < 2) {
+ throw new IOException("Truncated quoted printable data");
+ }
+ if (b[0] == '\r') {
+ // we've found an encoded carriage return. The next char needs to
be a newline
+ if (b[1] != '\n') {
+ throw new IOException("Invalid quoted printable encoding");
+ }
+ // this was a soft linebreak inserted by the encoding. We just
toss this away
+ // on decode. We need to return something, so recurse and decode
the next.
+ return read();
+ }
+ // this is a hex pair we need to convert back to a single byte.
+ b[0] = DECODING_TABLE[b[0]];
+ b[1] = DECODING_TABLE[b[1]];
+ return (b[0] << 4) | b[1];
+ }
+
+ @Override
+ public int read() throws IOException {
+ // we potentially need to scan over spans of whitespace characters to
determine if they're real
+ // we just return blanks until the count goes to zero.
+ if (deferredWhitespace > 0) {
+ deferredWhitespace--;
+ return ' ';
+ }
+ // we may have needed to scan ahead to find the first non-blank
character, which we would store here.
+ // hand that back once we're done with the blanks.
+ if (cachedCharacter != -1) {
+ int result = cachedCharacter;
+ cachedCharacter = -1;
+ return result;
+ }
+ int ch = in.read();
+ if (ch != ' ') {
+ return decodeNonspaceChar(ch);
+ }
+ // space characters are a pain. We need to scan ahead until we find a
non-space character.
+ // if the character is a line terminator, we need to discard the
blanks.
+ // scan forward, counting the characters.
+ while ((ch = in.read()) == ' ') {
+ deferredWhitespace++;
+ }
+ // is this a lineend at the current location?
+ if (ch == -1 || ch == '\r' || ch == '\n') {
+ // those blanks we so zealously counted up don't really exist.
Clear out the counter.
+ deferredWhitespace = 0;
+ // return the real significant character now.
+ return ch;
+ }
+ // remember this character for later, after we've used up the deferred
blanks.
+ cachedCharacter = decodeNonspaceChar(ch);
+ // return this space. We did not include this one in the deferred
count, so we're right in sync.
+ return ' ';
+ }
+}
Propchange:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/QuotedPrintableDecoderStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/QuotedPrintableDecoderStream.java
------------------------------------------------------------------------------
svn:keywords = Rev Date