Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.binding; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.istack.internal.NotNull; |
aoqi@0 | 29 | import com.sun.istack.internal.Nullable; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.BindingID; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.api.FeatureListValidator; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.api.FeatureListValidatorAnnotation; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.api.ImpliesWebServiceFeature; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.api.SOAPVersion; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.api.WSBinding; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.api.WSFeatureList; |
aoqi@0 | 37 | import com.sun.xml.internal.ws.api.FeatureConstructor; |
aoqi@0 | 38 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
aoqi@0 | 39 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLFeaturedObject; |
aoqi@0 | 40 | import com.sun.xml.internal.ws.model.RuntimeModelerException; |
aoqi@0 | 41 | import com.sun.xml.internal.ws.resources.ModelerMessages; |
aoqi@0 | 42 | import com.sun.xml.internal.bind.util.Which; |
aoqi@0 | 43 | |
aoqi@0 | 44 | import javax.xml.ws.RespectBinding; |
aoqi@0 | 45 | import javax.xml.ws.RespectBindingFeature; |
aoqi@0 | 46 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 47 | import javax.xml.ws.WebServiceFeature; |
aoqi@0 | 48 | import javax.xml.ws.soap.Addressing; |
aoqi@0 | 49 | import javax.xml.ws.soap.AddressingFeature; |
aoqi@0 | 50 | import javax.xml.ws.soap.MTOM; |
aoqi@0 | 51 | import javax.xml.ws.soap.MTOMFeature; |
aoqi@0 | 52 | import javax.xml.ws.spi.WebServiceFeatureAnnotation; |
aoqi@0 | 53 | |
aoqi@0 | 54 | import com.oracle.webservices.internal.api.EnvelopeStyleFeature; |
aoqi@0 | 55 | |
aoqi@0 | 56 | import java.lang.annotation.Annotation; |
aoqi@0 | 57 | import java.lang.reflect.InvocationTargetException; |
aoqi@0 | 58 | import java.lang.reflect.Method; |
aoqi@0 | 59 | import java.lang.reflect.Constructor; |
aoqi@0 | 60 | import java.util.*; |
aoqi@0 | 61 | import java.util.logging.Logger; |
aoqi@0 | 62 | |
aoqi@0 | 63 | /** |
aoqi@0 | 64 | * Represents a list of {@link WebServiceFeature}s that has bunch of utility |
aoqi@0 | 65 | * methods pertaining to web service features. |
aoqi@0 | 66 | * |
aoqi@0 | 67 | * @author Rama Pulavarthi |
aoqi@0 | 68 | */ |
aoqi@0 | 69 | public final class WebServiceFeatureList extends AbstractMap<Class<? extends WebServiceFeature>, WebServiceFeature> implements WSFeatureList { |
aoqi@0 | 70 | public static WebServiceFeatureList toList(Iterable<WebServiceFeature> features) { |
aoqi@0 | 71 | if (features instanceof WebServiceFeatureList) |
aoqi@0 | 72 | return (WebServiceFeatureList) features; |
aoqi@0 | 73 | WebServiceFeatureList w = new WebServiceFeatureList(); |
aoqi@0 | 74 | if (features != null) |
aoqi@0 | 75 | w.addAll(features); |
aoqi@0 | 76 | return w; |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | private Map<Class<? extends WebServiceFeature>, WebServiceFeature> wsfeatures = new HashMap<Class<? extends WebServiceFeature>, WebServiceFeature>(); |
aoqi@0 | 80 | private boolean isValidating = false; |
aoqi@0 | 81 | |
aoqi@0 | 82 | public WebServiceFeatureList() { |
aoqi@0 | 83 | } |
aoqi@0 | 84 | |
aoqi@0 | 85 | /** |
aoqi@0 | 86 | * Delegate to this parent if non-null. |
aoqi@0 | 87 | */ |
aoqi@0 | 88 | private @Nullable |
aoqi@0 | 89 | WSDLFeaturedObject parent; |
aoqi@0 | 90 | |
aoqi@0 | 91 | public WebServiceFeatureList(@NotNull WebServiceFeature... features) { |
aoqi@0 | 92 | if (features != null) { |
aoqi@0 | 93 | for (WebServiceFeature f : features) { |
aoqi@0 | 94 | addNoValidate(f); |
aoqi@0 | 95 | } |
aoqi@0 | 96 | } |
aoqi@0 | 97 | } |
aoqi@0 | 98 | |
aoqi@0 | 99 | public void validate() { |
aoqi@0 | 100 | if (!isValidating) { |
aoqi@0 | 101 | isValidating = true; |
aoqi@0 | 102 | |
aoqi@0 | 103 | // validation |
aoqi@0 | 104 | for (WebServiceFeature ff : this) { |
aoqi@0 | 105 | validate(ff); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | } |
aoqi@0 | 108 | } |
aoqi@0 | 109 | |
aoqi@0 | 110 | private void validate(WebServiceFeature feature) { |
aoqi@0 | 111 | // run validation |
aoqi@0 | 112 | FeatureListValidatorAnnotation fva = feature.getClass().getAnnotation(FeatureListValidatorAnnotation.class); |
aoqi@0 | 113 | if (fva != null) { |
aoqi@0 | 114 | Class<? extends FeatureListValidator> beanClass = fva.bean(); |
aoqi@0 | 115 | try { |
aoqi@0 | 116 | FeatureListValidator validator = beanClass.newInstance(); |
aoqi@0 | 117 | validator.validate(this); |
aoqi@0 | 118 | } catch (InstantiationException e) { |
aoqi@0 | 119 | throw new WebServiceException(e); |
aoqi@0 | 120 | } catch (IllegalAccessException e) { |
aoqi@0 | 121 | throw new WebServiceException(e); |
aoqi@0 | 122 | } |
aoqi@0 | 123 | } |
aoqi@0 | 124 | } |
aoqi@0 | 125 | |
aoqi@0 | 126 | public WebServiceFeatureList(WebServiceFeatureList features) { |
aoqi@0 | 127 | if (features != null) { |
aoqi@0 | 128 | wsfeatures.putAll(features.wsfeatures); |
aoqi@0 | 129 | parent = features.parent; |
aoqi@0 | 130 | isValidating = features.isValidating; |
aoqi@0 | 131 | } |
aoqi@0 | 132 | } |
aoqi@0 | 133 | |
aoqi@0 | 134 | /** |
aoqi@0 | 135 | * Creates a list by reading featuers from the annotation on a class. |
aoqi@0 | 136 | */ |
aoqi@0 | 137 | public WebServiceFeatureList(@NotNull Class<?> endpointClass) { |
aoqi@0 | 138 | parseAnnotations(endpointClass); |
aoqi@0 | 139 | } |
aoqi@0 | 140 | |
aoqi@0 | 141 | /** |
aoqi@0 | 142 | * Adds the corresponding features to the list for feature annotations(i.e |
aoqi@0 | 143 | * which have {@link WebServiceFeatureAnnotation} meta annotation) |
aoqi@0 | 144 | * |
aoqi@0 | 145 | * @param annIt collection of annotations(that can have non-feature annotations) |
aoqi@0 | 146 | */ |
aoqi@0 | 147 | public void parseAnnotations(Iterable<Annotation> annIt) { |
aoqi@0 | 148 | for(Annotation ann : annIt) { |
aoqi@0 | 149 | WebServiceFeature feature = getFeature(ann); |
aoqi@0 | 150 | if (feature != null) { |
aoqi@0 | 151 | add(feature); |
aoqi@0 | 152 | } |
aoqi@0 | 153 | } |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | /** |
aoqi@0 | 157 | * Returns a corresponding feature for a feature annotation(i.e which has |
aoqi@0 | 158 | * {@link WebServiceFeatureAnnotation} meta annotation) |
aoqi@0 | 159 | * |
aoqi@0 | 160 | * @return corresponding feature for the annotation |
aoqi@0 | 161 | * null, if the annotation is nota feature annotation |
aoqi@0 | 162 | */ |
aoqi@0 | 163 | public static WebServiceFeature getFeature(Annotation a) { |
aoqi@0 | 164 | WebServiceFeature ftr = null; |
aoqi@0 | 165 | if (!(a.annotationType().isAnnotationPresent(WebServiceFeatureAnnotation.class))) { |
aoqi@0 | 166 | ftr = null; |
aoqi@0 | 167 | } else if (a instanceof Addressing) { |
aoqi@0 | 168 | Addressing addAnn = (Addressing) a; |
aoqi@0 | 169 | try { |
aoqi@0 | 170 | ftr = new AddressingFeature(addAnn.enabled(), addAnn.required(),addAnn.responses()); |
aoqi@0 | 171 | } catch(NoSuchMethodError e) { |
aoqi@0 | 172 | //throw error. We can't default to Responses.ALL as we dont know if the user has not used 2.2 annotation with responses. |
aoqi@0 | 173 | throw new RuntimeModelerException(ModelerMessages.RUNTIME_MODELER_ADDRESSING_RESPONSES_NOSUCHMETHOD(toJar(Which.which(Addressing.class)))); |
aoqi@0 | 174 | } |
aoqi@0 | 175 | } else if (a instanceof MTOM) { |
aoqi@0 | 176 | MTOM mtomAnn = (MTOM) a; |
aoqi@0 | 177 | ftr = new MTOMFeature(mtomAnn.enabled(), mtomAnn.threshold()); |
aoqi@0 | 178 | } else if (a instanceof RespectBinding) { |
aoqi@0 | 179 | RespectBinding rbAnn = (RespectBinding) a; |
aoqi@0 | 180 | ftr = new RespectBindingFeature(rbAnn.enabled()); |
aoqi@0 | 181 | } else { |
aoqi@0 | 182 | ftr = getWebServiceFeatureBean(a); |
aoqi@0 | 183 | } |
aoqi@0 | 184 | return ftr; |
aoqi@0 | 185 | } |
aoqi@0 | 186 | |
aoqi@0 | 187 | /** |
aoqi@0 | 188 | * |
aoqi@0 | 189 | * @param endpointClass web service impl class |
aoqi@0 | 190 | */ |
aoqi@0 | 191 | public void parseAnnotations(Class<?> endpointClass) { |
aoqi@0 | 192 | for (Annotation a : endpointClass.getAnnotations()) { |
aoqi@0 | 193 | WebServiceFeature ftr = getFeature(a); |
aoqi@0 | 194 | if (ftr != null) { |
aoqi@0 | 195 | if (ftr instanceof MTOMFeature) { |
aoqi@0 | 196 | // check conflict with @BindingType |
aoqi@0 | 197 | BindingID bindingID = BindingID.parse(endpointClass); |
aoqi@0 | 198 | MTOMFeature bindingMtomSetting = bindingID.createBuiltinFeatureList().get(MTOMFeature.class); |
aoqi@0 | 199 | if (bindingMtomSetting != null && bindingMtomSetting.isEnabled() ^ ftr.isEnabled()) { |
aoqi@0 | 200 | throw new RuntimeModelerException( |
aoqi@0 | 201 | ModelerMessages.RUNTIME_MODELER_MTOM_CONFLICT(bindingID, ftr.isEnabled())); |
aoqi@0 | 202 | } |
aoqi@0 | 203 | } |
aoqi@0 | 204 | add(ftr); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | } |
aoqi@0 | 207 | } |
aoqi@0 | 208 | |
aoqi@0 | 209 | /** |
aoqi@0 | 210 | * Given the URL String inside jar, returns the URL to the jar itself. |
aoqi@0 | 211 | */ |
aoqi@0 | 212 | private static String toJar(String url) { |
aoqi@0 | 213 | if(!url.startsWith("jar:")) |
aoqi@0 | 214 | return url; |
aoqi@0 | 215 | url = url.substring(4); // cut off jar: |
aoqi@0 | 216 | return url.substring(0,url.lastIndexOf('!')); // cut off everything after '!' |
aoqi@0 | 217 | } |
aoqi@0 | 218 | |
aoqi@0 | 219 | private static WebServiceFeature getWebServiceFeatureBean(Annotation a) { |
aoqi@0 | 220 | WebServiceFeatureAnnotation wsfa = a.annotationType().getAnnotation(WebServiceFeatureAnnotation.class); |
aoqi@0 | 221 | Class<? extends WebServiceFeature> beanClass = wsfa.bean(); |
aoqi@0 | 222 | WebServiceFeature bean; |
aoqi@0 | 223 | |
aoqi@0 | 224 | Constructor ftrCtr = null; |
aoqi@0 | 225 | String[] paramNames = null; |
aoqi@0 | 226 | for (Constructor con : beanClass.getConstructors()) { |
aoqi@0 | 227 | FeatureConstructor ftrCtrAnn = (FeatureConstructor) con.getAnnotation(FeatureConstructor.class); |
aoqi@0 | 228 | if (ftrCtrAnn != null) { |
aoqi@0 | 229 | if (ftrCtr == null) { |
aoqi@0 | 230 | ftrCtr = con; |
aoqi@0 | 231 | paramNames = ftrCtrAnn.value(); |
aoqi@0 | 232 | } else { |
aoqi@0 | 233 | throw new WebServiceException( |
aoqi@0 | 234 | ModelerMessages.RUNTIME_MODELER_WSFEATURE_MORETHANONE_FTRCONSTRUCTOR(a, beanClass)); |
aoqi@0 | 235 | } |
aoqi@0 | 236 | } |
aoqi@0 | 237 | } |
aoqi@0 | 238 | if (ftrCtr == null) { |
aoqi@0 | 239 | bean = getWebServiceFeatureBeanViaBuilder(a, beanClass); |
aoqi@0 | 240 | if (bean != null) { |
aoqi@0 | 241 | return bean; |
aoqi@0 | 242 | } else { |
aoqi@0 | 243 | throw new WebServiceException( |
aoqi@0 | 244 | ModelerMessages.RUNTIME_MODELER_WSFEATURE_NO_FTRCONSTRUCTOR(a, beanClass)); |
aoqi@0 | 245 | } |
aoqi@0 | 246 | } |
aoqi@0 | 247 | if (ftrCtr.getParameterTypes().length != paramNames.length) { |
aoqi@0 | 248 | throw new WebServiceException( |
aoqi@0 | 249 | ModelerMessages.RUNTIME_MODELER_WSFEATURE_ILLEGAL_FTRCONSTRUCTOR(a, beanClass)); |
aoqi@0 | 250 | } |
aoqi@0 | 251 | |
aoqi@0 | 252 | try { |
aoqi@0 | 253 | Object[] params = new Object[paramNames.length]; |
aoqi@0 | 254 | for (int i = 0; i < paramNames.length; i++) { |
aoqi@0 | 255 | Method m = a.annotationType().getDeclaredMethod(paramNames[i]); |
aoqi@0 | 256 | params[i] = m.invoke(a); |
aoqi@0 | 257 | } |
aoqi@0 | 258 | bean = (WebServiceFeature) ftrCtr.newInstance(params); |
aoqi@0 | 259 | } catch (Exception e) { |
aoqi@0 | 260 | throw new WebServiceException(e); |
aoqi@0 | 261 | } |
aoqi@0 | 262 | return bean; |
aoqi@0 | 263 | } |
aoqi@0 | 264 | |
aoqi@0 | 265 | private static WebServiceFeature getWebServiceFeatureBeanViaBuilder( |
aoqi@0 | 266 | final Annotation annotation, |
aoqi@0 | 267 | final Class<? extends WebServiceFeature> beanClass) |
aoqi@0 | 268 | { |
aoqi@0 | 269 | try { |
aoqi@0 | 270 | final Method featureBuilderMethod = beanClass.getDeclaredMethod("builder"); |
aoqi@0 | 271 | final Object builder = featureBuilderMethod.invoke(beanClass); |
aoqi@0 | 272 | final Method buildMethod = builder.getClass().getDeclaredMethod("build"); |
aoqi@0 | 273 | |
aoqi@0 | 274 | for (Method builderMethod : builder.getClass().getDeclaredMethods()) { |
aoqi@0 | 275 | if (!builderMethod.equals(buildMethod)) { |
aoqi@0 | 276 | final String methodName = builderMethod.getName(); |
aoqi@0 | 277 | final Method annotationMethod = annotation.annotationType().getDeclaredMethod(methodName); |
aoqi@0 | 278 | final Object annotationFieldValue = annotationMethod.invoke(annotation); |
aoqi@0 | 279 | final Object[] arg = { annotationFieldValue }; |
aoqi@0 | 280 | if (skipDuringOrgJvnetWsToComOracleWebservicesPackageMove(builderMethod, annotationFieldValue)) { |
aoqi@0 | 281 | continue; |
aoqi@0 | 282 | } |
aoqi@0 | 283 | builderMethod.invoke(builder, arg); |
aoqi@0 | 284 | } |
aoqi@0 | 285 | } |
aoqi@0 | 286 | |
aoqi@0 | 287 | final Object result = buildMethod.invoke(builder); |
aoqi@0 | 288 | if (result instanceof WebServiceFeature) { |
aoqi@0 | 289 | return (WebServiceFeature) result; |
aoqi@0 | 290 | } else { |
aoqi@0 | 291 | throw new WebServiceException("Not a WebServiceFeature: " + result); |
aoqi@0 | 292 | } |
aoqi@0 | 293 | } catch (final NoSuchMethodException e) { |
aoqi@0 | 294 | return null; |
aoqi@0 | 295 | } catch (final IllegalAccessException e) { |
aoqi@0 | 296 | throw new WebServiceException(e); |
aoqi@0 | 297 | } catch (final InvocationTargetException e) { |
aoqi@0 | 298 | throw new WebServiceException(e); |
aoqi@0 | 299 | } |
aoqi@0 | 300 | } |
aoqi@0 | 301 | |
aoqi@0 | 302 | // TODO this will be removed after package move is complete. |
aoqi@0 | 303 | private static boolean skipDuringOrgJvnetWsToComOracleWebservicesPackageMove( |
aoqi@0 | 304 | final Method builderMethod, |
aoqi@0 | 305 | final Object annotationFieldValue) |
aoqi@0 | 306 | { |
aoqi@0 | 307 | final Class<?> annotationFieldValueClass = annotationFieldValue.getClass(); |
aoqi@0 | 308 | if (! annotationFieldValueClass.isEnum()) { |
aoqi@0 | 309 | return false; |
aoqi@0 | 310 | } |
aoqi@0 | 311 | final Class<?>[] builderMethodParameterTypes = builderMethod.getParameterTypes(); |
aoqi@0 | 312 | if (builderMethodParameterTypes.length != 1) { |
aoqi@0 | 313 | throw new WebServiceException("expected only 1 parameter"); |
aoqi@0 | 314 | } |
aoqi@0 | 315 | final String builderParameterTypeName = builderMethodParameterTypes[0].getName(); |
aoqi@0 | 316 | if (! builderParameterTypeName.startsWith("com.oracle.webservices.internal.test.features_annotations_enums.apinew") && |
aoqi@0 | 317 | ! builderParameterTypeName.startsWith("com.oracle.webservices.internal.api")) { |
aoqi@0 | 318 | return false; |
aoqi@0 | 319 | } |
aoqi@0 | 320 | return false; |
aoqi@0 | 321 | } |
aoqi@0 | 322 | |
aoqi@0 | 323 | public Iterator<WebServiceFeature> iterator() { |
aoqi@0 | 324 | if (parent != null) |
aoqi@0 | 325 | return new MergedFeatures(parent.getFeatures()); |
aoqi@0 | 326 | return wsfeatures.values().iterator(); |
aoqi@0 | 327 | } |
aoqi@0 | 328 | |
aoqi@0 | 329 | public @NotNull |
aoqi@0 | 330 | WebServiceFeature[] toArray() { |
aoqi@0 | 331 | if (parent != null) |
aoqi@0 | 332 | return new MergedFeatures(parent.getFeatures()).toArray(); |
aoqi@0 | 333 | return wsfeatures.values().toArray(new WebServiceFeature[] {}); |
aoqi@0 | 334 | } |
aoqi@0 | 335 | |
aoqi@0 | 336 | public boolean isEnabled(@NotNull Class<? extends WebServiceFeature> feature) { |
aoqi@0 | 337 | WebServiceFeature ftr = get(feature); |
aoqi@0 | 338 | return ftr != null && ftr.isEnabled(); |
aoqi@0 | 339 | } |
aoqi@0 | 340 | |
aoqi@0 | 341 | public boolean contains(@NotNull Class<? extends WebServiceFeature> feature) { |
aoqi@0 | 342 | WebServiceFeature ftr = get(feature); |
aoqi@0 | 343 | return ftr != null; |
aoqi@0 | 344 | } |
aoqi@0 | 345 | |
aoqi@0 | 346 | public @Nullable |
aoqi@0 | 347 | <F extends WebServiceFeature> F get(@NotNull Class<F> featureType) { |
aoqi@0 | 348 | WebServiceFeature f = featureType.cast(wsfeatures.get(featureType)); |
aoqi@0 | 349 | if (f == null && parent != null) { |
aoqi@0 | 350 | return parent.getFeatures().get(featureType); |
aoqi@0 | 351 | } |
aoqi@0 | 352 | return (F) f; |
aoqi@0 | 353 | } |
aoqi@0 | 354 | |
aoqi@0 | 355 | /** |
aoqi@0 | 356 | * Adds a feature to the list if it's not already added. |
aoqi@0 | 357 | */ |
aoqi@0 | 358 | public void add(@NotNull WebServiceFeature f) { |
aoqi@0 | 359 | if(addNoValidate(f) && isValidating) |
aoqi@0 | 360 | validate(f); |
aoqi@0 | 361 | } |
aoqi@0 | 362 | |
aoqi@0 | 363 | private boolean addNoValidate(@NotNull WebServiceFeature f) { |
aoqi@0 | 364 | if (!wsfeatures.containsKey(f.getClass())) { |
aoqi@0 | 365 | wsfeatures.put(f.getClass(), f); |
aoqi@0 | 366 | |
aoqi@0 | 367 | if (f instanceof ImpliesWebServiceFeature) |
aoqi@0 | 368 | ((ImpliesWebServiceFeature) f).implyFeatures(this); |
aoqi@0 | 369 | |
aoqi@0 | 370 | return true; |
aoqi@0 | 371 | } |
aoqi@0 | 372 | |
aoqi@0 | 373 | return false; |
aoqi@0 | 374 | } |
aoqi@0 | 375 | |
aoqi@0 | 376 | /** |
aoqi@0 | 377 | * Adds features to the list if it's not already added. |
aoqi@0 | 378 | */ |
aoqi@0 | 379 | public void addAll(@NotNull Iterable<WebServiceFeature> list) { |
aoqi@0 | 380 | for (WebServiceFeature f : list) |
aoqi@0 | 381 | add(f); |
aoqi@0 | 382 | } |
aoqi@0 | 383 | |
aoqi@0 | 384 | /** |
aoqi@0 | 385 | * Sets MTOM feature, overriding any existing feature. This is necessary for compatibility |
aoqi@0 | 386 | * with the existing {@link SOAPBinding.setMTOMEnabled}. |
aoqi@0 | 387 | * @param b if MTOM will be enabled |
aoqi@0 | 388 | */ |
aoqi@0 | 389 | void setMTOMEnabled(boolean b) { |
aoqi@0 | 390 | wsfeatures.put(MTOMFeature.class, new MTOMFeature(b)); |
aoqi@0 | 391 | } |
aoqi@0 | 392 | |
aoqi@0 | 393 | public boolean equals(Object other) { |
aoqi@0 | 394 | if (!(other instanceof WebServiceFeatureList)) |
aoqi@0 | 395 | return false; |
aoqi@0 | 396 | |
aoqi@0 | 397 | WebServiceFeatureList w = (WebServiceFeatureList) other; |
aoqi@0 | 398 | return wsfeatures.equals(w.wsfeatures) && (parent == w.parent); |
aoqi@0 | 399 | } |
aoqi@0 | 400 | |
aoqi@0 | 401 | public String toString() { |
aoqi@0 | 402 | return wsfeatures.toString(); |
aoqi@0 | 403 | } |
aoqi@0 | 404 | |
aoqi@0 | 405 | /** |
aoqi@0 | 406 | * Merges the extra features that are not already set on binding. |
aoqi@0 | 407 | * i.e, if a feature is set already on binding through some other API |
aoqi@0 | 408 | * the corresponding wsdlFeature is not set. |
aoqi@0 | 409 | * |
aoqi@0 | 410 | * @param features Web Service features that need to be merged with already configured features. |
aoqi@0 | 411 | * @param reportConflicts If true, checks if the feature setting in WSDL (wsdl extension or |
aoqi@0 | 412 | * policy configuration) conflicts with feature setting in Deployed Service and |
aoqi@0 | 413 | * logs warning if there are any conflicts. |
aoqi@0 | 414 | */ |
aoqi@0 | 415 | public void mergeFeatures(@NotNull Iterable<WebServiceFeature> features, boolean reportConflicts) { |
aoqi@0 | 416 | for (WebServiceFeature wsdlFtr : features) { |
aoqi@0 | 417 | if (get(wsdlFtr.getClass()) == null) { |
aoqi@0 | 418 | add(wsdlFtr); |
aoqi@0 | 419 | } else if (reportConflicts) { |
aoqi@0 | 420 | if (isEnabled(wsdlFtr.getClass()) != wsdlFtr.isEnabled()) { |
aoqi@0 | 421 | LOGGER.warning(ModelerMessages.RUNTIME_MODELER_FEATURE_CONFLICT( |
aoqi@0 | 422 | get(wsdlFtr.getClass()), wsdlFtr)); |
aoqi@0 | 423 | } |
aoqi@0 | 424 | } |
aoqi@0 | 425 | } |
aoqi@0 | 426 | } |
aoqi@0 | 427 | |
aoqi@0 | 428 | public void mergeFeatures(WebServiceFeature[] features, boolean reportConflicts) { |
aoqi@0 | 429 | for (WebServiceFeature wsdlFtr : features) { |
aoqi@0 | 430 | if (get(wsdlFtr.getClass()) == null) { |
aoqi@0 | 431 | add(wsdlFtr); |
aoqi@0 | 432 | } else if (reportConflicts) { |
aoqi@0 | 433 | if (isEnabled(wsdlFtr.getClass()) != wsdlFtr.isEnabled()) { |
aoqi@0 | 434 | LOGGER.warning(ModelerMessages.RUNTIME_MODELER_FEATURE_CONFLICT( |
aoqi@0 | 435 | get(wsdlFtr.getClass()), wsdlFtr)); |
aoqi@0 | 436 | } |
aoqi@0 | 437 | } |
aoqi@0 | 438 | } |
aoqi@0 | 439 | } |
aoqi@0 | 440 | |
aoqi@0 | 441 | /** |
aoqi@0 | 442 | * Extracts features from {@link WSDLPort#getFeatures()}. Extra features |
aoqi@0 | 443 | * that are not already set on binding. i.e, if a feature is set already on |
aoqi@0 | 444 | * binding through some other API the corresponding wsdlFeature is not set. |
aoqi@0 | 445 | * |
aoqi@0 | 446 | * @param wsdlPort |
aoqi@0 | 447 | * WSDLPort model |
aoqi@0 | 448 | * @param honorWsdlRequired |
aoqi@0 | 449 | * If this is true add WSDL Feature only if wsd:Required=true In |
aoqi@0 | 450 | * SEI case, it should be false In Provider case, it should be |
aoqi@0 | 451 | * true |
aoqi@0 | 452 | * @param reportConflicts |
aoqi@0 | 453 | * If true, checks if the feature setting in WSDL (wsdl extension |
aoqi@0 | 454 | * or policy configuration) conflicts with feature setting in |
aoqi@0 | 455 | * Deployed Service and logs warning if there are any conflicts. |
aoqi@0 | 456 | */ |
aoqi@0 | 457 | public void mergeFeatures(@NotNull WSDLPort wsdlPort, |
aoqi@0 | 458 | boolean honorWsdlRequired, boolean reportConflicts) { |
aoqi@0 | 459 | if (honorWsdlRequired && !isEnabled(RespectBindingFeature.class)) |
aoqi@0 | 460 | return; |
aoqi@0 | 461 | if (!honorWsdlRequired) { |
aoqi@0 | 462 | addAll(wsdlPort.getFeatures()); |
aoqi@0 | 463 | return; |
aoqi@0 | 464 | } |
aoqi@0 | 465 | // Add only if isRequired returns true, when honorWsdlRequired is true |
aoqi@0 | 466 | for (WebServiceFeature wsdlFtr : wsdlPort.getFeatures()) { |
aoqi@0 | 467 | if (get(wsdlFtr.getClass()) == null) { |
aoqi@0 | 468 | try { |
aoqi@0 | 469 | // if it is a WSDL Extension , it will have required |
aoqi@0 | 470 | // attribute |
aoqi@0 | 471 | Method m = (wsdlFtr.getClass().getMethod("isRequired")); |
aoqi@0 | 472 | try { |
aoqi@0 | 473 | boolean required = (Boolean) m.invoke(wsdlFtr); |
aoqi@0 | 474 | if (required) |
aoqi@0 | 475 | add(wsdlFtr); |
aoqi@0 | 476 | } catch (IllegalAccessException e) { |
aoqi@0 | 477 | throw new WebServiceException(e); |
aoqi@0 | 478 | } catch (InvocationTargetException e) { |
aoqi@0 | 479 | throw new WebServiceException(e); |
aoqi@0 | 480 | } |
aoqi@0 | 481 | } catch (NoSuchMethodException e) { |
aoqi@0 | 482 | // this wsdlFtr is not an WSDL extension, just add it |
aoqi@0 | 483 | add(wsdlFtr); |
aoqi@0 | 484 | } |
aoqi@0 | 485 | } else if (reportConflicts) { |
aoqi@0 | 486 | if (isEnabled(wsdlFtr.getClass()) != wsdlFtr.isEnabled()) { |
aoqi@0 | 487 | LOGGER.warning(ModelerMessages.RUNTIME_MODELER_FEATURE_CONFLICT( |
aoqi@0 | 488 | get(wsdlFtr.getClass()), wsdlFtr)); |
aoqi@0 | 489 | } |
aoqi@0 | 490 | |
aoqi@0 | 491 | } |
aoqi@0 | 492 | } |
aoqi@0 | 493 | } |
aoqi@0 | 494 | |
aoqi@0 | 495 | /** |
aoqi@0 | 496 | * Set the parent features. Basically the parent feature list will be |
aoqi@0 | 497 | * overriden by this feature list. |
aoqi@0 | 498 | */ |
aoqi@0 | 499 | public void setParentFeaturedObject(@NotNull WSDLFeaturedObject parent) { |
aoqi@0 | 500 | this.parent = parent; |
aoqi@0 | 501 | } |
aoqi@0 | 502 | |
aoqi@0 | 503 | public static @Nullable <F extends WebServiceFeature> F getFeature(@NotNull WebServiceFeature[] features, |
aoqi@0 | 504 | @NotNull Class<F> featureType) { |
aoqi@0 | 505 | for (WebServiceFeature f : features) { |
aoqi@0 | 506 | if (f.getClass() == featureType) |
aoqi@0 | 507 | return (F) f; |
aoqi@0 | 508 | } |
aoqi@0 | 509 | return null; |
aoqi@0 | 510 | } |
aoqi@0 | 511 | |
aoqi@0 | 512 | /** |
aoqi@0 | 513 | * A Union of this WebServiceFeatureList and the parent. |
aoqi@0 | 514 | */ |
aoqi@0 | 515 | private final class MergedFeatures implements Iterator<WebServiceFeature> { |
aoqi@0 | 516 | private final Stack<WebServiceFeature> features = new Stack<WebServiceFeature>(); |
aoqi@0 | 517 | |
aoqi@0 | 518 | public MergedFeatures(@NotNull WSFeatureList parent) { |
aoqi@0 | 519 | |
aoqi@0 | 520 | for (WebServiceFeature f : wsfeatures.values()) { |
aoqi@0 | 521 | features.push(f); |
aoqi@0 | 522 | } |
aoqi@0 | 523 | |
aoqi@0 | 524 | for (WebServiceFeature f : parent) { |
aoqi@0 | 525 | if (!wsfeatures.containsKey(f.getClass())) { |
aoqi@0 | 526 | features.push(f); |
aoqi@0 | 527 | } |
aoqi@0 | 528 | } |
aoqi@0 | 529 | } |
aoqi@0 | 530 | |
aoqi@0 | 531 | public boolean hasNext() { |
aoqi@0 | 532 | return !features.empty(); |
aoqi@0 | 533 | } |
aoqi@0 | 534 | |
aoqi@0 | 535 | public WebServiceFeature next() { |
aoqi@0 | 536 | if (!features.empty()) { |
aoqi@0 | 537 | return features.pop(); |
aoqi@0 | 538 | } |
aoqi@0 | 539 | throw new NoSuchElementException(); |
aoqi@0 | 540 | } |
aoqi@0 | 541 | |
aoqi@0 | 542 | public void remove() { |
aoqi@0 | 543 | if (!features.empty()) { |
aoqi@0 | 544 | features.pop(); |
aoqi@0 | 545 | } |
aoqi@0 | 546 | } |
aoqi@0 | 547 | |
aoqi@0 | 548 | public WebServiceFeature[] toArray() { |
aoqi@0 | 549 | return features.toArray(new WebServiceFeature[] {}); |
aoqi@0 | 550 | } |
aoqi@0 | 551 | } |
aoqi@0 | 552 | |
aoqi@0 | 553 | private static final Logger LOGGER = Logger.getLogger(WebServiceFeatureList.class.getName()); |
aoqi@0 | 554 | |
aoqi@0 | 555 | @Override |
aoqi@0 | 556 | public Set<java.util.Map.Entry<Class<? extends WebServiceFeature>, WebServiceFeature>> entrySet() { |
aoqi@0 | 557 | return wsfeatures.entrySet(); |
aoqi@0 | 558 | } |
aoqi@0 | 559 | |
aoqi@0 | 560 | @Override |
aoqi@0 | 561 | public WebServiceFeature put(Class<? extends WebServiceFeature> key, WebServiceFeature value) { |
aoqi@0 | 562 | return wsfeatures.put(key, value); |
aoqi@0 | 563 | } |
aoqi@0 | 564 | |
aoqi@0 | 565 | static public SOAPVersion getSoapVersion(WSFeatureList features) { |
aoqi@0 | 566 | { |
aoqi@0 | 567 | EnvelopeStyleFeature env = features.get(EnvelopeStyleFeature.class); |
aoqi@0 | 568 | if (env != null) { |
aoqi@0 | 569 | return SOAPVersion.from(env); |
aoqi@0 | 570 | } |
aoqi@0 | 571 | } |
aoqi@0 | 572 | com.oracle.webservices.internal.api.EnvelopeStyleFeature env = features.get(com.oracle.webservices.internal.api.EnvelopeStyleFeature.class); |
aoqi@0 | 573 | return env != null ? SOAPVersion.from(env) : null; |
aoqi@0 | 574 | } |
aoqi@0 | 575 | |
aoqi@0 | 576 | static public boolean isFeatureEnabled(Class<? extends WebServiceFeature> type, WebServiceFeature[] features) { |
aoqi@0 | 577 | WebServiceFeature ftr = getFeature(features, type); |
aoqi@0 | 578 | return ftr != null && ftr.isEnabled(); |
aoqi@0 | 579 | } |
aoqi@0 | 580 | |
aoqi@0 | 581 | static public WebServiceFeature[] toFeatureArray(WSBinding binding) { |
aoqi@0 | 582 | //TODO scchen convert BindingID to WebServiceFeature[] |
aoqi@0 | 583 | if(!binding.isFeatureEnabled(EnvelopeStyleFeature.class)) { |
aoqi@0 | 584 | WebServiceFeature[] f = { binding.getSOAPVersion().toFeature() }; |
aoqi@0 | 585 | binding.getFeatures().mergeFeatures(f, false); |
aoqi@0 | 586 | } |
aoqi@0 | 587 | return binding.getFeatures().toArray(); |
aoqi@0 | 588 | } |
aoqi@0 | 589 | } |