Search in sources :

Example 1 with NestedPolicy

use of com.sun.xml.ws.policy.NestedPolicy in project metro-jax-ws by eclipse-ee4j.

the class AddressingFeatureConfigurator method getFeatures.

public Collection<WebServiceFeature> getFeatures(final PolicyMapKey key, final PolicyMap policyMap) throws PolicyException {
    LOGGER.entering(key, policyMap);
    final Collection<WebServiceFeature> features = new LinkedList<>();
    if ((key != null) && (policyMap != null)) {
        final Policy policy = policyMap.getEndpointEffectivePolicy(key);
        for (QName addressingAssertionQName : ADDRESSING_ASSERTIONS) {
            if ((policy != null) && policy.contains(addressingAssertionQName)) {
                final Iterator<AssertionSet> assertions = policy.iterator();
                while (assertions.hasNext()) {
                    final AssertionSet assertionSet = assertions.next();
                    final Iterator<PolicyAssertion> policyAssertion = assertionSet.iterator();
                    while (policyAssertion.hasNext()) {
                        final PolicyAssertion assertion = policyAssertion.next();
                        if (assertion.getName().equals(addressingAssertionQName)) {
                            final WebServiceFeature feature = AddressingVersion.getFeature(addressingAssertionQName.getNamespaceURI(), true, !assertion.isOptional());
                            if (LOGGER.isLoggable(Level.FINE)) {
                                LOGGER.fine("Added addressing feature \"" + feature + "\" for element \"" + key + "\"");
                            }
                            features.add(feature);
                        }
                    // end-if non optional wsa assertion found
                    }
                // next assertion
                }
            // next alternative
            }
        // end-if policy contains wsa assertion
        }
        // Deal with WS-Addressing 1.0 Metadata assertions
        if (policy != null && policy.contains(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
            for (AssertionSet assertions : policy) {
                for (PolicyAssertion assertion : assertions) {
                    if (assertion.getName().equals(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
                        NestedPolicy nestedPolicy = assertion.getNestedPolicy();
                        boolean requiresAnonymousResponses = false;
                        boolean requiresNonAnonymousResponses = false;
                        if (nestedPolicy != null) {
                            requiresAnonymousResponses = nestedPolicy.contains(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION);
                            requiresNonAnonymousResponses = nestedPolicy.contains(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION);
                        }
                        if (requiresAnonymousResponses && requiresNonAnonymousResponses) {
                            throw new WebServiceException("Only one among AnonymousResponses and NonAnonymousResponses can be nested in an Addressing assertion");
                        }
                        final WebServiceFeature feature;
                        try {
                            if (requiresAnonymousResponses) {
                                feature = new AddressingFeature(true, !assertion.isOptional(), AddressingFeature.Responses.ANONYMOUS);
                            } else if (requiresNonAnonymousResponses) {
                                feature = new AddressingFeature(true, !assertion.isOptional(), AddressingFeature.Responses.NON_ANONYMOUS);
                            } else {
                                feature = new AddressingFeature(true, !assertion.isOptional());
                            }
                        } catch (NoSuchMethodError e) {
                            throw LOGGER.logSevereException(new PolicyException(ModelerMessages.RUNTIME_MODELER_ADDRESSING_RESPONSES_NOSUCHMETHOD(toJar(Which.which(AddressingFeature.class))), e));
                        }
                        if (LOGGER.isLoggable(Level.FINE)) {
                            LOGGER.fine("Added addressing feature \"" + feature + "\" for element \"" + key + "\"");
                        }
                        features.add(feature);
                    }
                }
            }
        }
    }
    LOGGER.exiting(features);
    return features;
}
Also used : Policy(com.sun.xml.ws.policy.Policy) NestedPolicy(com.sun.xml.ws.policy.NestedPolicy) PolicyAssertion(com.sun.xml.ws.policy.PolicyAssertion) AddressingFeature(jakarta.xml.ws.soap.AddressingFeature) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) AssertionSet(com.sun.xml.ws.policy.AssertionSet) LinkedList(java.util.LinkedList) PolicyException(com.sun.xml.ws.policy.PolicyException) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) NestedPolicy(com.sun.xml.ws.policy.NestedPolicy)

Example 2 with NestedPolicy

use of com.sun.xml.ws.policy.NestedPolicy in project metro-jax-ws by eclipse-ee4j.

the class AddressingPolicyValidator method validateServerSide.

public Fitness validateServerSide(PolicyAssertion assertion) {
    if (!supportedAssertions.contains(assertion.getName()))
        return Fitness.UNKNOWN;
    // Make sure wsam:Addressing contains only one of the allowed nested assertions.
    if (assertion.getName().equals(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
        NestedPolicy nestedPolicy = assertion.getNestedPolicy();
        if (nestedPolicy != null) {
            boolean requiresAnonymousResponses = false;
            boolean requiresNonAnonymousResponses = false;
            for (PolicyAssertion nestedAsser : nestedPolicy.getAssertionSet()) {
                if (nestedAsser.getName().equals(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION)) {
                    requiresAnonymousResponses = true;
                } else if (nestedAsser.getName().equals(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION)) {
                    requiresNonAnonymousResponses = true;
                } else {
                    LOGGER.warning("Found unsupported assertion:\n" + nestedAsser + "\nnested into assertion:\n" + assertion);
                    return Fitness.UNSUPPORTED;
                }
            }
            if (requiresAnonymousResponses && requiresNonAnonymousResponses) {
                LOGGER.warning("Only one among AnonymousResponses and NonAnonymousResponses can be nested in an Addressing assertion");
                return Fitness.INVALID;
            }
        }
    }
    return Fitness.SUPPORTED;
}
Also used : PolicyAssertion(com.sun.xml.ws.policy.PolicyAssertion) NestedPolicy(com.sun.xml.ws.policy.NestedPolicy)

Aggregations

NestedPolicy (com.sun.xml.ws.policy.NestedPolicy)2 PolicyAssertion (com.sun.xml.ws.policy.PolicyAssertion)2 AssertionSet (com.sun.xml.ws.policy.AssertionSet)1 Policy (com.sun.xml.ws.policy.Policy)1 PolicyException (com.sun.xml.ws.policy.PolicyException)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)1 AddressingFeature (jakarta.xml.ws.soap.AddressingFeature)1 LinkedList (java.util.LinkedList)1 QName (javax.xml.namespace.QName)1