325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.addressing.policy;
325N/A
325N/Aimport com.sun.xml.internal.ws.api.addressing.AddressingVersion;
325N/Aimport com.sun.xml.internal.ws.policy.AssertionSet;
325N/Aimport com.sun.xml.internal.ws.policy.NestedPolicy;
325N/Aimport com.sun.xml.internal.ws.policy.Policy;
325N/Aimport com.sun.xml.internal.ws.policy.PolicyAssertion;
325N/Aimport com.sun.xml.internal.ws.policy.PolicyException;
325N/Aimport com.sun.xml.internal.ws.policy.PolicyMap;
325N/Aimport com.sun.xml.internal.ws.policy.PolicyMapKey;
325N/Aimport com.sun.xml.internal.ws.policy.jaxws.spi.PolicyFeatureConfigurator;
325N/Aimport com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
325N/Aimport com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants;
325N/Aimport com.sun.xml.internal.ws.resources.ModelerMessages;
325N/Aimport com.sun.xml.internal.bind.util.Which;
325N/A
325N/Aimport java.util.Collection;
325N/Aimport java.util.Iterator;
325N/Aimport java.util.LinkedList;
325N/Aimport java.util.logging.Level;
325N/Aimport javax.xml.namespace.QName;
325N/Aimport javax.xml.ws.WebServiceFeature;
325N/Aimport javax.xml.ws.WebServiceException;
325N/Aimport javax.xml.ws.soap.AddressingFeature;
325N/A
325N/A/**
325N/A * This Policy extension configures the WSDLModel with AddressingFeature when Addressing assertions are present in the
325N/A * PolicyMap.
325N/A *
325N/A * @author japod
325N/A * @author Rama Pulavarthi
325N/A */
325N/Apublic class AddressingFeatureConfigurator implements PolicyFeatureConfigurator {
325N/A
325N/A private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AddressingFeatureConfigurator.class);
325N/A
325N/A private static final QName[] ADDRESSING_ASSERTIONS = {
325N/A new QName(AddressingVersion.MEMBER.policyNsUri, "UsingAddressing")};
325N/A
325N/A /**
325N/A * Creates a new instance of AddressingFeatureConfigurator
325N/A */
325N/A public AddressingFeatureConfigurator() {
325N/A }
325N/A
325N/A public Collection<WebServiceFeature> getFeatures(final PolicyMapKey key, final PolicyMap policyMap) throws PolicyException {
325N/A LOGGER.entering(key, policyMap);
325N/A final Collection<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
325N/A if ((key != null) && (policyMap != null)) {
325N/A final Policy policy = policyMap.getEndpointEffectivePolicy(key);
325N/A for (QName addressingAssertionQName : ADDRESSING_ASSERTIONS) {
325N/A if ((policy != null) && policy.contains(addressingAssertionQName)) {
325N/A final Iterator <AssertionSet> assertions = policy.iterator();
325N/A while(assertions.hasNext()){
325N/A final AssertionSet assertionSet = assertions.next();
325N/A final Iterator<PolicyAssertion> policyAssertion = assertionSet.iterator();
325N/A while(policyAssertion.hasNext()){
325N/A final PolicyAssertion assertion = policyAssertion.next();
325N/A if(assertion.getName().equals(addressingAssertionQName)){
325N/A final WebServiceFeature feature = AddressingVersion.getFeature(addressingAssertionQName.getNamespaceURI(), true, !assertion.isOptional());
325N/A if (LOGGER.isLoggable(Level.FINE)) {
325N/A LOGGER.fine("Added addressing feature \"" + feature + "\" for element \"" + key + "\"");
325N/A }
325N/A features.add(feature);
325N/A } // end-if non optional wsa assertion found
325N/A } // next assertion
325N/A } // next alternative
325N/A } // end-if policy contains wsa assertion
325N/A } //end foreach addr assertion
325N/A
325N/A // Deal with WS-Addressing 1.0 Metadata assertions
325N/A if (policy != null && policy.contains(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
325N/A for (AssertionSet assertions : policy) {
325N/A for (PolicyAssertion assertion : assertions) {
325N/A if (assertion.getName().equals(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
325N/A NestedPolicy nestedPolicy = assertion.getNestedPolicy();
325N/A boolean requiresAnonymousResponses = false;
325N/A boolean requiresNonAnonymousResponses = false;
325N/A if (nestedPolicy != null) {
325N/A requiresAnonymousResponses = nestedPolicy.contains(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION);
325N/A requiresNonAnonymousResponses = nestedPolicy.contains(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION);
325N/A }
325N/A if(requiresAnonymousResponses && requiresNonAnonymousResponses) {
325N/A throw new WebServiceException("Only one among AnonymousResponses and NonAnonymousResponses can be nested in an Addressing assertion");
325N/A }
325N/A
325N/A final WebServiceFeature feature;
325N/A try {
325N/A if (requiresAnonymousResponses) {
325N/A feature = new AddressingFeature(true, !assertion.isOptional(), AddressingFeature.Responses.ANONYMOUS);
325N/A } else if (requiresNonAnonymousResponses) {
325N/A feature = new AddressingFeature(true, !assertion.isOptional(), AddressingFeature.Responses.NON_ANONYMOUS);
325N/A } else {
325N/A feature = new AddressingFeature(true, !assertion.isOptional());
325N/A }
325N/A } catch (NoSuchMethodError e) {
325N/A throw LOGGER.logSevereException(new PolicyException(ModelerMessages.RUNTIME_MODELER_ADDRESSING_RESPONSES_NOSUCHMETHOD(toJar(Which.which(AddressingFeature.class))), e));
325N/A }
325N/A if (LOGGER.isLoggable(Level.FINE)) {
325N/A LOGGER.fine("Added addressing feature \"" + feature + "\" for element \"" + key + "\"");
325N/A }
325N/A features.add(feature);
325N/A }
325N/A }
325N/A }
325N/A }
325N/A }
325N/A LOGGER.exiting(features);
325N/A return features;
325N/A }
325N/A
325N/A /**
325N/A * Given the URL String inside jar, returns the URL to the jar itself.
325N/A */
325N/A private static String toJar(String url) {
325N/A if(!url.startsWith("jar:"))
325N/A return url;
325N/A url = url.substring(4); // cut off jar:
325N/A return url.substring(0,url.lastIndexOf('!')); // cut off everything after '!'
325N/A }
325N/A}