Search in sources :

Example 26 with ToolException

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

the class AbstractWSDLToProcessor method getOutputWriter.

protected Writer getOutputWriter(String newNameExt) throws ToolException {
    Writer writer = null;
    String newName = null;
    String outputDir;
    if (env.get(ToolConstants.CFG_OUTPUTFILE) != null) {
        newName = (String) env.get(ToolConstants.CFG_OUTPUTFILE);
    } else {
        String oldName = (String) env.get(ToolConstants.CFG_WSDLURL);
        int position = oldName.lastIndexOf("/");
        if (position < 0) {
            position = oldName.lastIndexOf("\\");
        }
        if (position >= 0) {
            oldName = oldName.substring(position + 1, oldName.length());
        }
        if (oldName.toLowerCase().indexOf(WSDL_FILE_NAME_EXT) >= 0) {
            newName = oldName.substring(0, oldName.length() - 5) + newNameExt + WSDL_FILE_NAME_EXT;
        } else {
            newName = oldName + newNameExt;
        }
    }
    if (env.get(ToolConstants.CFG_OUTPUTDIR) != null) {
        outputDir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
        if (!("/".equals(outputDir.substring(outputDir.length() - 1)) || "\\".equals(outputDir.substring(outputDir.length() - 1)))) {
            outputDir = outputDir + "/";
        }
    } else {
        outputDir = "./";
    }
    FileWriterUtil fw = new FileWriterUtil(outputDir, env.get(OutputStreamCreator.class));
    try {
        writer = fw.getWriter("", newName);
    } catch (IOException ioe) {
        Message msg = new Message("FAIL_TO_WRITE_FILE", LOG, env.get(ToolConstants.CFG_OUTPUTDIR) + System.getProperty("file.seperator") + newName);
        throw new ToolException(msg, ioe);
    }
    return writer;
}
Also used : Message(org.apache.cxf.common.i18n.Message) FileWriterUtil(org.apache.cxf.tools.util.FileWriterUtil) OutputStreamCreator(org.apache.cxf.tools.util.OutputStreamCreator) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) Writer(java.io.Writer)

Example 27 with ToolException

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

the class WSDLToServiceProcessor method doAppendService.

private void doAppendService() throws ToolException {
    if (service == null) {
        service = wsdlDefinition.createService();
        service.setQName(new QName(WSDLConstants.WSDL_PREFIX, (String) env.get(ToolConstants.CFG_SERVICE)));
    }
    if (port == null) {
        port = wsdlDefinition.createPort();
        port.setName((String) env.get(ToolConstants.CFG_PORT));
        port.setBinding(binding);
    }
    setAddrElement();
    service.addPort(port);
    wsdlDefinition.addService(service);
    WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
    Writer outputWriter = getOutputWriter(NEW_FILE_NAME_MODIFIER);
    try {
        wsdlWriter.writeWSDL(wsdlDefinition, outputWriter);
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_WRITE_WSDL", LOG);
        throw new ToolException(msg, wse);
    }
    try {
        outputWriter.close();
    } catch (IOException ioe) {
        Message msg = new Message("FAIL_TO_CLOSE_WSDL_FILE", LOG);
        throw new ToolException(msg, ioe);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) WSDLWriter(javax.wsdl.xml.WSDLWriter) ToolException(org.apache.cxf.tools.common.ToolException) IOException(java.io.IOException) Writer(java.io.Writer) WSDLWriter(javax.wsdl.xml.WSDLWriter)

Example 28 with ToolException

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

the class WSDLToServiceProcessor method setAddrElement.

private void setAddrElement() throws ToolException {
    String transport = (String) env.get(ToolConstants.CFG_TRANSPORT);
    Address address = AddressFactory.getInstance().getAddresser(transport);
    Map<String, String> ns = address.getNamespaces(env);
    for (Map.Entry<String, String> entry : ns.entrySet()) {
        wsdlDefinition.addNamespace(entry.getKey(), entry.getValue());
    }
    WSDLExtensibilityPlugin plugin = getWSDLPlugin(transport, Port.class);
    try {
        ExtensibilityElement extElement = plugin.createExtension(address.buildAddressArguments(env));
        port.addExtensibilityElement(extElement);
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_CREATE_SOAP_ADDRESS", LOG);
        throw new ToolException(msg, wse);
    }
}
Also used : Address(org.apache.cxf.tools.misc.processor.address.Address) Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) WSDLExtensibilityPlugin(org.apache.cxf.wsdl.WSDLExtensibilityPlugin) ToolException(org.apache.cxf.tools.common.ToolException) Map(java.util.Map) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement)

Example 29 with ToolException

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

the class WSDLToServiceProcessor method process.

public void process() throws ToolException {
    init();
    if (isServicePortExisted()) {
        Message msg = new Message("SERVICE_PORT_EXIST", LOG);
        throw new ToolException(msg);
    }
    if (!isBindingExisted()) {
        Message msg = new Message("BINDING_NOT_EXIST", LOG);
        throw new ToolException(msg);
    }
    doAppendService();
}
Also used : Message(org.apache.cxf.common.i18n.Message) ToolException(org.apache.cxf.tools.common.ToolException)

Example 30 with ToolException

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

the class WSDLToSoapProcessor method doAppendBinding.

private void doAppendBinding() throws ToolException {
    if (binding == null) {
        binding = wsdlDefinition.createBinding();
        binding.setQName(new QName(wsdlDefinition.getTargetNamespace(), (String) env.get(ToolConstants.CFG_BINDING)));
        binding.setUndefined(false);
        binding.setPortType(portType);
    }
    setSoapBindingExtElement();
    addBindingOperation();
    wsdlDefinition.addBinding(binding);
    WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
    Writer outputWriter = getOutputWriter(NEW_FILE_NAME_MODIFIER);
    try {
        wsdlWriter.writeWSDL(wsdlDefinition, outputWriter);
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_WRITE_WSDL", LOG, wse.getMessage());
        throw new ToolException(msg);
    }
    try {
        outputWriter.close();
    } catch (IOException ioe) {
        Message msg = new Message("PORTTYPE_NOT_EXIST", LOG);
        throw new ToolException(msg);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) WSDLWriter(javax.wsdl.xml.WSDLWriter) ToolException(org.apache.cxf.tools.common.ToolException) IOException(java.io.IOException) WSDLWriter(javax.wsdl.xml.WSDLWriter) Writer(java.io.Writer)

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