src/share/jaxws_classes/com/sun/xml/internal/ws/addressing/policy/AddressingFeatureConfigurator.java

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/addressing/policy/AddressingFeatureConfigurator.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,146 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.addressing.policy;
    1.30 +
    1.31 +import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
    1.32 +import com.sun.xml.internal.ws.policy.AssertionSet;
    1.33 +import com.sun.xml.internal.ws.policy.NestedPolicy;
    1.34 +import com.sun.xml.internal.ws.policy.Policy;
    1.35 +import com.sun.xml.internal.ws.policy.PolicyAssertion;
    1.36 +import com.sun.xml.internal.ws.policy.PolicyException;
    1.37 +import com.sun.xml.internal.ws.policy.PolicyMap;
    1.38 +import com.sun.xml.internal.ws.policy.PolicyMapKey;
    1.39 +import com.sun.xml.internal.ws.policy.jaxws.spi.PolicyFeatureConfigurator;
    1.40 +import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
    1.41 +import com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants;
    1.42 +import com.sun.xml.internal.ws.resources.ModelerMessages;
    1.43 +import com.sun.xml.internal.bind.util.Which;
    1.44 +
    1.45 +import java.util.Collection;
    1.46 +import java.util.Iterator;
    1.47 +import java.util.LinkedList;
    1.48 +import java.util.logging.Level;
    1.49 +import javax.xml.namespace.QName;
    1.50 +import javax.xml.ws.WebServiceFeature;
    1.51 +import javax.xml.ws.WebServiceException;
    1.52 +import javax.xml.ws.soap.AddressingFeature;
    1.53 +
    1.54 +/**
    1.55 + * This Policy extension configures the WSDLModel with AddressingFeature when Addressing assertions are present in the
    1.56 + * PolicyMap.
    1.57 + *
    1.58 + * @author japod
    1.59 + * @author Rama Pulavarthi
    1.60 + */
    1.61 +public class AddressingFeatureConfigurator implements PolicyFeatureConfigurator {
    1.62 +
    1.63 +    private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AddressingFeatureConfigurator.class);
    1.64 +
    1.65 +    private static final QName[] ADDRESSING_ASSERTIONS = {
    1.66 +        new QName(AddressingVersion.MEMBER.policyNsUri, "UsingAddressing")};
    1.67 +
    1.68 +    /**
    1.69 +     * Creates a new instance of AddressingFeatureConfigurator
    1.70 +     */
    1.71 +    public AddressingFeatureConfigurator() {
    1.72 +    }
    1.73 +
    1.74 +    public Collection<WebServiceFeature> getFeatures(final PolicyMapKey key, final PolicyMap policyMap) throws PolicyException {
    1.75 +        LOGGER.entering(key, policyMap);
    1.76 +        final Collection<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
    1.77 +        if ((key != null) && (policyMap != null)) {
    1.78 +            final Policy policy = policyMap.getEndpointEffectivePolicy(key);
    1.79 +            for (QName addressingAssertionQName : ADDRESSING_ASSERTIONS) {
    1.80 +                if ((policy != null) && policy.contains(addressingAssertionQName)) {
    1.81 +                    final Iterator <AssertionSet> assertions = policy.iterator();
    1.82 +                    while(assertions.hasNext()){
    1.83 +                        final AssertionSet assertionSet = assertions.next();
    1.84 +                        final Iterator<PolicyAssertion> policyAssertion = assertionSet.iterator();
    1.85 +                        while(policyAssertion.hasNext()){
    1.86 +                            final PolicyAssertion assertion = policyAssertion.next();
    1.87 +                            if(assertion.getName().equals(addressingAssertionQName)){
    1.88 +                                final WebServiceFeature feature = AddressingVersion.getFeature(addressingAssertionQName.getNamespaceURI(), true, !assertion.isOptional());
    1.89 +                                if (LOGGER.isLoggable(Level.FINE)) {
    1.90 +                                    LOGGER.fine("Added addressing feature \"" + feature + "\" for element \"" + key + "\"");
    1.91 +                                }
    1.92 +                                features.add(feature);
    1.93 +                            } // end-if non optional wsa assertion found
    1.94 +                        } // next assertion
    1.95 +                    } // next alternative
    1.96 +                } // end-if policy contains wsa assertion
    1.97 +            } //end foreach addr assertion
    1.98 +
    1.99 +            // Deal with WS-Addressing 1.0 Metadata assertions
   1.100 +            if (policy != null && policy.contains(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
   1.101 +                for (AssertionSet assertions : policy) {
   1.102 +                    for (PolicyAssertion assertion : assertions) {
   1.103 +                        if (assertion.getName().equals(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
   1.104 +                            NestedPolicy nestedPolicy = assertion.getNestedPolicy();
   1.105 +                            boolean requiresAnonymousResponses = false;
   1.106 +                            boolean requiresNonAnonymousResponses = false;
   1.107 +                            if (nestedPolicy != null) {
   1.108 +                                requiresAnonymousResponses = nestedPolicy.contains(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION);
   1.109 +                                requiresNonAnonymousResponses = nestedPolicy.contains(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION);
   1.110 +                            }
   1.111 +                            if(requiresAnonymousResponses && requiresNonAnonymousResponses) {
   1.112 +                                throw new WebServiceException("Only one among AnonymousResponses and NonAnonymousResponses can be nested in an Addressing assertion");
   1.113 +                            }
   1.114 +
   1.115 +                            final WebServiceFeature feature;
   1.116 +                            try {
   1.117 +                                if (requiresAnonymousResponses) {
   1.118 +                                    feature = new AddressingFeature(true, !assertion.isOptional(), AddressingFeature.Responses.ANONYMOUS);
   1.119 +                                } else if (requiresNonAnonymousResponses) {
   1.120 +                                    feature = new AddressingFeature(true, !assertion.isOptional(), AddressingFeature.Responses.NON_ANONYMOUS);
   1.121 +                                } else {
   1.122 +                                    feature = new AddressingFeature(true, !assertion.isOptional());
   1.123 +                                }
   1.124 +                            } catch (NoSuchMethodError e) {
   1.125 +                                throw LOGGER.logSevereException(new PolicyException(ModelerMessages.RUNTIME_MODELER_ADDRESSING_RESPONSES_NOSUCHMETHOD(toJar(Which.which(AddressingFeature.class))), e));
   1.126 +                            }
   1.127 +                            if (LOGGER.isLoggable(Level.FINE)) {
   1.128 +                                LOGGER.fine("Added addressing feature \"" + feature + "\" for element \"" + key + "\"");
   1.129 +                            }
   1.130 +                            features.add(feature);
   1.131 +                        }
   1.132 +                    }
   1.133 +                }
   1.134 +            }
   1.135 +        }
   1.136 +        LOGGER.exiting(features);
   1.137 +        return features;
   1.138 +    }
   1.139 +
   1.140 +    /**
   1.141 +     * Given the URL String inside jar, returns the URL to the jar itself.
   1.142 +     */
   1.143 +    private static String toJar(String url) {
   1.144 +        if(!url.startsWith("jar:"))
   1.145 +            return url;
   1.146 +        url = url.substring(4); // cut off jar:
   1.147 +        return url.substring(0,url.lastIndexOf('!'));    // cut off everything after '!'
   1.148 +    }
   1.149 +}

mercurial