Search in sources :

Example 76 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class CustomizationParser method parse.

public void parse(ToolContext pe) {
    this.env = pe;
    String[] bindingFiles;
    try {
        wsdlURL = URIParserUtil.getAbsoluteURI((String) env.get(ToolConstants.CFG_WSDLURL));
        if (env.get(ToolConstants.CFG_CATALOG) != null) {
            wsdlNode = resolveNodeByCatalog(wsdlURL);
        }
        if (wsdlNode == null) {
            wsdlNode = getTargetNode(this.wsdlURL);
        }
        if (wsdlNode == null) {
            throw new ToolException(new Message("MISSING_WSDL", LOG, wsdlURL));
        }
        customizedElements.put(wsdlURL, wsdlNode);
        bindingFiles = (String[]) env.get(ToolConstants.CFG_BINDING);
        if (bindingFiles == null) {
            return;
        }
    } catch (ClassCastException e) {
        bindingFiles = new String[1];
        bindingFiles[0] = (String) env.get(ToolConstants.CFG_BINDING);
    }
    for (int i = 0; i < bindingFiles.length; i++) {
        try {
            addBinding(bindingFiles[i]);
        } catch (XMLStreamException xse) {
            Message msg = new Message("STAX_PARSER_ERROR", LOG);
            throw new ToolException(msg, xse);
        }
    }
    for (Map.Entry<Element, Element> entry : jaxwsBindingsMap.entrySet()) {
        nodeSelector.addNamespaces(entry.getKey());
        Element oldTargetNode = entry.getValue();
        Element targetNode = oldTargetNode;
        internalizeBinding(entry.getKey(), targetNode, "");
        String uri = entry.getKey().getAttribute("wsdlLocation");
        customizedElements.put(uri, targetNode);
        updateJaxwsBindingMapValue(targetNode);
    }
    buildHandlerChains();
}
Also used : Message(org.apache.cxf.common.i18n.Message) XMLStreamException(javax.xml.stream.XMLStreamException) Element(org.w3c.dom.Element) ToolException(org.apache.cxf.tools.common.ToolException) HashMap(java.util.HashMap) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 77 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class CustomizationParser method resolveByCatalog.

private String resolveByCatalog(String url) {
    if (StringUtils.isEmpty(url)) {
        return null;
    }
    Bus bus = env.get(Bus.class);
    OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus);
    try {
        return new OASISCatalogManagerHelper().resolve(catalogResolver, url, null);
    } catch (Exception e1) {
        Message msg = new Message("FAILED_RESOLVE_CATALOG", LOG, url);
        throw new ToolException(msg, e1);
    }
}
Also used : Bus(org.apache.cxf.Bus) OASISCatalogManagerHelper(org.apache.cxf.catalog.OASISCatalogManagerHelper) Message(org.apache.cxf.common.i18n.Message) OASISCatalogManager(org.apache.cxf.catalog.OASISCatalogManager) ToolException(org.apache.cxf.tools.common.ToolException) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 78 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class CustomizationParser method addBinding.

private void addBinding(String bindingFile) throws XMLStreamException {
    Element root = null;
    XMLStreamReader xmlReader = null;
    try {
        URIResolver resolver = new URIResolver(bindingFile);
        xmlReader = StaxUtils.createXMLStreamReader(resolver.getURI().toString(), resolver.getInputStream());
        root = StaxUtils.read(xmlReader, true).getDocumentElement();
    } catch (Exception e1) {
        Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { bindingFile });
        throw new ToolException(msg, e1);
    } finally {
        StaxUtils.close(xmlReader);
    }
    XMLStreamReader reader = StaxUtils.createXMLStreamReader(root);
    StaxUtils.toNextTag(reader);
    if (isValidJaxwsBindingFile(bindingFile, reader)) {
        String wsdlLocation = root.getAttribute("wsdlLocation");
        Element targetNode = null;
        if (!StringUtils.isEmpty(wsdlLocation)) {
            String wsdlURI = getAbsoluteURI(wsdlLocation, bindingFile);
            targetNode = getTargetNode(wsdlURI);
            String resolvedLoc = wsdlURI;
            if (targetNode == null && env.get(ToolConstants.CFG_CATALOG) != null) {
                resolvedLoc = resolveByCatalog(wsdlURI);
                targetNode = getTargetNode(resolvedLoc);
            }
            if (targetNode == null) {
                Message msg = new Message("POINT_TO_WSDL_DOES_NOT_EXIST", LOG, new Object[] { bindingFile, resolvedLoc });
                throw new ToolException(msg);
            }
            root.setAttributeNS(null, "wsdlLocation", wsdlURI);
        } else {
            targetNode = wsdlNode;
            root.setAttributeNS(null, "wsdlLocation", wsdlURL);
        }
        jaxwsBindingsMap.put(root, targetNode);
    } else if (isValidJaxbBindingFile(reader)) {
        String schemaLocation = root.getAttribute("schemaLocation");
        String resolvedSchemaLocation = resolveByCatalog(schemaLocation);
        if (resolvedSchemaLocation != null) {
            InputSource tmpIns = null;
            try {
                tmpIns = convertToTmpInputSource(root, resolvedSchemaLocation);
            } catch (Exception e1) {
                Message msg = new Message("FAILED_TO_ADD_SCHEMALOCATION", LOG, bindingFile);
                throw new ToolException(msg, e1);
            }
            jaxbBindings.add(tmpIns);
        } else {
            jaxbBindings.add(new InputSource(bindingFile));
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(org.apache.cxf.common.i18n.Message) Element(org.w3c.dom.Element) URIResolver(org.apache.cxf.resource.URIResolver) ToolException(org.apache.cxf.tools.common.ToolException) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 79 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class FaultGenerator method generate.

public void generate(ToolContext penv) throws ToolException {
    this.env = penv;
    if (passthrough()) {
        return;
    }
    Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) penv.get(WSDLToJavaProcessor.MODEL_MAP));
    for (JavaModel javaModel : map.values()) {
        Map<String, JavaExceptionClass> exceptionClasses = javaModel.getExceptionClasses();
        for (Entry<String, JavaExceptionClass> entry : exceptionClasses.entrySet()) {
            JavaExceptionClass expClz = entry.getValue();
            clearAttributes();
            if (penv.containsKey(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID)) {
                String faultSerialVersionUID = penv.get(ToolConstants.CFG_FAULT_SERIAL_VERSION_UID).toString();
                setAttributes("faultSerialVersionUID", faultSerialVersionUID);
                if ("FQCN".equalsIgnoreCase(faultSerialVersionUID)) {
                    setAttributes("suid", generateHashSUID(expClz.getFullClassName()));
                } else if ("TIMESTAMP".equalsIgnoreCase(faultSerialVersionUID)) {
                    setAttributes("suid", generateTimestampSUID());
                } else if ("NONE".equalsIgnoreCase(faultSerialVersionUID)) {
                    // nothing
                    setAttributes("suid", "");
                } else {
                    // do a quick Parse to make sure it looks like a Long
                    try {
                        Long.parseLong(faultSerialVersionUID);
                    } catch (NumberFormatException nfe) {
                        throw new ToolException(nfe);
                    }
                    setAttributes("suid", faultSerialVersionUID);
                }
            } else {
                setAttributes("suid", "");
            }
            setAttributes("expClass", expClz);
            String exceptionSuperclass;
            if (penv.containsKey(ToolConstants.CFG_EXCEPTION_SUPER)) {
                exceptionSuperclass = penv.get(ToolConstants.CFG_EXCEPTION_SUPER).toString();
            } else {
                exceptionSuperclass = "java.lang.Exception";
            }
            String simpleName = exceptionSuperclass.indexOf('.') == -1 ? exceptionSuperclass : exceptionSuperclass.substring(exceptionSuperclass.lastIndexOf('.') + 1);
            String exceptionSuperclassString = simpleName;
            for (JavaField jf : expClz.getFields()) {
                String jfClassName = jf.getClassName();
                if (jfClassName.substring(jfClassName.lastIndexOf(".") + 1).equals(simpleName)) {
                    exceptionSuperclassString = exceptionSuperclass;
                }
                setAttributes("paraName", ProcessorUtil.mangleNameToVariableName(jf.getName()));
            }
            ClassCollector collector = penv.get(ClassCollector.class);
            for (String pkg : collector.getTypesPackages()) {
                if (collector.containTypesClass(pkg, simpleName)) {
                    exceptionSuperclassString = exceptionSuperclass;
                }
            }
            if (expClz.getName().equals(exceptionSuperclassString)) {
                exceptionSuperclassString = exceptionSuperclass;
            }
            setAttributes("exceptionSuperclass", exceptionSuperclassString);
            if (!exceptionSuperclass.startsWith("java.lang.") && !exceptionSuperclassString.equals(exceptionSuperclass)) {
                expClz.addImport(exceptionSuperclass);
            }
            setCommonAttributes();
            doWrite(FAULT_TEMPLATE, parseOutputName(expClz.getPackageName(), expClz.getName()));
        }
    }
}
Also used : JavaField(org.apache.cxf.tools.common.model.JavaField) QName(javax.xml.namespace.QName) JavaModel(org.apache.cxf.tools.common.model.JavaModel) ClassCollector(org.apache.cxf.tools.util.ClassCollector) JavaExceptionClass(org.apache.cxf.tools.common.model.JavaExceptionClass) ToolException(org.apache.cxf.tools.common.ToolException)

Example 80 with ToolException

use of org.apache.cxf.tools.common.ToolException in project cxf by apache.

the class ParameterProcessor method processWrappedAbstractOutput.

private void processWrappedAbstractOutput(JavaMethod method, MessageInfo inputMessage, MessageInfo outputMessage) throws ToolException {
    if (messagePartsNotUnique(inputMessage) || messagePartsNotUnique(outputMessage)) {
        processOutput(method, inputMessage, outputMessage);
        return;
    }
    if (outputMessage.getMessagePartsNumber() == 0) {
        addVoidReturn(method);
        return;
    }
    MessagePartInfo inputPart = inputMessage.getMessagePartsNumber() > 0 ? inputMessage.getFirstMessagePart() : null;
    MessagePartInfo outputPart = outputMessage.getMessagePartsNumber() > 0 ? outputMessage.getFirstMessagePart() : null;
    List<QName> inputWrapElement = null;
    List<QName> outputWrapElement = null;
    if (inputPart != null) {
        inputWrapElement = ProcessorUtil.getWrappedElementQNames(context, inputPart.getElementQName());
    }
    if (outputPart != null) {
        outputWrapElement = ProcessorUtil.getWrappedElementQNames(context, outputPart.getElementQName());
    }
    if (inputWrapElement == null || outputWrapElement.isEmpty()) {
        addVoidReturn(method);
        return;
    }
    method.setReturn(null);
    boolean qualified = ProcessorUtil.isSchemaFormQualified(context, outputPart.getElementQName());
    if (outputWrapElement.size() == 1) {
        QName outElement = outputWrapElement.iterator().next();
        boolean sameWrapperChild = false;
        for (QName inElement : inputWrapElement) {
            if (isSameWrapperChild(inElement, outElement)) {
                JavaParameter jpIn = null;
                for (JavaParameter j : method.getParameters()) {
                    if (inElement.equals(j.getQName())) {
                        jpIn = j;
                    }
                }
                JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.INOUT, outputPart);
                if (!qualified && !isRefElement(outputPart, outElement)) {
                    jp.setTargetNamespace("");
                }
                if (jpIn != null && !jpIn.getClassName().equals(jp.getClassName())) {
                    jp.setStyle(JavaType.Style.OUT);
                }
                addParameter(outputPart, method, jp);
                sameWrapperChild = true;
                if (method.getReturn() == null) {
                    addVoidReturn(method);
                }
                break;
            }
        }
        if (!sameWrapperChild) {
            JavaReturn jreturn = getReturnFromQName(outElement, outputPart);
            if (!qualified && !this.isRefElement(outputPart, outElement)) {
                jreturn.setTargetNamespace("");
            }
            method.setReturn(jreturn);
        }
        return;
    }
    for (QName outElement : outputWrapElement) {
        if ("return".equals(outElement.getLocalPart())) {
            if (method.getReturn() != null) {
                org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("WRAPPER_STYLE_TWO_RETURN_TYPES", LOG);
                throw new ToolException(msg);
            }
            JavaReturn jreturn = getReturnFromQName(outElement, outputPart);
            if (!qualified) {
                jreturn.setTargetNamespace("");
            }
            method.setReturn(jreturn);
            continue;
        }
        boolean sameWrapperChild = false;
        if (inputWrapElement != null) {
            for (QName inElement : inputWrapElement) {
                if (isSameWrapperChild(inElement, outElement)) {
                    JavaParameter jpIn = null;
                    for (JavaParameter j : method.getParameters()) {
                        if (inElement.equals(j.getQName())) {
                            jpIn = j;
                        }
                    }
                    JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.INOUT, outputPart);
                    if (!qualified && !isRefElement(outputPart, outElement)) {
                        jp.setTargetNamespace("");
                    }
                    if (jpIn != null && !jpIn.getClassName().equals(jp.getClassName())) {
                        jp.setStyle(JavaType.Style.OUT);
                        checkPartName(outputMessage, outElement, jp);
                    }
                    addParameter(outputPart, method, jp);
                    sameWrapperChild = true;
                    break;
                }
            }
        }
        if (!sameWrapperChild) {
            JavaParameter jp = getParameterFromQName(outputPart.getElementQName(), outElement, JavaType.Style.OUT, outputPart);
            if (!qualified && !isRefElement(outputPart, outElement)) {
                jp.setTargetNamespace("");
            }
            checkPartName(outputMessage, outElement, jp);
            addParameter(outputPart, method, jp);
        }
    }
    if (method.getReturn() == null) {
        addVoidReturn(method);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) QName(javax.xml.namespace.QName) Message(org.apache.cxf.common.i18n.Message) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) JavaReturn(org.apache.cxf.tools.common.model.JavaReturn) JavaParameter(org.apache.cxf.tools.common.model.JavaParameter) ToolException(org.apache.cxf.tools.common.ToolException)

Aggregations

ToolException (org.apache.cxf.tools.common.ToolException)129 Message (org.apache.cxf.common.i18n.Message)69 IOException (java.io.IOException)38 File (java.io.File)30 QName (javax.xml.namespace.QName)19 WSDLException (javax.wsdl.WSDLException)18 BadUsageException (org.apache.cxf.tools.common.toolspec.parser.BadUsageException)16 ToolContext (org.apache.cxf.tools.common.ToolContext)15 XMLStreamException (javax.xml.stream.XMLStreamException)14 FileNotFoundException (java.io.FileNotFoundException)12 Test (org.junit.Test)12 Element (org.w3c.dom.Element)10 InputStream (java.io.InputStream)9 Writer (java.io.Writer)9 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)8 SoapBinding (org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)8 WSDLWriter (javax.wsdl.xml.WSDLWriter)7