001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.binding;
020:
021: import org.apache.axis2.jaxws.ExceptionFactory;
022: import org.apache.axis2.jaxws.description.EndpointDescription;
023: import org.apache.axis2.jaxws.i18n.Messages;
024: import org.apache.axis2.jaxws.utility.SAAJFactory;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027:
028: import javax.xml.soap.MessageFactory;
029: import javax.xml.soap.SOAPConstants;
030: import javax.xml.soap.SOAPException;
031: import javax.xml.soap.SOAPFactory;
032: import javax.xml.ws.WebServiceException;
033:
034: import java.util.AbstractSet;
035: import java.util.HashSet;
036: import java.util.Set;
037:
038: /**
039: * An implementation of the <link>javax.xml.ws.soap.SOAPBinding</link>
040: * interface. This is the default binding for JAX-WS, and will exist for all
041: * Dispatch and Dynamic Proxy instances unless the XML/HTTP Binding is
042: * explicitly specificied.
043: */
044: public class SOAPBinding extends BindingImpl implements
045: javax.xml.ws.soap.SOAPBinding {
046:
047: private boolean mtomEnabled = false;
048:
049: private static Log log = LogFactory.getLog(SOAPBinding.class);
050:
051: public SOAPBinding(EndpointDescription endpointDesc) {
052: super (endpointDesc);
053: }
054:
055: /*
056: * (non-Javadoc)
057: *
058: * @see javax.xml.ws.soap.SOAPBinding#getMessageFactory()
059: */
060: public MessageFactory getMessageFactory() {
061: String bindingNamespace = null;
062: try {
063: /*
064: * SAAJFactory.createMessageFactory takes a namespace String as a
065: * param: "http://schemas.xmlsoap.org/soap/envelope/" (SOAP1.1)
066: * "http://www.w3.org/2003/05/soap-envelope" (SOAP1.2)
067: *
068: * The bindingId will be in one of the following forms:
069: * "http://schemas.xmlsoap.org/wsdl/soap/http" (SOAP1.1)
070: * "http://www.w3.org/2003/05/soap/bindings/HTTP/" (SOAP1.2)
071: */
072: if (bindingId
073: .equalsIgnoreCase(SOAPBinding.SOAP12HTTP_BINDING)
074: || bindingId
075: .equalsIgnoreCase(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
076: bindingNamespace = SOAP12_ENV_NS;
077: } else {
078: // TODO currently defaults to SOAP11. Should we be more stricct
079: // about checking?
080: bindingNamespace = SOAP11_ENV_NS;
081: }
082: return SAAJFactory.createMessageFactory(bindingNamespace);
083: } catch (WebServiceException e) {
084: // TODO log it and then what?
085: if (log.isDebugEnabled()) {
086: log
087: .debug("WebServiceException calling SAAJFactory.createMessageFactory(\""
088: + bindingNamespace + "\")");
089: }
090: } catch (SOAPException e) {
091: // TODO log it and then what?
092: if (log.isDebugEnabled()) {
093: log
094: .debug("SOAPException calling SAAJFactory.createMessageFactory(\""
095: + bindingNamespace + "\")");
096: }
097: }
098: return null;
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see javax.xml.ws.soap.SOAPBinding#getRoles()
105: */
106: public Set<String> getRoles() {
107: // do not allow null roles, per the JAX-WS CTS
108: if (roles == null)
109: roles = addDefaultRoles(null);
110: return roles;
111: }
112:
113: /*
114: * (non-Javadoc)
115: *
116: * @see javax.xml.ws.soap.SOAPBinding#getSOAPFactory()
117: */
118: public SOAPFactory getSOAPFactory() {
119: String bindingNamespace = null;
120: try {
121: /*
122: * SAAJFactory.createMessageFactory takes a namespace String as a
123: * param: "http://schemas.xmlsoap.org/soap/envelope/" (SOAP1.1)
124: * "http://www.w3.org/2003/05/soap-envelope" (SOAP1.2)
125: *
126: * The bindingId will be in one of the following forms:
127: * "http://schemas.xmlsoap.org/wsdl/soap/http" (SOAP1.1)
128: * "http://www.w3.org/2003/05/soap/bindings/HTTP/" (SOAP1.2)
129: */
130: if (bindingId
131: .equalsIgnoreCase(SOAPBinding.SOAP12HTTP_BINDING)
132: || bindingId
133: .equalsIgnoreCase(SOAPBinding.SOAP12HTTP_MTOM_BINDING)) {
134: bindingNamespace = SOAP12_ENV_NS;
135: } else {
136: // TODO currently defaults to SOAP11. Should we be more stricct
137: // about checking?
138: bindingNamespace = SOAP11_ENV_NS;
139: }
140: return SAAJFactory.createSOAPFactory(bindingNamespace);
141: } catch (WebServiceException e) {
142: // TODO log it and then what?
143: if (log.isDebugEnabled()) {
144: log
145: .debug("WebServiceException calling SAAJFactory.createSOAPFactory(\""
146: + bindingNamespace + "\")");
147: }
148: } catch (SOAPException e) {
149: // TODO log it and then what?
150: if (log.isDebugEnabled()) {
151: log
152: .debug("SOAPException calling SAAJFactory.createSOAPFactory(\""
153: + bindingNamespace + "\")");
154: }
155: }
156: return null;
157: }
158:
159: /*
160: * (non-Javadoc)
161: *
162: * @see javax.xml.ws.soap.SOAPBinding#isMTOMEnabled()
163: */
164: public boolean isMTOMEnabled() {
165: return mtomEnabled;
166: }
167:
168: /*
169: * (non-Javadoc)
170: *
171: * @see javax.xml.ws.soap.SOAPBinding#setMTOMEnabled(boolean)
172: */
173: public void setMTOMEnabled(boolean flag) {
174: mtomEnabled = flag;
175: }
176:
177: /*
178: * (non-Javadoc)
179: *
180: * @see javax.xml.ws.soap.SOAPBinding#setRoles(java.util.Set)
181: */
182: public void setRoles(Set<String> set) {
183: // Validate the values in the set
184: if (set != null && !set.isEmpty()) {
185: // Throw an exception for setting a role of "none"
186: // Per JAXWS 2.0 Sec 10.1.1.1 SOAP Roles, page 116:
187: if (set.contains(SOAPConstants.URI_SOAP_1_2_ROLE_NONE)) {
188: // TODO: RAS/NLS
189: throw ExceptionFactory
190: .makeWebServiceException("The role of 'none' is not allowed.");
191: }
192: }
193:
194: roles = addDefaultRoles(set);
195: }
196:
197: private Set<String> addDefaultRoles(Set<String> set) {
198:
199: Set<String> returnSet = set;
200: if (returnSet == null) {
201: returnSet = new HashSet<String>();
202: }
203:
204: // Make sure the defaults for the binding type are in the set
205: // and add them if not. Note that for both SOAP11 and SOAP12, the role of ultimate
206: // reciever can be indicated by the omission of the role attribute.
207: // REVIEW: This is WRONG because the bindingID from the WSDL is not the same value as
208: // SOAPBinding annotation constants. There are other places in the code that have
209: // this same issue I am sure.
210: if (SOAPBinding.SOAP12HTTP_BINDING.equals(bindingId)
211: || SOAPBinding.SOAP12HTTP_MTOM_BINDING
212: .equals(bindingId)) {
213: if (returnSet.isEmpty()
214: || !returnSet
215: .contains(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT)) {
216: returnSet.add(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT);
217: }
218:
219: // } else if (SOAPBinding.SOAP11HTTP_BINDING.equals(bindingId)
220: // || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(bindingId)) {
221: } else {
222: if (returnSet.isEmpty()
223: || !returnSet
224: .contains(SOAPConstants.URI_SOAP_ACTOR_NEXT)) {
225: returnSet.add(SOAPConstants.URI_SOAP_ACTOR_NEXT);
226: }
227: }
228: // else {
229: // // Invalid binding
230: // // TODO: RAS / NLS
231: // if (log.isDebugEnabled()) {
232: // log.debug("Invalid binding type set on the binding: " + bindingId);
233: // }
234: // }
235: return returnSet;
236: }
237:
238: }
|