Search in sources :

Example 36 with ToolException

use of org.apache.cxf.tools.common.ToolException 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 37 with ToolException

use of org.apache.cxf.tools.common.ToolException 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 38 with ToolException

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

the class WSDLToServiceProcessorTest method testDefaultLocation.

@Test
public void testDefaultLocation() throws Exception {
    String[] args = new String[] { "-transport", "soap", "-e", "serviceins", "-p", "portins", "-n", "Greeter_SOAPBinding", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
    WSDLToService.main(args);
    File outputFile = new File(output, "hello_world-service.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "serviceins"));
        if (service == null) {
            fail("Element wsdl:service serviceins Missed!");
        }
        Iterator<?> it = service.getPort("portins").getExtensibilityElements().iterator();
        if (it == null || !it.hasNext()) {
            fail("Element wsdl:port portins Missed!");
        }
        boolean found = false;
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof SOAPAddress) {
                SOAPAddress soapAddress = (SOAPAddress) obj;
                if (soapAddress.getLocationURI() != null && soapAddress.getLocationURI().equals("http://localhost:9000/serviceins/portins")) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            fail("Element soap:address of service port Missed!");
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) WSDLToService(org.apache.cxf.tools.misc.WSDLToService) Service(javax.wsdl.Service) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) Test(org.junit.Test)

Example 39 with ToolException

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

the class WSDLToServiceProcessorTest method testNewServiceSoap12.

@Test
public void testNewServiceSoap12() throws Exception {
    String[] args = new String[] { "-soap12", "-transport", "soap", "-e", "SOAPService", "-p", "SoapPort", "-n", "Greeter_SOAPBinding", "-a", "http://localhost:9000/SOAPService/SoapPort", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world_soap12.wsdl") };
    WSDLToService.main(args);
    File outputFile = new File(output, "hello_world_soap12-service.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "SOAPService"));
        if (service == null) {
            fail("Element wsdl:service serviceins Missed!");
        }
        Iterator<?> it = service.getPort("SoapPort").getExtensibilityElements().iterator();
        if (it == null || !it.hasNext()) {
            fail("Element wsdl:port portins Missed!");
        }
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof SOAP12Address) {
                SOAP12Address soapAddress = (SOAP12Address) obj;
                assertNotNull(soapAddress.getLocationURI());
                assertEquals("http://localhost:9000/SOAPService/SoapPort", soapAddress.getLocationURI());
                break;
            }
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
Also used : QName(javax.xml.namespace.QName) WSDLToService(org.apache.cxf.tools.misc.WSDLToService) Service(javax.wsdl.Service) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) SOAP12Address(javax.wsdl.extensions.soap12.SOAP12Address) Test(org.junit.Test)

Example 40 with ToolException

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

the class WSDLToServiceProcessorTest method testNewService.

@Test
public void testNewService() throws Exception {
    String[] args = new String[] { "-transport", "soap", "-e", "serviceins", "-p", "portins", "-n", "Greeter_SOAPBinding", "-a", "http://localhost:9000/newservice/newport", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
    WSDLToService.main(args);
    File outputFile = new File(output, "hello_world-service.wsdl");
    assertTrue("New wsdl file is not generated", outputFile.exists());
    WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
    processor.setEnvironment(env);
    try {
        processor.parseWSDL(outputFile.getAbsolutePath());
        Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "serviceins"));
        if (service == null) {
            fail("Element wsdl:service serviceins Missed!");
        }
        Iterator<?> it = service.getPort("portins").getExtensibilityElements().iterator();
        if (it == null || !it.hasNext()) {
            fail("Element wsdl:port portins Missed!");
        }
        boolean found = false;
        while (it.hasNext()) {
            Object obj = it.next();
            if (obj instanceof SOAPAddress) {
                SOAPAddress soapAddress = (SOAPAddress) obj;
                if (soapAddress.getLocationURI() != null && soapAddress.getLocationURI().equals("http://localhost:9000/newservice/newport")) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            fail("Element soap:address of service port Missed!");
        }
    } catch (ToolException e) {
        fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
    }
}
Also used : QName(javax.xml.namespace.QName) SOAPAddress(javax.wsdl.extensions.soap.SOAPAddress) WSDLToService(org.apache.cxf.tools.misc.WSDLToService) Service(javax.wsdl.Service) ToolException(org.apache.cxf.tools.common.ToolException) File(java.io.File) Test(org.junit.Test)

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