CXF publishes WebService

Dependent jar

commons-logging-1.1.1.jar
cxf-2.7.5.jar
httpasyncclient-4.0-beta3.jar
httpclient-4.2.1.jar
httpcore-4.2.2.jar
httpcore-nio-4.2.2.jar
neethi-3.0.2.jar
org.springframework.aop-3.1.3.RELEASE.jar
org.springframework.asm-3.1.3.RELEASE.jar
org.springframework.beans-3.1.3.RELEASE.jar
org.springframework.context-3.1.3.RELEASE.jar
org.springframework.core-3.1.3.RELEASE.jar
org.springframework.expression-3.1.3.RELEASE.jar
org.springframework.web-3.1.3.RELEASE.jar
org.springframework.web.servlet-3.1.3.RELEASE.jar
stax2-api-3.1.1.jar
woodstox-core-asl-4.2.0.jar
wsdl4j-1.6.3.jar
wss4j-1.6.10.jar
xmlschema-core-2.0.3.jar
xmlsec-1.5.4.jar

download url

http://cxf.apache.org/download.html
http://www.springsource.org/download/community
1. An interface
Java code collection code
package org.demo.ws;

import javax.jws.WebService;

@WebService
public interface HelloWorld
{
String sayHi(String text);
}
2. An implementation class
Java code collection code
package org.demo.ws.server;

import javax.jws.WebService;
import org.demo.ws.HelloWorld;

@WebService(serviceName=”hello”, endpointInterface=”org.demo.ws.HelloWorld”)
public class HelloWorldImpl implements HelloWorld
{

public HelloWorldImpl()  
{  
    System.out.println("-- init HelloWorldImpl --");  
}  

public String sayHi(String text)  
{  
    System.out.println("in sayHi, text : " + text);  
    return "hi " + text + ".";  
}  

}
3. A server-side user name password callback class
Java code collection code
package org.demo.ws.server;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.ws.security.WSPasswordCallback;

public class MyPasswordCallback implements CallbackHandler
{

@Override  
public void handle(Callback[] callbacks) throws IOException,  
        UnsupportedCallbackException  
{  
    WSPasswordCallback pwCallback = (WSPasswordCallback)callbacks[0];  
    String user = pwCallback.getIdentifier();  
    if ("user1".equals(user))  
    {  
        pwCallback.setPassword("password1");  
    }  
}  

}
4. web.xml
Html code collection code

Guess you like

Origin blog.csdn.net/ke_weiquan/article/details/52303906