1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
import java.io.*;
import javax.wsdl.*;
import javax.wsdl.factory.WSDLFactory;
import javax.xml.namespace.QName;
import javax.wsdl.extensions.*;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.ExtensionDeserializer;
class VSOAPBinding implements SOAPBinding {
QName qname=null;
Boolean bol=null;
String st="", stt="";
public void setElementType(QName elName){
elName=qname;
}
public void setRequired(Boolean b){
b=bol;
}
public void setTransportURI(String s){
s=st;
}
public void setStyle(String s){
s=stt;
}
public QName getElementType(){
VSOAPBinding soapBinding=null;
soapBinding.setElementType(new QName("http://localhost:8080/testwsdl.java","binding"));
QName elName=soapBinding.getElementType();
return elName;
}
public Boolean getRequired(){
Boolean b=null;
VSOAPBinding soapBinding=null;
soapBinding.setRequired(b.TRUE);
return soapBinding.getRequired();
}
public String getTransportURI(){
VSOAPBinding soapBinding=null;
soapBinding.setTransportURI("http://schemas.xmlsoap.org/wsdl/http/");
return soapBinding.getTransportURI();
}
public String getStyle(){
VSOAPBinding soapBinding=null;
soapBinding.setStyle("rpc");
return soapBinding.getStyle();
}
static final long serialVersionUID=0;
}
class BindDeserializer implements ExtensionDeserializer {
public BindDeserializer(){}
public SOAPBinding unmarshall(Class cla, QName elName, org.w3c.dom.Element element,Definition def, ExtensionRegistry extReg){
SOAPBinding exEl=null;
String tns = "http://localhost:8080/testwsdl.java";
exEl.setElementType(new QName(tns,"binding"));
exEl.setStyle("rpc");
exEl.setTransportURI("http://schemas.xmlsoap.org/wsdl/http/");
return exEl;
}
}
class BindSerializer implements ExtensionSerializer{
public BindSerializer(){}
public void marshall(Class cla, QName elName, ExtensibilityElement element, PrintWriter pw, Definition def, ExtensionRegistry extReg){
}
}
public class Testwsdl {
public Testwsdl(){}
public static void main(String[] args) {
String xsd = "http://www.w3.org/2001/XMLSchema";
String http = "http://schemas.xmlsoap.org/wsdl/http/";
String tns = "http://localhost:8080/testwsdl.java";
String xenc = "http://schemas.xmlsoap.org/soap/encoding/";
String soap="http://scheams.xmlsoap.org/wsdl/soap/";
String wsdl="http://schemas.xmlsoap.org/wsdl/";
String n="";
n="mamadou";
n=n.substring(0,1).toUpperCase()+n.substring(1,n.length());
// String nomfich="wsdldoc.wsdl";
String serviceName = "order_service";
String opName = "create_order";
try {
// "com.ibm.wsdl.factory.WSDLFactoryImpl"
WSDLFactory f = null;
f=WSDLFactory.newInstance();
javax.wsdl.xml.WSDLWriter wwi = f.newWSDLWriter();
PrintWriter pw=null;
Definition d = null;
d = f.newDefinition();
d.setQName(new QName(tns,serviceName));
d.setTargetNamespace(tns);
d.addNamespace("http",http);
d.addNamespace("soap", soap);
d.addNamespace("xenc", xenc);
d.addNamespace("xsd", xsd);
d.addNamespace("tns",tns);
d.addNamespace("wsdl",wsdl);
Input input = d.createInput();
Message inputMessage = d.createMessage();
inputMessage.setQName(new QName(tns,"Mess1"));
Message outputMessage = d.createMessage();
outputMessage.setQName(new QName(tns,"Mess2"));
Part inputPart = d.createPart();
inputPart.setName("string");
inputPart.setTypeName(new QName("http://www.w3.org/2001/XMLSchema", "string"));
inputMessage.addPart(inputPart);
inputMessage.setUndefined(false);
d.addMessage(inputMessage);
input.setMessage(inputMessage);
Output output = d.createOutput();
outputMessage.setUndefined(false);
d.addMessage(outputMessage);
output.setMessage(outputMessage);
Operation operation = d.createOperation();
operation.setName(opName);
operation.setInput(input);
operation.setOutput(output);
operation.setUndefined(false);
PortType portType = d.createPortType();
portType.setQName(new QName(tns,serviceName + "PortType"));
portType.addOperation(operation);
portType.setUndefined(false);
d.addPortType(portType);
BindingInput bindingInput = d.createBindingInput();
BindingOutput bindingOutput = d.createBindingOutput();
BindingOperation bindOp = d.createBindingOperation();
bindOp.setBindingInput(bindingInput);
bindOp.setBindingOutput(bindingOutput);
bindOp.setName(opName);
bindOp.setOperation(operation);
Binding bind = d.createBinding();
bind.setQName(new QName(tns,serviceName + "Binding"));
bind.setPortType(portType);
ExtensionRegistry extReg= new ExtensionRegistry();
extReg=WSDLFactory.newInstance().newPopulatedExtensionRegistry();
extReg.registerDeserializer(Binding.class, new QName(tns,"binding"), new BindDeserializer());
extReg.registerSerializer(Binding.class, new QName(tns,"binding"), new BindSerializer());
extReg.mapExtensionTypes(Binding.class, new QName(tns,"binding"), VSOAPBinding.class);
SOAPBinding soapBinding=null;
soapBinding=new VSOAPBinding();
soapBinding =(VSOAPBinding)extReg.createExtension(Binding.class, new QName("http://schemas.xmlsoap.org/wsdl/soap/","binding"));
bind.addExtensibilityElement(soapBinding);
bind.addBindingOperation(bindOp);
bind.setUndefined(false);
d.addBinding(bind);
Port port = d.createPort();
port.setName(serviceName + "Port");
port.setBinding(bind);
Service srv = d.createService();
srv.setQName(new QName(tns,serviceName));
srv.addPort(port);
d.addService(srv);
System.out.println(tns);
System.out.println(n);
wwi.writeWSDL(d, System.out);
pw = new PrintWriter(new FileWriter("wsdldoc.txt"));
wwi.writeWSDL(d, pw); // impression dans le fichier .wsdl
} catch (IOException ex) {
} catch (WSDLException ex) {System.out.println("ERREUR WSDLException");
ex.printStackTrace();}
catch (Exception ex){}
}
} |
Partager