Skip to content

Instantly share code, notes, and snippets.

@mathieuancelin
Created April 18, 2011 18:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathieuancelin/925828 to your computer and use it in GitHub Desktop.
Save mathieuancelin/925828 to your computer and use it in GitHub Desktop.
package com.sample.ws;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.cxf.service.model.OperationInfo;
public class DynamicWSDLClient {
public void readWSDL() {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://ecs.amazonaws.com/AWSECommerceService/AWSECommerceService.wsdl");
for (OperationInfo op : client.getEndpoint().getEndpointInfo().getInterface().getOperations()) {
System.out.println("operation : " + op.getName().getLocalPart());
System.out.println(" input : " + op.getInput().getName().getLocalPart());
for (MessagePartInfo part : op.getInput().getMessageParts()) {
System.out.println(" part : " + part.getName().getLocalPart() + " of type " + part.getTypeClass());
Map<String, String> properties = new HashMap<String, String>();
for (Method f : part.getTypeClass().getMethods()) {
if (!f.getDeclaringClass().equals(Object.class)) {
if (f.getName().startsWith("set")) {
properties.put(f.getName().substring(3), f.getParameterTypes()[0].getName());
}
if (f.getName().startsWith("get")) {
properties.put(f.getName().substring(3), f.getReturnType().getName());
}
}
}
for (String name : properties.keySet()) {
System.out.println(" property : " + name + " of type : " + properties.get(name));
}
}
System.out.println(" output : " + op.getOutput().getName().getLocalPart());
for (MessagePartInfo part : op.getOutput().getMessageParts()) {
System.out.println(" part : " + part.getTypeClass());
Map<String, String> properties = new HashMap<String, String>();
for (Method f : part.getTypeClass().getMethods()) {
if (!f.getDeclaringClass().equals(Object.class)) {
if (f.getName().startsWith("set")) {
properties.put(f.getName().substring(3), f.getParameterTypes()[0].getName());
}
if (f.getName().startsWith("get")) {
properties.put(f.getName().substring(3), f.getReturnType().getName());
}
}
}
for (String name : properties.keySet()) {
System.out.println(" property : " + name + " of type : " + properties.get(name));
}
}
System.out.println("");
}
}
}
/**
dependencies :
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.3</version>
</dependency>
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment