Search in sources :

Example 1 with PolicySourceModel

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

the class PolicyMapUtilTest method testRejectAlternativesComplex.

public void testRejectAlternativesComplex() throws PolicyException {
    PolicySourceModel model = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_5, "id", null);
    ModelNode root = model.getRootNode();
    ModelNode alternatives = root.createChildExactlyOneNode();
    ModelNode alternative1 = alternatives.createChildAllNode();
    ModelNode alternative2 = alternatives.createChildAllNode();
    AssertionData assertion1 = AssertionData.createAssertionData(new QName("test1", "test1"));
    alternative1.createChildAssertionNode(assertion1);
    AssertionData assertion2 = AssertionData.createAssertionData(new QName("test2", "test2"));
    alternative2.createChildAssertionNode(assertion2);
    PolicyModelTranslator translator = PolicyModelTranslator.getTranslator();
    Policy policy = translator.translate(model);
    PolicyMapExtender extender = PolicyMapExtender.createPolicyMapExtender();
    PolicyMap map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] { extender }));
    PolicySubject subject = new PolicySubject("dummy", policy);
    PolicyMapKey key = PolicyMap.createWsdlServiceScopeKey(new QName("1"));
    extender.putServiceSubject(key, subject);
    key = PolicyMap.createWsdlServiceScopeKey(new QName("2"));
    extender.putServiceSubject(key, subject);
    try {
        PolicyMapUtil.rejectAlternatives(map);
        fail("Expected a PolicyException");
    } catch (PolicyException e) {
    }
}
Also used : PolicySourceModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel) QName(javax.xml.namespace.QName) PolicyModelTranslator(com.sun.xml.ws.policy.sourcemodel.PolicyModelTranslator) ModelNode(com.sun.xml.ws.policy.sourcemodel.ModelNode) AssertionData(com.sun.xml.ws.policy.sourcemodel.AssertionData)

Example 2 with PolicySourceModel

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

the class PolicyResourceLoader method unmarshallModel.

public static PolicySourceModel unmarshallModel(String resource) throws PolicyException, IOException {
    Reader resourceReader = getResourceReader(resource);
    PolicySourceModel model = PolicyModelUnmarshaller.getXmlUnmarshaller().unmarshalModel(resourceReader);
    resourceReader.close();
    return model;
}
Also used : PolicySourceModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Example 3 with PolicySourceModel

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

the class PolicyWSDLGeneratorExtension method writePolicyOrReferenceIt.

/**
 * Adds a PolicyReference element that points to the policy of the element,
 * if the policy does not have any id or name. Writes policy inside the element otherwise.
 *
 * @param subject
 *      PolicySubject to be referenced or marshalled
 * @param writer
 *      A TXW on to which we shall add the PolicyReference
 */
private void writePolicyOrReferenceIt(final PolicySubject subject, final TypedXmlWriter writer) {
    final Policy policy;
    try {
        policy = subject.getEffectivePolicy(merger);
    } catch (PolicyException e) {
        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e));
    }
    if (policy != null) {
        if (null == policy.getIdOrName()) {
            final PolicyModelGenerator generator = ModelGenerator.getGenerator();
            try {
                final PolicySourceModel policyInfoset = generator.translate(policy);
                marshaller.marshal(policyInfoset, writer);
            } catch (PolicyException pe) {
                throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1002_UNABLE_TO_MARSHALL_POLICY_OR_POLICY_REFERENCE(), pe));
            }
        } else {
            final TypedXmlWriter policyReference = writer._element(policy.getNamespaceVersion().asQName(XmlToken.PolicyReference), TypedXmlWriter.class);
            policyReference._attribute(XmlToken.Uri.toString(), '#' + policy.getIdOrName());
        }
    }
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicySourceModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel) WebServiceException(jakarta.xml.ws.WebServiceException) PolicyException(com.sun.xml.ws.policy.PolicyException) PolicyModelGenerator(com.sun.xml.ws.policy.sourcemodel.PolicyModelGenerator) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter)

Example 4 with PolicySourceModel

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

the class PolicyWSDLGeneratorExtension method addDefinitionsExtension.

@Override
public void addDefinitionsExtension(final TypedXmlWriter definitions) {
    try {
        LOGGER.entering();
        if (policyMap == null) {
            LOGGER.fine(PolicyMessages.WSP_1009_NOT_MARSHALLING_ANY_POLICIES_POLICY_MAP_IS_NULL());
        } else {
            subjects.addAll(policyMap.getPolicySubjects());
            final PolicyModelGenerator generator = ModelGenerator.getGenerator();
            Set<String> policyIDsOrNamesWritten = new HashSet<>();
            for (PolicySubject subject : subjects) {
                if (subject.getSubject() == null) {
                    LOGGER.fine(PolicyMessages.WSP_1008_NOT_MARSHALLING_WSDL_SUBJ_NULL(subject));
                } else {
                    final Policy policy;
                    try {
                        policy = subject.getEffectivePolicy(merger);
                    } catch (PolicyException e) {
                        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e));
                    }
                    if ((null == policy.getIdOrName()) || (policyIDsOrNamesWritten.contains(policy.getIdOrName()))) {
                        LOGGER.fine(PolicyMessages.WSP_1016_POLICY_ID_NULL_OR_DUPLICATE(policy));
                    } else {
                        try {
                            final PolicySourceModel policyInfoset = generator.translate(policy);
                            marshaller.marshal(policyInfoset, definitions);
                        } catch (PolicyException e) {
                            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1018_FAILED_TO_MARSHALL_POLICY(policy.getIdOrName()), e));
                        }
                        policyIDsOrNamesWritten.add(policy.getIdOrName());
                    }
                }
            }
        }
    } finally {
        LOGGER.exiting();
    }
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicySubject(com.sun.xml.ws.policy.PolicySubject) PolicySourceModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel) WebServiceException(jakarta.xml.ws.WebServiceException) PolicyException(com.sun.xml.ws.policy.PolicyException) PolicyModelGenerator(com.sun.xml.ws.policy.sourcemodel.PolicyModelGenerator) HashSet(java.util.HashSet)

Example 5 with PolicySourceModel

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

the class PolicyWSDLParserExtension method getPolicyURIs.

private Collection<String> getPolicyURIs(final Collection<PolicyRecordHandler> handlers, final PolicySourceModelContext modelContext) throws PolicyException {
    final Collection<String> result = new ArrayList<>(handlers.size());
    String policyUri;
    for (PolicyRecordHandler handler : handlers) {
        policyUri = handler.handler;
        if (HandlerType.AnonymousPolicyId == handler.type) {
            final PolicySourceModel policyModel = getAnonymousPolicyModels().get(policyUri);
            policyModel.expand(modelContext);
            while (getPolicyModels().containsKey(policyUri)) {
                policyUri = AnonymnousPolicyIdPrefix.append(anonymousPoliciesCount++).toString();
            }
            getPolicyModels().put(policyUri, policyModel);
        }
        result.add(policyUri);
    }
    return result;
}
Also used : PolicySourceModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel) ArrayList(java.util.ArrayList)

Aggregations

PolicySourceModel (com.sun.xml.ws.policy.sourcemodel.PolicySourceModel)10 Policy (com.sun.xml.ws.policy.Policy)3 PolicyException (com.sun.xml.ws.policy.PolicyException)3 AssertionData (com.sun.xml.ws.policy.sourcemodel.AssertionData)3 ModelNode (com.sun.xml.ws.policy.sourcemodel.ModelNode)3 PolicyModelTranslator (com.sun.xml.ws.policy.sourcemodel.PolicyModelTranslator)3 PolicyModelGenerator (com.sun.xml.ws.policy.sourcemodel.PolicyModelGenerator)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 HashSet (java.util.HashSet)2 QName (javax.xml.namespace.QName)2 TypedXmlWriter (com.sun.xml.txw2.TypedXmlWriter)1 ModelTranslator (com.sun.xml.ws.api.policy.ModelTranslator)1 PolicySubject (com.sun.xml.ws.policy.PolicySubject)1 PolicyRecord (com.sun.xml.ws.policy.jaxws.SafePolicyReader.PolicyRecord)1 PolicySourceModelContext (com.sun.xml.ws.policy.sourcemodel.PolicySourceModelContext)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1