通过CXF,开发soap协议接口
1. 引入cxf的jar包
pom文件里面直接增加依赖
< dependency>
<groupId > junit</ groupId>
<artifactId > junit</ artifactId>
<version >4.11 </version >
<scope >test </scope >
</dependency >
<dependency >
<groupId >org.springframework </groupId >
<artifactId >spring- webmvc</ artifactId>
<version >4.0.0.RELEASE </version >
</dependency >
<dependency >
<groupId >org.apache.cxf </groupId >
<artifactId > apache-cxf </artifactId >
<version >2.4.3</version >
<type > pom</ type>
</dependency >
2. 配置web.xml文件
<? xml version= "1.0" encoding= "UTF-8" ?>
< web-app xmlns= "http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation= "http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version= "3.1" >
< display-name >Archetype Created Web Application </display-name >
< context-param >
<param-name >contextConfigLocation </param-name >
<param-value >classpath:config/spring/metadataWebService-spring.xml </param-value >
</context-param >
<listener >
<listener-class >org.springframework.web.context.ContextLoaderListener </listener-class >
</listener >
<servlet >
<servlet-name >CXFServlet </servlet-name >
<servlet-class >org.apache.cxf.transport.servlet.CXFServlet </servlet-class >
</servlet >
<servlet-mapping >
<servlet-name >CXFServlet </servlet-name >
<url-pattern >/services/* </url-pattern >
</servlet-mapping >
<filter >
<filter-name >encodingFilter </filter-name >
< filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class >
<init-param >
<param-name >encoding </param-name >
<param-value >UTF-8 </param-value >
</init-param >
<init-param >
<param-name >forceEncoding </param-name >
<param-value >true </param-value >
</init-param >
</filter >
<filter-mapping >
<filter-name >encodingFilter </filter-name >
<url-pattern >/* </url-pattern >
</filter-mapping >
</ web-app>
3. 配置cxf.xml文件
<? xml version= "1.0" encoding= "UTF-8" ?>
< beans xmlns= "http://www.springframework.org/schema/beans"
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws= "http://cxf.apache.org/jaxws"
xmlns:context= "http://www.springframework.org/schema/context"
xmlns:jaxrs= "http://cxf.apache.org/jaxrs"
xsi:schemaLocation= "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd" >
<!-- simpleWebService.xml配置文件 start -->
<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" />
<context:annotation-config />
<!-- SOAP 服务开放 -->
<bean id = "wSS4JInInterceptor" class= "org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor" >
<constructor-arg >
<!--
<map >
<entry key = "action" value= "UsernameToken" />
<entry key = "passwordType" value= "PasswordText" />
<entry key = "user" value= "cxfServer" />
<entry key = "passwordCallbackRef" value= "ss" />
</map >
-->
</constructor-arg >
</bean >
<bean id = "jaxWsServerFactoryBean" class= "org.apache.cxf.jaxws.JaxWsServerFactoryBean"
scope= "prototype" >
<property name = "inInterceptors">
<list >
<!-- <ref bean = "wSS4JInInterceptor" /> -->
</list >
</property >
</bean >
<bean id = "jaxWsWebServicePublisherBeanPostProcessor"
class= "org.apache.cxf.jaxws.spring.JaxWsWebServicePublisherBeanPostProcessor" >
<property name = "urlPrefix" value= "/" />
<property name = "prototypeServerFactoryBeanName" value= "jaxWsServerFactoryBean" />
</bean >
<!-- simpleWebService.xml配置文件 end-->
<!-- 导入soap协议的服务支持 serviceClass为对应的webService接口类-->
< jaxws:server id= "ResumeUpload" serviceClass= "com.sigmatrix.soap.webService.DemoService"
address= "/ResumeUpload" >
<!-- 添加webService接口实现类 -->
<jaxws:serviceBean >
<ref bean = "demoServiceImpl" />
</jaxws:serviceBean >
<!-- 添加协议 使用MTOM附件-->
<jaxws:properties >
<entry key = "mtom-enabled" value= "true" />
</jaxws:properties >
</jaxws:server >
</ beans>
4. 要开放的接口加上cxf服务的注解
接口类:
@WebService (portName = "inbound.webServices.ticket.saServiceSoap12" )
@javax.xml.ws.soap. MTOM
public interface DemoService {
@WebMethod
public String demo( @WebParam(name = "demo") Demo demo);
}
接口实现类:
@Component
@WebService (portName = "inbound.webServices.ticket.saServiceSoap12" )
@BindingType (value = "http://www.w3.org/2003/05/soap/bindings/HTTP/" )
public class DemoServiceImpl implements DemoService {
public String Demo(Demo demo) {
String userName = demo.getUserName();
String password= demo.getPassword();
return "success";
}
Demo实体类:
public Class Demo() {
public String userName;
public String 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;
}
}
5. 部署到tomcat启动即可,测试访问 ip:端口号//项目名称/services/
通过CXF,开发soap协议接口的更多相关文章
- JMeter5.1开发Java协议接口脚本【待完成】
JMeter5.1开发Java协议接口脚本
- 通过CXF,开发rest协议接口
1. 引入cxf的jar包 pom文件里面直接增加依赖 < dependency> <groupId > junit</ groupId> <artifact ...
- WebService- 使用 CXF 开发 SOAP 服务
选框架犹如选媳妇,选来选去,最后我还是选了“丑媳妇(CXF)”,为什么是它?因为 CXF 是 Apache 旗下的一款非常优秀的 WS 开源框架,具备轻量级的特性,而且能无缝整合到 Spring 中. ...
- (二)使用CXF开发WebService服务器端接口
CXF作为java领域主流的WebService实现框架,Java程序员有必要掌握它. CXF主页:http://cxf.apache.org/ 简介:百度百科 今天的话,主要是用CXF来开发下Web ...
- cxf+spring+soap简单接口开发
最近学了cxf框架开发webservice,简单搭了个接口,方便后续翻阅,本人才疏学浅,若有不足,请多多谅解! 一.服务端: 1.所用到的jar包: maven的pom.xml配置: <proj ...
- JMeter5.1开发TCP协议接口脚本
最简单的方法,就是找开发给报文,直接复制到tcp取样器中,将需要变化的值做参数化就可以了.(xml报文要去掉回车换行) 下面是一个通讯头定义 通讯头56个字节(1个字符一个字节) 3 + 9 + 9 ...
- LoadRunner开发ftp协议接口之上传文件脚本
Action() { //建立一个ftp对象 FTP ftp1=0; //建立FTP连接并登录 ftp_logon_ex(&ftp1,"ftpLogon", "U ...
- LoadRunner开发http协议接口之form表单脚本
loadrunner传form表单,用web_submit_data函数. Action() { // lr_start_transaction("hp_homepage"); / ...
- JMeter5.1开发http协议接口之form表单脚本
get请求--jmeter:form表单 下载文件 响应结果 post请求--jmeter:form表单 登录请求 响应结果 post请求--jmeter:form表单中传token 请求(token ...
随机推荐
- 查看分析器(Analyzer)的分词效果
1 测试代码 package com.test.lucene.helloworld; import org.apache.lucene.analysis.Analyzer; import org.ap ...
- 【随笔】nginx下的301跳转,两个域名指向同一个服务器ip
301跳转 页面永久性移走,通常叫做301跳转,也叫301重定向,301转向. 指的是当用户点击一个网址时,通过技术手段,跳转到指定的一个网站. 用以解决两个域名指向同一个服务器ip,当访问m.xxx ...
- a[i]==i[a]==*(i+a)==*(a+i)
在C语言中,如果我们要访问一个数组的某个下标对应的元素,通常的写法是a[i].但从汇编的角度看,写成i[a]一点问题都没有. 下面通过代码给出证明. o foo1.c int main(int arg ...
- 关于发布webservice提示The test form is only available for requests from the local machine
通过编辑 Web 服务所在的 vroot 的 Web.config 文件,可以启用 HTTP GET 和 HTTP POST.以下配置同时启用了 HTTP GET 和 HTTP POST: <c ...
- nginx启动,停止,重启
Nginx的启动.停止与重启 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/ ...
- 如何优雅的封装一个DOM事件库
1.DOM0级事件和DOM2级事件 DOM 0级事件是元素内的一个私有属性:div.onclick = function () {},对一个私有属性赋值(在该事件上绑定一个方法).由此可知DOM 0级 ...
- 【HTML基础】表格和表单
本次博客的主要内容如下: meta和link 表格 表单 meta和link meta meta的属性有两种:name和http-equiv. name属性主要用于描述网页内容,对应与网页内容. 1. ...
- [转]NLog 自定义字段 写入 oracle
本文转自:http://www.cnblogs.com/skyapplezhao/p/5690695.html 1.通过Nuget安装NLog 下载,简单入门 请参照 我刚才转的几篇文章,下面我直接贴 ...
- Autofac +webapi 配置
Autofac配置 using Autofac; using System; using System.Collections.Generic; using System.Linq; using Sy ...
- 另一个C#模拟post请求的例子
private string returninstallTmnl(AddTmnlInstallParameter model) { string url = ConfigurationSettings ...