I started learning Apache CXF with Spring. First of all, I tried to create a simple client / server model.
Server side: service.HelloWorld.java
@WebService public interface HelloWorld { String sayHi(String text); }
service.HelloWorldImpl.java
@WebService(endpointInterface = "service.HelloWorld") public class HelloWorldImpl implements HelloWorld { public String sayHi(String text) { return "Hello, " + text; } }
Client side: client.Client.java public class Client {
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"cxf-client-servlet.xml"}); HelloWorld client = (HelloWorld) context.getBean("client"); System.out.println(client.sayHi("Batman")); } }
CXF-client-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd"> <bean id="client" class="service.HelloWorld" factory-bean="clientFactory" factory-method="create"/> <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"> <property name="serviceClass" value="service.HelloWorld"/> <property name="address" value="http://localhost:8080/services/HelloWorld"/> </bean>
The problem is this: for the client to work, I had to add service.HelloWorld (package + interface) to the clients project. I heard that before using the service I need to create a stub. So it baffles me. So, what is the right approach and what is the best practice (maybe it is better to use some kind of contract-first approach or something like that)? Later I want to add WS-Security, so I need a strong background =)
Thanks in advance.
source share