Created
April 18, 2011 18:08
-
-
Save mathieuancelin/925828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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