[java-opensaml COMMIT] in /trunk/opensaml-soap-impl/src: main/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOA...

noreply at shibboleth.net noreply at shibboleth.net
Thu Jun 5 17:22:27 EDT 2014


Author: putmanb
Date: Thu Jun  5 17:22:26 2014
New Revision: 3918

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3918&view=rev
Log:
OSJ-80: SOAP encoders should use 500 HTTP status for SOAP faults 

Modified:
    trunk/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11Encoder.java
    trunk/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java

Modified: trunk/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11Encoder.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11Encoder.java?rev=3918&r1=3917&r2=3918&view=diff
==============================================================================
--- trunk/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11Encoder.java (original)
+++ trunk/opensaml-soap-impl/src/main/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11Encoder.java Thu Jun  5 17:22:26 2014
@@ -37,6 +37,7 @@
 import org.opensaml.soap.messaging.context.SOAP11Context;
 import org.opensaml.soap.soap11.Body;
 import org.opensaml.soap.soap11.Envelope;
+import org.opensaml.soap.soap11.Fault;
 import org.opensaml.soap.soap11.Header;
 import org.opensaml.soap.wsaddressing.Action;
 import org.slf4j.Logger;
@@ -177,8 +178,10 @@
         } else {
             response.setHeader("SOAPAction", "");
         }
-    }
- 
+        
+        response.setStatus(getHTTPResponseStatusCode());
+    }
+
     /**
      * Determine the value of the SOAPAction HTTP header to send.
      * 
@@ -203,6 +206,26 @@
         }
     }
     
+    /**
+     * Get the HTTP response status code to return.
+     * 
+     * @return the HTTP response status code
+     */
+    protected int getHTTPResponseStatusCode() {
+        //TODO support explicit arbitrary code and message via SOAP context
+        
+        Envelope envelope = getSOAPEnvelope();
+        if (envelope != null && envelope.getBody() != null) {
+            Body body = envelope.getBody();
+            List<XMLObject> faults = body.getUnknownXMLObjects(Fault.DEFAULT_ELEMENT_NAME);
+            if (!faults.isEmpty()) {
+                return 500;
+            }
+        }
+        
+        return 200;
+    }
+    
     /** {@inheritDoc} */
     protected XMLObject getMessageToLog() {
         return getMessageContext().getSubcontext(SOAP11Context.class, true).getEnvelope();

Modified: trunk/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java?rev=3918&r1=3917&r2=3918&view=diff
==============================================================================
--- trunk/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java (original)
+++ trunk/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java Thu Jun  5 17:22:26 2014
@@ -19,6 +19,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.UnsupportedEncodingException;
+import java.util.List;
 
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
@@ -36,6 +37,9 @@
 import org.opensaml.soap.messaging.context.SOAP11Context;
 import org.opensaml.soap.soap11.Body;
 import org.opensaml.soap.soap11.Envelope;
+import org.opensaml.soap.soap11.Fault;
+import org.opensaml.soap.soap11.FaultCode;
+import org.opensaml.soap.soap11.FaultString;
 import org.opensaml.soap.soap11.Header;
 import org.opensaml.soap.soap11.encoder.http.impl.HTTPSOAP11Encoder;
 import org.opensaml.soap.util.SOAPSupport;
@@ -87,6 +91,7 @@
         Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
         Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
         Assert.assertEquals(response.getHeader("SOAPAction"), "");
+        Assert.assertEquals(response.getStatus(), 200);
         
         Envelope encodedEnv = (Envelope) parseUnmarshallResourceByteArray(response.getContentAsByteArray(), false);
         
@@ -138,6 +143,8 @@
         Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");
         Assert.assertEquals(response.getHeader("Cache-control"), "no-cache, no-store", "Unexpected cache controls");
         Assert.assertEquals(response.getHeader("SOAPAction"), "");
+        Assert.assertEquals(response.getStatus(), 200);
+        
         
         Envelope encodedEnv = (Envelope) parseUnmarshallResourceByteArray(response.getContentAsByteArray(), false);
         
@@ -195,6 +202,7 @@
         Assert.assertEquals("UTF-8", response.getCharacterEncoding(), "Unexpected character encoding");

[... 59 lines stripped ...]


More information about the commits mailing list