Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java WSDL parsing

Posted on 2011-09-29
6
Medium Priority
?
1,488 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

718 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