Author: tterm
Date: Wed Jan 26 13:52:02 2011
New Revision: 1063719

URL: http://svn.apache.org/viewvc?rev=1063719&view=rev
Log:
SMXCOMP-845 http provider processor - simple response content type check 
missing which can lead to errors.

Modified:
    
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
    
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java

Modified: 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?rev=1063719&r1=1063718&r2=1063719&view=diff
==============================================================================
--- 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
 (original)
+++ 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
 Wed Jan 26 13:52:02 2011
@@ -61,6 +61,7 @@ public class HttpEndpoint extends SoapEn
     protected boolean synchronous;
     protected boolean wantContentTypeHeaderFromExchangeIntoHttpRequest;
     protected int timeout;
+    protected boolean responseContentTypeCheck;
 
     public HttpEndpoint() {
     }
@@ -92,6 +93,32 @@ public class HttpEndpoint extends SoapEn
     }
 
     /**
+     *
+     * @return <code>true</code> it the http provider checks the content type 
agains the keyword xml
+     */
+    public boolean isResponseContentTypeCheck() {
+        return responseContentTypeCheck;
+    }
+
+    /**
+     * Specifies if the http provider checks the response content type for the
+     * keyword xml. If it is true the provider will throw an exception if the 
content type
+     * does not contain the word xml. This should avoid that non valid xml is 
received by the
+     * provider endpoint and set as normalize message. Because the target 
expect to get an
+     * valid xml.
+     *
+     * @param responseContentTypeCheck
+     * @org.apache.xbean.Property description="Specifies if the http provider 
checks the response content type for the
+     *                            keyword xml. If it is true the provider will 
throw an exception if the content type
+     *                            does not contain the word xml. This should 
avoid that non valid xml is received by the
+     *                            provider endpoint and set as normalize 
message. Because the target expect to get an
+     *                            valid xml"
+     */
+    public void setResponseContentTypeCheck(boolean responseContentTypeCheck) {
+        this.responseContentTypeCheck = responseContentTypeCheck;
+    }
+  
+    /**
      * @return the synchronous
      */
     public boolean isSynchronous() {

Modified: 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL: 
http://svn.apache.org/viewvc/servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?rev=1063719&r1=1063718&r2=1063719&view=diff
==============================================================================
--- 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
 (original)
+++ 
servicemix/components/trunk/bindings/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
 Wed Jan 26 13:52:02 2011
@@ -163,10 +163,15 @@ public class ProviderProcessor extends A
             }
             // Execute the HTTP method
             int response = 
getClient().executeMethod(getHostConfiguration(locationURI, exchange, nm), 
method);
+            Header contentType = method.getResponseHeader(HEADER_CONTENT_TYPE);
+            // if true check if xml is contained (it is actually not enough) 
and if not it will throw an exception
+            // with the complete response is logged.
+            if (endpoint.isResponseContentTypeCheck() && 
!contentType.toExternalForm().contains("xml")) {
+                throw new Exception(method.getResponseBodyAsString());
+            }
             if (response != HttpStatus.SC_OK && response != 
HttpStatus.SC_ACCEPTED) {
                 if (!(exchange instanceof InOnly)) {
                     SoapReader reader = 
soapHelper.getSoapMarshaler().createReader();
-                    Header contentType = 
method.getResponseHeader(HEADER_CONTENT_TYPE);
                     soapMessage = 
reader.read(method.getResponseBodyAsStream(), 
                                               contentType != null ? 
contentType.getValue() : null);
                     context.setFaultMessage(soapMessage);


Reply via email to