use of javax.wsdl.Binding in project cxf by apache.
the class WSDLToIDLAction method createInterface.
private IdlType createInterface(org.apache.cxf.binding.corba.wsdl.Object obj, IdlScopeBase scope, String local) throws Exception {
IdlType result = null;
QName bqname = obj.getBinding();
Binding binding = def.getBinding(bqname);
if (binding != null) {
IdlDefn defn = scope.lookup(local);
if (defn instanceof IdlInterface) {
return (IdlInterface) defn;
} else if (defn == null) {
try {
IdlInterface storedIntf = intf;
intf = IdlInterface.create(scope, local);
scope.holdForScope(intf);
collectIdlDefns(binding);
scope.promoteHeldToScope();
result = intf;
intf = storedIntf;
} catch (Exception ex) {
// NOPMD
String msgStr = "Interface type " + intf.fullName() + " not found.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new Exception(msg.toString());
}
}
}
return result;
}
use of javax.wsdl.Binding in project cxf by apache.
the class WSDLToIDLAction method generateIDL.
public void generateIDL(Definition definition) throws Exception {
if (definition == null) {
typeProcessor.parseWSDL(wsdlFileName);
def = typeProcessor.getWSDLDefinition();
} else {
def = definition;
}
if (printWriter == null) {
printWriter = createPrintWriter(outputFile);
}
try (PrintWriter pw = printWriter != null ? printWriter : createPrintWriter(outputFile)) {
if (!isGenerateAllBindings()) {
Binding binding = findBinding(def);
if (binding == null) {
String msgStr = "Binding " + bindingName + " doesn't exists in WSDL.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new ToolException(msg.toString());
}
generateIDL(def, binding);
} else {
// generate idl for all bindings in the file.
// each idl file will have the name of the binding.
Collection<Binding> bindings = CastUtils.cast(def.getAllBindings().values());
if (bindings.isEmpty()) {
String msgStr = "No bindings exists within this WSDL.";
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message(msgStr, LOG);
throw new ToolException(msg.toString());
}
List<QName> portTypes = new ArrayList<>();
for (Binding binding : bindings) {
List<?> ext = binding.getExtensibilityElements();
if (!(ext.get(0) instanceof BindingType)) {
continue;
}
if (portTypes.contains(binding.getPortType().getQName())) {
continue;
}
portTypes.add(binding.getPortType().getQName());
generateIDL(def, binding);
root = IdlRoot.create();
}
}
}
}
use of javax.wsdl.Binding in project cxf by apache.
the class WSDLToCorbaBinding method generateCORBABinding.
public Binding[] generateCORBABinding(Definition definition) throws Exception {
def = definition;
helper.setWsdlDefinition(def);
typeProcessor.setWSDLDefinition(def);
wsdlParameter = new WSDLParameter();
if (idlNamespace == null) {
setIdlNamespace(def);
}
generateNSPrefix(def, getIdlNamespace(), "ns");
typeProcessor.process();
xmlSchemaList = typeProcessor.getXmlSchemaTypes();
helper.setXMLSchemaList(xmlSchemaList);
final List<PortType> intfs;
if (!interfaceNames.isEmpty()) {
intfs = new ArrayList<>(interfaceNames.size());
for (String interfaceName : interfaceNames) {
PortType portType = null;
Map<QName, PortType> portTypes = CastUtils.cast(def.getAllPortTypes());
if (portTypes != null) {
for (Entry<QName, PortType> entry : portTypes.entrySet()) {
if (!entry.getKey().getLocalPart().equals(interfaceName)) {
portType = null;
} else {
portType = entry.getValue();
break;
}
}
}
if (portType == null) {
String msgStr = "PortType " + interfaceName + " doesn't exist in WSDL.";
throw new ToolException(msgStr);
}
intfs.add(portType);
}
} else {
// gets default portType or all portTypes.
intfs = getPortTypeList();
}
Binding[] bindings = new Binding[intfs.size()];
for (int i = 0; i < intfs.size(); i++) {
bindings[i] = generateCORBABinding(def, intfs.get(i));
generateCORBAServiceForBinding(def, intfs.get(i), bindings[i]);
}
return bindings;
}
use of javax.wsdl.Binding in project cxf by apache.
the class WSDLToCorbaBindingTest method testCORBABindingGeneration.
@Test
public void testCORBABindingGeneration() throws Exception {
String fileName = getClass().getResource("/wsdl/simpleList.wsdl").toString();
generator.setWsdlFile(fileName);
generator.addInterfaceName("BasePortType");
Definition model = generator.generateCORBABinding();
QName bName = new QName("http://schemas.apache.org/tests", "BaseCORBABinding", "tns");
Binding binding = model.getBinding(bName);
assertNotNull(binding);
assertEquals("BaseCORBABinding", binding.getQName().getLocalPart());
assertEquals("BasePortType", binding.getPortType().getQName().getLocalPart());
assertEquals(1, binding.getExtensibilityElements().size());
assertEquals(1, binding.getBindingOperations().size());
for (ExtensibilityElement extElement : getExtensibilityElements(binding)) {
if ("binding".equals(extElement.getElementType().getLocalPart())) {
BindingType bindingType = (BindingType) extElement;
assertEquals(bindingType.getRepositoryID(), "IDL:BasePortType:1.0");
}
}
Iterator<?> j = binding.getBindingOperations().iterator();
while (j.hasNext()) {
BindingOperation bindingOperation = (BindingOperation) j.next();
assertEquals(1, bindingOperation.getExtensibilityElements().size());
assertEquals(bindingOperation.getBindingInput().getName(), "echoString");
assertEquals(bindingOperation.getBindingOutput().getName(), "echoStringResponse");
for (ExtensibilityElement extElement : getExtensibilityElements(bindingOperation)) {
if ("operation".equals(extElement.getElementType().getLocalPart())) {
OperationType corbaOpType = (OperationType) extElement;
assertEquals(corbaOpType.getName(), "echoString");
assertEquals(3, corbaOpType.getParam().size());
assertEquals(corbaOpType.getReturn().getName(), "return");
assertEquals(corbaOpType.getReturn().getIdltype(), CorbaConstants.NT_CORBA_STRING);
assertEquals(corbaOpType.getParam().get(0).getName(), "x");
assertEquals(corbaOpType.getParam().get(0).getMode().value(), "in");
QName qname = new QName("http://schemas.apache.org/tests/corba/typemap/", "StringEnum1", "ns1");
assertEquals(corbaOpType.getParam().get(0).getIdltype(), qname);
}
}
}
}
use of javax.wsdl.Binding in project cxf by apache.
the class WSDLToCorbaBindingTest method testExceptionCORBABindingGeneration.
// next story to add Fault support
@Test
public void testExceptionCORBABindingGeneration() throws Exception {
String fileName = getClass().getResource("/wsdl/exceptions.wsdl").toString();
generator.setWsdlFile(fileName);
generator.addInterfaceName("TestException.ExceptionTest");
Definition model = generator.generateCORBABinding();
QName bName = new QName("http://schemas.apache.org/idl/exceptions.idl", "TestException.ExceptionTestCORBABinding", "tns");
Binding binding = model.getBinding(bName);
assertNotNull(binding);
assertEquals("TestException.ExceptionTestCORBABinding", binding.getQName().getLocalPart());
assertEquals("TestException.ExceptionTest", binding.getPortType().getQName().getLocalPart());
assertEquals(1, binding.getExtensibilityElements().size());
assertEquals(1, binding.getBindingOperations().size());
for (ExtensibilityElement extElement : getExtensibilityElements(binding)) {
if ("binding".equals(extElement.getElementType().getLocalPart())) {
BindingType bindingType = (BindingType) extElement;
assertEquals(bindingType.getRepositoryID(), "IDL:TestException/ExceptionTest:1.0");
}
}
Iterator<?> j = binding.getBindingOperations().iterator();
while (j.hasNext()) {
BindingOperation bindingOperation = (BindingOperation) j.next();
assertEquals(1, bindingOperation.getExtensibilityElements().size());
assertEquals(bindingOperation.getBindingInput().getName(), "review_data");
assertEquals(bindingOperation.getBindingOutput().getName(), "review_dataResponse");
Iterator<?> f = bindingOperation.getBindingFaults().values().iterator();
boolean hasBadRecord = false;
boolean hasMyException = false;
while (f.hasNext()) {
BindingFault bindingFault = (BindingFault) f.next();
if ("TestException.BadRecord".equals(bindingFault.getName())) {
hasBadRecord = true;
} else if ("MyException".equals(bindingFault.getName())) {
hasMyException = true;
} else {
fail("Unexpected BindingFault: " + bindingFault.getName());
}
}
assertTrue("Did not get expected TestException.BadRecord", hasBadRecord);
assertTrue("Did not get expected MyException", hasMyException);
for (ExtensibilityElement extElement : getExtensibilityElements(bindingOperation)) {
if ("operation".equals(extElement.getElementType().getLocalPart())) {
OperationType corbaOpType = (OperationType) extElement;
assertEquals(corbaOpType.getName(), "review_data");
assertEquals(1, corbaOpType.getParam().size());
assertEquals(2, corbaOpType.getRaises().size());
hasBadRecord = false;
hasMyException = false;
for (int k = 0; k < corbaOpType.getRaises().size(); k++) {
String localPart = corbaOpType.getRaises().get(k).getException().getLocalPart();
if ("TestException.BadRecord".equals(localPart)) {
hasBadRecord = true;
} else if ("MyExceptionType".equals(localPart)) {
hasMyException = true;
} else {
fail("Unexpected Raises: " + localPart);
}
}
assertTrue("Did not find expected TestException.BadRecord", hasBadRecord);
assertTrue("Did not find expected MyException", hasMyException);
}
}
}
}
Aggregations