CXF WS-Discovery Client

CXF WS-Discovery Client explains step by step details of discovering a JAX-WS service using CXF WS-Discovery feature
For Creating Apache CXF WS-Discovery Client, We are using org.apache.cxf.ws.discovery.WSDiscoveryClient. WSDiscoveryClient is an in built CXF class
Which helps us to search the services on the network and invoke the operation on that available service.
Required Libraries
You need to download following libraries in order to Generate CXF WS-Discovery Client
- JDK 6
- Eclipse 3.7
- CXF-2.7.12
- Tomcat 7 (Deploying Web Service)
Following jar must be in classpath
- commons-collections-3.2.1.jar
- commons-lang-2.6.jar
- cxf-2.7.12.jar
- cxf-services-ws-discovery-api-2.7.12.jar
- jaxb-impl-2.2.6.jar
- jaxb-xjc-2.2.6.jar
- mina-core-2.0.7.jar
- neethi-3.0.3.jar
- slf4j-api-1.7.7.jar
- slf4j-jdk14-1.7.7.jar
- stax2-api-3.1.4.jar
- velocity-1.7.jar
- woodstox-core-asl-4.4.0.jar
- wsdl4j-1.6.3.jar
- xml-resolver-1.2.jar
- xmlschema-core-2.1.0.jar
CXF WS-Discovery Client
package com.student;
import java.util.List;
import javax.xml.ws.EndpointReference;
import org.apache.cxf.ws.discovery.WSDiscoveryClient;
public final class WSDiscovery_Client {
public static void main(String[] args) throws Exception {
//Use WS-Discovery to find references to services that implement the changeName portType
WSDiscoveryClient client = new WSDiscoveryClient();
// Setting timeout for WS-Discovery
client.setDefaultProbeTimeout(1000);
// Use WS-discovery 1.0
// client.setVersion10();
System.out.println("Probe:" + client.getAddress());
List<EndpointReference> references = client.probe();
client.close();
ChangeStudentDetailsImplService service = new ChangeStudentDetailsImplService();
Student student = new Student();
student.setName("Rockey");
// loop through all of them and have them & invoke changeName method.
for (EndpointReference ref : references) {
ChangeStudentDetails details = service.getPort(ref, ChangeStudentDetails.class);
Student changeName = details.changeName(student);
System.out.println("Server said: " + changeName.getName());
}
}
}
import java.util.List;
import javax.xml.ws.EndpointReference;
import org.apache.cxf.ws.discovery.WSDiscoveryClient;
public final class WSDiscovery_Client {
public static void main(String[] args) throws Exception {
//Use WS-Discovery to find references to services that implement the changeName portType
WSDiscoveryClient client = new WSDiscoveryClient();
// Setting timeout for WS-Discovery
client.setDefaultProbeTimeout(1000);
// Use WS-discovery 1.0
// client.setVersion10();
System.out.println("Probe:" + client.getAddress());
List<EndpointReference> references = client.probe();
client.close();
ChangeStudentDetailsImplService service = new ChangeStudentDetailsImplService();
Student student = new Student();
student.setName("Rockey");
// loop through all of them and have them & invoke changeName method.
for (EndpointReference ref : references) {
ChangeStudentDetails details = service.getPort(ref, ChangeStudentDetails.class);
Student changeName = details.changeName(student);
System.out.println("Server said: " + changeName.getName());
}
}
}
Output
Probe:soap.udp://239.255.255.250:3702 Oct 16, 2014 8:10:23 AM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass INFO: Creating Service {http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01}DiscoveryProxy from class org.apache.cxf.jaxws.support.DummyImpl Oct 16, 2014 8:10:24 AM com.student.ChangeStudentDetailsImplService INFO: Can not initialize the default wsdl from ChangeStudent.wsdl Oct 16, 2014 8:10:24 AM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass INFO: Creating Service {http://student.com/}ChangeStudentDetailsImplService from class com.student.ChangeStudentDetails Oct 16, 2014 8:10:25 AM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass INFO: Creating Service {http://student.com/}ChangeStudentDetailsImplService from class com.student.ChangeStudentDetails Server said: Hello Rockey
2 Responses to "CXF WS-Discovery Client"