View Javadoc

1   /*
2    * Copyright 2007 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.wsdl.wsdl11.builder;
18  
19  import javax.wsdl.Binding;
20  import javax.wsdl.BindingFault;
21  import javax.wsdl.BindingInput;
22  import javax.wsdl.BindingOperation;
23  import javax.wsdl.BindingOutput;
24  import javax.wsdl.Definition;
25  import javax.wsdl.Fault;
26  import javax.wsdl.Input;
27  import javax.wsdl.Operation;
28  import javax.wsdl.Output;
29  import javax.wsdl.Port;
30  import javax.wsdl.PortType;
31  import javax.wsdl.WSDLException;
32  import javax.wsdl.extensions.ExtensibilityElement;
33  import javax.wsdl.extensions.ExtensionRegistry;
34  import javax.wsdl.extensions.soap12.SOAP12Address;
35  import javax.wsdl.extensions.soap12.SOAP12Binding;
36  import javax.wsdl.extensions.soap12.SOAP12Body;
37  import javax.wsdl.extensions.soap12.SOAP12Fault;
38  import javax.wsdl.extensions.soap12.SOAP12Operation;
39  import javax.xml.namespace.QName;
40  
41  /**
42   * Abstract base class for <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J and contain a SOAP 1.2
43   * binding. Requires the <code>locationUri</code> property to be set before use.
44   *
45   * @author Arjen Poutsma
46   * @author Alex Marshall
47   * @see #setLocationUri(String)
48   * @since 1.5.0
49   * @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
50   *             and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
51   */
52  public abstract class AbstractSoap12Wsdl4jDefinitionBuilder extends AbstractBindingWsdl4jDefinitionBuilder {
53  
54      private static final String WSDL_SOAP_NAMESPACE_URI = "http://schemas.xmlsoap.org/wsdl/soap12/";
55  
56      private static final String WSDL_SOAP_PREFIX = "soap12";
57  
58      /** The default soap12:binding transport attribute value. */
59      public static final String DEFAULT_TRANSPORT_URI = "http://schemas.xmlsoap.org/soap/http";
60  
61      private String transportUri = DEFAULT_TRANSPORT_URI;
62  
63      private String locationUri;
64  
65      /**
66       * Sets the value used for the soap12:binding transport attribute value.
67       *
68       * @see SOAP12Binding#setTransportURI(String)
69       * @see #DEFAULT_TRANSPORT_URI
70       */
71      public void setTransportUri(String transportUri) {
72          this.transportUri = transportUri;
73      }
74  
75      /** Sets the value used for the soap12:address location attribute value. */
76      public void setLocationUri(String locationUri) {
77          this.locationUri = locationUri;
78      }
79  
80      /** Adds the WSDL SOAP namespace to the definition. */
81      protected void populateDefinition(Definition definition) throws WSDLException {
82          definition.addNamespace(WSDL_SOAP_PREFIX, WSDL_SOAP_NAMESPACE_URI);
83      }
84  
85      /**
86       * Calls {@link AbstractBindingWsdl4jDefinitionBuilder#populateBinding(Binding, PortType)}, creates {@link
87       * SOAP12Binding}, and calls {@link #populateSoapBinding(SOAP12Binding)}.
88       *
89       * @param binding  the WSDL4J <code>Binding</code>
90       * @param portType the corresponding <code>PortType</code>
91       * @throws WSDLException in case of errors
92       */
93      protected void populateBinding(Binding binding, PortType portType) throws WSDLException {
94          super.populateBinding(binding, portType);
95          SOAP12Binding soapBinding = (SOAP12Binding) createSoapExtension(Binding.class, "binding");
96          populateSoapBinding(soapBinding);
97          binding.addExtensibilityElement(soapBinding);
98      }
99  
100     /**
101      * Called after the {@link SOAP12Binding} has been created. Default implementation sets the binding style to
102      * <code>"document"</code>, and set the transport URI to the value set on this builder. Subclasses can override this
103      * behavior.
104      *
105      * @param soapBinding the WSDL4J <code>SOAP12Binding</code>
106      * @throws WSDLException in case of errors
107      * @see SOAP12Binding#setStyle(String)
108      * @see SOAP12Binding#setTransportURI(String)
109      * @see #setTransportUri(String)
110      * @see #DEFAULT_TRANSPORT_URI
111      */
112     protected void populateSoapBinding(SOAP12Binding soapBinding) throws WSDLException {
113         soapBinding.setStyle("document");
114         soapBinding.setTransportURI(transportUri);
115     }
116 
117     /**
118      * Calls {@link AbstractBindingWsdl4jDefinitionBuilder#populateBindingOperation(BindingOperation, Operation)},
119      * creates a {@link SOAP12Operation}, and calls {@link #populateSoapOperation(SOAP12Operation)}.
120      *
121      * @param bindingOperation the WSDL4J <code>BindingOperation</code>
122      * @throws WSDLException in case of errors
123      */
124     protected void populateBindingOperation(BindingOperation bindingOperation, Operation operation)
125             throws WSDLException {
126         super.populateBindingOperation(bindingOperation, operation);
127         SOAP12Operation soapOperation = (SOAP12Operation) createSoapExtension(BindingOperation.class, "operation");
128         populateSoapOperation(soapOperation);
129         bindingOperation.addExtensibilityElement(soapOperation);
130     }
131 
132     /**
133      * Called after the {@link SOAP12Operation} has been created.
134      * <p/>
135      * Default implementation set the <code>SOAPAction</code> uri to an empty string.
136      *
137      * @param soapOperation the WSDL4J <code>SOAP12Operation</code>
138      * @throws WSDLException in case of errors
139      * @see SOAP12Operation#setSoapActionURI(String)
140      */
141     protected void populateSoapOperation(SOAP12Operation soapOperation) throws WSDLException {
142         soapOperation.setSoapActionURI("");
143     }
144 
145     /**
146      * Creates a {@link SOAP12Body}, and calls {@link #populateSoapBody(SOAP12Body)}.
147      *
148      * @param bindingInput the WSDL4J <code>BindingInput</code>
149      * @throws WSDLException in case of errors
150      */
151     protected void populateBindingInput(BindingInput bindingInput, Input input) throws WSDLException {
152         super.populateBindingInput(bindingInput, input);
153         SOAP12Body soapBody = (SOAP12Body) createSoapExtension(BindingInput.class, "body");
154         populateSoapBody(soapBody);
155         bindingInput.addExtensibilityElement(soapBody);
156     }
157 
158     /**
159      * Creates a {@link SOAP12Body}, and calls {@link #populateSoapBody(SOAP12Body)}.
160      *
161      * @param bindingOutput the WSDL4J <code>BindingOutput</code>
162      * @throws WSDLException in case of errors
163      */
164     protected void populateBindingOutput(BindingOutput bindingOutput, Output output) throws WSDLException {
165         super.populateBindingOutput(bindingOutput, output);
166         SOAP12Body soapBody = (SOAP12Body) createSoapExtension(BindingOutput.class, "body");
167         populateSoapBody(soapBody);
168         bindingOutput.addExtensibilityElement(soapBody);
169     }
170 
171     /**
172      * Creates a {@link SOAP12Body}, and calls {@link #populateSoapBody(SOAP12Body)}.
173      *
174      * @param bindingFault the WSDL4J <code>BindingFault</code>
175      * @throws WSDLException in case of errors
176      */
177     protected void populateBindingFault(BindingFault bindingFault, Fault fault) throws WSDLException {
178         super.populateBindingFault(bindingFault, fault);
179         SOAP12Fault soapFault = (SOAP12Fault) createSoapExtension(BindingFault.class, "fault");
180         populateSoapFault(bindingFault, soapFault);
181         bindingFault.addExtensibilityElement(soapFault);
182     }
183 
184     /**
185      * Called after the {@link SOAP12Body} has been created. Default implementation sets the use style to
186      * <code>"literal"</code>. Subclasses can override this behavior.
187      *
188      * @param soapBody the WSDL4J <code>SOAP12Body</code>
189      * @throws WSDLException in case of errors
190      * @see SOAP12Body#setUse(String)
191      */
192     protected void populateSoapBody(SOAP12Body soapBody) throws WSDLException {
193         soapBody.setUse("literal");
194     }
195 
196     /**
197      * Called after the {@link SOAP12Fault} has been created. Default implementation sets the use style to
198      * <code>"literal"</code>, and sets the name equal to the binding fault. Subclasses can override this behavior.
199      *
200      * @param bindingFault the WSDL4J <code>BindingFault</code>
201      * @param soapFault    the WSDL4J <code>SOAPFault</code>
202      * @throws WSDLException in case of errors
203      * @see SOAP12Fault#setUse(String)
204      */
205     protected void populateSoapFault(BindingFault bindingFault, SOAP12Fault soapFault) throws WSDLException {
206         soapFault.setName(bindingFault.getName());
207         soapFault.setUse("literal");
208     }
209 
210     /**
211      * Creates a {@link SOAP12Address}, and calls {@link #populateSoapAddress(SOAP12Address)}.
212      *
213      * @param port the WSDL4J <code>Port</code>
214      * @throws WSDLException in case of errors
215      */
216     protected void populatePort(Port port, Binding binding) throws WSDLException {
217         super.populatePort(port, binding);
218         SOAP12Address soapAddress = (SOAP12Address) createSoapExtension(Port.class, "address");
219         populateSoapAddress(soapAddress);
220         port.addExtensibilityElement(soapAddress);
221     }
222 
223     /**
224      * Called after the {@link SOAP12Address} has been created. Default implementation sets the location URI to the
225      * value set on this builder. Subclasses can override this behavior.
226      *
227      * @param soapAddress the WSDL4J <code>SOAPAddress</code>
228      * @throws WSDLException in case of errors
229      * @see SOAP12Address#setLocationURI(String)
230      * @see #setLocationUri(String)
231      */
232     protected void populateSoapAddress(SOAP12Address soapAddress) throws WSDLException {
233         soapAddress.setLocationURI(locationUri);
234     }
235 
236     /**
237      * Creates a SOAP 1.2 extensibility element.
238      *
239      * @param parentType a class object indicating where in the WSDL definition this extension will exist
240      * @param localName  the local name of the extensibility element
241      * @return the extensibility element
242      * @throws WSDLException in case of errors
243      * @see ExtensionRegistry#createExtension(Class,javax.xml.namespace.QName)
244      */
245     protected ExtensibilityElement createSoapExtension(Class parentType, String localName) throws WSDLException {
246         return createExtension(parentType, new QName(WSDL_SOAP_NAMESPACE_URI, localName));
247     }
248 
249 }