use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class XSDToWSDLProcessor method initXSD.
private void initXSD() throws ToolException {
InputStream in;
try {
in = new URL(xsdUrl).openStream();
} catch (Exception m) {
try {
in = Files.newInputStream(Paths.get(xsdUrl));
} catch (IOException ioe) {
Message msg = new Message("FAIL_TO_OPEN_XSD_FILE", LOG, xsdUrl);
throw new ToolException(msg, ioe);
}
}
if (in == null) {
throw new NullPointerException("Cannot create a ToolSpec object from a null stream");
}
try {
xsdBuilder.setValidating(false);
this.xsdDoc = xsdBuilder.parse(in);
} catch (Exception ex) {
Message msg = new Message("FAIL_TO_PARSE_TOOLSPEC", LOG);
throw new ToolException(msg, ex);
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class XSDToWSDLProcessor method addWSDLTypes.
private void addWSDLTypes() throws ToolException {
Element sourceElement = this.xsdDoc.getDocumentElement();
Element targetElement = (Element) sourceElement.cloneNode(true);
this.wsdlDefinition.setTargetNamespace((String) env.get(ToolConstants.CFG_NAMESPACE));
this.wsdlDefinition.setQName(new QName(WSDLConstants.NS_WSDL11, (String) env.get(ToolConstants.CFG_NAME)));
Types types = this.wsdlDefinition.createTypes();
ExtensibilityElement extElement;
try {
registry = wsdlFactory.newPopulatedExtensionRegistry();
registerJAXWSBinding(Definition.class);
registerJAXWSBinding(Types.class);
registerJAXWSBinding(Schema.class);
extElement = registry.createExtension(Types.class, WSDLConstants.QNAME_SCHEMA);
} catch (WSDLException wse) {
Message msg = new Message("FAIL_TO_CREATE_SCHEMA_EXTENSION", LOG);
throw new ToolException(msg, wse);
}
((Schema) extElement).setElement(targetElement);
types.addExtensibilityElement(extElement);
this.wsdlDefinition.setTypes(types);
WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
Writer outputWriter = getOutputWriter();
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 WSDLToServiceProcessorTest method testDefaultLocation.
@Test
public void testDefaultLocation() throws Exception {
String[] args = new String[] { "-transport", "soap", "-e", "serviceins", "-p", "portins", "-n", "Greeter_SOAPBinding", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
WSDLToService.main(args);
File outputFile = new File(output, "hello_world-service.wsdl");
assertTrue("New wsdl file is not generated", outputFile.exists());
WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
processor.setEnvironment(env);
try {
processor.parseWSDL(outputFile.getAbsolutePath());
Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "serviceins"));
if (service == null) {
fail("Element wsdl:service serviceins Missed!");
}
Iterator<?> it = service.getPort("portins").getExtensibilityElements().iterator();
if (it == null || !it.hasNext()) {
fail("Element wsdl:port portins Missed!");
}
boolean found = false;
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof SOAPAddress) {
SOAPAddress soapAddress = (SOAPAddress) obj;
if (soapAddress.getLocationURI() != null && soapAddress.getLocationURI().equals("http://localhost:9000/serviceins/portins")) {
found = true;
break;
}
}
}
if (!found) {
fail("Element soap:address of service port Missed!");
}
} catch (ToolException e) {
fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToServiceProcessorTest method testNewServiceSoap12.
@Test
public void testNewServiceSoap12() throws Exception {
String[] args = new String[] { "-soap12", "-transport", "soap", "-e", "SOAPService", "-p", "SoapPort", "-n", "Greeter_SOAPBinding", "-a", "http://localhost:9000/SOAPService/SoapPort", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world_soap12.wsdl") };
WSDLToService.main(args);
File outputFile = new File(output, "hello_world_soap12-service.wsdl");
assertTrue("New wsdl file is not generated", outputFile.exists());
WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
processor.setEnvironment(env);
try {
processor.parseWSDL(outputFile.getAbsolutePath());
Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "SOAPService"));
if (service == null) {
fail("Element wsdl:service serviceins Missed!");
}
Iterator<?> it = service.getPort("SoapPort").getExtensibilityElements().iterator();
if (it == null || !it.hasNext()) {
fail("Element wsdl:port portins Missed!");
}
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof SOAP12Address) {
SOAP12Address soapAddress = (SOAP12Address) obj;
assertNotNull(soapAddress.getLocationURI());
assertEquals("http://localhost:9000/SOAPService/SoapPort", soapAddress.getLocationURI());
break;
}
}
} catch (ToolException e) {
fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
}
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToServiceProcessorTest method testNewService.
@Test
public void testNewService() throws Exception {
String[] args = new String[] { "-transport", "soap", "-e", "serviceins", "-p", "portins", "-n", "Greeter_SOAPBinding", "-a", "http://localhost:9000/newservice/newport", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world.wsdl") };
WSDLToService.main(args);
File outputFile = new File(output, "hello_world-service.wsdl");
assertTrue("New wsdl file is not generated", outputFile.exists());
WSDLToServiceProcessor processor = new WSDLToServiceProcessor();
processor.setEnvironment(env);
try {
processor.parseWSDL(outputFile.getAbsolutePath());
Service service = processor.getWSDLDefinition().getService(new QName(processor.getWSDLDefinition().getTargetNamespace(), "serviceins"));
if (service == null) {
fail("Element wsdl:service serviceins Missed!");
}
Iterator<?> it = service.getPort("portins").getExtensibilityElements().iterator();
if (it == null || !it.hasNext()) {
fail("Element wsdl:port portins Missed!");
}
boolean found = false;
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof SOAPAddress) {
SOAPAddress soapAddress = (SOAPAddress) obj;
if (soapAddress.getLocationURI() != null && soapAddress.getLocationURI().equals("http://localhost:9000/newservice/newport")) {
found = true;
break;
}
}
}
if (!found) {
fail("Element soap:address of service port Missed!");
}
} catch (ToolException e) {
fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
}
}
Aggregations