Search in sources :

Example 81 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class XSDToWSDLProcessor method addWSDLTypes.

private void addWSDLTypes() throws ToolException {
    Element sourceElement = this.xsdDoc.getDocumentElement();
    Element targetElement = (Element) sourceElement.cloneNode(true);
    this.wsdlDefinition.setTargetNamespace((String) env.get(ToolConstants.CFG_NAMESPACE));
    this.wsdlDefinition.setQName(new QName(WSDLConstants.NS_WSDL11, (String) env.get(ToolConstants.CFG_NAME)));
    Types types = this.wsdlDefinition.createTypes();
    ExtensibilityElement extElement;
    try {
        registry = wsdlFactory.newPopulatedExtensionRegistry();
        registerJAXWSBinding(Definition.class);
        registerJAXWSBinding(Types.class);
        registerJAXWSBinding(Schema.class);
        extElement = registry.createExtension(Types.class, WSDLConstants.QNAME_SCHEMA);
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_CREATE_SCHEMA_EXTENSION", LOG);
        throw new ToolException(msg, wse);
    }
    ((Schema) extElement).setElement(targetElement);
    types.addExtensibilityElement(extElement);
    this.wsdlDefinition.setTypes(types);
    WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
    Writer outputWriter = getOutputWriter();
    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 : Types(javax.wsdl.Types) Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) Schema(javax.wsdl.extensions.schema.Schema) ToolException(org.apache.cxf.tools.common.ToolException) WSDLWriter(javax.wsdl.xml.WSDLWriter) IOException(java.io.IOException) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) WSDLWriter(javax.wsdl.xml.WSDLWriter) Writer(java.io.Writer)

Example 82 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class XSDToWSDLProcessor method initXSD.

private void initXSD() throws ToolException {
    InputStream in;
    try {
        in = new URL(xsdUrl).openStream();
    } catch (Exception m) {
        try {
            in = Files.newInputStream(Paths.get(xsdUrl));
        } catch (IOException ioe) {
            Message msg = new Message("FAIL_TO_OPEN_XSD_FILE", LOG, xsdUrl);
            throw new ToolException(msg, ioe);
        }
    }
    if (in == null) {
        throw new NullPointerException("Cannot create a ToolSpec object from a null stream");
    }
    try {
        xsdBuilder.setValidating(false);
        this.xsdDoc = xsdBuilder.parse(in);
    } catch (Exception ex) {
        Message msg = new Message("FAIL_TO_PARSE_TOOLSPEC", LOG);
        throw new ToolException(msg, ex);
    }
}
Also used : Message(org.apache.cxf.common.i18n.Message) InputStream(java.io.InputStream) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) URL(java.net.URL) IOException(java.io.IOException) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException)

Example 83 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class AbstractWSDLToProcessor method getOutputWriter.

protected Writer getOutputWriter(String newNameExt) throws ToolException {
    final String newName;
    final 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);
    } else {
        outputDir = "./";
    }
    FileWriterUtil fw = new FileWriterUtil(outputDir, env.get(OutputStreamCreator.class));
    try {
        return 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);
    }
}
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)

Example 84 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class WSDLToSoapProcessor method getSoapBody.

private SoapBody getSoapBody(Class<?> parent) throws ToolException {
    if (extReg == null) {
        extReg = wsdlFactory.newPopulatedExtensionRegistry();
    }
    final SoapBody soapBody;
    try {
        soapBody = SOAPBindingUtil.createSoapBody(extReg, parent, isSOAP12());
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_CREATE_SOAPBINDING", LOG);
        throw new ToolException(msg, wse);
    }
    soapBody.setUse((String) env.get(ToolConstants.CFG_USE));
    if (WSDLConstants.RPC.equalsIgnoreCase((String) env.get(ToolConstants.CFG_STYLE)) && env.optionSet(ToolConstants.CFG_NAMESPACE)) {
        soapBody.setNamespaceURI((String) env.get(ToolConstants.CFG_NAMESPACE));
    }
    return soapBody;
}
Also used : Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) SoapBody(org.apache.cxf.binding.soap.wsdl.extensions.SoapBody) ToolException(org.apache.cxf.tools.common.ToolException)

Example 85 with Message

use of org.apache.cxf.common.i18n.Message in project cxf by apache.

the class WSDLToSoapProcessor method setSoapBindingExtElement.

private void setSoapBindingExtElement() throws ToolException {
    if (extReg == null) {
        extReg = wsdlFactory.newPopulatedExtensionRegistry();
    }
    SOAPBindingUtil.addSOAPNamespace(wsdlDefinition, isSOAP12());
    final SoapBinding soapBinding;
    try {
        soapBinding = SOAPBindingUtil.createSoapBinding(extReg, isSOAP12());
    } catch (WSDLException wse) {
        Message msg = new Message("FAIL_TO_CREATE_SOAPBINDING", LOG);
        throw new ToolException(msg, wse);
    }
    soapBinding.setStyle((String) env.get(ToolConstants.CFG_STYLE));
    binding.addExtensibilityElement(soapBinding);
}
Also used : Message(org.apache.cxf.common.i18n.Message) WSDLException(javax.wsdl.WSDLException) ToolException(org.apache.cxf.tools.common.ToolException) SoapBinding(org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding)

Aggregations

Message (org.apache.cxf.common.i18n.Message)201 ToolException (org.apache.cxf.tools.common.ToolException)69 IOException (java.io.IOException)45 QName (javax.xml.namespace.QName)42 Fault (org.apache.cxf.interceptor.Fault)34 XMLStreamException (javax.xml.stream.XMLStreamException)27 JAXBException (javax.xml.bind.JAXBException)23 ArrayList (java.util.ArrayList)19 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)17 Element (org.w3c.dom.Element)17 File (java.io.File)16 WSDLException (javax.wsdl.WSDLException)15 Method (java.lang.reflect.Method)14 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)13 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)12 InputStream (java.io.InputStream)11 HashMap (java.util.HashMap)11 List (java.util.List)11 Map (java.util.Map)11 ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)11