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 the August 2004 edition of the WS-Addressing specification. This version of the specification is used by
30   * Microsoft's Web Services Enhancements (WSE) 3.0, and supported by Axis 1 and 2, and XFire.
31   *
32   * @author Arjen Poutsma
33   * @see <a href="http://www.w3.org/Submission/2004/SUBM-ws-addressing-20040810/">Web Services Addressing, August
34   *      2004</a>
35   * @since 1.5.0
36   */
37  public class Addressing200408 extends AbstractAddressingVersion {
38  
39      private static final String NAMESPACE_URI = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
40  
41      @Override
42      public void addAddressingHeaders(SoapMessage message, MessageAddressingProperties map) {
43          Assert.notNull(map.getAction(), "'Action' is required");
44          Assert.notNull(map.getTo(), "'To' is required");
45          super.addAddressingHeaders(message, map);
46      }
47  
48      public boolean hasRequiredProperties(MessageAddressingProperties map) {
49          if (map.getTo() == null) {
50              return false;
51          }
52          if (map.getAction() == null) {
53              return false;
54          }
55          if (map.getReplyTo() != null || map.getFaultTo() != null) {
56              return map.getMessageId() != null;
57          }
58          return true;
59      }
60  
61      @Override
62      protected final URI getAnonymous() {
63          return URI.create(NAMESPACE_URI + "/role/anonymous");
64      }
65  
66      @Override
67      protected final String getInvalidAddressingHeaderFaultReason() {
68          return "A message information header is not valid and the message cannot be processed.";
69      }
70  
71      @Override
72      protected final QName getInvalidAddressingHeaderFaultSubcode() {
73          return QNameUtils.createQName(NAMESPACE_URI, "InvalidMessageInformationHeader", getNamespacePrefix());
74      }
75  
76      @Override
77      protected final String getMessageAddressingHeaderRequiredFaultReason() {
78          return "A required message information header, To, MessageID, or Action, is not present.";
79      }
80  
81      @Override
82      protected final QName getMessageAddressingHeaderRequiredFaultSubcode() {
83          return QNameUtils.createQName(NAMESPACE_URI, "MessageInformationHeaderRequired", getNamespacePrefix());
84      }
85  
86      @Override
87      protected final String getNamespaceUri() {
88          return NAMESPACE_URI;
89      }
90  
91      @Override
92      protected URI getDefaultTo() {
93          return null;
94      }
95  
96      @Override
97      protected final EndpointReference getDefaultReplyTo(EndpointReference from) {
98          return from;
99      }
100 
101     @Override
102     protected final URI getNone() {
103         return null;
104     }
105 
106     public String toString() {
107         return "WS-Addressing August 2004";
108     }
109 }