Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1602
  • Last Modified:

java WSDL parsing

using WSDLreader and other javax.wsdl classes how can I read complex types' definitions.
  • 3
  • 2
1 Solution
benchpresserAuthor Commented:

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();

			Map messages = def.getMessages();
			/*Iterator messagesIterator = messages.values().iterator();
			while (messagesIterator.hasNext()) {
				MessageImpl mess = (MessageImpl) messagesIterator.next();
			} */

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

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


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

					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(",");
								} 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();
								} 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) {

Open in new window


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:

maybe this could be of some help:

Cyber Threats to Small Businesses (Part 1)

This past May, Webroot surveyed more than 600 IT decision-makers at medium-sized companies to see how these small businesses perceived new threats facing their organizations.  Read what Webroot CISO, Gary Hayslip, has to say about the survey in part 1 of this 2-part blog series.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
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/
benchpresserAuthor Commented:
http://easywsdl.ow2.org/ libraries are helpful. now we are trying to implement the solution.
benchpresserAuthor Commented:
my answer is the best and solves the problem

Featured Post

Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now