cxf的使用及安全校验-01创建简单的服务端接口
最近因为项目的需要,研究了一下webservice的使用;
这里以cxf2.7.0为例,大致介绍一下,也用于备份啦(张立胜)
大致介绍一下项目的情况:项目有maven管理,webservice调用的方式cxf(是通过接口地址在客户端先生成相关文件)
我们先来介绍服务端:
1.引入相关jar包,因为项目是通过maven管理的,所以直接在pom文件添加
<dependency>
<groupId>org.apache</groupId>
<artifactId>cxf</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0-beta3</version>
</dependency>
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.6.10</version>
</dependency>
2.创建webservice接口,例如:
package com.cpic.caf.demo.service;
import javax.jws.WebService;
@WebService
public interface GreetingService {
public String greeting(String username);
}
3.创建webservice接口的实现类
package com.cpic.caf.demo.service.impl;
import javax.jws.WebService;
import com.cpic.caf.demo.service.GreetingService;
@WebService(endpointInterface="com.cpic.caf.demo.service.GreetingService")
public class GreetingServiceImpl implements GreetingService {
@Override
public String greeting(String username) {
return "Hello ! " + username;
}
}
4.配置applicationContext.xml文件
在xml文件中配置我们要发布的webservice接口,
<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" />
<jaxws:endpoint id="greetingService"
implementor="com.cpic.caf.demo.service.impl.GreetingServiceImpl"
address="/greetingService" >
</jaxws:endpoint>
注:在此xml文件头中要添加上 xmlns:jaxws="http://cxf.apache.org/jaxws",xsi:schemaLocation后面要加上http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd ,不然启动的时候会报<jaxws:endpoint>无法识别的错误
5.配置web.xml
在web.xml中添加
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<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>/webservice/*</url-pattern><!--这样配置后,本例的接口地址则为 localhost:8080(ip地址)/项目名/webservice/greetingService-->
</servlet-mapping>
现在启动你的项目,看是否可以正常访问你的接口地址localhost:8080(ip地址)/项目名/webservice/greetingService?wsdl
cxf的使用及安全校验-01创建简单的服务端接口的更多相关文章
- cxf的使用及安全校验-02创建简单的客户端接口
上一篇文章中,我们已经讲了如果简单的创建一个webservice接口 http://www.cnblogs.com/snowstar123/p/3395568.html 现在我们创建一个简单客户端接口 ...
- 创建APPID&&部署服务端教程
创建APPID&&部署服务端 一.创建APPID 1.打开https://console.developers.google.com ,左击顶部Project,然后左击创建项目 2.输 ...
- 创建配置中心服务端(Spring Cloud Config)
创建配置中心服务端 创建好项目后添加配置文件内容 server.port=9004 spring.application.name=spring-cloud-config-server-01 #git ...
- SpringCloud02 Eureka知识点、Eureka服务端和客户端的创建、Eureka服务端集群、Eureka客户端向集群的Eureka服务端注册
1 Eureka知识点 按照功能划分: Eureka由Eureka服务端和Eureka客户端组成 按照角色划分: Eureka由Eureka Server.Service Provider.Servi ...
- 利用IDEA创建Web Service服务端和客户端的详细过程
创建服务端 一.file–>new–>project 二.点击next后输入服务端名,点击finish,生成目录如下 三.在 HelloWorld.Java 文件中右击,选 WebServ ...
- 使用PHP创建一个socket服务端
与常规web开发不同,使用socket开发可以摆脱http的限制.可自定义协议,使用长连接.PHP代码常驻内存等.学习资料来源于workerman官方视频与文档. 通常创建一个socket服务包括这几 ...
- [Swift通天遁地]四、网络和线程-(14)创建一个Socket服务端
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- WebSocketSharp 创建客户端和服务端
这里没有对onOpen.onClose.onError做案例,生产环境需要具备. 1.客户端 只推送不接收数据 创建WebSocketClient类 class WebSocketClient { W ...
- Axis2创建WebService服务端接口+SoupUI以及Client端demo测试调用
第一步:引入axis2相关jar包,如果是pom项目,直接在pom文件中引入依赖就好 <dependency> <groupId>org.apache.axis2</gr ...
随机推荐
- MRC和ARC混编
iOS5.0以后就开始可以使用ARC( Automatic Reference Counting:自动引用计数)来代替之前的MRC(Manual Reference Counting:人工引用计数). ...
- 你好,C++(20).4.2.2 表达并列条件选择的switch语句:如果……如果……如果……
4.2.2 表达并列条件选择的switch语句:如果……如果……如果…… 在现实世界中,还有这样一类特殊的条件选择: 如果明天是晴天,我就穿T恤: 如果明天是阴天,我就穿衬衣: 如果明天是雨天,我就 ...
- 用jquery向网页添加背景图片 拉伸 模糊 遮罩层 代码
方法一:手动添加 1.在body内任意位置添加html代码 <div id="web_bg" style=" position:fixed; _position:a ...
- EasyUI datagrid简单运用
jquery的前端框架挺多的,有easyUI ,bootstrap...,对于做系统软件或许easyUI比较好,因为里面控件很丰富,而bootstrap非常简洁大方,但是控件相 对比较少,特别是复杂的 ...
- 字符串时间日期转为Date格式和long格式
public static Long compare_date(String DATE1, String DATE2) { DateFormat df = new SimpleDateFormat(& ...
- 程序被送入后台后,向 iOS 借时间,完成长期任务-备
12.2.2. 方案 使用UIApplication的beginBackgroundTaskWithExpirationHandler: 实例方法.在你完成任务后,调用UIApplication的en ...
- 调用Android系统设置中的Intent
开发Android软件时,常常需要打开系统设置或信息界面,来设置相关系统项或查看系统的相关信息,这时我们就可以使用以下语句来实现:(如打开“无线和网络设置”界面) Intent intent = ne ...
- HADOOP都升级到2.5啦~~~
经过前年的初次接触,现在已大约能理解整个体系啦.MAPREDUCE都改成YARN啦. 不过,还得继续往前走,再能实用... HIVE,HBASE,ZOOKEEPER,, 思路如下: 安装系统,配置网络 ...
- Codeforces 4D Mysterious Present
http://codeforces.com/contest/4/problem/D 题目大意: 给出n个信封,这n个信封有长和宽,给出卡片的尺寸,求取能够装入卡片的最长的序列,序列满足后一个的长和宽一 ...
- Bootstrap风格登录界面设计样例
参考:http://bootsnipp.com/tags/login Register Page 127.8K 187 Modal Login with jQuery Effects 159. ...