wsdl4j 解析 wsdl

需要下载 wsdl4j.jar 包,大家可以到我的资源中下载,附链接 wsdl4j下载

import javax.wsdl.*;  
import javax.wsdl.extensions.*;  
import javax.wsdl.factory.*;  
import javax.wsdl.xml.*;  
import javax.xml.namespace.QName;  
import java.util.*;  
import org.w3c.dom.*;  
public class NavigatingWSDL {  
public static void main(String[]args)  
{  
try{  
   WSDLFactory factory = WSDLFactory.newInstance();  
   WSDLReader reader=factory.newWSDLReader();  
   reader.setFeature("javax.wsdl.verbose",true);  
   reader.setFeature("javax.wsdl.importDocuments",true);  
   //http://localhost:8080/ode/processes/HelloBPELService
   //http://localhost:8080/axis/services/SayHelloService
   Definition def=reader.readWSDL("http://localhost:8080/ode/processes/HelloBPELService?wsdl");  
         //解析服务名   
   System.out.println("---------------------------------------------");  
   System.out.println("nService Name:");  
   String tns="http://sample.bpel.org/bpel/sample";  
        Service service =def.getService(new QName(tns,"HelloBPELService"));  
   System.out.println(service.getQName().getLocalPart());
   System.out.println();
   
   //解析接口方法名  
   System.out.println("nOperation Name:");  
   Port port =service.getPort("HelloBPELProcessPort");  
   Binding binding=port.getBinding();  
   PortType portType=binding.getPortType();  
   List operations=portType.getOperations();  
   Iterator operIter=operations.iterator();  
   while(operIter.hasNext())  
   {  
   Operation operation=(Operation)operIter.next();  
   if(!operation.isUndefined())  
   {
    System.out.println(operation.getName()) ;
   }  
   
   }  
   System.out.println();
   
   
   
   //解析消息,输入输出  
   System.out.println("nMessages:");  
   Map messages=def.getMessages();  
   Iterator msgIter=messages.values().iterator();  
   while(msgIter.hasNext())  
   {  
    Message msg=(Message)msgIter.next();  
    if(!msg.isUndefined())  
    {  
    System.out.println(msg.getQName().getLocalPart());  
    Iterator partIter=msg.getParts().values().iterator();  
    while(partIter.hasNext())  
    {  
     Part part=(Part) partIter.next();  
    // System.out.print("parameter name:"+part.getName()+"t");  
     System.out.print("parameter name:"+part.getName());  
   //  System.out.println("parameter type:"+part.getTypeName().getLocalPart());  
     System.out.print(" ......parameter element:"+part.getElementName().getLocalPart()); 
     System.out.println(" ......parameter type:"+part.getTypeName());     
    }  
    }       
   }  
   System.out.println();
   //解析服务地址  
   System.out.println("nService location:");  
   List l=port.getExtensibilityElements();  
   ExtensibilityElement element=(ExtensibilityElement) l.get(0);  
   String s=element.toString();  
 
     System.out.println(s.substring(s.indexOf("location")));  
     System.out.println("-----------------------------------------------------");  
    
}catch(WSDLException e){e.printStackTrace();}   
}  

}  

wsdl4j 解析 wsdl_第1张图片

你可能感兴趣的:(wsdl4j 解析 wsdl)