- 浏览: 36201 次
- 性别:
- 来自: 深圳
最新评论
第一部分:环境
1.系统版本:Fedora14
2.Eclipse版本:J2ee版3.5
3.jdk版本:jdk1.6
4.maven local repository:/var/javaproject/repo
5.tomcat 版本:1.6
6.tomcat 端口:9080
假设以上环境已经安装完毕,各软件能独立正确运行。
第二部分:配置eclipse工作区
在适当的地方建立一个cxftest目录,然后在此目录再建一个cxftest_build目录
在cxftest_build目录中建立pom.xml文件,输入一下内容:
<!-- sub pom.xml start--->
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bruce.cxftest</groupId>
<artifactId>cxftest_build</artifactId>
<packaging>pom</packaging>
<name>cxf test Parent Project</name>
<version>1.0-SNAPSHOT</version>
<modules>
<module>../cxftest_public_impl</module>
<module>../cxftest_public_intf</module>
<module>../cxftest_web</module>
<module>../cxftest_client</module>
</modules>
<properties>
<wss4j.version>1.6.4</wss4j.version>
<spring.version>3.0.2.RELEASE</spring.version>
<cxf.version>2.5.2</cxf.version>
<junit.version>4.8.1</junit.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</project>
<!-- sub pom.xml end --->
我的电脑最终目录结构为:
cxftest/
|/cxftest_build
|/cxftest_client
|/cxftest_public_impl
|/cxftest_public_intf
|/cxftest_web
并以 cxftest目录为基础建立eclipse 工作区
第二部分:开发公共接口项目
在eclipse中建立名为cxftest_public_intf的java工程,设置java源文件的目录为/src/main/java, 资源目录为/src/main/resorces
在cxftest_public_intf项目根目录建立名为pom.xml输入以下内容:
<!-- pom.xml start →
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bruce.cxftest</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>cxftest_build</artifactId>
<relativePath>../cxftest_build/pom.xml</relativePath>
</parent>
<artifactId>cxftest_public_intf</artifactId>
<packaging>jar</packaging>
<name>cxf test web service interface Project</name>
<build>
<finalName>${artifactId}-${version}</finalName>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/service.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
</project>
<!-- pom.xml end -->
用eclipse自带的工具src/main/wsdl 目录编辑wsdl文件 service.wsdl与dto.xsd:
<!-- service.wsdl start -->
<?xml version="1.0" ?>
<wsdl:definitions targetNamespace="http://www.bruce.com/cxftest/service"
xmlns:service="http://www.bruce.com/cxftest/service"
xmlns:dto="http://www.bruce.com/cxftest/dto"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.bruce.com/cxftest/dto" schemaLocation="dto.xsd">
</xsd:import>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetPhoneRequest">
<wsdl:part name="name" element="dto:getPhoneRequest" />
</wsdl:message>
<wsdl:message name="GetPhoneResponse">
<wsdl:part name="phone" element="dto:getPhoneResponse" />
</wsdl:message>
<wsdl:portType name="AddressBookService">
<wsdl:operation name="getPhone">
<wsdl:input message="service:GetPhoneRequest" />
<wsdl:output message="service:GetPhoneResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AddressBook" type="service:AddressBookService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getPhone">
<soap:operation
soapAction="http://www.bruce.com/cxftest/service/getPhone" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AddressBookService">
<wsdl:port name="AddressBookService" binding="service:AddressBook">
<soap:address location="http://www.bruce.com/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<!-- service.wsdl end -->
<!-- dto.xsd start -->
<?xml version="1.0" ?>
<xsd:schema targetNamespace="http://www.bruce.com/cxftest/dto" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dto="http://www.bruce.com/cxftest/dto">
<xsd:complexType name="Phone">
<xsd:sequence>
<xsd:element name="areaCode" type="xsd:int" />
<xsd:element name="exchange" type="xsd:int" />
<xsd:element name="number" type="xsd:int" />
<xsd:element name="date" type="xsd:date"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="getPhoneRequest" type="xsd:string"></xsd:element>
<xsd:element name="getPhoneResponse" type="dto:Phone"></xsd:element>
</xsd:schema>
<!-- dto.xsd end -->
在目录cxftest/cxftest_public_intf/ 下运行:
#mvn install
以生成Webservice的接口与Dto类。
第三部分:开发公共实现项目
在eclipse中建立名为cxftest_public_impl的java工程,设置java源文件的目录为/src/main/java, 资源目录为/src/main/resorces
在cxftest_public_impl项目根目录建立名为pom.xml输入以下内容:
<!-- pom.xml start →
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bruce.cxftest</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>cxftest_build</artifactId>
<relativePath>../cxftest_build/pom.xml</relativePath>
</parent>
<artifactId>cxftest_public_impl</artifactId>
<packaging>jar</packaging>
<name>cxf test web service implement Project</name>
<build>
<finalName>${artifactId}-${version}</finalName>
<defaultGoal>process-resources</defaultGoal>
<plugins>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.bruce.cxftest</groupId>
<version>${version}</version>
<artifactId>cxftest_public_intf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>${wss4j.version}</version>
</dependency>
</dependencies>
</project>
<!-- pom.xml end -->
建立 服务实现类com.bruce.cxftest.service.AddressBookServiceImpl,输入以下内容(这个类应该也有相应的工具生成,但是我还没找到):
//**************AddressBookServiceImpl start ********************
package com.bruce.cxftest.service;
import com.bruce.cxftest.dto.Phone;
public class AddressBookServiceImpl implements AddressBookService {
@Override
public Phone getPhone(String name) {
Phone phone;
System.out.println(name);
phone = new Phone();
phone.setAreaCode(120);
phone.setExchange(10);
phone.setNumber(10);
return phone;
}
}
//**************AddressBookServiceImpl end ********************
建立 服务端用户回调类类com.bruce.cxftest.security . ServerPasswordCallback,输入以下内容(这个类应该也有相应的工具生成,但是我还没找到):
//**************ServerPasswordCallback start ********************
package com.bruce.cxftest.security;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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 ServerPasswordCallback implements CallbackHandler {
Map<String,String> userMap = new HashMap<String,String>();
public ServerPasswordCallback(){
userMap.put("joe", "password");
}
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
if (userMap.containsKey(pc.getIdentifier())) {
pc.setPassword(userMap.get(pc.getIdentifier()));
}
}
}
第四部分:开发公共WEB服务项目
在eclipse中建立名为cxftest_web的java工程,设置java源文件的目录为/src/main/java, 资源文件目录为 /src/main/resources.
目录结构为:
cxftest_web
/src
| /main
| /java
| /resources
/WebContent
/WEB-INF
/classes
/lib
在cxftest_web项目根目录建立名为pom.输入以下内容:
<!-- pom.xml start -->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bruce.cxftest</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>cxftest_build</artifactId>
<relativePath>../cxftest_build/pom.xml</relativePath>
</parent>
<artifactId>cxftest_web</artifactId>
<packaging>war</packaging>
<name>cxf test web Project</name>
<build>
<finalName>${artifactId}-${version}</finalName>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.bruce.cxftest</groupId>
<version>${version}</version>
<artifactId>cxftest_public_intf</artifactId>
</dependency>
<dependency>
<groupId>com.bruce.cxftest</groupId>
<version>${version}</version>
<artifactId>cxftest_public_impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-common-utilities</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-policy</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>
<!-- pom.xml end -->
建立Service配置文件 /src/main/resources/applicationContext-server.xml,输入以下内容:
<!--******* applicationContext-server.xml start ************* -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="addressBookServiceImpl" class="com.bruce.cxftest.service.AddressBookServiceImpl" />
<bean id="myPasswordCallback" class="com.bruce.cxftest.security.ServerPasswordCallback" />
<bean id="sAAJInInterceptor" class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor" />
<bean id="wSS4JInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="passwordType" value="PasswordDigest" />
<entry key="passwordCallbackRef">
<ref bean="myPasswordCallback" />
</entry>
</map>
</constructor-arg>
</bean>
<jaxws:endpoint id="addressBookService" implementor="#addressBookServiceImpl"
address="/AddressBookService">
<jaxws:inInterceptors>
<ref bean="sAAJInInterceptor" />
<ref bean="wSS4JInInterceptor" />
</jaxws:inInterceptors>
</jaxws:endpoint>
</beans>
<!--******** applicationContext-server.xml end ************ -->
5 在目录/WebContent/WEB-INF 下创建名为 web.xml 的文件,输入以下内容:
<!-- web.xml **********start -->
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>xfireserver</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:applicationContext-server.xml
classpath:META-INF/cxf/cxf-extension-policy.xml
classpath:META-INF/cxf/cxf-extension-ws-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
<!-- web.xml **********end -->
第五部分:开发webservice服务客户端
在eclipse中建立名为cxftest_client的java工程,设置java源文件的目录为/src/main/java, 资源目录为/src/main/resources.
目录结构为:
cxftest_client
/src
/main
/java
/resources
在cxftest_client项目根目录建立名为pom.输入以下内容:
<!-- pom.xml start -->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bruce.cxftest</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>cxftest_build</artifactId>
<relativePath>../cxftest_build/pom.xml</relativePath>
</parent>
<artifactId>cxftest_client</artifactId>
<packaging>jar</packaging>
<name>cxf test client Project</name>
<build>
<finalName>${artifactId}-${version}</finalName>
<defaultGoal>process-resources</defaultGoal>
<plugins>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.bruce.cxftest</groupId>
<version>${version}</version>
<artifactId>cxftest_public_intf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>${wss4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>
<!-- pom.xml end -->
建立 服务测试类SpringUsersWsClient.java,输入以下内容
//************** SpringUsersWsClient start ********************
package com.bruce.cxftest.client;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.bruce.cxftest.dto.Phone;
import com.bruce.cxftest.service.AddressBookService;
public class SpringUsersWsClient {
public static void main(String[] args) {
try {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-client.xml");
AddressBookService service = ctx.getBean("addressBookClient", AddressBookService.class);
System.out.println("#############Client getPhone##############");
Phone phone = service.getPhone("zph");
System.out.println("AreaCode:" + phone.getAreaCode());
System.out.println("Exchange:" + phone.getExchange());
System.out.println("Number:" + phone.getNumber());
} catch (BeansException e) {
e.printStackTrace();
}
}
}
//**************SpringUsersWsClient end ********************
建立 用户认证回调类ServerPasswordCallback.java,输入以下内容
//************** ServerPasswordCallback start ********************
package com.bruce.cxftest.security;
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 ServerPasswordCallback implements CallbackHandler {
String userName = "joe";
String password = "password";
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword(password);
pc.setIdentifier(userName);
}
}
//**************ServerPasswordCallback end ********************
建立Client Service配置文件 /src/main/resources/ applicationContext-client.xml ,输入以下内容:
<!--******* applicationContext-client.xml start ************* -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="myPasswordCallback" class="com.bruce.cxftest.security.ServerPasswordCallback" />
<bean id="wSS4JOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="passwordType" value="PasswordDigest" />
<entry key="user" value="joe" />
<entry key="passwordCallbackRef">
<ref bean="myPasswordCallback" />
</entry>
</map>
</constructor-arg>
</bean>
<jaxws:client id="addressBookClient"
serviceClass="com.bruce.cxftest.service.AddressBookService"
address="http://127.0.0.1:9080/cxftest/service/AddressBookService">
<jaxws:outInterceptors>
<ref bean="wSS4JOutInterceptor" />
</jaxws:outInterceptors>
</jaxws:client>
</beans>
<!--******** applicationContext-client.xml end ************ -->
第六部分:调试运行
1.打开命令行转至cxftest_build目录,运行如下命令
$mvn clean install
$mvn eclipse:eclipse
2.将打好的Wea包拷贝至Tomcat webapps 目录下的 cxftest 目录中。
3.启动Tomcat
4.启动cxftest_client工程里的 SpringUsersWsClient 类:输出如下信息:
AreaCode:120
Exchange:10
Number:10
至此表明Webservice调用成功!
1.系统版本:Fedora14
2.Eclipse版本:J2ee版3.5
3.jdk版本:jdk1.6
4.maven local repository:/var/javaproject/repo
5.tomcat 版本:1.6
6.tomcat 端口:9080
假设以上环境已经安装完毕,各软件能独立正确运行。
第二部分:配置eclipse工作区
在适当的地方建立一个cxftest目录,然后在此目录再建一个cxftest_build目录
在cxftest_build目录中建立pom.xml文件,输入一下内容:
<!-- sub pom.xml start--->
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bruce.cxftest</groupId>
<artifactId>cxftest_build</artifactId>
<packaging>pom</packaging>
<name>cxf test Parent Project</name>
<version>1.0-SNAPSHOT</version>
<modules>
<module>../cxftest_public_impl</module>
<module>../cxftest_public_intf</module>
<module>../cxftest_web</module>
<module>../cxftest_client</module>
</modules>
<properties>
<wss4j.version>1.6.4</wss4j.version>
<spring.version>3.0.2.RELEASE</spring.version>
<cxf.version>2.5.2</cxf.version>
<junit.version>4.8.1</junit.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
</project>
<!-- sub pom.xml end --->
我的电脑最终目录结构为:
cxftest/
|/cxftest_build
|/cxftest_client
|/cxftest_public_impl
|/cxftest_public_intf
|/cxftest_web
并以 cxftest目录为基础建立eclipse 工作区
第二部分:开发公共接口项目
在eclipse中建立名为cxftest_public_intf的java工程,设置java源文件的目录为/src/main/java, 资源目录为/src/main/resorces
在cxftest_public_intf项目根目录建立名为pom.xml输入以下内容:
<!-- pom.xml start →
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bruce.cxftest</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>cxftest_build</artifactId>
<relativePath>../cxftest_build/pom.xml</relativePath>
</parent>
<artifactId>cxftest_public_intf</artifactId>
<packaging>jar</packaging>
<name>cxf test web service interface Project</name>
<build>
<finalName>${artifactId}-${version}</finalName>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/wsdl/service.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
</project>
<!-- pom.xml end -->
用eclipse自带的工具src/main/wsdl 目录编辑wsdl文件 service.wsdl与dto.xsd:
<!-- service.wsdl start -->
<?xml version="1.0" ?>
<wsdl:definitions targetNamespace="http://www.bruce.com/cxftest/service"
xmlns:service="http://www.bruce.com/cxftest/service"
xmlns:dto="http://www.bruce.com/cxftest/dto"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.bruce.com/cxftest/dto" schemaLocation="dto.xsd">
</xsd:import>
</xsd:schema>
</wsdl:types>
<wsdl:message name="GetPhoneRequest">
<wsdl:part name="name" element="dto:getPhoneRequest" />
</wsdl:message>
<wsdl:message name="GetPhoneResponse">
<wsdl:part name="phone" element="dto:getPhoneResponse" />
</wsdl:message>
<wsdl:portType name="AddressBookService">
<wsdl:operation name="getPhone">
<wsdl:input message="service:GetPhoneRequest" />
<wsdl:output message="service:GetPhoneResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AddressBook" type="service:AddressBookService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getPhone">
<soap:operation
soapAction="http://www.bruce.com/cxftest/service/getPhone" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AddressBookService">
<wsdl:port name="AddressBookService" binding="service:AddressBook">
<soap:address location="http://www.bruce.com/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<!-- service.wsdl end -->
<!-- dto.xsd start -->
<?xml version="1.0" ?>
<xsd:schema targetNamespace="http://www.bruce.com/cxftest/dto" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dto="http://www.bruce.com/cxftest/dto">
<xsd:complexType name="Phone">
<xsd:sequence>
<xsd:element name="areaCode" type="xsd:int" />
<xsd:element name="exchange" type="xsd:int" />
<xsd:element name="number" type="xsd:int" />
<xsd:element name="date" type="xsd:date"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="getPhoneRequest" type="xsd:string"></xsd:element>
<xsd:element name="getPhoneResponse" type="dto:Phone"></xsd:element>
</xsd:schema>
<!-- dto.xsd end -->
在目录cxftest/cxftest_public_intf/ 下运行:
#mvn install
以生成Webservice的接口与Dto类。
第三部分:开发公共实现项目
在eclipse中建立名为cxftest_public_impl的java工程,设置java源文件的目录为/src/main/java, 资源目录为/src/main/resorces
在cxftest_public_impl项目根目录建立名为pom.xml输入以下内容:
<!-- pom.xml start →
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bruce.cxftest</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>cxftest_build</artifactId>
<relativePath>../cxftest_build/pom.xml</relativePath>
</parent>
<artifactId>cxftest_public_impl</artifactId>
<packaging>jar</packaging>
<name>cxf test web service implement Project</name>
<build>
<finalName>${artifactId}-${version}</finalName>
<defaultGoal>process-resources</defaultGoal>
<plugins>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.bruce.cxftest</groupId>
<version>${version}</version>
<artifactId>cxftest_public_intf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>${wss4j.version}</version>
</dependency>
</dependencies>
</project>
<!-- pom.xml end -->
建立 服务实现类com.bruce.cxftest.service.AddressBookServiceImpl,输入以下内容(这个类应该也有相应的工具生成,但是我还没找到):
//**************AddressBookServiceImpl start ********************
package com.bruce.cxftest.service;
import com.bruce.cxftest.dto.Phone;
public class AddressBookServiceImpl implements AddressBookService {
@Override
public Phone getPhone(String name) {
Phone phone;
System.out.println(name);
phone = new Phone();
phone.setAreaCode(120);
phone.setExchange(10);
phone.setNumber(10);
return phone;
}
}
//**************AddressBookServiceImpl end ********************
建立 服务端用户回调类类com.bruce.cxftest.security . ServerPasswordCallback,输入以下内容(这个类应该也有相应的工具生成,但是我还没找到):
//**************ServerPasswordCallback start ********************
package com.bruce.cxftest.security;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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 ServerPasswordCallback implements CallbackHandler {
Map<String,String> userMap = new HashMap<String,String>();
public ServerPasswordCallback(){
userMap.put("joe", "password");
}
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
if (userMap.containsKey(pc.getIdentifier())) {
pc.setPassword(userMap.get(pc.getIdentifier()));
}
}
}
第四部分:开发公共WEB服务项目
在eclipse中建立名为cxftest_web的java工程,设置java源文件的目录为/src/main/java, 资源文件目录为 /src/main/resources.
目录结构为:
cxftest_web
/src
| /main
| /java
| /resources
/WebContent
/WEB-INF
/classes
/lib
在cxftest_web项目根目录建立名为pom.输入以下内容:
<!-- pom.xml start -->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bruce.cxftest</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>cxftest_build</artifactId>
<relativePath>../cxftest_build/pom.xml</relativePath>
</parent>
<artifactId>cxftest_web</artifactId>
<packaging>war</packaging>
<name>cxf test web Project</name>
<build>
<finalName>${artifactId}-${version}</finalName>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>${basedir}/WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.bruce.cxftest</groupId>
<version>${version}</version>
<artifactId>cxftest_public_intf</artifactId>
</dependency>
<dependency>
<groupId>com.bruce.cxftest</groupId>
<version>${version}</version>
<artifactId>cxftest_public_impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-common-utilities</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-policy</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>
<!-- pom.xml end -->
建立Service配置文件 /src/main/resources/applicationContext-server.xml,输入以下内容:
<!--******* applicationContext-server.xml start ************* -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="addressBookServiceImpl" class="com.bruce.cxftest.service.AddressBookServiceImpl" />
<bean id="myPasswordCallback" class="com.bruce.cxftest.security.ServerPasswordCallback" />
<bean id="sAAJInInterceptor" class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor" />
<bean id="wSS4JInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="passwordType" value="PasswordDigest" />
<entry key="passwordCallbackRef">
<ref bean="myPasswordCallback" />
</entry>
</map>
</constructor-arg>
</bean>
<jaxws:endpoint id="addressBookService" implementor="#addressBookServiceImpl"
address="/AddressBookService">
<jaxws:inInterceptors>
<ref bean="sAAJInInterceptor" />
<ref bean="wSS4JInInterceptor" />
</jaxws:inInterceptors>
</jaxws:endpoint>
</beans>
<!--******** applicationContext-server.xml end ************ -->
5 在目录/WebContent/WEB-INF 下创建名为 web.xml 的文件,输入以下内容:
<!-- web.xml **********start -->
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>xfireserver</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:applicationContext-server.xml
classpath:META-INF/cxf/cxf-extension-policy.xml
classpath:META-INF/cxf/cxf-extension-ws-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
<!-- web.xml **********end -->
第五部分:开发webservice服务客户端
在eclipse中建立名为cxftest_client的java工程,设置java源文件的目录为/src/main/java, 资源目录为/src/main/resources.
目录结构为:
cxftest_client
/src
/main
/java
/resources
在cxftest_client项目根目录建立名为pom.输入以下内容:
<!-- pom.xml start -->
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.bruce.cxftest</groupId>
<version>1.0-SNAPSHOT</version>
<artifactId>cxftest_build</artifactId>
<relativePath>../cxftest_build/pom.xml</relativePath>
</parent>
<artifactId>cxftest_client</artifactId>
<packaging>jar</packaging>
<name>cxf test client Project</name>
<build>
<finalName>${artifactId}-${version}</finalName>
<defaultGoal>process-resources</defaultGoal>
<plugins>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.bruce.cxftest</groupId>
<version>${version}</version>
<artifactId>cxftest_public_intf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>${wss4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>
<!-- pom.xml end -->
建立 服务测试类SpringUsersWsClient.java,输入以下内容
//************** SpringUsersWsClient start ********************
package com.bruce.cxftest.client;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.bruce.cxftest.dto.Phone;
import com.bruce.cxftest.service.AddressBookService;
public class SpringUsersWsClient {
public static void main(String[] args) {
try {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext-client.xml");
AddressBookService service = ctx.getBean("addressBookClient", AddressBookService.class);
System.out.println("#############Client getPhone##############");
Phone phone = service.getPhone("zph");
System.out.println("AreaCode:" + phone.getAreaCode());
System.out.println("Exchange:" + phone.getExchange());
System.out.println("Number:" + phone.getNumber());
} catch (BeansException e) {
e.printStackTrace();
}
}
}
//**************SpringUsersWsClient end ********************
建立 用户认证回调类ServerPasswordCallback.java,输入以下内容
//************** ServerPasswordCallback start ********************
package com.bruce.cxftest.security;
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 ServerPasswordCallback implements CallbackHandler {
String userName = "joe";
String password = "password";
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
pc.setPassword(password);
pc.setIdentifier(userName);
}
}
//**************ServerPasswordCallback end ********************
建立Client Service配置文件 /src/main/resources/ applicationContext-client.xml ,输入以下内容:
<!--******* applicationContext-client.xml start ************* -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="myPasswordCallback" class="com.bruce.cxftest.security.ServerPasswordCallback" />
<bean id="wSS4JOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="passwordType" value="PasswordDigest" />
<entry key="user" value="joe" />
<entry key="passwordCallbackRef">
<ref bean="myPasswordCallback" />
</entry>
</map>
</constructor-arg>
</bean>
<jaxws:client id="addressBookClient"
serviceClass="com.bruce.cxftest.service.AddressBookService"
address="http://127.0.0.1:9080/cxftest/service/AddressBookService">
<jaxws:outInterceptors>
<ref bean="wSS4JOutInterceptor" />
</jaxws:outInterceptors>
</jaxws:client>
</beans>
<!--******** applicationContext-client.xml end ************ -->
第六部分:调试运行
1.打开命令行转至cxftest_build目录,运行如下命令
$mvn clean install
$mvn eclipse:eclipse
2.将打好的Wea包拷贝至Tomcat webapps 目录下的 cxftest 目录中。
3.启动Tomcat
4.启动cxftest_client工程里的 SpringUsersWsClient 类:输出如下信息:
AreaCode:120
Exchange:10
Number:10
至此表明Webservice调用成功!
发表评论
-
windows10上编译openjdk12
2019-10-09 18:36 6751. 安装cygwin64 下载地址: https://c ... -
Windows10上优化Tomcat9速度
2019-10-07 23:59 902一、环境 OS:windows10 CPU:I7-67 ... -
Java调用tesseract识别中文
2019-05-09 14:57 1255环境: java:jdk1.8 os:windows1 ... -
java实现逻辑回归
2019-05-03 23:41 833pom.xml <!-- 用于矩阵运算 --&g ... -
java实现决策树算法
2018-09-17 23:06 1881决策树 package decisiontree; ... -
opencv 读取摄像头数据
2018-08-14 08:28 1549opencv 读取摄像头数据代码: package ope ... -
opencv 播放视频
2018-08-14 08:26 621opencv播放视频代码: package openvc; ... -
windows10上配置opencv开发环境
2018-08-14 08:21 9521. 下载opencv 3.4.2 地址:htt ... -
centos7上编译openjdk10
2018-08-07 19:34 956一、准备 确保服务器能连上网,最好能连国外的网。 安装J ... -
window10上编译openjdk9
2018-08-06 10:26 11851. 安装cygwin64 下载地址: https://c ... -
软件调用时间数量级
2017-08-04 14:21 348No. 类型类型 耗时 1 本地 ... -
加快tomcat8启动速度
2017-02-08 09:28 16501.禁止Servlet 3扫描 修改tomcat/conf/c ... -
CXF Message Level Security
2016-03-28 15:10 657The firsts:Environment 1.Opera ... -
MAVEN 常用命令
2016-03-28 14:57 4911.下载包的源文件与文旦 mvn eclipse:eclips ... -
iReport&Jaspereport 显示二维码
2016-03-25 10:05 16981) 将 ZXing’s Core and JavaSE ja ... -
window10上编译openJDK8
2016-02-03 11:37 20811. MinGW + msys + OpenJDK8: 我已经 ...
相关推荐
【标签】:“cxf例子认证登录客户端,cxf学习,cxf实例,cxf” 这些标签突出了几个关键的学习点:首先,你需要熟悉CXF的基础知识,包括如何创建服务和客户端;其次,了解如何实现认证机制,这对于任何涉及用户访问...
【CXF入门例子(安全认证)】 Apache CXF 是一个开源的 Java 框架,主要用于构建和开发服务导向架构(SOA)和 RESTful Web 服务。它提供了丰富的功能,包括SOAP、REST、WS-* 标准支持、数据绑定、JAX-RS 和 JAX-WS ...
Apache CXF 安全认证主要涉及两种机制:基于密码的安全认证和基于CA证书的安全认证。 首先,基于密码的安全认证方法需要在客户端和服务端配置相应的拦截器以实现用户验证。客户端配置包括使用`WSS4JOutInterceptor`...
【CXF WSSCEURITRY 身份认证demo】是一个关于在WEB服务中使用Apache CXF框架实现WS-Security(Web Services Security)标准的身份验证的示例项目。该示例着重展示了如何在CXF中配置和使用WS-SecureConversation(WS-...
同时,`org.apache.cxf.interceptor.security.BasicAuthInterceptor`拦截器处理了实际的身份验证过程,它会检查收到的请求是否包含正确的认证信息。 工具方面,CXF提供了多种工具帮助开发者管理和调试服务,如CXF的...
在Web服务中,安全认证是验证客户端请求的身份的过程,以确保只有授权的用户或系统可以访问服务。在CXF中,我们可以使用WS-Security(Web Services Security)标准来实现这一功能,它支持多种安全机制,如用户名令牌...
基于spring+cxf实现用户文件传输的webservice 在本文中,我们将探讨如何使用Spring+CXF实现用户文件传输的Webservice。该Webservice提供了基本的报文上传和查询功能,同时还提供了用户身份验证功能。 Spring 和 ...
在Web服务中,认证是确保用户身份的过程,而授权则是决定用户可以执行哪些操作。在CXF中,我们可以使用WS-Security(Web Services Security)标准来实现这一功能,其中包含了用户名令牌(Username Token)策略,允许...
本实例将详细介绍如何在Spring环境中集成CXF,并使用WSS4J进行安全认证。 **一、Spring与CXF集成** 1. **配置CXFServlet**: 首先,我们需要在Spring的`web.xml`配置文件中声明CXF的Servlet,如`...
3. 配置Spring Security以实现认证。 4. 使用CXF生成客户端代码。 5. 在客户端应用中创建代理对象并调用服务。 通过这种方式,你可以构建安全、可靠的Web服务,并在Spring Boot环境中轻松地进行客户端调用。
apache cxf 2.1.3 的用户手册
在CXF中,这可以通过实现不同级别的安全性来完成,如基本认证、OAuth、WS-Security等。我们将重点讨论基本认证和WS-Security这两种常见的实现方式。 1. **基本认证**: 基本认证是最简单的HTTP身份验证形式,它...
【描述】中的“客户端和服务端都已经做好了”意味着这个示例包含了完整的CXF服务端应用和客户端应用,用户可以直接运行体验安全验证的过程。同时,提到的“包含cxf所有的jar”,表明压缩包中可能包含了CXF框架的所有...
接下来,命令会提示用户输入一些关于密钥的信息,例如组织名称、城市、国家等。这些信息构成了 X.509 标准中的 Distinguished Name (DN)。 ### 步骤二:配置 Tomcat 服务器 完成密钥库的创建后,下一步是在 Tomcat...
8. **cxf-rt-ws-security.jar**: 包含了WS-Security和其他安全相关的实现,用于Web服务的安全认证和加密。 9. **cxf-tools-common.jar** 和 **cxf-tools-wsdlto-core.jar** 等工具类库,用于生成服务端和客户端代码...
Apache CXF支持多种安全模型,包括基本认证、digest认证、WS-Security(如WS-SecurityPolicy、WS-Trust等)以及OAuth等。 标题“使用CXF的Web服务安全验证”提示我们关注的重点是通过CXF实现Web服务的安全配置。CXF...
6. **安全特性**:CXF集成了多种安全机制,包括基本认证、 Digest 认证、WS-Security(如WS-SecureConversation和WS-Trust),以确保Web服务的安全性。 7. **扩展性**:CXF的模块化设计使其易于扩展,用户可以根据...
本篇文章详细介绍了WebService的基本概念和AXIS、XFire、CXF这三个流行的Java WebService框架,以及授权认证和加密解密在WebService中的应用。这些内容对于理解和实践WebService开发具有重要价值,为开发者提供了...
例如,如果你的Web服务不涉及安全认证,可以不包含`cxf-rt-ws-security.jar`;如果不需要集群,那么`cxf-rt-features-clustering.jar`也可以省略。但请注意,精简过多可能会导致功能缺失或运行错误,因此需要确保你...
配置: trial-cxf-server.xml 其中配置了对传入请求的拦截器用以验证调用者身份 验证程序: WsServerAuthHandler. 这里只需要提供调用者应该使用的正确的口令. 是否和调用者实际传入的口令一致,由cxf完成. web.xml ...