[java-opensaml COMMIT] in /trunk: opensaml-soap-api/src/main/java/org/opensaml/soap/messaging/context/SOAP11Context.j...

noreply at shibboleth.net noreply at shibboleth.net
Thu Jun 5 20:44:18 EDT 2014


Author: putmanb
Date: Thu Jun  5 20:44:16 2014
New Revision: 3919

URL: http://svn.shibboleth.net/view/java-opensaml?rev=3919&view=rev
Log:
Add SOAP encoder and context support to allow explicitly specifying the HTTP response code to return.

Modified:
    trunk/opensaml-soap-api/src/main/java/org/opensaml/soap/messaging/context/SOAP11Context.java
    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-api/src/main/java/org/opensaml/soap/messaging/context/SOAP11Context.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-soap-api/src/main/java/org/opensaml/soap/messaging/context/SOAP11Context.java?rev=3919&r1=3918&r2=3919&view=diff
==============================================================================
--- trunk/opensaml-soap-api/src/main/java/org/opensaml/soap/messaging/context/SOAP11Context.java (original)
+++ trunk/opensaml-soap-api/src/main/java/org/opensaml/soap/messaging/context/SOAP11Context.java Thu Jun  5 20:44:16 2014
@@ -31,6 +31,9 @@
 
     /** The SAML protocol in use. */
     private Envelope envelope;
+    
+    /** The HTTP response status code to return. */
+    private Integer httpResponseStatus;
 
     /**
      * Gets the current SOAP 1.1 Envelope.
@@ -49,5 +52,25 @@
     public void setEnvelope(@Nullable final Envelope newEnvelope) {
         envelope = newEnvelope;
     }
+
+    /**
+     * Get the optional HTTP response status code to return.
+     * 
+     * @return HTTP response status code, may be null
+     */
+    @Nullable public Integer getHTTPResponseStatus() {
+        return httpResponseStatus;
+    }
+
+    /**
+     * Set the optional HTTP response status code to return.
+     * 
+     * @param status the HTTP response status code, may be null
+     */
+    public void setHTTPResponseStatus(@Nullable final Integer status) {
+        httpResponseStatus = status;
+    }
+    
+    
     
 }

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=3919&r1=3918&r2=3919&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 20:44:16 2014
@@ -212,18 +212,21 @@
      * @return the HTTP response status code
      */
     protected int getHTTPResponseStatusCode() {
-        //TODO support explicit arbitrary code and message via SOAP context
+        Integer contextStatus = getMessageContext().getSubcontext(SOAP11Context.class, true).getHTTPResponseStatus();
+        if (contextStatus != null) {
+            return contextStatus;
+        }
         
         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 HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
             }
         }
         
-        return 200;
+        return HttpServletResponse.SC_OK;
     }
     
     /** {@inheritDoc} */

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=3919&r1=3918&r2=3919&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 20:44:16 2014
@@ -20,6 +20,8 @@
 import java.io.ByteArrayInputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
 
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
@@ -308,6 +310,28 @@
         Assert.assertEquals(encodedFault.getMessage().getValue(), "Something bad happened");
     }
     
+    @Test
+    public void testContextReturnStatus() throws ComponentInitializationException, MessageEncodingException, XMLParserException, UnmarshallingException {
+        XMLObject payload = buildXMLObject(simpleXMLObjectQName);
+        
+        MessageContext<XMLObject> messageContext = new MessageContext<XMLObject>();

[... 21 lines stripped ...]


More information about the commits mailing list