1 /*
2  * Copyright 2005-2014 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
27 /**
28  * Implements WS-Addressing 1.0 (May 2006). This version of the specification is used by Microsoft's Windows
29  * Communication Foundation (WCF), and supported by Axis 1 and 2.
30  *
31  * @author Arjen Poutsma
32  * @see <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509">Web Services Addressing, August 2004</a>
33  * @since 1.5.0
34  */

35
36 public class Addressing10 extends AbstractAddressingVersion {
37
38     private static final String NAMESPACE_URI = "http://www.w3.org/2005/08/addressing";
39
40     @Override
41     public void addAddressingHeaders(SoapMessage message, MessageAddressingProperties map) {
42         Assert.notNull(map.getAction(), "'Action' is required");
43         super.addAddressingHeaders(message, map);
44     }
45
46     @Override
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 new QName(NAMESPACE_URI, "MessageAddressingHeaderRequired",
91                 getNamespacePrefix());
92     }
93
94     @Override
95     protected final String getMessageAddressingHeaderRequiredFaultReason() {
96         return "A required header representing a Message Addressing Property is not present";
97     }
98
99     @Override
100     protected QName getInvalidAddressingHeaderFaultSubcode() {
101         return new QName(NAMESPACE_URI, "InvalidAddressingHeader", getNamespacePrefix());
102     }
103
104     @Override
105     protected String getInvalidAddressingHeaderFaultReason() {
106         return "A header representing a Message Addressing Property is not valid and the message cannot be processed";
107     }
108
109     public String toString() {
110         return "WS-Addressing 1.0";
111     }
112 }
113