use of javax.wsdl.Binding 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.Binding 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.Binding in project cxf by apache.
the class WSDLServiceFactory method create.
public Service create() {
List<ServiceInfo> services;
if (serviceName == null) {
try {
WSDLServiceBuilder builder = new WSDLServiceBuilder(getBus());
builder.setAllowElementRefs(allowRefs);
services = builder.buildServices(definition);
} catch (XmlSchemaException ex) {
throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
}
if (services.isEmpty()) {
throw new ServiceConstructionException(new Message("NO_SERVICE_EXC", LOG));
}
// @@TODO - this isn't good, need to return all the services
serviceName = services.get(0).getName();
// get all the service info's that match that first one.
Iterator<ServiceInfo> it = services.iterator();
while (it.hasNext()) {
if (!it.next().getName().equals(serviceName)) {
it.remove();
}
}
} else {
javax.wsdl.Service wsdlService = definition.getService(serviceName);
if (wsdlService == null) {
if ((!PartialWSDLProcessor.isServiceExisted(definition, serviceName)) && (!PartialWSDLProcessor.isBindingExisted(definition, serviceName)) && (PartialWSDLProcessor.isPortTypeExisted(definition, serviceName))) {
try {
Map<QName, PortType> portTypes = CastUtils.cast(definition.getAllPortTypes());
String existPortName = null;
PortType portType = null;
for (Map.Entry<QName, PortType> entry : portTypes.entrySet()) {
existPortName = entry.getKey().getLocalPart();
if (serviceName.getLocalPart().contains(existPortName)) {
portType = entry.getValue();
break;
}
}
WSDLFactory factory = WSDLFactory.newInstance();
ExtensionRegistry extReg = factory.newPopulatedExtensionRegistry();
Binding binding = PartialWSDLProcessor.doAppendBinding(definition, existPortName, portType, extReg);
definition.addBinding(binding);
wsdlService = PartialWSDLProcessor.doAppendService(definition, existPortName, extReg, binding);
definition.addService(wsdlService);
} catch (Exception e) {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
} else {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
}
try {
services = new WSDLServiceBuilder(getBus()).buildServices(definition, wsdlService, endpointName);
if (services.isEmpty()) {
throw new ServiceConstructionException(new Message("NO_SUCH_ENDPOINT_EXC", LOG, endpointName));
}
} catch (XmlSchemaException ex) {
throw new ServiceConstructionException(new Message("SERVICE_CREATION_MSG", LOG), ex);
}
}
ServiceImpl service = new ServiceImpl(services);
setService(service);
return service;
}
use of javax.wsdl.Binding in project cxf by apache.
the class ServiceWSDLBuilderTest method testBinding.
@Test
public void testBinding() throws Exception {
setupWSDL(WSDL_PATH);
assertEquals(newDef.getBindings().size(), 1);
Binding binding = newDef.getBinding(new QName(newDef.getTargetNamespace(), "Greeter_SOAPBinding"));
assertNotNull(binding);
assertEquals(4, binding.getBindingOperations().size());
}
use of javax.wsdl.Binding in project cxf by apache.
the class ServiceWSDLBuilder method buildBinding.
protected void buildBinding(Definition definition, Collection<BindingInfo> bindingInfos, Collection<PortType> portTypes) {
for (BindingInfo bindingInfo : bindingInfos) {
final Binding binding = definition.createBinding();
addDocumentation(binding, bindingInfo.getDocumentation());
binding.setUndefined(false);
for (PortType portType : portTypes) {
if (portType.getQName().equals(bindingInfo.getInterface().getName())) {
binding.setPortType(portType);
break;
}
}
binding.setQName(bindingInfo.getName());
if (!bindingInfo.getName().getNamespaceURI().equals(definition.getTargetNamespace())) {
addNamespace(bindingInfo.getName().getNamespaceURI(), definition);
}
buildBindingOperation(definition, binding, bindingInfo.getOperations());
addExtensibilityElements(definition, binding, getWSDL11Extensors(bindingInfo));
definition.addBinding(binding);
}
}
Aggregations