read wsdl with WSDL4J
Hello. I write him to solve a doubt as for the use of the WSDL4J API.
I have a small function which should pass a route of a wsdl, this function reads the address and the content travels determining the different properties of the service.
...
try{
String url = "url";
InputSource ins = new InputSource(url);
DocumentBuilderFactory dbf;
dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder buil = (DocumentBuilder)dbf.newDocumentBuilder();
Document doc = buil.parse(ins);
buil.setErrorHandler(null);
buil.setEntityResolver(null);
String uri = url;
File f = new File(url);
if(f.exists())
uri = f.toURL().toString();
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
wsdlReader.setFeature("javax.wsdl.verbose",false);
//wsdlReader.setFeature("javax.wsdl.importDocuments",true);
ExtensionRegistry extReg = new ExtensionRegistry();
Definition definition = wsdlReader.readWSDL(uri,doc);
if (definition == null) {//retornar mensaje d error....
System.out.println("ERROR IN DEFINITION");
}
Map servicesMap = definition.getServices();
Set s = servicesMap.keySet();
Iterator it = s.iterator();
if (it.hasNext()) {
javax.wsdl.Service serv =(javax.wsdl.Service) servicesMap.get(it.next());
Map m= serv.getPorts();
Set set= m.keySet();
Iterator itr = set.iterator();
if (itr.hasNext()) {
Port port = (Port) m.get(itr.next());
Binding bind = port.getBinding();
PortType pt = bind.getPortType();
QName name = (QName) pt.getQName();
List operations = pt.getOperations();
Iterator oper = operations.iterator();
for (int i = 0; oper.hasNext(); i++) {
Operation op = (Operation) oper.next();
System.out.println(" ....... " + op.getName());
javax.wsdl.Part part = null;
QName nameT = null;
javax.wsdl.Message input = op.getInput().getMessage();
List entradal = op.getParameterOrdering();
System.out.println("--------------");
Iterator entradai = new Vector().iterator();
if(entradal != null)
entradai = entradal.iterator();
while (entradai.hasNext()) {
part = (javax.wsdl.Part) input.getPart((String)entradai.next());
nameT=part.getTypeName();
System.out.println(" \t-> " + part.getName());
}
javax.wsdl.Message output= op.getOutput().getMessage();
Map salidam = output.getParts();
Set salidaS = salidam.keySet();
Iterator ite = new Vector().iterator();
if(salidaS != null)
ite = salidaS.iterator();
while(ite.hasNext()){
part = (javax.wsdl.Part) output.getPart((String)ite.next());
nameT = part.getTypeName();
if(nameT == null){continue; }
System.out.println(" \t<- " + part.getName());
}
}
}
}
} catch(Exception e){
System.out.println("problems --- " + e);
e.printStackTrace();
}
...
Him but important and that me this causing problems is to obtain the name of the operations as well as the name and fact types of each one of the request and response of each operation. The curious thing of everything is that while it is a service put up in axis it doesn't generate me this problem, this happens alone with other services where the description of the wsdl specifies the input and output of the operations with spaces of names and prefixes different to those of axis.
I know that the API of WSDL4J can read any wsdl that fulfills the standard since the axis it generates the classes clients of a web service starting from a wsdl without problems but one doesn't eat the they use.
Thank you.