use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class AbstractWSDLToProcessor method getOutputWriter.
protected Writer getOutputWriter(String newNameExt) throws ToolException {
Writer writer = null;
String newName = null;
String outputDir;
if (env.get(ToolConstants.CFG_OUTPUTFILE) != null) {
newName = (String) env.get(ToolConstants.CFG_OUTPUTFILE);
} else {
String oldName = (String) env.get(ToolConstants.CFG_WSDLURL);
int position = oldName.lastIndexOf("/");
if (position < 0) {
position = oldName.lastIndexOf("\\");
}
if (position >= 0) {
oldName = oldName.substring(position + 1, oldName.length());
}
if (oldName.toLowerCase().indexOf(WSDL_FILE_NAME_EXT) >= 0) {
newName = oldName.substring(0, oldName.length() - 5) + newNameExt + WSDL_FILE_NAME_EXT;
} else {
newName = oldName + newNameExt;
}
}
if (env.get(ToolConstants.CFG_OUTPUTDIR) != null) {
outputDir = (String) env.get(ToolConstants.CFG_OUTPUTDIR);
if (!("/".equals(outputDir.substring(outputDir.length() - 1)) || "\\".equals(outputDir.substring(outputDir.length() - 1)))) {
outputDir = outputDir + "/";
}
} else {
outputDir = "./";
}
FileWriterUtil fw = new FileWriterUtil(outputDir, env.get(OutputStreamCreator.class));
try {
writer = fw.getWriter("", newName);
} catch (IOException ioe) {
Message msg = new Message("FAIL_TO_WRITE_FILE", LOG, env.get(ToolConstants.CFG_OUTPUTDIR) + System.getProperty("file.seperator") + newName);
throw new ToolException(msg, ioe);
}
return writer;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToServiceProcessor method doAppendService.
private void doAppendService() throws ToolException {
if (service == null) {
service = wsdlDefinition.createService();
service.setQName(new QName(WSDLConstants.WSDL_PREFIX, (String) env.get(ToolConstants.CFG_SERVICE)));
}
if (port == null) {
port = wsdlDefinition.createPort();
port.setName((String) env.get(ToolConstants.CFG_PORT));
port.setBinding(binding);
}
setAddrElement();
service.addPort(port);
wsdlDefinition.addService(service);
WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
Writer outputWriter = getOutputWriter(NEW_FILE_NAME_MODIFIER);
try {
wsdlWriter.writeWSDL(wsdlDefinition, outputWriter);
} catch (WSDLException wse) {
Message msg = new Message("FAIL_TO_WRITE_WSDL", LOG);
throw new ToolException(msg, wse);
}
try {
outputWriter.close();
} catch (IOException ioe) {
Message msg = new Message("FAIL_TO_CLOSE_WSDL_FILE", LOG);
throw new ToolException(msg, ioe);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToServiceProcessor method setAddrElement.
private void setAddrElement() throws ToolException {
String transport = (String) env.get(ToolConstants.CFG_TRANSPORT);
Address address = AddressFactory.getInstance().getAddresser(transport);
Map<String, String> ns = address.getNamespaces(env);
for (Map.Entry<String, String> entry : ns.entrySet()) {
wsdlDefinition.addNamespace(entry.getKey(), entry.getValue());
}
WSDLExtensibilityPlugin plugin = getWSDLPlugin(transport, Port.class);
try {
ExtensibilityElement extElement = plugin.createExtension(address.buildAddressArguments(env));
port.addExtensibilityElement(extElement);
} catch (WSDLException wse) {
Message msg = new Message("FAIL_TO_CREATE_SOAP_ADDRESS", LOG);
throw new ToolException(msg, wse);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToServiceProcessor method process.
public void process() throws ToolException {
init();
if (isServicePortExisted()) {
Message msg = new Message("SERVICE_PORT_EXIST", LOG);
throw new ToolException(msg);
}
if (!isBindingExisted()) {
Message msg = new Message("BINDING_NOT_EXIST", LOG);
throw new ToolException(msg);
}
doAppendService();
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToSoapProcessor method doAppendBinding.
private void doAppendBinding() throws ToolException {
if (binding == null) {
binding = wsdlDefinition.createBinding();
binding.setQName(new QName(wsdlDefinition.getTargetNamespace(), (String) env.get(ToolConstants.CFG_BINDING)));
binding.setUndefined(false);
binding.setPortType(portType);
}
setSoapBindingExtElement();
addBindingOperation();
wsdlDefinition.addBinding(binding);
WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
Writer outputWriter = getOutputWriter(NEW_FILE_NAME_MODIFIER);
try {
wsdlWriter.writeWSDL(wsdlDefinition, outputWriter);
} catch (WSDLException wse) {
Message msg = new Message("FAIL_TO_WRITE_WSDL", LOG, wse.getMessage());
throw new ToolException(msg);
}
try {
outputWriter.close();
} catch (IOException ioe) {
Message msg = new Message("PORTTYPE_NOT_EXIST", LOG);
throw new ToolException(msg);
}
}
Aggregations