View Javadoc
1   /*
2    * Copyright 2005-2010 the original author or authors.
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.springframework.ws.soap.addressing.version;
18  
19  import java.net.URI;
20  import javax.xml.namespace.QName;
21  
22  import org.springframework.util.Assert;
23  import org.springframework.ws.soap.SoapMessage;
24  import org.springframework.ws.soap.addressing.core.EndpointReference;
25  import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
26  import org.springframework.xml.namespace.QNameUtils;
27  
28  /**
29   * Implements WS-Addressing 1.0 (May 2006). This version of the specification is used by Microsoft's Windows
30   * Communication Foundation (WCF), and supported by Axis 1 and 2.
31   *
32   * @author Arjen Poutsma
33   * @see <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509">Web Services Addressing, August 2004</a>
34   * @since 1.5.0
35   */
36  
37  public class Addressing10 extends AbstractAddressingVersion {
38  
39      private static final String NAMESPACE_URI = "http://www.w3.org/2005/08/addressing";
40  
41      @Override
42      public void addAddressingHeaders(SoapMessage message, MessageAddressingProperties map) {
43          Assert.notNull(map.getAction(), "'Action' is required");
44          super.addAddressingHeaders(message, map);
45      }
46  
47      public boolean hasRequiredProperties(MessageAddressingProperties map) {
48          if (map.getAction() == null) {
49              return false;
50          }
51          if (map.getReplyTo() != null || map.getFaultTo() != null) {
52              return map.getMessageId() != null;
53          }
54          return true;
55  
56      }
57  
58      @Override
59      protected String getNamespaceUri() {
60          return NAMESPACE_URI;
61      }
62  
63      @Override
64      protected QName getReferencePropertiesName() {
65          return null;
66      }
67  
68      @Override
69      protected URI getDefaultTo() {
70          return getAnonymous();
71      }
72  
73      @Override
74      protected EndpointReference getDefaultReplyTo(EndpointReference from) {
75          return new EndpointReference(getAnonymous());
76      }
77  
78      @Override
79      protected final URI getAnonymous() {
80          return URI.create(NAMESPACE_URI + "/anonymous");
81      }
82  
83      @Override
84      protected final URI getNone() {
85          return URI.create(NAMESPACE_URI + "/none");
86      }
87  
88      @Override
89      protected final QName getMessageAddressingHeaderRequiredFaultSubcode() {
90          return QNameUtils.createQName(NAMESPACE_URI, "MessageAddressingHeaderRequired", getNamespacePrefix());
91      }
92  
93      @Override
94      protected final String getMessageAddressingHeaderRequiredFaultReason() {
95          return "A required header representing a Message Addressing Property is not present";
96      }
97  
98      @Override
99      protected QName getInvalidAddressingHeaderFaultSubcode() {
100         return QNameUtils.createQName(NAMESPACE_URI, "InvalidAddressingHeader", getNamespacePrefix());
101     }
102 
103     @Override
104     protected String getInvalidAddressingHeaderFaultReason() {
105         return "A header representing a Message Addressing Property is not valid and the message cannot be processed";
106     }
107 
108     public String toString() {
109         return "WS-Addressing 1.0";
110     }
111 }