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);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JavaScriptContainer method execute.
@SuppressWarnings("unchecked")
public void execute() throws ToolException {
if (hasInfoOption()) {
return;
}
buildToolContext();
validate(context);
WSDLConstants.WSDLVersion version = getWSDLVersion();
String wsdlURL = (String) context.get(ToolConstants.CFG_WSDLURL);
List<ServiceInfo> serviceList = (List<ServiceInfo>) context.get(ToolConstants.SERVICE_LIST);
if (serviceList == null) {
serviceList = new ArrayList<>();
PluginLoader pluginLoader = PluginLoader.newInstance();
// for JavaScript generation, we always use JAX-WS.
FrontEndProfile frontend = pluginLoader.getFrontEndProfile("jaxws");
// Build the ServiceModel from the WSDLModel
if (version == WSDLConstants.WSDLVersion.WSDL11) {
AbstractWSDLBuilder builder = frontend.getWSDLBuilder();
builder.setContext(context);
builder.setBus(getBus());
context.put(Bus.class, getBus());
builder.build(URIParserUtil.getAbsoluteURI(wsdlURL));
builder.customize();
Definition definition = builder.getWSDLModel();
context.put(Definition.class, definition);
builder.validate(definition);
WSDLServiceBuilder serviceBuilder = new WSDLServiceBuilder(getBus());
String serviceName = (String) context.get(ToolConstants.CFG_SERVICENAME);
if (serviceName != null) {
List<ServiceInfo> services = serviceBuilder.buildServices(definition, getServiceQName(definition));
serviceList.addAll(services);
} else if (definition.getServices().size() > 0) {
serviceList = serviceBuilder.buildServices(definition);
} else {
serviceList = serviceBuilder.buildMockServices(definition);
}
} else {
// TODO: wsdl2.0 support
throw new ToolException("Only WSDL 1.1 supported");
}
}
if (serviceList.isEmpty()) {
throw new ToolException("Did not find any services in WSDL");
}
Map<String, InterfaceInfo> interfaces = new LinkedHashMap<>();
ServiceInfo service0 = serviceList.get(0);
SchemaCollection schemaCollection = service0.getXmlSchemaCollection();
context.put(ToolConstants.XML_SCHEMA_COLLECTION, schemaCollection);
context.put(ToolConstants.PORTTYPE_MAP, interfaces);
context.put(ClassCollector.class, new ClassCollector());
WSDLToJavaScriptProcessor processor = new WSDLToJavaScriptProcessor();
for (ServiceInfo service : serviceList) {
context.put(ServiceInfo.class, service);
validate(service);
processor.setEnvironment(context);
processor.process();
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JavaScriptContainer method validate.
public void validate(final ServiceInfo service) throws ToolException {
for (ServiceValidator validator : getServiceValidators()) {
service.setProperty(ToolContext.class.getName(), context);
validator.setService(service);
if (!validator.isValid()) {
throw new ToolException(validator.getErrorMessage());
}
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JavaScriptContainer method setNamespaceJavascriptPrefixes.
public void setNamespaceJavascriptPrefixes(ToolContext env) {
Map<String, String> nsPrefixMap = new HashMap<>();
if (env.get(ToolConstants.CFG_JSPACKAGEPREFIX) != null) {
final String[] pns;
try {
pns = (String[]) env.get(ToolConstants.CFG_JSPACKAGEPREFIX);
} catch (ClassCastException e) {
Message msg = new Message("INVALID_PREFIX_MAPPING", LOG, env.get(ToolConstants.CFG_JSPACKAGEPREFIX));
throw new ToolException(msg);
}
for (String jsprefix : pns) {
int pos = jsprefix.indexOf('=');
if (pos != -1) {
String ns = jsprefix.substring(0, pos);
jsprefix = jsprefix.substring(pos + 1);
nsPrefixMap.put(ns, jsprefix);
}
}
env.put(ToolConstants.CFG_JSPREFIXMAP, nsPrefixMap);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JavaScriptContainer method validate.
public void validate(ToolContext env) throws ToolException {
String outdir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
if (outdir != null) {
File dir = new File(outdir);
if (!dir.exists() && !dir.mkdirs()) {
Message msg = new Message("DIRECTORY_COULD_NOT_BE_CREATED", LOG, outdir);
throw new ToolException(msg);
}
if (!dir.isDirectory()) {
Message msg = new Message("NOT_A_DIRECTORY", LOG, outdir);
throw new ToolException(msg);
}
}
if (env.optionSet(ToolConstants.CFG_COMPILE)) {
String clsdir = (String) env.get(ToolConstants.CFG_CLASSDIR);
if (clsdir != null) {
File dir = new File(clsdir);
if (!dir.exists() && !dir.mkdirs()) {
Message msg = new Message("DIRECTORY_COULD_NOT_BE_CREATED", LOG, clsdir);
throw new ToolException(msg);
}
}
}
String wsdl = (String) env.get(ToolConstants.CFG_WSDLURL);
if (StringUtils.isEmpty(wsdl)) {
Message msg = new Message("NO_WSDL_URL", LOG);
throw new ToolException(msg);
}
env.put(ToolConstants.CFG_WSDLURL, URIParserUtil.normalize(wsdl));
String[] bindingFiles;
try {
bindingFiles = (String[]) env.get(ToolConstants.CFG_BINDING);
if (bindingFiles == null) {
return;
}
} catch (ClassCastException e) {
bindingFiles = new String[1];
bindingFiles[0] = (String) env.get(ToolConstants.CFG_BINDING);
}
for (int i = 0; i < bindingFiles.length; i++) {
bindingFiles[i] = URIParserUtil.getAbsoluteURI(bindingFiles[i]);
}
env.put(ToolConstants.CFG_BINDING, bindingFiles);
}
Aggregations