Skip to content

Instantly share code, notes, and snippets.

@afsinka
Last active August 7, 2016 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afsinka/abb87569e2a67d12424f96ffd5ac2024 to your computer and use it in GitHub Desktop.
Save afsinka/abb87569e2a67d12424f96ffd5ac2024 to your computer and use it in GitHub Desktop.
Apache CXF Server Example
package com.cxf.server;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
String sayHi(@WebParam(name = "text") String text);
}
package com.cxf.server;
import javax.jws.WebService;
@WebService
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String name) {
System.out.println("say hello to " + name);
return "Hello " + name + "!";
}
}
package com.cxf.server;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public class Main {
public static void main(String[] args) {
HelloWorld helloWorld = new HelloWorldImpl();
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceClass(HelloWorld.class);
factory.setAddress("http://localhost:9000/HelloWorld");
factory.setServiceBean(helloWorld);
factory.create();
System.out.println("Server ready...");
}
}
<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>CXF_Server_Example</groupId>
<artifactId>CXF_Server_Example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.5</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.1.5</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment