Search in sources :

Example 1 with PolicyRecord

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

the class PolicyWSDLParserExtension method finished.

@Override
public void finished(final WSDLParserExtensionContext context) {
    LOGGER.entering(context);
    // need to make sure proper beginning order of internal policies within unresolvedUris list
    if (null != expandQueueHead) {
        // any policies found
        // protect list of possible external policies
        final List<String> externalUris = getUnresolvedUris(false);
        // cleaning up the list only
        getUnresolvedUris(true);
        final LinkedList<String> baseUnresolvedUris = new LinkedList<>();
        for (PolicyRecord currentRec = expandQueueHead; null != currentRec; currentRec = currentRec.next) {
            baseUnresolvedUris.addFirst(currentRec.getUri());
        }
        getUnresolvedUris(false).addAll(baseUnresolvedUris);
        // cut the queue off
        expandQueueHead = null;
        getUnresolvedUris(false).addAll(externalUris);
    }
    while (!getUnresolvedUris(false).isEmpty()) {
        final List<String> urisToBeSolvedList = getUnresolvedUris(false);
        // just cleaning up the list
        getUnresolvedUris(true);
        for (String currentUri : urisToBeSolvedList) {
            if (!isPolicyProcessed(currentUri)) {
                final PolicyRecord prefetchedRecord = getPolicyRecordsPassedBy().get(currentUri);
                if (null == prefetchedRecord) {
                    if (policyReader.getUrlsRead().contains(getBaseUrl(currentUri))) {
                        // --> unresolvable policy
                        LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1014_CAN_NOT_FIND_POLICY(currentUri)));
                    } else {
                        if (readExternalFile(getBaseUrl(currentUri))) {
                            getUnresolvedUris(false).add(currentUri);
                        }
                    }
                } else {
                    // policy has not been yet passed by
                    if (null != prefetchedRecord.unresolvedURIs) {
                        getUnresolvedUris(false).addAll(prefetchedRecord.unresolvedURIs);
                    }
                    // end-if null != prefetchedRecord.unresolvedURIs
                    addNewPolicyNeeded(currentUri, prefetchedRecord.policyModel);
                }
            }
        // end-if policy already processed
        }
    // end-foreach unresolved uris
    }
    final PolicySourceModelContext modelContext = PolicySourceModelContext.createContext();
    for (String policyUri : urisNeeded) {
        final PolicySourceModel sourceModel = modelsNeeded.get(policyUri);
        try {
            sourceModel.expand(modelContext);
            modelContext.addModel(new URI(policyUri), sourceModel);
        } catch (URISyntaxException | PolicyException e) {
            LOGGER.logSevereException(e);
        }
    }
    // iterating over all services and binding all the policies read before
    try {
        // messageSet holds the handlers for all wsdl:message elements. There
        // may otherwise be multiple entries for policies that are contained
        // by fault messages.
        HashSet<BuilderHandlerMessageScope> messageSet = new HashSet<>();
        for (EditableWSDLService service : context.getWSDLModel().getServices().values()) {
            if (getHandlers4ServiceMap().containsKey(service)) {
                getPolicyMapBuilder().registerHandler(new BuilderHandlerServiceScope(getPolicyURIs(getHandlers4ServiceMap().get(service), modelContext), getPolicyModels(), service, service.getName()));
            }
            for (EditableWSDLPort port : service.getPorts()) {
                if (getHandlers4PortMap().containsKey(port)) {
                    getPolicyMapBuilder().registerHandler(new BuilderHandlerEndpointScope(getPolicyURIs(getHandlers4PortMap().get(port), modelContext), getPolicyModels(), port, port.getOwner().getName(), port.getName()));
                }
                if (// port.getBinding may not be null, but in case ...
                null != port.getBinding()) {
                    if (// handler for binding
                    getHandlers4BindingMap().containsKey(port.getBinding())) {
                        getPolicyMapBuilder().registerHandler(new BuilderHandlerEndpointScope(getPolicyURIs(getHandlers4BindingMap().get(port.getBinding()), modelContext), getPolicyModels(), port.getBinding(), service.getName(), port.getName()));
                    }
                    // endif handler for binding
                    if (// handler for port type
                    getHandlers4PortTypeMap().containsKey(port.getBinding().getPortType())) {
                        getPolicyMapBuilder().registerHandler(new BuilderHandlerEndpointScope(getPolicyURIs(getHandlers4PortTypeMap().get(port.getBinding().getPortType()), modelContext), getPolicyModels(), port.getBinding().getPortType(), service.getName(), port.getName()));
                    }
                    for (EditableWSDLBoundOperation boundOperation : port.getBinding().getBindingOperations()) {
                        final EditableWSDLOperation operation = boundOperation.getOperation();
                        final QName operationName = new QName(boundOperation.getBoundPortType().getName().getNamespaceURI(), boundOperation.getName().getLocalPart());
                        // We store the message and portType/operation under the same namespace as the binding/operation so that we can match them up later
                        if (// handler for operation scope -- by boundOperation
                        getHandlers4BoundOperationMap().containsKey(boundOperation)) {
                            getPolicyMapBuilder().registerHandler(new BuilderHandlerOperationScope(getPolicyURIs(getHandlers4BoundOperationMap().get(boundOperation), modelContext), getPolicyModels(), boundOperation, service.getName(), port.getName(), operationName));
                        }
                        // endif handler for binding:operation scope
                        if (// handler for operation scope -- by operation map
                        getHandlers4OperationMap().containsKey(operation)) {
                            getPolicyMapBuilder().registerHandler(new BuilderHandlerOperationScope(getPolicyURIs(getHandlers4OperationMap().get(operation), modelContext), getPolicyModels(), operation, service.getName(), port.getName(), operationName));
                        }
                        // endif for portType:operation scope
                        // end operation scope
                        final EditableWSDLInput input = operation.getInput();
                        if (null != input) {
                            EditableWSDLMessage inputMsg = input.getMessage();
                            if (inputMsg != null && getHandlers4MessageMap().containsKey(inputMsg)) {
                                messageSet.add(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4MessageMap().get(inputMsg), modelContext), getPolicyModels(), inputMsg, BuilderHandlerMessageScope.Scope.InputMessageScope, service.getName(), port.getName(), operationName, null));
                            }
                        }
                        if (// binding op input msg
                        getHandlers4BindingInputOpMap().containsKey(boundOperation)) {
                            getPolicyMapBuilder().registerHandler(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4BindingInputOpMap().get(boundOperation), modelContext), getPolicyModels(), boundOperation, BuilderHandlerMessageScope.Scope.InputMessageScope, service.getName(), port.getName(), operationName, null));
                        }
                        // endif binding op input msg
                        if (// portType op input msg
                        null != input && getHandlers4InputMap().containsKey(input)) {
                            getPolicyMapBuilder().registerHandler(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4InputMap().get(input), modelContext), getPolicyModels(), input, BuilderHandlerMessageScope.Scope.InputMessageScope, service.getName(), port.getName(), operationName, null));
                        }
                        // endif portType op input msg
                        // end input message scope
                        final EditableWSDLOutput output = operation.getOutput();
                        if (null != output) {
                            EditableWSDLMessage outputMsg = output.getMessage();
                            if (outputMsg != null && getHandlers4MessageMap().containsKey(outputMsg)) {
                                messageSet.add(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4MessageMap().get(outputMsg), modelContext), getPolicyModels(), outputMsg, BuilderHandlerMessageScope.Scope.OutputMessageScope, service.getName(), port.getName(), operationName, null));
                            }
                        }
                        if (// binding op output msg
                        getHandlers4BindingOutputOpMap().containsKey(boundOperation)) {
                            getPolicyMapBuilder().registerHandler(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4BindingOutputOpMap().get(boundOperation), modelContext), getPolicyModels(), boundOperation, BuilderHandlerMessageScope.Scope.OutputMessageScope, service.getName(), port.getName(), operationName, null));
                        }
                        // endif binding op output msg
                        if (// portType op output msg
                        null != output && getHandlers4OutputMap().containsKey(output)) {
                            getPolicyMapBuilder().registerHandler(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4OutputMap().get(output), modelContext), getPolicyModels(), output, BuilderHandlerMessageScope.Scope.OutputMessageScope, service.getName(), port.getName(), operationName, null));
                        }
                        for (EditableWSDLBoundFault boundFault : boundOperation.getFaults()) {
                            final EditableWSDLFault fault = boundFault.getFault();
                            // but since this scenario tested in lagacy tests, dont' fail here
                            if (fault == null) {
                                LOGGER.warning(PolicyMessages.WSP_1021_FAULT_NOT_BOUND(boundFault.getName()));
                                continue;
                            }
                            final EditableWSDLMessage faultMessage = fault.getMessage();
                            final QName faultName = new QName(boundOperation.getBoundPortType().getName().getNamespaceURI(), boundFault.getName());
                            // We store the message and portType/fault under the same namespace as the binding/fault so that we can match them up later
                            if (faultMessage != null && getHandlers4MessageMap().containsKey(faultMessage)) {
                                messageSet.add(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4MessageMap().get(faultMessage), modelContext), getPolicyModels(), new WSDLBoundFaultContainer(boundFault, boundOperation), BuilderHandlerMessageScope.Scope.FaultMessageScope, service.getName(), port.getName(), operationName, faultName));
                            }
                            if (getHandlers4FaultMap().containsKey(fault)) {
                                messageSet.add(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4FaultMap().get(fault), modelContext), getPolicyModels(), new WSDLBoundFaultContainer(boundFault, boundOperation), BuilderHandlerMessageScope.Scope.FaultMessageScope, service.getName(), port.getName(), operationName, faultName));
                            }
                            if (getHandlers4BindingFaultOpMap().containsKey(boundFault)) {
                                messageSet.add(new BuilderHandlerMessageScope(getPolicyURIs(getHandlers4BindingFaultOpMap().get(boundFault), modelContext), getPolicyModels(), new WSDLBoundFaultContainer(boundFault, boundOperation), BuilderHandlerMessageScope.Scope.FaultMessageScope, service.getName(), port.getName(), operationName, faultName));
                            }
                        }
                    // end foreach binding operation fault msg
                    // end fault message scope
                    }
                // end foreach boundOperation in port
                }
            // endif port.getBinding() != null
            }
        // end foreach port in service
        }
        // Add handlers for wsdl:message elements
        for (BuilderHandlerMessageScope scopeHandler : messageSet) {
            getPolicyMapBuilder().registerHandler(scopeHandler);
        }
    } catch (PolicyException e) {
        LOGGER.logSevereException(e);
    }
    // End-preparation of policy map builder
    LOGGER.exiting();
}
Also used : PolicySourceModel(com.sun.xml.ws.policy.sourcemodel.PolicySourceModel) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) PolicyRecord(com.sun.xml.ws.policy.jaxws.SafePolicyReader.PolicyRecord) PolicyException(com.sun.xml.ws.policy.PolicyException) HashSet(java.util.HashSet) QName(javax.xml.namespace.QName) LinkedList(java.util.LinkedList) PolicySourceModelContext(com.sun.xml.ws.policy.sourcemodel.PolicySourceModelContext)

Aggregations

PolicyException (com.sun.xml.ws.policy.PolicyException)1 PolicyRecord (com.sun.xml.ws.policy.jaxws.SafePolicyReader.PolicyRecord)1 PolicySourceModel (com.sun.xml.ws.policy.sourcemodel.PolicySourceModel)1 PolicySourceModelContext (com.sun.xml.ws.policy.sourcemodel.PolicySourceModelContext)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 QName (javax.xml.namespace.QName)1