Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

wsdl4j and writing definition

843833Oct 6 2005 — edited Dec 9 2009
Hi All,

I am trying to create and write a wsdl with wsdl4j. So I build it from scratch and I think I am adding all that is required. But when I write is with the WSDLWriter only the serivce defintion is written and no bindings, operations etc.

How can I find out what I am doing wrong ? This is my code:

String serviceName = "order_service";
String opName = "create_order";

WSDLFactory wsdlFactory;
try {
wsdlFactory = WSDLFactory.newInstance();
Definition def = wsdlFactory.newDefinition();
ExtensionRegistry extensionRegistry = wsdlFactory.newPopulatedExtensionRegistry();

WSDLWriter writer = wsdlFactory.newWSDLWriter();

def.addNamespace("soap","http://schemas.xmlsoap.org/wsdl/soap/");
//xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

Operation operation = def.createOperation();
operation.setName(opName);
operation.setStyle(OperationType.REQUEST_RESPONSE);

Input input = def.createInput();
Message inputMessage = def.createMessage();
Part inputPart = def.createPart();
inputPart.setName("string");
inputPart.setTypeName(new QName("http://www.w3.org/2001/XMLSchema", "string"));
inputMessage.addPart(inputPart);
operation.setInput(input);
input.setMessage(inputMessage);
Output output = def.createOutput();
Message outputMessage = def.createMessage();
operation.setOutput(output);
output.setMessage(outputMessage);

BindingOperation bindOp = def.createBindingOperation();
bindOp.setName(opName);
SOAPOperation soapOperation = (SOAPOperation) extensionRegistry.createExtension(BindingOperation.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/", "operation"));
soapOperation.setStyle("document");
soapOperation.setSoapActionURI("");
bindOp.addExtensibilityElement(soapOperation);
bindOp.setOperation(operation);

BindingInput bindingInput = def.createBindingInput();

SOAPBody inputBody = (SOAPBody) extensionRegistry.createExtension(BindingInput.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/", "body"));
inputBody.setUse("literal");
bindingInput.addExtensibilityElement(inputBody);
bindOp.setBindingInput(bindingInput);
BindingOutput bindingOutput = def.createBindingOutput();
bindingOutput.addExtensibilityElement(inputBody);
bindOp.setBindingOutput(bindingOutput);









PortType portType = def.createPortType();
portType.setQName(new QName("",serviceName + "PortType"));
portType.addOperation(operation);


Binding bind = def.createBinding();
bind.setQName(new QName("",serviceName + "Binding"));
bind.setPortType(portType );
bind.setUndefined(true);

SOAPBinding soapBinding = (SOAPBinding) extensionRegistry.createExtension(Binding.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/", "binding"));
soapBinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
soapBinding.setStyle("rpc");
bind.addExtensibilityElement(soapBinding);
bind.addBindingOperation(bindOp);

Port port = def.createPort();
port.setName(serviceName + "Port");



SOAPAddress soapAddress = (SOAPAddress) extensionRegistry.createExtension(Port.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/", "address"));
soapAddress.setLocationURI("http://127.0.0.1:8080/foo");
port.addExtensibilityElement(soapAddress);
port.setBinding(bind);

def.addBinding(bind);

Service srv = def.createService();
srv.setQName(new QName("",serviceName));
srv.addPort(port);
def.addService(srv);


writer.writeWSDL(def,System.out);

} catch (WSDLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


and this is the output:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:service name="order_service">
<wsdl:port name="order_servicePort" binding="order_serviceBinding">
<soap:address location="http://127.0.0.1:8080/foo"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Any hints will be appreciated,

Kind regards,
Marco Laponder
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2010
Added on Oct 6 2005
9 comments
691 views