use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class WSDLToSoapProcessorTest method testNewSoap12Binding.
@Test
public void testNewSoap12Binding() throws Exception {
String[] args = new String[] { "-i", "Greeter", "-soap12", "-b", "Greeter_SOAP12Binding", "-d", output.getCanonicalPath(), "-o", "hello_world_soap12_newbinding.wsdl", getLocation("/misctools_wsdl/hello_world_soap12_nobinding.wsdl") };
WSDLToSoap.main(args);
File outputFile = new File(output, "hello_world_soap12_newbinding.wsdl");
assertTrue("New wsdl file is not generated", outputFile.exists());
assertTrue("Generated file is empty!", outputFile.length() > 0);
WSDLToSoapProcessor processor = new WSDLToSoapProcessor();
processor.setEnvironment(env);
try {
processor.parseWSDL(outputFile.getAbsolutePath());
Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_SOAP12Binding"));
if (binding == null) {
fail("Element wsdl:binding Greeter_SOAPBinding_NewBinding Missed!");
}
for (Object obj : binding.getExtensibilityElements()) {
assertTrue(SOAPBindingUtil.isSOAPBinding(obj));
assertTrue(obj instanceof SOAP12Binding);
SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
assertNotNull(soapBinding);
assertTrue("document".equalsIgnoreCase(soapBinding.getStyle()));
assertTrue(WSDLConstants.NS_SOAP_HTTP_TRANSPORT.equalsIgnoreCase(soapBinding.getTransportURI()));
}
BindingOperation bo = binding.getBindingOperation("sayHi", null, null);
if (bo == null) {
fail("Element <wsdl:operation name=\"sayHi\"> Missed!");
}
for (Object obj : bo.getExtensibilityElements()) {
assertTrue(SOAPBindingUtil.isSOAPOperation(obj));
assertTrue(obj instanceof SOAP12Operation);
SoapOperation soapOperation = SOAPBindingUtil.getSoapOperation(obj);
assertNotNull(soapOperation);
assertTrue("document".equalsIgnoreCase(soapOperation.getStyle()));
}
BindingInput bi = bo.getBindingInput();
for (Object obj : bi.getExtensibilityElements()) {
assertTrue(SOAPBindingUtil.isSOAPBody(obj));
assertTrue(obj instanceof SOAP12Body);
SoapBody soapBody = SOAPBindingUtil.getSoapBody(obj);
assertNotNull(soapBody);
assertTrue("literal".equalsIgnoreCase(soapBody.getUse()));
}
} 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 WSDLToSoapProcessorTest method testAddSoap12Binding.
@Test
public void testAddSoap12Binding() throws Exception {
String[] args = new String[] { "-i", "Greeter", "-soap12", "-b", "Greeter_SOAP12Binding", "-d", output.getCanonicalPath(), "-o", "hello_world_soap12_newbinding.wsdl", getLocation("/misctools_wsdl/hello_world_soap12.wsdl") };
WSDLToSoap.main(args);
File outputFile = new File(output, "hello_world_soap12_newbinding.wsdl");
assertTrue("New wsdl file is not generated", outputFile.exists());
WSDLToSoapProcessor processor = new WSDLToSoapProcessor();
processor.setEnvironment(env);
try {
processor.parseWSDL(outputFile.getAbsolutePath());
Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_SOAP12Binding"));
if (binding == null) {
fail("Element wsdl:binding Greeter_SOAPBinding_NewBinding Missed!");
}
for (Object obj : binding.getExtensibilityElements()) {
assertTrue(SOAPBindingUtil.isSOAPBinding(obj));
assertTrue(obj instanceof SOAP12Binding);
SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
assertNotNull(soapBinding);
assertTrue("document".equalsIgnoreCase(soapBinding.getStyle()));
}
BindingOperation bo = binding.getBindingOperation("sayHi", null, null);
if (bo == null) {
fail("Element <wsdl:operation name=\"sayHi\"> Missed!");
}
for (Object obj : bo.getExtensibilityElements()) {
assertTrue(SOAPBindingUtil.isSOAPOperation(obj));
assertTrue(obj instanceof SOAP12Operation);
SoapOperation soapOperation = SOAPBindingUtil.getSoapOperation(obj);
assertNotNull(soapOperation);
assertTrue("document".equalsIgnoreCase(soapOperation.getStyle()));
}
BindingInput bi = bo.getBindingInput();
for (Object obj : bi.getExtensibilityElements()) {
assertTrue(SOAPBindingUtil.isSOAPBody(obj));
assertTrue(obj instanceof SOAP12Body);
SoapBody soapBody = SOAPBindingUtil.getSoapBody(obj);
assertNotNull(soapBody);
assertTrue("literal".equalsIgnoreCase(soapBody.getUse()));
}
bo = binding.getBindingOperation("pingMe", null, null);
assertNotNull(bo);
Iterator<?> it = bo.getExtensibilityElements().iterator();
assertTrue(it != null && it.hasNext());
assertTrue(it.next() instanceof SOAP12Operation);
it = bo.getBindingInput().getExtensibilityElements().iterator();
assertTrue(it != null && it.hasNext());
assertTrue(it.next() instanceof SOAP12Body);
it = bo.getBindingOutput().getExtensibilityElements().iterator();
assertTrue(it != null && it.hasNext());
assertTrue(it.next() instanceof SOAP12Body);
Map<?, ?> faults = bo.getBindingFaults();
assertTrue(faults != null && faults.size() == 1);
Object bf = faults.get("pingMeFault");
assertNotNull(bf);
assertTrue(bf instanceof BindingFault);
assertEquals("pingMeFault", ((BindingFault) bf).getName());
} 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 JavaToWSDLProcessor method getOutputFile.
protected File getOutputFile(File nameFromClz, String defaultOutputFile) {
String output = (String) context.get(ToolConstants.CFG_OUTPUTFILE);
String dir = (String) context.get(ToolConstants.CFG_OUTPUTDIR);
if (dir == null) {
dir = "./";
}
File result;
if (output != null) {
result = new File(output);
if (!result.isAbsolute()) {
result = new File(new File(dir), output);
}
} else {
result = new File(new File(dir), defaultOutputFile);
}
if (nameFromClz != null) {
result = nameFromClz;
}
// rename the exising wsdl file
if (result.exists() && !result.renameTo(new File(result.getParent(), result.getName()))) {
throw new ToolException(new Message("OUTFILE_EXISTS", LOG));
}
return result;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class DefaultServiceBuilderFactory method newBuilder.
@Override
public ServiceBuilder newBuilder(FrontendFactory.Style s) {
DataBinding dataBinding;
final String dbn = getDatabindingName();
if (ToolConstants.JAXB_DATABINDING.equals(dbn)) {
dataBinding = new JAXBDataBinding();
} else if (ToolConstants.AEGIS_DATABINDING.equals(dbn)) {
dataBinding = new AegisDatabinding();
} else {
throw new ToolException("Unsupported databinding: " + dbn);
}
AbstractServiceFactory builder = null;
if (Style.Jaxws.equals(s)) {
builder = new JaxwsServiceBuilder();
} else if (Style.Simple.equals(s)) {
builder = new SimpleServiceBuilder();
} else {
throw new ToolException("Unsupported frontend style: " + s);
}
builder.setDataBinding(dataBinding);
builder.setServiceClass(serviceClass);
return builder;
}
use of org.apache.cxf.tools.common.ToolException in project cxf by apache.
the class JAXWSFrontEndProcessor method checkJaxwsClass.
public void checkJaxwsClass() {
Class<?> clz = context.get(Class.class);
WebService webServiceAnno = clz.getAnnotation(WebService.class);
if (webServiceAnno == null) {
Message msg = new Message("CLASS_DOESNOT_CARRY_WEBSERVICE_ANNO", LOG, clz.getName());
LOG.log(Level.WARNING, msg.toString());
throw new ToolException(msg);
}
if (isImplRmiRemote(clz)) {
Message msg = new Message("PARA_OR_RETURN_IMPL_REMOTE", LOG, clz.getName());
LOG.log(Level.WARNING, msg.toString());
throw new ToolException(msg);
}
}
Aggregations