Search in sources :

Example 1 with WsgenTool

use of com.sun.tools.ws.wscompile.WsgenTool in project metro-jax-ws by eclipse-ee4j.

the class WebServiceApTest method testRemoteException.

public void testRemoteException() {
    options.add("-r");
    options.add(destDir.getAbsolutePath());
    options.add("-wsdl");
    options.add("-inlineSchemas");
    options.add("-verbose");
    options.add("com.sun.tools.ws.test.processor.modeler.annotation.RMITestWs");
    WsgenTool wsgen = new WsgenTool(System.out);
    wsgen.run(options.toArray(new String[options.size()]));
    WsgenOptions opts = getOptions(wsgen);
    int count = 0;
    for (File f : opts.getGeneratedFiles()) {
        count++;
    }
    Assert.assertEquals(11, count);
    try {
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(destDir, "RMITestWsService.wsdl"));
        NodeList faults = doc.getElementsByTagName("fault");
        Assert.assertEquals("CustomEx", faults.item(1).getAttributes().getNamedItem("name").getTextContent());
        Assert.assertEquals(faults.item(0).getAttributes().getNamedItem("name").getTextContent(), faults.item(1).getAttributes().getNamedItem("name").getTextContent());
        Assert.assertEquals(2, faults.getLength());
    } catch (ParserConfigurationException | SAXException | IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : WsgenOptions(com.sun.tools.ws.wscompile.WsgenOptions) WsgenTool(com.sun.tools.ws.wscompile.WsgenTool) NodeList(org.w3c.dom.NodeList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) SAXException(org.xml.sax.SAXException)

Example 2 with WsgenTool

use of com.sun.tools.ws.wscompile.WsgenTool in project axis-axis2-java-core by apache.

the class JAXWS2WSDLCodegenEngine method generate.

/**
 * Generate.
 *
 * @throws Exception
 *             the exception
 */
public void generate() throws Exception {
    WsgenTool genTool = new WsgenTool(new WriterOutputStream(new LogWriter(log)));
    List<String> args = new ArrayList<String>();
    configurImportToolOptions(args);
    mergeOriginalArgs(args);
    boolean success = genTool.run(args.toArray(new String[args.size()]));
    if (success) {
        log.info("Code generation completed");
    }
}
Also used : LogWriter(org.apache.axis2.util.LogWriter) WsgenTool(com.sun.tools.ws.wscompile.WsgenTool) ArrayList(java.util.ArrayList) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream)

Example 3 with WsgenTool

use of com.sun.tools.ws.wscompile.WsgenTool in project metro-jax-ws by eclipse-ee4j.

the class NillableArrayTest method testNillableArray.

public void testNillableArray() {
    File destDir;
    List<String> options;
    destDir = new File(System.getProperty("java.io.tmpdir"), NillableArrayTest.class.getSimpleName());
    destDir.mkdirs();
    options = new ArrayList<>();
    options.add("-d");
    options.add(destDir.getAbsolutePath());
    options.add("-cp");
    options.add(System.getProperty("java.class.path") + File.pathSeparator + System.getProperty("jdk.module.path"));
    options.add("com.sun.tools.ws.test.processor.modeler.annotation.NillableTestWs");
    options.add("-wsdl");
    Properties props = System.getProperties();
    props.setProperty("com.sun.xml.ws.jaxb.allowNonNillableArray", "true");
    WsgenTool wsgen = new WsgenTool(System.out);
    try {
        wsgen.run(options.toArray(new String[options.size()]));
        File file = new File(destDir, "NillableTestWsService_schema1.xsd");
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file);
        NodeList complexTypesNodes = doc.getElementsByTagName("xs:complexType");
        for (int i = 0; i < complexTypesNodes.getLength(); i++) {
            // the nillable value is not set so nillable attribute in the schema for that array element will be true
            if ((complexTypesNodes.item(i).getAttributes().getNamedItem("name").getNodeValue()).equals("setEntitlements")) {
                Assert.assertEquals("true", complexTypesNodes.item(i).getChildNodes().item(1).getChildNodes().item(1).getAttributes().getNamedItem("nillable").getNodeValue());
            }
            // the nillable value is set to false so nillable attribute in the schema for that element will be null
            if ((complexTypesNodes.item(i).getAttributes().getNamedItem("name").getNodeValue()).equals("getEntitlementsResponse")) {
                Assert.assertNull(complexTypesNodes.item(i).getChildNodes().item(1).getChildNodes().item(1).getAttributes().getNamedItem("nillable"));
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    } finally {
        System.clearProperty("com.sun.xml.ws.jaxb.allowNonNillableArray");
    }
}
Also used : WsgenTool(com.sun.tools.ws.wscompile.WsgenTool) NodeList(org.w3c.dom.NodeList) Properties(java.util.Properties) Document(org.w3c.dom.Document) File(java.io.File)

Aggregations

WsgenTool (com.sun.tools.ws.wscompile.WsgenTool)3 File (java.io.File)2 Document (org.w3c.dom.Document)2 NodeList (org.w3c.dom.NodeList)2 WsgenOptions (com.sun.tools.ws.wscompile.WsgenOptions)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 LogWriter (org.apache.axis2.util.LogWriter)1 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)1 SAXException (org.xml.sax.SAXException)1