Search in sources :

Example 21 with ToolException

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

the class Stax2DOM method getDocument.

public Document getDocument(URL url) throws ToolException {
    XMLStreamReader reader = null;
    try (InputStream input = url.openStream()) {
        StreamSource src = new StreamSource(input, url.toExternalForm());
        reader = StaxUtils.createXMLStreamReader(src);
        return StaxUtils.read(reader, true);
    } catch (Exception e) {
        throw new ToolException(e);
    } finally {
        try {
            StaxUtils.close(reader);
        } catch (XMLStreamException e1) {
            throw new ToolException(e1);
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) ToolException(org.apache.cxf.tools.common.ToolException) ToolException(org.apache.cxf.tools.common.ToolException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 22 with ToolException

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

the class WSDL11Validator method isValid.

public boolean isValid() throws ToolException {
    // boolean isValid = true;
    String schemaDir = getSchemaDir();
    SchemaValidator schemaValidator = null;
    String[] schemas = (String[]) env.get(ToolConstants.CFG_SCHEMA_URL);
    // Tool will use the following sequence to find the schema files
    // 1.ToolConstants.CFG_SCHEMA_DIR from ToolContext
    // 2.ToolConstants.CXF_SCHEMA_DIR from System property
    // 3.If 1 and 2 is null , then load these schema files from jar file
    String wsdl = (String) env.get(ToolConstants.CFG_WSDLURL);
    Document doc = getWSDLDoc(wsdl);
    if (doc == null) {
        return true;
    }
    if (this.def == null) {
        try {
            this.def = getBus().getExtension(WSDLManager.class).getDefinition(wsdl);
        } catch (WSDLException e) {
            throw new ToolException(e);
        }
    }
    WSDLRefValidator wsdlRefValidator = new WSDLRefValidator(this.def, doc, getBus());
    wsdlRefValidator.setSuppressWarnings(env.optionSet(ToolConstants.CFG_SUPPRESS_WARNINGS));
    validators.add(wsdlRefValidator);
    if (env.fullValidateWSDL()) {
        validators.add(new UniqueBodyPartsValidator(this.def));
        validators.add(new WSIBPValidator(this.def));
        validators.add(new MIMEBindingValidator(this.def));
    }
    boolean notValid = false;
    for (AbstractValidator validator : validators) {
        if (!validator.isValid()) {
            notValid = true;
            addErrorMessage(validator.getErrorMessage());
        }
    }
    if (notValid) {
        throw new ToolException(this.getErrorMessage());
    }
    // By default just use WsdlRefValidator
    if (!env.fullValidateWSDL()) {
        return true;
    }
    if (!StringUtils.isEmpty(schemaDir)) {
        schemaValidator = new SchemaValidator(schemaDir, wsdl, schemas);
    } else {
        try {
            schemaValidator = new SchemaValidator(getDefaultSchemas(), wsdl, schemas);
        } catch (IOException e) {
            throw new ToolException("Schemas can not be loaded before validating wsdl", e);
        }
    }
    if (!schemaValidator.isValid()) {
        this.addErrorMessage(schemaValidator.getErrorMessage());
        throw new ToolException(this.getErrorMessage());
    }
    return true;
}
Also used : WSDLException(javax.wsdl.WSDLException) AbstractValidator(org.apache.cxf.tools.validator.AbstractValidator) IOException(java.io.IOException) Document(org.w3c.dom.Document) ToolException(org.apache.cxf.tools.common.ToolException)

Example 23 with ToolException

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

the class WSDLRefValidator method processSchemas.

private void processSchemas(Bus bus) {
    try {
        ServiceSchemaInfo info = bus.getExtension(WSDLManager.class).getSchemasForDefinition(definition);
        if (info == null) {
            getSchemas(bus);
        } else {
            schemaCollection = info.getSchemaCollection();
        }
        checkTargetNamespace(this.definition.getTargetNamespace());
    } catch (Exception ex) {
        throw new ToolException(ex);
    }
}
Also used : WSDLManager(org.apache.cxf.wsdl.WSDLManager) ToolException(org.apache.cxf.tools.common.ToolException) URISyntaxException(java.net.URISyntaxException) ToolException(org.apache.cxf.tools.common.ToolException) ServiceSchemaInfo(org.apache.cxf.service.model.ServiceSchemaInfo)

Example 24 with ToolException

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

the class WADLToJava method main.

public static void main(String[] pargs) {
    System.setProperty("org.apache.cxf.JDKBugHacks.defaultUsesCaches", "true");
    CommandInterfaceUtils.commandCommonMain();
    WADLToJava w2j = new WADLToJava(pargs);
    try {
        w2j.run(new ToolContext());
    } catch (ToolException ex) {
        System.err.println();
        System.err.println("WADLToJava Error: " + ex.getMessage());
        System.err.println();
        if (w2j.isVerbose()) {
            ex.printStackTrace();
        }
        if (w2j.isExitOnFinish()) {
            System.exit(1);
        }
    } catch (Exception ex) {
        System.err.println("WADLToJava 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 25 with ToolException

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

the class JAXRSContainer method readWadl.

protected String readWadl(String wadlURI, String authentication) {
    try {
        URL url = new URL(wadlURI);
        InputStream is = null;
        if (wadlURI.startsWith("https") && authentication != null) {
            is = SecureConnectionHelper.getStreamFromSecureConnection(url, authentication);
        } else {
            is = url.openStream();
        }
        Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8);
        return IOUtils.toString(reader);
    } catch (IOException e) {
        throw new ToolException(e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) ToolException(org.apache.cxf.tools.common.ToolException) URL(java.net.URL)

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