- Create java (maven) project
 - if you are not using Maven, then you have to manually configure to include the required JAR dependencies.
 - see Maven POM file below about required CXF libraries.
- Define Service Endpoint Interface (SEI)
- Define SEI Implementation (service layer)
- Create web service implementation (interaction layer)
- Deploy/execute
http://localhost:9000/helloWorld?wsdl
The Service End Point Interface (SEI)
package com.jadobo.ws;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
    String sayHi(@WebParam(name="text")String text);
    
}
The Service End Point Implementation
package com.jadobo.ws;
import javax.jws.WebService;
@WebService(endpointInterface = "com.jadobo.ws.HelloWorld",
            serviceName = "HelloWorldService",
            portName="HelloWorldPort")
public class HelloWorldImpl implements HelloWorld {
    @Resource private WebServiceContext wsCtxt;
    public String sayHi(String text) {
        System.out.println("sayHi called");
        return "Hello: " + text;
    }
    
}
The Server Implementation
package com.jadobo.ws;
import javax.xml.ws.Endpoint;
public class Server {
    protected Server() throws Exception {
        // START SNIPPET: publish
        System.out.println("Starting Server");
        HelloWorldImpl implementor = new HelloWorldImpl();
        String address = "http://localhost:9000/helloWorld";
        Endpoint.publish(address, implementor);
        // END SNIPPET: publish
    }
    public static void main(String args[]) throws Exception {
        new Server();
        System.out.println("Server ready...");
        Thread.sleep(5 * 60 * 1000);
        System.out.println("Server exiting");
        System.exit(0);
    }
}
The Project's Maven POM
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.jadobo.ws</groupId>
   <artifactId>bottomup</artifactId>
   <version>0.0.1-SNAPSHOT</version>
  
    <repositories>
        <repository>
            <id>default</id>
            <name>Maven Repository</name>
            <layout>default</layout>
            <url>http://repo1.maven.org/maven2</url>
        </repository>
    </repositories>
    <dependencies>
    
        <!-- CXF Web Service -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-core</artifactId>
            <version>2.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-api</artifactId>
            <version>2.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>2.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-bundle</artifactId>
            <version>2.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-common-schemas</artifactId>
            <version>2.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>2.4.1</version>
        </dependency>
    
    </dependencies>
  
</project>
 
Another useful post by you. Hats off to you! I was looking for it and got here in your post. Many thanks!
ReplyDeletedigital signature Adobe Acrobat