View Javadoc

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