Solved

java WSDL parsing

Posted on 2011-09-29
6
1,348 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

734 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