Author: gmazza
Date: Wed Mar 26 18:09:23 2008
New Revision: 641675

URL: http://svn.apache.org/viewvc?rev=641675&view=rev
Log:
CXF-1490 (http://tinyurl.com/24j2y3) fixed.  HTML errors are now output on the 
response; no more cryptic Woodstox errors.


Modified:
    
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
    
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/Messages.properties
    
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java

Modified: 
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=641675&r1=641674&r2=641675&view=diff
==============================================================================
--- 
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
 (original)
+++ 
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java
 Wed Mar 26 18:09:23 2008
@@ -96,18 +96,29 @@
     
     public static String toString(final InputStream input) 
         throws IOException {
-        
-        StringBuilder buf = new StringBuilder();
-        final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
-        int n = 0;
-        n = input.read(buffer);
-        while (-1 != n) {
-            buf.append(new String(buffer, 0, n));
-            n = input.read(buffer);
+        return toString(input, DEFAULT_BUFFER_SIZE);
+    }
+    
+    public static String toString(final InputStream input, int bufferSize) 
+           throws IOException {
+           
+        int avail = input.available();
+        if (avail > bufferSize) {
+            bufferSize = avail;
         }
-        input.close();
-        return buf.toString();
+
+        StringBuilder buf = new StringBuilder();
+           final byte[] buffer = new byte[bufferSize];
+           int n = 0;
+           n = input.read(buffer);
+           while (-1 != n) {
+               buf.append(new String(buffer, 0, n));
+               n = input.read(buffer);
+           }
+           input.close();
+           return buf.toString();
     }
+    
     public static String toString(final Reader input) 
         throws IOException {
         

Modified: 
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/Messages.properties
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/Messages.properties?rev=641675&r1=641674&r2=641675&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/Messages.properties
 (original)
+++ 
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/Messages.properties
 Wed Mar 26 18:09:23 2008
@@ -18,7 +18,8 @@
 #    under the License.
 #
 #
-STREAM_CREATE_EXC = Could not create XMLStreamReader(encoding {0}).
+STREAM_CREATE_EXC = Could not create XMLStreamReader (input was of encoding 
{0}).
+INVALID_HTML_RESPONSETYPE = Response was of unexpected text/html ContentType.  
Incoming portion of HTML stream: {0}
 STAX_READ_EXC = Could not read from XMLStreamReader.
 STAX_WRITE_EXC = Could not write to XMLStreamWriter.
 NO_OPERATION_ELEMENT=There must be an operation element.

Modified: 
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java?rev=641675&r1=641674&r2=641675&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
 (original)
+++ 
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
 Wed Mar 26 18:09:23 2008
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.interceptor;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
@@ -30,6 +31,7 @@
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
@@ -58,6 +60,20 @@
         InputStream is = message.getContent(InputStream.class);
         assert is != null;
 
+        String contentType = (String)message.get(Message.CONTENT_TYPE);
+        
+        if (contentType != null && contentType.contains("text/html")) {
+               String htmlMessage = null;
+               try {
+                       htmlMessage = IOUtils.toString(is, 500);
+               } catch (IOException e) {
+                       throw new Fault(new 
org.apache.cxf.common.i18n.Message("INVALID_HTML_RESPONSETYPE",
+                           LOG, "(none)"));
+               }
+               throw new Fault(new 
org.apache.cxf.common.i18n.Message("INVALID_HTML_RESPONSETYPE",
+                    LOG, (htmlMessage == null || htmlMessage.length() == 0) ? 
"(none)" : htmlMessage));
+        }
+        
         String encoding = (String)message.get(Message.ENCODING);
 
         XMLStreamReader reader;
@@ -66,8 +82,7 @@
         } catch (XMLStreamException e) {
             throw new Fault(new 
org.apache.cxf.common.i18n.Message("STREAM_CREATE_EXC",
                                                                    LOG,
-                                                                   encoding),
-                            e);
+                                                                   encoding), 
e);
         }
 
         message.setContent(XMLStreamReader.class, reader);


Reply via email to