0
|
1 package lsdis;
|
|
2
|
|
3 import java.util.ArrayList;
|
|
4 import java.util.Iterator;
|
|
5 import java.util.List;
|
|
6 import java.util.Scanner;
|
|
7
|
|
8 import org.apache.woden.WSDLException;
|
|
9 import org.apache.woden.WSDLFactory;
|
|
10 import org.apache.woden.WSDLReader;
|
|
11 import org.apache.woden.wsdl20.Description;
|
|
12 import org.apache.woden.wsdl20.ElementDeclaration;
|
|
13 import org.apache.woden.wsdl20.Endpoint;
|
|
14 import org.apache.woden.wsdl20.InterfaceMessageReference;
|
|
15 import org.apache.woden.wsdl20.InterfaceOperation;
|
|
16 import org.apache.woden.wsdl20.Service;
|
|
17 import org.apache.woden.wsdl20.Interface;
|
|
18 import org.apache.woden.wsdl20.extensions.rpc.Direction;
|
|
19 import org.apache.woden.wsdl20.xml.DescriptionElement;
|
|
20 import org.apache.ws.commons.schema.XmlSchemaAll;
|
|
21 import org.apache.ws.commons.schema.XmlSchemaComplexType;
|
|
22 import org.apache.ws.commons.schema.XmlSchemaElement;
|
|
23 import org.apache.ws.commons.schema.XmlSchemaGroupBase;
|
|
24 import org.apache.ws.commons.schema.XmlSchemaParticle;
|
|
25 import org.apache.ws.commons.schema.XmlSchemaSequence;
|
|
26 import org.apache.ws.commons.schema.XmlSchemaType;
|
|
27 import org.w3c.dom.NamedNodeMap;
|
|
28
|
|
29 import java.net.URI;
|
|
30
|
|
31 import javax.xml.namespace.QName;
|
|
32
|
|
33 public class WSDLParserDriver {
|
|
34
|
|
35 private List<InterfaceOperation> completeMethodList = new ArrayList<InterfaceOperation>();
|
|
36 private List<String> url = new ArrayList<String>();
|
|
37 private List<String> paramList = new ArrayList<String>();
|
|
38 private List<String> paramTypeList = new ArrayList<String>();
|
|
39 private String WSDLtype;
|
|
40 private BindingElement[] bindingElement = new BindigElement();
|
|
41
|
|
42 public List<InterfaceOperation> getCompleteMethodList() {
|
|
43 return completeMethodList;
|
|
44 }
|
|
45
|
|
46 public List<String> getUrl() {
|
|
47 return url;
|
|
48 }
|
|
49
|
|
50 public List<String> getParamList() {
|
|
51 return paramList;
|
|
52 }
|
|
53 public List<String> getParamTypeList() {
|
|
54 return paramTypeList;
|
|
55 }
|
|
56
|
|
57 public static void main(String[] args) {
|
|
58 /*Scanner keyboard = new Scanner(System.in);
|
|
59
|
|
60 System.out.println("Enter the wsdl url: ");
|
|
61 String wsdlurl = keyboard.next();*/
|
|
62 WSDLParserDriver a = new WSDLParserDriver();
|
|
63 a.parse("/home/ganjoo/parser/bookstore-sample/booklist.wsdl");
|
|
64 for(InterfaceOperation oper:a.getCompleteMethodList()){
|
|
65 a.getParameters(oper);
|
|
66 }
|
|
67 }
|
|
68
|
|
69 public boolean isWSDL2()
|
|
70 {
|
|
71
|
|
72 }
|
|
73 public void parse(String wsdlurl){
|
|
74
|
|
75 try {
|
|
76
|
|
77 WSDLFactory factory;
|
|
78 factory = WSDLFactory.newInstance();
|
|
79 WSDLReader reader = factory.newWSDLReader();
|
|
80 reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
|
|
81 Description desc = reader.readWSDL(wsdlurl);
|
|
82 Service[] services = desc.getServices();
|
|
83 BindingElement []
|
|
84 for(int i=0;i<services.length;i++){
|
|
85 Endpoint[] endpoints = services[i].getEndpoints();
|
|
86 boolean foundRestBinding = false;
|
|
87 int count=0;
|
|
88 while(count<endpoints.length){
|
|
89 foundRestBinding = endpoints[count].getBinding().getType().equals(new URI("http://www.w3.org/ns/wsdl/http"));
|
|
90 count++;
|
|
91
|
|
92 if(foundRestBinding){
|
|
93 System.out.println("-----------------REST Web services--------------");
|
|
94 URI address = endpoints[count-1].getAddress();
|
|
95 String serviceName = services[i].getName().getLocalPart();
|
|
96 System.out.println("Service Name : " + serviceName + "\t address : " + address);
|
|
97 Interface intrfce = services[i].getInterface();
|
|
98 InterfaceOperation[] intrfceOpers = intrfce.getAllInterfaceOperations();
|
|
99 for(int j=0;j<intrfceOpers.length;j++){
|
|
100 InterfaceOperation oper = intrfceOpers[j];
|
|
101 String operName = oper.getName().getLocalPart();
|
|
102 System.out.println("\t operation name " + j + ": " + operName);
|
|
103 completeMethodList.add(oper);
|
|
104 url.add(address.toString());
|
|
105
|
|
106
|
|
107
|
|
108 }
|
|
109 }
|
|
110 }
|
|
111 }
|
|
112
|
|
113 } catch (Exception e) {
|
|
114 // TODO Auto-generated catch block
|
|
115 e.printStackTrace();
|
|
116 }
|
|
117 }
|
|
118
|
|
119 public void getParameters(String operName){
|
|
120 try{
|
|
121 InterfaceOperation oper = null;
|
|
122 for(InterfaceOperation oper1 :getCompleteMethodList()){
|
|
123 if(oper1.getName().getLocalPart().equals(operName))
|
|
124 {
|
|
125 oper = oper1;
|
|
126 break;
|
|
127 }
|
|
128
|
|
129 }
|
|
130 if(oper==null){
|
|
131 System.out.println("Wrong method name passed in getParameters() method");
|
|
132 System.exit(0);
|
|
133 }
|
|
134
|
|
135 InterfaceMessageReference[] messageRefs = oper.getInterfaceMessageReferences();
|
|
136 for(int k=0;k<messageRefs.length;k++){
|
|
137 if(messageRefs[k].getDirection().toString().equals("in")){
|
|
138
|
|
139 ElementDeclaration ed = messageRefs[k].getElementDeclaration();
|
|
140 String inputMessageName = ed.getName().getLocalPart();
|
|
141
|
|
142 if(ed.getContentModel().equalsIgnoreCase("org.w3c.dom")){
|
|
143 org.w3c.dom.Element element = (org.w3c.dom.Element) ed.getContent();
|
|
144 if(element.hasChildNodes()){
|
|
145 System.out.println("Element has child nodes");
|
|
146 org.w3c.dom.NodeList nl = element.getChildNodes();
|
|
147
|
|
148 }
|
|
149 if(element.hasAttributes()){
|
|
150 System.out.println("Element has attributes");
|
|
151 NamedNodeMap nodeMap = element.getAttributes();
|
|
152
|
|
153 }
|
|
154 }
|
|
155 else if(ed.getContentModel().equalsIgnoreCase("org.apache.ws.commons.schema")){
|
|
156 org.apache.ws.commons.schema.XmlSchemaElement element = (org.apache.ws.commons.schema.XmlSchemaElement ) ed.getContent();
|
|
157 System.out.println("element: " + element);
|
|
158 if(element != null){
|
|
159 String targetNamespace = element.getQName().getNamespaceURI();
|
|
160 QName bodyFirstChildQName;
|
|
161 if (targetNamespace != null && !"".equals(targetNamespace)) {
|
|
162 bodyFirstChildQName = new QName(targetNamespace, element.getName());
|
|
163 } else {
|
|
164 bodyFirstChildQName = new QName(element.getName());
|
|
165 }
|
|
166 if(oper.getStyle()[0].equals(new URI("http://www.w3.org/ns/wsdl/style/iri"))){
|
|
167 XmlSchemaType schemaType = element.getSchemaType();
|
|
168 if (schemaType instanceof XmlSchemaComplexType) {
|
|
169 XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
|
|
170 XmlSchemaParticle particle = complexType.getParticle();
|
|
171 if (particle instanceof XmlSchemaSequence || particle instanceof XmlSchemaAll) {
|
|
172 XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) particle;
|
|
173 Iterator iterator = xmlSchemaGroupBase.getItems().getIterator();
|
|
174 while (iterator.hasNext()) {
|
|
175 XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next();
|
|
176 QName qName = innerElement.getQName();
|
|
177 if (qName ==null && innerElement.getSchemaTypeName().equals(org.apache.ws.commons.schema.constants.Constants.XSD_ANYTYPE)) {
|
|
178 System.out.println("create soap message without schema and break");
|
|
179 break;
|
|
180 }
|
|
181 long minOccurs = innerElement.getMinOccurs();
|
|
182 boolean nillable = innerElement.isNillable();
|
|
183
|
|
184 String name =
|
|
185 qName != null ? qName.getLocalPart() : innerElement.getName();
|
|
186 System.out.println("Name of parameter is :" + name);
|
|
187 paramList.add(name);
|
|
188 System.out.println("Type of Parameter is :"+innerElement.getSchemaTypeName().getLocalPart()+"\n");
|
|
189 paramTypeList.add(innerElement.getSchemaTypeName().getLocalPart());
|
|
190 }
|
|
191
|
|
192
|
|
193 }
|
|
194
|
|
195 }
|
|
196
|
|
197 }
|
|
198
|
|
199 }else{
|
|
200 System.out.println("element is null");
|
|
201 }
|
|
202
|
|
203
|
|
204 }
|
|
205 }
|
|
206 }
|
|
207 } catch (Exception e) {
|
|
208 // TODO Auto-generated catch block
|
|
209 e.printStackTrace();
|
|
210 }
|
|
211 }
|
|
212
|
|
213 }
|