Search in sources :

Example 6 with ToolException

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

the class WSDLToJavaScript method main.

public static void main(String[] pargs) {
    CommandInterfaceUtils.commandCommonMain();
    WSDLToJavaScript w2j = new WSDLToJavaScript(pargs);
    try {
        w2j.run(new ToolContext());
    } catch (ToolException ex) {
        System.err.println();
        System.err.println("WSDLToJS Error : " + ex.getMessage());
        System.err.println();
        if (w2j.isVerbose()) {
            ex.printStackTrace();
        }
        if (w2j.isExitOnFinish()) {
            System.exit(1);
        }
    } catch (Exception ex) {
        System.err.println("WSDLToJS Error : " + ex.getMessage());
        System.err.println();
        if (w2j.isVerbose()) {
            ex.printStackTrace();
        }
        if (w2j.isExitOnFinish()) {
            System.exit(1);
        }
    }
    if (w2j.isExitOnFinish()) {
        System.exit(0);
    }
}
Also used : ToolContext(org.apache.cxf.tools.common.ToolContext) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 7 with ToolException

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

the class WSDLToJavaScriptProcessor method process.

public void process() throws ToolException {
    super.process();
    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    File jsFile = getOutputFile(serviceInfo.getName().getLocalPart() + ".js");
    BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, null);
    NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
    Map<String, String> nsPrefixMap = CastUtils.cast(context.get(ToolConstants.CFG_JSPREFIXMAP, Map.class), String.class, String.class);
    if (nsPrefixMap != null) {
        for (Map.Entry<String, String> prefixEntry : nsPrefixMap.entrySet()) {
            prefixManager.collect(prefixEntry.getValue(), prefixEntry.getKey());
        }
    }
    BufferedWriter writer = null;
    try {
        OutputStream outputStream = Files.newOutputStream(jsFile.toPath());
        if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) {
            JavascriptGetInterceptor.writeUtilsToResponseStream(WSDLToJavaScriptProcessor.class, outputStream);
        }
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, UTF8);
        writer = new BufferedWriter(outputStreamWriter);
        XmlSchemaCollection collection = serviceInfo.getXmlSchemaCollection().getXmlSchemaCollection();
        SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), prefixManager, nameManager);
        String jsForSchemas = jsBuilder.generateCodeForSchemaCollection(collection);
        writer.append(jsForSchemas);
        ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null, prefixManager, nameManager);
        serviceBuilder.walk();
        String serviceJavascript = serviceBuilder.getCode();
        writer.append(serviceJavascript);
    } catch (FileNotFoundException e) {
        throw new ToolException(e);
    } catch (IOException e) {
        throw new ToolException(e);
    } finally {
        try {
            if (writer != null) {
                writer.close();
            }
        } catch (IOException e) {
            throw new ToolException(e);
        }
    }
}
Also used : ServiceJavascriptBuilder(org.apache.cxf.javascript.service.ServiceJavascriptBuilder) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) BufferedWriter(java.io.BufferedWriter) SchemaJavascriptBuilder(org.apache.cxf.javascript.types.SchemaJavascriptBuilder) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BasicNameManager(org.apache.cxf.javascript.BasicNameManager) OutputStreamWriter(java.io.OutputStreamWriter) ToolException(org.apache.cxf.tools.common.ToolException) NamespacePrefixAccumulator(org.apache.cxf.javascript.NamespacePrefixAccumulator) File(java.io.File) Map(java.util.Map)

Example 8 with ToolException

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

the class CustomizationParser method getTargetNode.

public Element getTargetNode(String uri) {
    if (uri == null) {
        return null;
    }
    if (uri.equals(wsdlURL) && wsdlNode != null) {
        return wsdlNode;
    }
    Document doc = null;
    InputStream ins = null;
    try {
        URIResolver resolver = new URIResolver(uri);
        ins = resolver.getInputStream();
    } catch (IOException e1) {
        return null;
    }
    if (ins == null) {
        return null;
    }
    XMLStreamReader reader = null;
    try {
        reader = StaxUtils.createXMLStreamReader(uri, ins);
        doc = StaxUtils.read(reader, true);
    } catch (Exception e) {
        Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { uri });
        throw new ToolException(msg, e);
    } finally {
        try {
            StaxUtils.close(reader);
        } catch (XMLStreamException e) {
        // ignore
        }
        try {
            ins.close();
        } catch (IOException ex) {
        // ignore
        }
    }
    try {
        doc.setDocumentURI(uri);
    } catch (Exception ex) {
    // ignore - probably not DOM level 3
    }
    if (doc != null) {
        return doc.getDocumentElement();
    }
    return null;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(org.apache.cxf.common.i18n.Message) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) URIResolver(org.apache.cxf.resource.URIResolver) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) Document(org.w3c.dom.Document) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 9 with ToolException

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

the class CustomizationParser method internalizeBinding.

protected void internalizeBinding(Element bindings, Element targetNode, String expression) {
    if (bindings.getAttributeNode("wsdlLocation") != null) {
        expression = "/";
    }
    if (isGlobaleBindings(bindings)) {
        nodeSelector.addNamespaces(wsdlNode);
        if (targetNode != wsdlNode) {
            nodeSelector.addNamespaces(targetNode);
        }
        copyBindingsToWsdl(targetNode, bindings, nodeSelector.getNamespaceContext());
    }
    if (isJAXWSBindings(bindings) && bindings.getAttributeNode("node") != null) {
        expression = expression + "/" + bindings.getAttribute("node");
        nodeSelector.addNamespaces(bindings);
        NodeList nodeList = nodeSelector.queryNodes(targetNode, expression);
        if (nodeList == null || nodeList.getLength() == 0) {
            throw new ToolException(new Message("NODE_NOT_EXISTS", LOG, new Object[] { expression }));
        }
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (hasJaxbBindingDeclaration(bindings)) {
                copyAllJaxbDeclarations(node, bindings);
            } else {
                copyBindingsToWsdl(node, bindings, nodeSelector.getNamespaceContext());
            }
        }
    }
    Element[] children = getChildElements(bindings, ToolConstants.NS_JAXWS_BINDINGS);
    for (Element child : children) {
        internalizeBinding(child, targetNode, expression);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ToolException(org.apache.cxf.tools.common.ToolException)

Example 10 with ToolException

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

the class CustomizationParser method getAbsoluteURI.

private String getAbsoluteURI(String uri, String bindingFile) {
    URI locURI = null;
    try {
        locURI = new URI(uri);
    } catch (URISyntaxException e) {
        Message msg = new Message("BINDING_LOC_ERROR", LOG, new Object[] { uri });
        throw new ToolException(msg);
    }
    if (!locURI.isAbsolute()) {
        try {
            String base = URIParserUtil.getAbsoluteURI(bindingFile);
            URI baseURI = new URI(base);
            locURI = baseURI.resolve(locURI);
        } catch (URISyntaxException e) {
            Message msg = new Message("NOT_URI", LOG, new Object[] { bindingFile });
            throw new ToolException(msg, e);
        }
    }
    return locURI.toString();
}
Also used : Message(org.apache.cxf.common.i18n.Message) URISyntaxException(java.net.URISyntaxException) ToolException(org.apache.cxf.tools.common.ToolException) URI(java.net.URI)

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