Solved

java WSDL parsing

Posted on 2011-09-29
6
1,130 Views
Last Modified: 2012-12-09
using WSDLreader and other javax.wsdl classes how can I read complex types' definitions.
0
Comment
Question by:benchpresser
  • 3
  • 2
6 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36823668
0
 

Author Comment

by:benchpresser
ID: 36890221

now i m using wsdl4j api, and reading operations, but i can not access complextypes and function parameters which are complextype. Here is my code.

I must read whole structure of defined complex types, and function signs to entegrate our own programming language to any web service. briefly, i need to write a tool like wsimport for a custom programming language.

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.wsdl.Binding;
import javax.wsdl.Definition;
import javax.wsdl.Operation;
import javax.wsdl.Port;
import javax.wsdl.PortType;
import javax.wsdl.Service;
import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import com.ibm.wsdl.PartImpl;

public class Application {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try {
			WSDLFactory factory = WSDLFactory.newInstance();
			WSDLReader reader = factory.newWSDLReader();
			
			reader.setFeature("javax.wsdl.verbose", false);
			reader.setFeature("javax.wsdl.importDocuments", true);
			Definition def = reader.readWSDL(null, "http://www.restfulwebservices.net/wcf/WeatherForecastService.svc?wsdl");
			def = reader.readWSDL(null, "http://footballpool.dataaccess.eu/data/info.wso?WSDL");

			Map services = def.getServices();
			Iterator servicesIterator = services.values().iterator();

			def.getTypes();
			
			
			
			Map messages = def.getMessages();
			
			/*Iterator messagesIterator = messages.values().iterator();
			while (messagesIterator.hasNext()) {
				MessageImpl mess = (MessageImpl) messagesIterator.next();
				System.out.println(mess.getQName().getLocalPart());
			} */
			
			

			while (servicesIterator.hasNext()) {
				Service service = (Service) servicesIterator.next();

				Map ports = service.getPorts();
				Iterator portsIterator = ports.keySet().iterator();

				//System.out.println(service.getQName().getLocalPart());

				while (portsIterator.hasNext()) {
					String strPort = portsIterator.next().toString();

					System.out.println(strPort);
					Port port = service.getPort(strPort);
					Binding binding = port.getBinding();
					PortType portType = binding.getPortType();

					List operations = portType.getOperations();
					Iterator opIterator = operations.iterator();
					while (opIterator.hasNext()) {
						Operation operation = (Operation) opIterator.next();
						if (!operation.isUndefined()) {

							// read input
							Map params = operation.getInput().getMessage().getParts();
							Iterator paramsIterator = params.keySet().iterator();

							int n = 1;

							StringBuffer sbParams = new StringBuffer();
							while (paramsIterator.hasNext()) {

								PartImpl iParam = (PartImpl) params.get(paramsIterator.next());
								if (iParam.getTypeName() == null) {
									sbParams.append(iParam.getElementName().getLocalPart()).append(" p").append(n).append(",");
									n++;
								} else if (iParam.getElementName() == null) {
									sbParams.append(iParam.getTypeName().getLocalPart()).append(" ").append(iParam.getName()).append(", ");
								} else {
									System.err.println("sicis .:.");
								}
							}

							if (sbParams.length() > 0) {
								sbParams.delete(sbParams.length() - 1, sbParams.length());
							}

							// read output

							Map output = operation.getOutput().getMessage().getParts();
							Iterator outputIterator = output.keySet().iterator();
							String strOutput = "";
							while (outputIterator.hasNext()) {

								PartImpl iOutput = (PartImpl) output.get(outputIterator.next());
								if (iOutput.getTypeName() == null) {
									strOutput = iOutput.getElementName().getLocalPart();
									n++;
								} else if (iOutput.getElementName() == null) {
									strOutput = iOutput.getTypeName().getLocalPart();
								} else {
									System.err.println("sicis .:.");
								}
							}

							StringBuffer sb = new StringBuffer(strOutput).append(" ").append(operation.getName()).append("(").append(sbParams).append(")");
							System.out.println("   " + sb.toString());
						}
					}
				}
			}
		} catch (WSDLException e) {
			e.printStackTrace();
		}
	}
}

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36890302

Well, that sounds like a tough task

Perhaps you saw the references below:

this paper suggests to use StAX to parse WSDL with custom types:
http://www.devx.com/Java/Article/29286/1954

maybe this could be of some help:

http://tech.groups.yahoo.com/group/wsdl/message/1943
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 36890476
Apache Woden is a good choice: http://ws.apache.org/woden/

And this Easy WSDL from OW2 guys is easy to use : http://easywsdl.ow2.org/
0
 

Accepted Solution

by:
benchpresser earned 0 total points
ID: 36891991
http://easywsdl.ow2.org/ libraries are helpful. now we are trying to implement the solution.
0
 

Author Closing Comment

by:benchpresser
ID: 38673705
my answer is the best and solves the problem
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now