Solved

java WSDL parsing

Posted on 2011-09-29
6
1,390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

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
Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

626 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