Search in sources :

Example 16 with WebServiceException

use of jakarta.xml.ws.WebServiceException 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 17 with WebServiceException

use of jakarta.xml.ws.WebServiceException 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)

Example 18 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class JavaMethodImpl method freeze.

/*package*/
void freeze(WSDLPort portType) {
    this.wsdlOperation = portType.getBinding().get(new QName(portType.getBinding().getPortType().getName().getNamespaceURI(), getOperationName()));
    // TODO: replace this with proper error handling
    if (wsdlOperation == null)
        throw new WebServiceException("Method " + seiMethod.getName() + " is exposed as WebMethod, but there is no corresponding wsdl operation with name " + operationName + " in the wsdl:portType" + portType.getBinding().getPortType().getName());
    // set the values from WSDLModel, if such annotations are not present or defaulted
    if (inputAction.equals("")) {
        inputAction = wsdlOperation.getOperation().getInput().getAction();
    } else if (!inputAction.equals(wsdlOperation.getOperation().getInput().getAction()))
        // TODO input action might be from @Action or WebMethod(action)
        LOGGER.warning("Input Action on WSDL operation " + wsdlOperation.getName().getLocalPart() + " and @Action on its associated Web Method " + seiMethod.getName() + " did not match and will cause problems in dispatching the requests");
    if (!mep.isOneWay()) {
        if (outputAction.equals(""))
            outputAction = wsdlOperation.getOperation().getOutput().getAction();
        for (CheckedExceptionImpl ce : exceptions) {
            if (ce.getFaultAction().equals("")) {
                QName detailQName = ce.getDetailType().tagName;
                WSDLFault wsdlfault = wsdlOperation.getOperation().getFault(detailQName);
                if (wsdlfault == null) {
                    // mismatch between wsdl model and SEI model, log a warning and use  SEI model for Action determination
                    LOGGER.warning("Mismatch between Java model and WSDL model found, For wsdl operation " + wsdlOperation.getName() + ",There is no matching wsdl fault with detail QName " + ce.getDetailType().tagName);
                    ce.setFaultAction(ce.getDefaultFaultAction());
                } else {
                    ce.setFaultAction(wsdlfault.getAction());
                }
            }
        }
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) WSDLFault(com.sun.xml.ws.api.model.wsdl.WSDLFault)

Example 19 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class PolicyWSDLParserExtension method postFinished.

// time to read possible config file and do alternative selection (on client side)
@Override
public void postFinished(final WSDLParserExtensionContext context) {
    // finally register the PolicyMap on the WSDLModel
    EditableWSDLModel wsdlModel = context.getWSDLModel();
    PolicyMap effectiveMap;
    try {
        if (context.isClientSide())
            effectiveMap = context.getPolicyResolver().resolve(new PolicyResolver.ClientContext(policyBuilder.getPolicyMap(), context.getContainer()));
        else
            effectiveMap = context.getPolicyResolver().resolve(new PolicyResolver.ServerContext(policyBuilder.getPolicyMap(), context.getContainer(), null));
        wsdlModel.setPolicyMap(effectiveMap);
    } catch (PolicyException e) {
        LOGGER.logSevereException(e);
        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1007_POLICY_EXCEPTION_WHILE_FINISHING_PARSING_WSDL(), e));
    }
    try {
        PolicyUtil.configureModel(wsdlModel, effectiveMap);
    } catch (PolicyException e) {
        LOGGER.logSevereException(e);
        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1012_FAILED_CONFIGURE_WSDL_MODEL(), e));
    }
    LOGGER.exiting();
}
Also used : PolicyMap(com.sun.xml.ws.policy.PolicyMap) WebServiceException(jakarta.xml.ws.WebServiceException) PolicyException(com.sun.xml.ws.policy.PolicyException) PolicyResolver(com.sun.xml.ws.api.policy.PolicyResolver)

Example 20 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class SafePolicyReader method readPolicyElement.

/**
 * Reads a policy expression from the XML stream.
 *
 * The XMLStreamReader should be in START_ELEMENT state and point to the policy element.
 * The content of the stream is copied and then the copy is unmarshalled. The result
 * is returned as a PolicyRecord.
 *
 * @param reader The XMLStreamReader should be in START_ELEMENT state and point to the policy element.
 * @param baseUrl The system id of the document read by the reader.
 * @return The policy that was read from the XML stream.
 */
public PolicyRecord readPolicyElement(final XMLStreamReader reader, final String baseUrl) {
    if ((null == reader) || (!reader.isStartElement())) {
        return null;
    }
    final StringBuilder elementCode = new StringBuilder();
    final PolicyRecord policyRec = new PolicyRecord();
    final QName elementName = reader.getName();
    boolean insidePolicyReferenceAttr;
    int depth = 0;
    try {
        do {
            switch(reader.getEventType()) {
                case // process start of next element
                XMLStreamConstants.START_ELEMENT:
                    QName curName = reader.getName();
                    insidePolicyReferenceAttr = NamespaceVersion.resolveAsToken(curName) == XmlToken.PolicyReference;
                    if (elementName.equals(curName)) {
                        // it is our element !
                        // we are then deeper
                        depth++;
                    }
                    // take care about namespaces as well
                    final StringBuilder xmlnsCode = new StringBuilder();
                    final Set<String> tmpNsSet = new HashSet<>();
                    if ((null == curName.getPrefix()) || ("".equals(curName.getPrefix()))) {
                        // no prefix
                        elementCode.append(// start tag
                        '<').append(curName.getLocalPart());
                        xmlnsCode.append(" xmlns=\"").append(curName.getNamespaceURI()).append('"');
                    } else {
                        // prefix presented
                        elementCode.append(// start tag
                        '<').append(curName.getPrefix()).append(':').append(curName.getLocalPart());
                        xmlnsCode.append(" xmlns:").append(curName.getPrefix()).append("=\"").append(curName.getNamespaceURI()).append('"');
                        tmpNsSet.add(curName.getPrefix());
                    }
                    // process element attributes
                    final int attrCount = reader.getAttributeCount();
                    final StringBuilder attrCode = new StringBuilder();
                    for (int i = 0; i < attrCount; i++) {
                        boolean uriAttrFlg = false;
                        if (insidePolicyReferenceAttr && "URI".equals(reader.getAttributeName(i).getLocalPart())) {
                            // PolicyReference found
                            uriAttrFlg = true;
                            if (null == policyRec.unresolvedURIs) {
                                // first such URI found
                                // initialize URIs set
                                policyRec.unresolvedURIs = new HashSet<>();
                            }
                            // add the URI
                            policyRec.unresolvedURIs.add(relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl));
                        }
                        // end-if PolicyReference attribute found
                        if ("xmlns".equals(reader.getAttributePrefix(i)) && tmpNsSet.contains(reader.getAttributeLocalName(i))) {
                            // do not append already defined ns
                            continue;
                        }
                        if ((null == reader.getAttributePrefix(i)) || ("".equals(reader.getAttributePrefix(i)))) {
                            // no attribute prefix
                            attrCode.append(' ').append(reader.getAttributeLocalName(i)).append("=\"").append(uriAttrFlg ? relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl) : reader.getAttributeValue(i)).append('"');
                        } else {
                            // prefix`presented
                            attrCode.append(' ').append(reader.getAttributePrefix(i)).append(':').append(reader.getAttributeLocalName(i)).append("=\"").append(uriAttrFlg ? relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl) : reader.getAttributeValue(i)).append('"');
                            if (!tmpNsSet.contains(reader.getAttributePrefix(i))) {
                                xmlnsCode.append(" xmlns:").append(reader.getAttributePrefix(i)).append("=\"").append(reader.getAttributeNamespace(i)).append('"');
                                tmpNsSet.add(reader.getAttributePrefix(i));
                            }
                        // end if prefix already processed
                        }
                    }
                    // end foreach attr
                    elementCode.append(// complete the start element tag
                    xmlnsCode).append(attrCode).append('>');
                    break;
                // break;
                case XMLStreamConstants.END_ELEMENT:
                    curName = reader.getName();
                    if (elementName.equals(curName)) {
                        // it is our element !
                        // go up
                        depth--;
                    }
                    elementCode.append(// append appropriate XML code
                    "</").append("".equals(curName.getPrefix()) ? "" : curName.getPrefix() + ':').append(curName.getLocalPart()).append(// complete the end element tag
                    '>');
                    break;
                case XMLStreamConstants.CHARACTERS:
                    // append text data
                    elementCode.append(reader.getText());
                    break;
                case XMLStreamConstants.CDATA:
                    elementCode.append(// append CDATA delimiters
                    "<![CDATA[").append(reader.getText()).append("]]>");
                    break;
                case // Ignore any comments
                XMLStreamConstants.COMMENT:
                    break;
                case // Ignore spaces as well
                XMLStreamConstants.SPACE:
                    break;
            }
            if (reader.hasNext() && depth > 0) {
                reader.next();
            }
        } while (XMLStreamConstants.END_DOCUMENT != reader.getEventType() && depth > 0);
        policyRec.policyModel = ModelUnmarshaller.getUnmarshaller().unmarshalModel(new StringReader(elementCode.toString()));
        if (null != policyRec.policyModel.getPolicyId()) {
            policyRec.setUri(baseUrl + "#" + policyRec.policyModel.getPolicyId(), policyRec.policyModel.getPolicyId());
        } else if (policyRec.policyModel.getPolicyName() != null) {
            policyRec.setUri(policyRec.policyModel.getPolicyName(), policyRec.policyModel.getPolicyName());
        }
    } catch (Exception e) {
        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1013_EXCEPTION_WHEN_READING_POLICY_ELEMENT(elementCode.toString()), e));
    }
    urlsRead.add(baseUrl);
    return policyRec;
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) StringReader(java.io.StringReader) PolicyException(com.sun.xml.ws.policy.PolicyException) WebServiceException(jakarta.xml.ws.WebServiceException) XMLStreamException(javax.xml.stream.XMLStreamException) HashSet(java.util.HashSet)

Aggregations

WebServiceException (jakarta.xml.ws.WebServiceException)386 QName (javax.xml.namespace.QName)49 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)36 SOAPException (jakarta.xml.soap.SOAPException)33 JAXBException (jakarta.xml.bind.JAXBException)30 Node (org.w3c.dom.Node)28 JAXBContext (jakarta.xml.bind.JAXBContext)27 IOException (java.io.IOException)26 SOAPMessage (jakarta.xml.soap.SOAPMessage)25 XMLStreamException (javax.xml.stream.XMLStreamException)25 Source (javax.xml.transform.Source)23 ProtocolException (jakarta.xml.ws.ProtocolException)20 Dispatch (jakarta.xml.ws.Dispatch)19 MalformedURLException (java.net.MalformedURLException)19 MessageContext (jakarta.xml.ws.handler.MessageContext)17 Map (java.util.Map)17 URL (java.net.URL)16 StreamSource (javax.xml.transform.stream.StreamSource)16 HandlerTracker (fromwsdl.handler.common.HandlerTracker)14 HandlerTracker (handler.handler_processing.common.HandlerTracker)14