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);
}
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations