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.

Note

For creating artifcats required to invoke this service, see this CXF wsdl2java Example. This WS-Discovery client is created based on mentioned Tutorial

For deploying the service you need to refere this CXF WS-Discovery Example.

When using wsdl2java option ChangeStudent.wsdl must be relative path, because we cant predict the exact path of the service to be deployed.

Required Libraries

You need to download following libraries in order to Generate CXF WS-Discovery Client

  1. JDK 6
  2. Eclipse 3.7
  3. CXF-2.7.12
  4. Tomcat 7 (Deploying Web Service)

Following jar must be in classpath

  1. commons-collections-3.2.1.jar
  2. commons-lang-2.6.jar
  3. cxf-2.7.12.jar
  4. cxf-services-ws-discovery-api-2.7.12.jar
  5. jaxb-impl-2.2.6.jar
  6. jaxb-xjc-2.2.6.jar
  7. mina-core-2.0.7.jar
  8. neethi-3.0.3.jar
  9. slf4j-api-1.7.7.jar
  10. slf4j-jdk14-1.7.7.jar
  11. stax2-api-3.1.4.jar
  12. velocity-1.7.jar
  13. woodstox-core-asl-4.4.0.jar
  14. wsdl4j-1.6.3.jar
  15. xml-resolver-1.2.jar
  16. 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());
       

    }

}
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"
  1. krishnaaa 2014-06-10 19:05:46.0
  1. krishnaaa 2014-06-11 19:05:46.0

Your email address will not be published. Required fields are marked *