Search in sources :

Example 1 with PolicySubject

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

the class PolicyWSDLGeneratorExtension method addBindingOperationFaultExtension.

@Override
public void addBindingOperationFaultExtension(final TypedXmlWriter writer, final JavaMethod method, final CheckedException exception) {
    LOGGER.entering(writer, method, exception);
    if (subjects != null) {
        for (PolicySubject subject : subjects) {
            // iterate over all subjects in policy map
            if (this.policyMap.isFaultMessageSubject(subject)) {
                final Object concreteSubject = subject.getSubject();
                if (concreteSubject != null) {
                    final String exceptionName = exception == null ? null : exception.getMessageName();
                    if (exceptionName == null) {
                        // no name provided to check
                        writePolicyOrReferenceIt(subject, writer);
                    }
                    if (WSDLBoundFaultContainer.class.isInstance(concreteSubject)) {
                        // is it our class?
                        WSDLBoundFaultContainer faultContainer = (WSDLBoundFaultContainer) concreteSubject;
                        WSDLBoundFault fault = faultContainer.getBoundFault();
                        WSDLBoundOperation operation = faultContainer.getBoundOperation();
                        if (exceptionName.equals(fault.getName()) && operation.getName().getLocalPart().equals(method.getOperationName())) {
                            writePolicyOrReferenceIt(subject, writer);
                        }
                    } else if (WsdlBindingSubject.class.isInstance(concreteSubject)) {
                        WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) concreteSubject;
                        if ((wsdlSubject.getMessageType() == WsdlBindingSubject.WsdlMessageType.FAULT) && exception.getOwner().getTargetNamespace().equals(wsdlSubject.getName().getNamespaceURI()) && exceptionName.equals(wsdlSubject.getName().getLocalPart())) {
                            writePolicyOrReferenceIt(subject, writer);
                        }
                    }
                }
            }
        }
    }
    LOGGER.exiting();
}
Also used : PolicySubject(com.sun.xml.ws.policy.PolicySubject) WSDLBoundOperation(com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation) WSDLBoundFault(com.sun.xml.ws.api.model.wsdl.WSDLBoundFault) WsdlBindingSubject(com.sun.xml.ws.policy.subject.WsdlBindingSubject)

Example 2 with PolicySubject

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

the class PolicyWSDLGeneratorExtension method selectAndProcessSubject.

/**
 * This method should only be invoked by interface methods that deal with WSDL binding because they
 * may use the QName of the WSDL binding element as PolicySubject instead of a WSDL object.
 *
 * @param xmlWriter A TypedXmlWriter.
 * @param clazz The policy subject.
 * @param scopeType The WSDL scope.
 * @param bindingName The WSDL binding name.
 */
private void selectAndProcessSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final QName bindingName) {
    LOGGER.entering(xmlWriter, clazz, scopeType, bindingName);
    if (bindingName == null) {
        selectAndProcessSubject(xmlWriter, clazz, scopeType, (String) null);
    } else {
        if (subjects != null) {
            for (PolicySubject subject : subjects) {
                if (bindingName.equals(subject.getSubject())) {
                    writePolicyOrReferenceIt(subject, xmlWriter);
                }
            }
        }
        selectAndProcessSubject(xmlWriter, clazz, scopeType, bindingName.getLocalPart());
    }
    LOGGER.exiting();
}
Also used : PolicySubject(com.sun.xml.ws.policy.PolicySubject)

Example 3 with PolicySubject

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

the class PolicyWSDLGeneratorExtension method start.

@Override
public void start(final WSDLGenExtnContext context) {
    LOGGER.entering();
    try {
        this.seiModel = context.getModel();
        final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators();
        final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length];
        for (int i = 0; i < policyMapConfigurators.length; i++) {
            extenders[i] = PolicyMapExtender.createPolicyMapExtender();
        }
        // Read policy config file
        policyMap = PolicyResolverFactory.create().resolve(new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders));
        if (policyMap == null) {
            LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP());
            policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders));
        }
        final WSBinding binding = context.getBinding();
        try {
            final Collection<PolicySubject> policySubjects = new LinkedList<>();
            for (int i = 0; i < policyMapConfigurators.length; i++) {
                policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding));
                extenders[i].disconnect();
            }
            PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName());
        } catch (PolicyException e) {
            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e));
        }
        final TypedXmlWriter root = context.getRoot();
        root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix());
        root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix());
        root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX);
    } finally {
        LOGGER.exiting();
    }
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) PolicySubject(com.sun.xml.ws.policy.PolicySubject) WebServiceException(jakarta.xml.ws.WebServiceException) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) PolicyMapExtender(com.sun.xml.ws.policy.PolicyMapExtender) LinkedList(java.util.LinkedList) PolicyException(com.sun.xml.ws.policy.PolicyException) PolicyMapConfigurator(com.sun.xml.ws.policy.jaxws.spi.PolicyMapConfigurator) MtomPolicyMapConfigurator(com.sun.xml.ws.encoding.policy.MtomPolicyMapConfigurator) AddressingPolicyMapConfigurator(com.sun.xml.ws.addressing.policy.AddressingPolicyMapConfigurator)

Example 4 with PolicySubject

use of com.sun.xml.ws.policy.PolicySubject 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 PolicySubject

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

the class PolicyWSDLGeneratorExtension method selectAndProcessSubject.

private void selectAndProcessSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final String wsdlName) {
    LOGGER.entering(xmlWriter, clazz, scopeType, wsdlName);
    if (subjects != null) {
        for (PolicySubject subject : subjects) {
            // iterate over all subjects in policy map
            if (isCorrectType(policyMap, subject, scopeType)) {
                final Object concreteSubject = subject.getSubject();
                if (clazz.isInstance(concreteSubject)) {
                    // is it our class?
                    if (null == wsdlName) {
                        // no name provided to check
                        writePolicyOrReferenceIt(subject, xmlWriter);
                    } else {
                        try {
                            final Method getNameMethod = clazz.getDeclaredMethod("getName");
                            if (stringEqualsToStringOrQName(wsdlName, getNameMethod.invoke(concreteSubject))) {
                                writePolicyOrReferenceIt(subject, xmlWriter);
                            }
                        } catch (NoSuchMethodException e) {
                            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e));
                        } catch (IllegalAccessException e) {
                            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e));
                        } catch (InvocationTargetException e) {
                            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e));
                        }
                    }
                }
            }
        }
    }
    LOGGER.exiting();
}
Also used : PolicySubject(com.sun.xml.ws.policy.PolicySubject) WebServiceException(jakarta.xml.ws.WebServiceException) JavaMethod(com.sun.xml.ws.api.model.JavaMethod) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

PolicySubject (com.sun.xml.ws.policy.PolicySubject)16 Policy (com.sun.xml.ws.policy.Policy)10 QName (javax.xml.namespace.QName)8 PolicyMapExtender (com.sun.xml.ws.policy.PolicyMapExtender)7 EffectivePolicyModifier (com.sun.xml.ws.policy.EffectivePolicyModifier)6 PolicyMap (com.sun.xml.ws.policy.PolicyMap)6 PolicyMapKey (com.sun.xml.ws.policy.PolicyMapKey)6 PolicyMapMutator (com.sun.xml.ws.policy.PolicyMapMutator)6 WsdlBindingSubject (com.sun.xml.ws.policy.subject.WsdlBindingSubject)4 WebServiceException (jakarta.xml.ws.WebServiceException)3 ArrayList (java.util.ArrayList)3 PolicyException (com.sun.xml.ws.policy.PolicyException)2 TypedXmlWriter (com.sun.xml.txw2.TypedXmlWriter)1 AddressingPolicyMapConfigurator (com.sun.xml.ws.addressing.policy.AddressingPolicyMapConfigurator)1 WSBinding (com.sun.xml.ws.api.WSBinding)1 JavaMethod (com.sun.xml.ws.api.model.JavaMethod)1 WSDLBoundFault (com.sun.xml.ws.api.model.wsdl.WSDLBoundFault)1 WSDLBoundOperation (com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation)1 MtomPolicyMapConfigurator (com.sun.xml.ws.encoding.policy.MtomPolicyMapConfigurator)1 PolicyMapConfigurator (com.sun.xml.ws.policy.jaxws.spi.PolicyMapConfigurator)1