use of javax.wsdl.BindingOperation in project cxf by apache.
the class WSDLToXMLProcessor method addBindingOperation.
@SuppressWarnings("unchecked")
private void addBindingOperation() throws ToolException {
List<Operation> ops = portType.getOperations();
for (Operation op : ops) {
BindingOperation bindingOperation = wsdlDefinition.createBindingOperation();
bindingOperation.setName(op.getName());
if (op.getInput() != null) {
bindingOperation.setBindingInput(getBindingInput(op.getInput(), op.getName()));
}
if (op.getOutput() != null) {
bindingOperation.setBindingOutput(getBindingOutput(op.getOutput(), op.getName()));
}
if (op.getFaults() != null && op.getFaults().size() > 0) {
addXMLFaults(op, bindingOperation);
}
bindingOperation.setOperation(op);
binding.addBindingOperation(bindingOperation);
}
}
use of javax.wsdl.BindingOperation in project cxf by apache.
the class WSDLToSoapProcessorTest method testDocLitWithFault.
@Test
public void testDocLitWithFault() throws Exception {
String[] args = new String[] { "-i", "Greeter", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world_doc_lit.wsdl") };
WSDLToSoap.main(args);
File outputFile = new File(output, "hello_world_doc_lit-soapbinding.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_Binding"));
if (binding == null) {
fail("Element wsdl:binding Greeter_Binding Missed!");
}
boolean found = false;
for (Object obj : binding.getExtensibilityElements()) {
SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
if (soapBinding != null && soapBinding.getStyle().equalsIgnoreCase("document")) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:binding Missed!");
}
BindingOperation bo = binding.getBindingOperation("pingMe", null, null);
if (bo == null) {
fail("Element <wsdl:operation name=\"pingMe\"> Missed!");
}
found = false;
for (Object obj : bo.getExtensibilityElements()) {
SoapOperation soapOperation = SOAPBindingUtil.getSoapOperation(obj);
if (soapOperation != null && soapOperation.getStyle().equalsIgnoreCase("document")) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:operation Missed!");
}
BindingFault fault = bo.getBindingFault("pingMeFault");
if (fault == null) {
fail("Element <wsdl:fault name=\"pingMeFault\"> Missed!");
}
found = false;
for (Object obj : fault.getExtensibilityElements()) {
if (SOAPBindingUtil.isSOAPFault(obj)) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:fault Missed!");
}
List<SoapFault> faults = SOAPBindingUtil.getBindingOperationSoapFaults(bo);
assertEquals(1, faults.size());
assertEquals("pingMeFault", faults.get(0).getName());
} catch (ToolException e) {
fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
}
}
use of javax.wsdl.BindingOperation in project cxf by apache.
the class WSDLToSoapProcessorTest method testWithoutBinding.
@Test
public void testWithoutBinding() throws Exception {
String[] args = new String[] { "-i", "Greeter", "-b", "Greeter_SOAPBinding", "-d", output.getCanonicalPath(), "-o", "hello_world_soap_newbinding.wsdl", getLocation("/misctools_wsdl/hello_world_nobinding.wsdl") };
WSDLToSoap.main(args);
File outputFile = new File(output, "hello_world_soap_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_SOAPBinding"));
if (binding == null) {
fail("Element wsdl:binding Greeter_SOAPBinding_NewBinding Missed!");
}
for (Object obj : binding.getExtensibilityElements()) {
assertTrue(SOAPBindingUtil.isSOAPBinding(obj));
assertTrue(obj instanceof SOAPBinding);
SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
assertNotNull(soapBinding);
assertTrue("document".equalsIgnoreCase(soapBinding.getStyle()));
assertTrue(WSDLConstants.NS_SOAP11_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 SOAPOperation);
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 SOAPBody);
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 javax.wsdl.BindingOperation in project cxf by apache.
the class WSDLToSoapProcessorTest method testRpcLitWithoutFault.
@Test
public void testRpcLitWithoutFault() throws Exception {
String[] args = new String[] { "-i", "GreeterRPCLit", "-n", "http://apache.org/hello_world_rpclit_test", "-b", "Greeter_SOAPBinding_NewBinding", "-style", "rpc", "-use", "literal", "-d", output.getCanonicalPath(), "-o", "hello_world_rpc_lit_newbinding.wsdl", getLocation("/misctools_wsdl/hello_world_rpc_lit.wsdl") };
WSDLToSoap.main(args);
File outputFile = new File(output, "hello_world_rpc_lit_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_SOAPBinding_NewBinding"));
if (binding == null) {
fail("Element wsdl:binding Greeter_SOAPBinding_NewBinding Missed!");
}
boolean found = false;
for (Object obj : binding.getExtensibilityElements()) {
SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
if (soapBinding != null && soapBinding.getStyle().equalsIgnoreCase("rpc")) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:binding style=rpc Missed!");
}
BindingOperation bo = binding.getBindingOperation("sendReceiveData", null, null);
if (bo == null) {
fail("Element <wsdl:operation name=\"sendReceiveData\"> Missed!");
}
found = false;
for (Object obj : bo.getExtensibilityElements()) {
SoapOperation soapOperation = SOAPBindingUtil.getSoapOperation(obj);
if (soapOperation != null && soapOperation.getStyle().equalsIgnoreCase("rpc")) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:operation style=rpc Missed!");
}
BindingInput bi = bo.getBindingInput();
found = false;
for (Object obj : bi.getExtensibilityElements()) {
SoapBody soapBody = SOAPBindingUtil.getSoapBody(obj);
if (soapBody != null && soapBody.getUse().equalsIgnoreCase("literal")) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:body use=literal Missed!");
}
} catch (ToolException e) {
fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
}
}
use of javax.wsdl.BindingOperation in project cxf by apache.
the class UniqueBodyPartsValidator method isValid.
public boolean isValid() {
Collection<Binding> bindings = CastUtils.cast(def.getAllBindings().values());
for (Binding binding : bindings) {
uniqueBodyPartsMap = new HashMap<>();
List<BindingOperation> ops = CastUtils.cast(binding.getBindingOperations());
for (BindingOperation op : ops) {
Operation operation = op.getOperation();
if (operation != null && operation.getInput() != null) {
Message inMessage = operation.getInput().getMessage();
BindingInput bin = op.getBindingInput();
Set<String> headers = new HashSet<>();
if (bin != null) {
List<ExtensibilityElement> lst = CastUtils.cast(bin.getExtensibilityElements());
for (ExtensibilityElement ext : lst) {
if (!(ext instanceof SOAPHeader)) {
continue;
}
SOAPHeader header = (SOAPHeader) ext;
if (!header.getMessage().equals(inMessage.getQName())) {
continue;
}
headers.add(header.getPart());
}
}
if (inMessage != null && !isUniqueBodyPart(operation.getName(), inMessage, headers, binding.getQName())) {
return false;
}
}
}
}
return true;
}
Aggregations