Search in sources :

Example 6 with PolicyMap

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

the class EndpointFactory method create.

public <T> WSEndpoint<T> create(Class<T> implType, boolean processHandlerAnnotation, @Nullable Invoker invoker, @Nullable QName serviceName, @Nullable QName portName, @Nullable Container container, @Nullable WSBinding binding, @Nullable SDDocumentSource primaryWsdl, @Nullable Collection<? extends SDDocumentSource> metadata, EntityResolver resolver, boolean isTransportSynchronous, boolean isStandard) {
    if (implType == null)
        throw new IllegalArgumentException();
    MetadataReader metadataReader = getExternalMetadatReader(implType, binding);
    if (isStandard) {
        verifyImplementorClass(implType, metadataReader);
    }
    if (invoker == null) {
        invoker = InstanceResolver.createDefault(implType).createInvoker();
    }
    // Performance analysis indicates that reading and parsing imported schemas is
    // a major component of Endpoint creation time.  Therefore, modify SDDocumentSource
    // handling to delay iterating collection as long as possible.
    Collection<SDDocumentSource> md = new CollectionCollection<>();
    if (primaryWsdl != null) {
        if (metadata != null) {
            Iterator<? extends SDDocumentSource> it = metadata.iterator();
            if (it.hasNext() && primaryWsdl.equals(it.next()))
                md.addAll(metadata);
            else {
                md.add(primaryWsdl);
                md.addAll(metadata);
            }
        } else
            md.add(primaryWsdl);
    } else if (metadata != null)
        md.addAll(metadata);
    if (container == null)
        container = ContainerResolver.getInstance().getContainer();
    if (serviceName == null)
        serviceName = getDefaultServiceName(implType, metadataReader);
    if (portName == null)
        portName = getDefaultPortName(serviceName, implType, metadataReader);
    {
        // error check
        String serviceNS = serviceName.getNamespaceURI();
        String portNS = portName.getNamespaceURI();
        if (!serviceNS.equals(portNS)) {
            throw new ServerRtException("wrong.tns.for.port", portNS, serviceNS);
        }
    }
    // setting a default binding
    if (binding == null)
        binding = BindingImpl.create(BindingID.parse(implType));
    if (isStandard && primaryWsdl != null) {
        verifyPrimaryWSDL(primaryWsdl, serviceName);
    }
    QName portTypeName = null;
    if (isStandard && implType.getAnnotation(WebServiceProvider.class) == null) {
        portTypeName = RuntimeModeler.getPortTypeName(implType, metadataReader);
    }
    // Categorises the documents as WSDL, Schema etc
    Collection<SDDocumentImpl> docList = categoriseMetadata(md.iterator(), serviceName, portTypeName);
    // Finds the primary WSDL and makes sure that metadata doesn't have
    // two concrete or abstract WSDLs
    SDDocumentImpl primaryDoc = primaryWsdl != null ? SDDocumentImpl.create(primaryWsdl, serviceName, portTypeName) : findPrimary(docList);
    EndpointAwareTube terminal;
    WSDLPort wsdlPort = null;
    AbstractSEIModelImpl seiModel = null;
    // create WSDL model
    if (primaryDoc != null) {
        wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver);
    }
    WebServiceFeatureList features = ((BindingImpl) binding).getFeatures();
    if (isStandard) {
        features.parseAnnotations(implType);
    }
    PolicyMap policyMap = null;
    // create terminal pipe that invokes the application
    if (isUseProviderTube(implType, isStandard)) {
        // TODO incase of Provider, provide a way to User for complete control of the message processing by giving
        // ability to turn off the WSDL/Policy based features and its associated tubes.
        // Even in case of Provider, merge all features configured via WSDL/Policy or deployment configuration
        Iterable<WebServiceFeature> configFtrs;
        if (wsdlPort != null) {
            policyMap = wsdlPort.getOwner().getParent().getPolicyMap();
            // Merge features from WSDL and other policy configuration
            configFtrs = wsdlPort.getFeatures();
        } else {
            // No WSDL, so try to merge features from Policy configuration
            policyMap = PolicyResolverFactory.create().resolve(new PolicyResolver.ServerContext(null, container, implType, false));
            configFtrs = PolicyUtil.getPortScopedFeatures(policyMap, serviceName, portName);
        }
        features.mergeFeatures(configFtrs, true);
        terminal = createProviderInvokerTube(implType, binding, invoker, container);
    } else {
        // Create runtime model for non Provider endpoints
        seiModel = createSEIModel(wsdlPort, implType, serviceName, portName, binding, primaryDoc);
        if (binding instanceof SOAPBindingImpl) {
            // set portKnownHeaders on Binding, so that they can be used for MU processing
            ((SOAPBindingImpl) binding).setPortKnownHeaders(((SOAPSEIModel) seiModel).getKnownHeaders());
        }
        // Generate WSDL for SEI endpoints(not for Provider endpoints)
        if (primaryDoc == null) {
            primaryDoc = generateWSDL(binding, seiModel, docList, container, implType);
            // create WSDL model
            wsdlPort = getWSDLPort(primaryDoc, docList, serviceName, portName, container, resolver);
            seiModel.freeze(wsdlPort);
        }
        policyMap = wsdlPort.getOwner().getParent().getPolicyMap();
        // New Features might have been added in WSDL through Policy.
        // Merge features from WSDL and other policy configuration
        // This sets only the wsdl features that are not already set(enabled/disabled)
        features.mergeFeatures(wsdlPort.getFeatures(), true);
        terminal = createSEIInvokerTube(seiModel, invoker, binding);
    }
    // Process @HandlerChain, if handler-chain is not set via Deployment Descriptor
    if (processHandlerAnnotation) {
        processHandlerAnnotation(binding, implType, serviceName, portName);
    }
    // Selects only required metadata for this endpoint from the passed-in metadata
    if (primaryDoc != null) {
        docList = findMetadataClosure(primaryDoc, docList, resolver);
    }
    ServiceDefinitionImpl serviceDefiniton = (primaryDoc != null) ? new ServiceDefinitionImpl(docList, primaryDoc) : null;
    return create(serviceName, portName, binding, container, seiModel, wsdlPort, implType, serviceDefiniton, terminal, isTransportSynchronous, policyMap);
}
Also used : BindingImpl(com.sun.xml.ws.binding.BindingImpl) SOAPBindingImpl(com.sun.xml.ws.binding.SOAPBindingImpl) AbstractSEIModelImpl(com.sun.xml.ws.model.AbstractSEIModelImpl) QName(javax.xml.namespace.QName) MetadataReader(com.sun.xml.ws.api.databinding.MetadataReader) WebServiceFeatureList(com.sun.xml.ws.binding.WebServiceFeatureList) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) PolicyMap(com.sun.xml.ws.policy.PolicyMap) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) SOAPBindingImpl(com.sun.xml.ws.binding.SOAPBindingImpl)

Example 7 with PolicyMap

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

the class ManagedClientAssertion method getAssertion.

/**
 * Return ManagedClient assertion if there is one associated with the client.
 *
 * @param portInfo The client PortInfo.
 * @return The policy assertion if found. Null otherwise.
 * @throws WebServiceException If computing the effective policy of the port failed.
 */
public static ManagedClientAssertion getAssertion(WSPortInfo portInfo) throws WebServiceException {
    if (portInfo == null)
        return null;
    LOGGER.entering(portInfo);
    // getPolicyMap is deprecated because it is only supposed to be used by Metro code
    // and not by other clients.
    @SuppressWarnings("deprecation") final PolicyMap policyMap = portInfo.getPolicyMap();
    final ManagedClientAssertion assertion = ManagementAssertion.getAssertion(MANAGED_CLIENT_QNAME, policyMap, portInfo.getServiceName(), portInfo.getPortName(), ManagedClientAssertion.class);
    LOGGER.exiting(assertion);
    return assertion;
}
Also used : PolicyMap(com.sun.xml.ws.policy.PolicyMap)

Example 8 with PolicyMap

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

the class ManagedServiceAssertion method getAssertion.

/**
 * Return ManagedService assertion if there is one associated with the endpoint.
 *
 * @param endpoint The endpoint. Must not be null.
 * @return The policy assertion if found. Null otherwise.
 * @throws WebServiceException If computing the effective policy of the endpoint failed.
 */
public static ManagedServiceAssertion getAssertion(WSEndpoint endpoint) throws WebServiceException {
    LOGGER.entering(endpoint);
    // getPolicyMap is deprecated because it is only supposed to be used by Metro code
    // and not by other clients.
    @SuppressWarnings("deprecation") final PolicyMap policyMap = endpoint.getPolicyMap();
    final ManagedServiceAssertion assertion = ManagementAssertion.getAssertion(MANAGED_SERVICE_QNAME, policyMap, endpoint.getServiceName(), endpoint.getPortName(), ManagedServiceAssertion.class);
    LOGGER.exiting(assertion);
    return assertion;
}
Also used : PolicyMap(com.sun.xml.ws.policy.PolicyMap)

Example 9 with PolicyMap

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

the class AlternativeSelectorTest method testDoSelectionAlternativesInput.

/**
 * Test of doSelection method, of class AlternativeSelector.
 */
public void testDoSelectionAlternativesInput() throws PolicyException {
    final PolicyMapExtender extender = PolicyMapExtender.createPolicyMapExtender();
    final PolicyMap map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] { extender }));
    final PolicySubject subject = new PolicySubject("dummy", this.multipleAlternativesPolicy);
    final PolicyMapKey key = PolicyMap.createWsdlMessageScopeKey(new QName("service"), new QName("port"), new QName("operation"));
    extender.putInputMessageSubject(key, subject);
    final EffectivePolicyModifier modifier = EffectivePolicyModifier.createEffectivePolicyModifier();
    modifier.connect(map);
    AlternativeSelector.doSelection(modifier);
    final Policy result = map.getInputMessageEffectivePolicy(key);
    if (result.contains(this.assertion1Name)) {
        assertFalse(result.contains(this.assertion2Name));
    } else if (result.contains(this.assertion2Name)) {
        assertFalse(result.contains(this.assertion1Name));
    } else {
        fail("Expected exactly one assertion in the resulting policy.");
    }
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicySubject(com.sun.xml.ws.policy.PolicySubject) EffectivePolicyModifier(com.sun.xml.ws.policy.EffectivePolicyModifier) PolicyMap(com.sun.xml.ws.policy.PolicyMap) PolicyMapKey(com.sun.xml.ws.policy.PolicyMapKey) QName(javax.xml.namespace.QName) PolicyMapMutator(com.sun.xml.ws.policy.PolicyMapMutator) PolicyMapExtender(com.sun.xml.ws.policy.PolicyMapExtender)

Example 10 with PolicyMap

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

the class AlternativeSelectorTest method testDoSelectionAlternativesService.

/**
 * Test of doSelection method, of class AlternativeSelector.
 */
public void testDoSelectionAlternativesService() throws PolicyException {
    final PolicyMapExtender extender = PolicyMapExtender.createPolicyMapExtender();
    final PolicyMap map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] { extender }));
    final PolicySubject subject = new PolicySubject("dummy", this.multipleAlternativesPolicy);
    final PolicyMapKey key = PolicyMap.createWsdlServiceScopeKey(new QName("service"));
    extender.putServiceSubject(key, subject);
    final EffectivePolicyModifier modifier = EffectivePolicyModifier.createEffectivePolicyModifier();
    modifier.connect(map);
    AlternativeSelector.doSelection(modifier);
    final Policy result = map.getServiceEffectivePolicy(key);
    if (result.contains(this.assertion1Name)) {
        assertFalse(result.contains(this.assertion2Name));
    } else if (result.contains(this.assertion2Name)) {
        assertFalse(result.contains(this.assertion1Name));
    } else {
        fail("Expected exactly one assertion in the resulting policy.");
    }
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicySubject(com.sun.xml.ws.policy.PolicySubject) EffectivePolicyModifier(com.sun.xml.ws.policy.EffectivePolicyModifier) PolicyMap(com.sun.xml.ws.policy.PolicyMap) PolicyMapKey(com.sun.xml.ws.policy.PolicyMapKey) QName(javax.xml.namespace.QName) PolicyMapMutator(com.sun.xml.ws.policy.PolicyMapMutator) PolicyMapExtender(com.sun.xml.ws.policy.PolicyMapExtender)

Aggregations

PolicyMap (com.sun.xml.ws.policy.PolicyMap)12 EffectivePolicyModifier (com.sun.xml.ws.policy.EffectivePolicyModifier)7 PolicyMapExtender (com.sun.xml.ws.policy.PolicyMapExtender)7 PolicyMapMutator (com.sun.xml.ws.policy.PolicyMapMutator)7 QName (javax.xml.namespace.QName)7 Policy (com.sun.xml.ws.policy.Policy)6 PolicyMapKey (com.sun.xml.ws.policy.PolicyMapKey)6 PolicySubject (com.sun.xml.ws.policy.PolicySubject)6 MetadataReader (com.sun.xml.ws.api.databinding.MetadataReader)1 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)1 PolicyResolver (com.sun.xml.ws.api.policy.PolicyResolver)1 SDDocumentSource (com.sun.xml.ws.api.server.SDDocumentSource)1 BindingImpl (com.sun.xml.ws.binding.BindingImpl)1 SOAPBindingImpl (com.sun.xml.ws.binding.SOAPBindingImpl)1 WebServiceFeatureList (com.sun.xml.ws.binding.WebServiceFeatureList)1 AbstractSEIModelImpl (com.sun.xml.ws.model.AbstractSEIModelImpl)1 PolicyException (com.sun.xml.ws.policy.PolicyException)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)1 HashSet (java.util.HashSet)1