use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToJavaScript method main.
public static void main(String[] pargs) {
CommandInterfaceUtils.commandCommonMain();
WSDLToJavaScript w2j = new WSDLToJavaScript(pargs);
try {
w2j.run(new ToolContext());
} catch (ToolException ex) {
System.err.println();
System.err.println("WSDLToJS Error : " + ex.getMessage());
System.err.println();
if (w2j.isVerbose()) {
ex.printStackTrace();
}
if (w2j.isExitOnFinish()) {
System.exit(1);
}
} catch (Exception ex) {
System.err.println("WSDLToJS 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 WSDLToJavaScriptProcessor method process.
public void process() throws ToolException {
super.process();
ServiceInfo serviceInfo = context.get(ServiceInfo.class);
File jsFile = getOutputFile(serviceInfo.getName().getLocalPart() + ".js");
BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, null);
NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
Map<String, String> nsPrefixMap = CastUtils.cast(context.get(ToolConstants.CFG_JSPREFIXMAP, Map.class), String.class, String.class);
if (nsPrefixMap != null) {
for (Map.Entry<String, String> prefixEntry : nsPrefixMap.entrySet()) {
prefixManager.collect(prefixEntry.getValue(), prefixEntry.getKey());
}
}
BufferedWriter writer = null;
try {
OutputStream outputStream = Files.newOutputStream(jsFile.toPath());
if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) {
JavascriptGetInterceptor.writeUtilsToResponseStream(WSDLToJavaScriptProcessor.class, outputStream);
}
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, UTF8);
writer = new BufferedWriter(outputStreamWriter);
XmlSchemaCollection collection = serviceInfo.getXmlSchemaCollection().getXmlSchemaCollection();
SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), prefixManager, nameManager);
String jsForSchemas = jsBuilder.generateCodeForSchemaCollection(collection);
writer.append(jsForSchemas);
ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null, prefixManager, nameManager);
serviceBuilder.walk();
String serviceJavascript = serviceBuilder.getCode();
writer.append(serviceJavascript);
} catch (FileNotFoundException e) {
throw new ToolException(e);
} catch (IOException e) {
throw new ToolException(e);
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException e) {
throw new ToolException(e);
}
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class CustomizationParser method getTargetNode.
public Element getTargetNode(String uri) {
if (uri == null) {
return null;
}
if (uri.equals(wsdlURL) && wsdlNode != null) {
return wsdlNode;
}
Document doc = null;
InputStream ins = null;
try {
URIResolver resolver = new URIResolver(uri);
ins = resolver.getInputStream();
} catch (IOException e1) {
return null;
}
if (ins == null) {
return null;
}
XMLStreamReader reader = null;
try {
reader = StaxUtils.createXMLStreamReader(uri, ins);
doc = StaxUtils.read(reader, true);
} catch (Exception e) {
Message msg = new Message("CAN_NOT_READ_AS_ELEMENT", LOG, new Object[] { uri });
throw new ToolException(msg, e);
} finally {
try {
StaxUtils.close(reader);
} catch (XMLStreamException e) {
// ignore
}
try {
ins.close();
} catch (IOException ex) {
// ignore
}
}
try {
doc.setDocumentURI(uri);
} catch (Exception ex) {
// ignore - probably not DOM level 3
}
if (doc != null) {
return doc.getDocumentElement();
}
return null;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class CustomizationParser method internalizeBinding.
protected void internalizeBinding(Element bindings, Element targetNode, String expression) {
if (bindings.getAttributeNode("wsdlLocation") != null) {
expression = "/";
}
if (isGlobaleBindings(bindings)) {
nodeSelector.addNamespaces(wsdlNode);
if (targetNode != wsdlNode) {
nodeSelector.addNamespaces(targetNode);
}
copyBindingsToWsdl(targetNode, bindings, nodeSelector.getNamespaceContext());
}
if (isJAXWSBindings(bindings) && bindings.getAttributeNode("node") != null) {
expression = expression + "/" + bindings.getAttribute("node");
nodeSelector.addNamespaces(bindings);
NodeList nodeList = nodeSelector.queryNodes(targetNode, expression);
if (nodeList == null || nodeList.getLength() == 0) {
throw new ToolException(new Message("NODE_NOT_EXISTS", LOG, new Object[] { expression }));
}
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (hasJaxbBindingDeclaration(bindings)) {
copyAllJaxbDeclarations(node, bindings);
} else {
copyBindingsToWsdl(node, bindings, nodeSelector.getNamespaceContext());
}
}
}
Element[] children = getChildElements(bindings, ToolConstants.NS_JAXWS_BINDINGS);
for (Element child : children) {
internalizeBinding(child, targetNode, expression);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class CustomizationParser method getAbsoluteURI.
private String getAbsoluteURI(String uri, String bindingFile) {
URI locURI = null;
try {
locURI = new URI(uri);
} catch (URISyntaxException e) {
Message msg = new Message("BINDING_LOC_ERROR", LOG, new Object[] { uri });
throw new ToolException(msg);
}
if (!locURI.isAbsolute()) {
try {
String base = URIParserUtil.getAbsoluteURI(bindingFile);
URI baseURI = new URI(base);
locURI = baseURI.resolve(locURI);
} catch (URISyntaxException e) {
Message msg = new Message("NOT_URI", LOG, new Object[] { bindingFile });
throw new ToolException(msg, e);
}
}
return locURI.toString();
}
Aggregations