Search in sources :

Example 11 with AssertionSet

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

the class PolicyModelTranslator method translate.

/**
 * The method translates {@link PolicySourceModel} structure into normalized {@link Policy} expression. The resulting Policy
 * is disconnected from its model, thus any additional changes in model will have no effect on the Policy expression.
 *
 * @param model the model to be translated into normalized policy expression. Must not be {@code null}.
 * @return translated policy expression in it's normalized form.
 * @throws PolicyException in case of translation failure
 */
public Policy translate(final PolicySourceModel model) throws PolicyException {
    LOGGER.entering(model);
    if (model == null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0043_POLICY_MODEL_TRANSLATION_ERROR_INPUT_PARAM_NULL()));
    }
    PolicySourceModel localPolicyModelCopy;
    try {
        localPolicyModelCopy = model.clone();
    } catch (CloneNotSupportedException e) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0016_UNABLE_TO_CLONE_POLICY_SOURCE_MODEL(), e));
    }
    final String policyId = localPolicyModelCopy.getPolicyId();
    final String policyName = localPolicyModelCopy.getPolicyName();
    final Collection<AssertionSet> alternatives = createPolicyAlternatives(localPolicyModelCopy);
    LOGGER.finest(LocalizationMessages.WSP_0052_NUMBER_OF_ALTERNATIVE_COMBINATIONS_CREATED(alternatives.size()));
    Policy policy = null;
    if (alternatives.size() == 0) {
        policy = Policy.createNullPolicy(model.getNamespaceVersion(), policyName, policyId);
        LOGGER.finest(LocalizationMessages.WSP_0055_NO_ALTERNATIVE_COMBINATIONS_CREATED());
    } else if (alternatives.size() == 1 && alternatives.iterator().next().isEmpty()) {
        policy = Policy.createEmptyPolicy(model.getNamespaceVersion(), policyName, policyId);
        LOGGER.finest(LocalizationMessages.WSP_0026_SINGLE_EMPTY_ALTERNATIVE_COMBINATION_CREATED());
    } else {
        policy = Policy.createPolicy(model.getNamespaceVersion(), policyName, policyId, alternatives);
        LOGGER.finest(LocalizationMessages.WSP_0057_N_ALTERNATIVE_COMBINATIONS_M_POLICY_ALTERNATIVES_CREATED(alternatives.size(), policy.getNumberOfAssertionSets()));
    }
    LOGGER.exiting(policy);
    return policy;
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicyException(com.sun.xml.ws.policy.PolicyException) AssertionSet(com.sun.xml.ws.policy.AssertionSet)

Example 12 with AssertionSet

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

the class MtomFeatureConfigurator method getFeatures.

/**
 * process Mtom policy assertions and if found and is not optional then mtom is enabled on the
 * {@link WSDLBoundPortType}
 *
 * @param key Key that identifies the endpoint scope
 * @param policyMap Must be non-null
 * @throws PolicyException If retrieving the policy triggered an exception
 */
public Collection<WebServiceFeature> getFeatures(PolicyMapKey key, PolicyMap policyMap) throws PolicyException {
    final Collection<WebServiceFeature> features = new LinkedList<>();
    if ((key != null) && (policyMap != null)) {
        Policy policy = policyMap.getEndpointEffectivePolicy(key);
        if (null != policy && policy.contains(EncodingConstants.OPTIMIZED_MIME_SERIALIZATION_ASSERTION)) {
            Iterator<AssertionSet> assertions = policy.iterator();
            while (assertions.hasNext()) {
                AssertionSet assertionSet = assertions.next();
                Iterator<PolicyAssertion> policyAssertion = assertionSet.iterator();
                while (policyAssertion.hasNext()) {
                    PolicyAssertion assertion = policyAssertion.next();
                    if (EncodingConstants.OPTIMIZED_MIME_SERIALIZATION_ASSERTION.equals(assertion.getName())) {
                        features.add(new MTOMFeature(true));
                    }
                // end-if non optional mtom assertion found
                }
            // next assertion
            }
        // next alternative
        }
    // end-if policy contains mtom assertion
    }
    return features;
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicyAssertion(com.sun.xml.ws.policy.PolicyAssertion) MTOMFeature(jakarta.xml.ws.soap.MTOMFeature) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) AssertionSet(com.sun.xml.ws.policy.AssertionSet) LinkedList(java.util.LinkedList)

Example 13 with AssertionSet

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

the class SelectOptimalEncodingFeatureConfigurator method getFeatures.

/**
 * Process SelectOptimalEncoding policy assertions.
 *
 * @param key Key that identifies the endpoint scope.
 * @param policyMap The policy map.
 * @throws PolicyException If retrieving the policy triggered an exception.
 */
public Collection<WebServiceFeature> getFeatures(PolicyMapKey key, PolicyMap policyMap) throws PolicyException {
    final Collection<WebServiceFeature> features = new LinkedList<>();
    if ((key != null) && (policyMap != null)) {
        Policy policy = policyMap.getEndpointEffectivePolicy(key);
        if (null != policy && policy.contains(EncodingConstants.SELECT_OPTIMAL_ENCODING_ASSERTION)) {
            Iterator<AssertionSet> assertions = policy.iterator();
            while (assertions.hasNext()) {
                AssertionSet assertionSet = assertions.next();
                Iterator<PolicyAssertion> policyAssertion = assertionSet.iterator();
                while (policyAssertion.hasNext()) {
                    PolicyAssertion assertion = policyAssertion.next();
                    if (EncodingConstants.SELECT_OPTIMAL_ENCODING_ASSERTION.equals(assertion.getName())) {
                        String value = assertion.getAttributeValue(enabled);
                        boolean isSelectOptimalEncodingEnabled = value == null || Boolean.parseBoolean(value.trim());
                        features.add(new SelectOptimalEncodingFeature(isSelectOptimalEncodingEnabled));
                    }
                }
            }
        }
    }
    return features;
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicyAssertion(com.sun.xml.ws.policy.PolicyAssertion) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) AssertionSet(com.sun.xml.ws.policy.AssertionSet) SelectOptimalEncodingFeature(com.sun.xml.ws.api.client.SelectOptimalEncodingFeature) LinkedList(java.util.LinkedList)

Aggregations

AssertionSet (com.sun.xml.ws.policy.AssertionSet)13 PolicyAssertion (com.sun.xml.ws.policy.PolicyAssertion)10 Policy (com.sun.xml.ws.policy.Policy)7 LinkedList (java.util.LinkedList)6 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)4 PolicyException (com.sun.xml.ws.policy.PolicyException)3 AssertionData (com.sun.xml.ws.policy.sourcemodel.AssertionData)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 AddressingFeature (jakarta.xml.ws.soap.AddressingFeature)2 QName (javax.xml.namespace.QName)2 SelectOptimalEncodingFeature (com.sun.xml.ws.api.client.SelectOptimalEncodingFeature)1 FastInfosetFeature (com.sun.xml.ws.api.fastinfoset.FastInfosetFeature)1 NestedPolicy (com.sun.xml.ws.policy.NestedPolicy)1 PolicyMapKey (com.sun.xml.ws.policy.PolicyMapKey)1 MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)1 StringReader (java.io.StringReader)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1