View Javadoc

1   /*
2    * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.opensaml.ws.soap.soap11.decoder ;
18  
19  import java.util.List;
20  
21  import org.opensaml.ws.message.MessageContext;
22  import org.opensaml.ws.message.decoder.MessageDecodingException;
23  import org.opensaml.ws.message.handler.BaseHandlerChainAwareMessageDecoder;
24  import org.opensaml.ws.soap.soap11.Envelope;
25  import org.opensaml.ws.soap.soap11.Header;
26  import org.opensaml.ws.transport.InTransport;
27  import org.opensaml.xml.XMLObject;
28  import org.opensaml.xml.parse.ParserPool;
29  import org.opensaml.xml.security.SecurityException;
30  import org.slf4j.Logger;
31  import org.slf4j.LoggerFactory;
32  
33  /**
34   * Basic SOAP 1.1 decoder.
35   */
36  public class SOAP11Decoder extends BaseHandlerChainAwareMessageDecoder {
37  
38      /** Class logger. */
39      private final Logger log = LoggerFactory.getLogger(SOAP11Decoder.class);
40      
41      /** Constructor. */
42      public SOAP11Decoder() {
43          super();
44      }
45      
46      /**
47       * Constructor.
48       * 
49       * @param pool parser pool used to deserialize messages
50       */
51      public SOAP11Decoder(ParserPool pool) {
52          super(pool);
53      }
54  
55      /** {@inheritDoc} */
56      protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
57  
58          InTransport inTransport = messageContext.getInboundMessageTransport();
59  
60          log.debug("Unmarshalling SOAP message");
61          Envelope soapMessage = (Envelope) unmarshallMessage(inTransport.getIncomingStream());
62          messageContext.setInboundMessage(soapMessage);
63      }
64      
65      
66      /** {@inheritDoc} */
67      public void decode(MessageContext messageContext) throws MessageDecodingException, SecurityException {
68              super.decode(messageContext);
69          
70              // TODO enable once header checking support is completed
71              // checkUnderstoodSOAPHeaders(messageContext);
72      }
73      
74      /**
75       * Check that all headers which carry the <code>soap11:mustUnderstand</code> attribute
76       * and which are targeted to this SOAP node via the <code>soap11:actor</code> were understood by the
77       * decoder.
78       * 
79       * @param messageContext the message context being processed
80       * 
81       * @throws MessageDecodingException thrown if a SOAP header requires understanding by 
82       *              this node but was not understood
83       */
84      private void checkUnderstoodSOAPHeaders(MessageContext messageContext)
85              throws MessageDecodingException {
86          
87          Envelope envelope = (Envelope) messageContext.getInboundMessage();
88          Header soapHeader = envelope.getHeader();
89          if (soapHeader == null) {
90              log.debug("SOAP Envelope contained no Header");
91              return;
92          }
93          List<XMLObject> headers = soapHeader.getUnknownXMLObjects();
94          if (headers == null || headers.isEmpty()) {
95              log.debug("SOAP Envelope header list was either null or empty");
96              return;
97          }
98  
99          for (XMLObject header : headers) {
100             //TODO
101         }
102     }
103 
104 }