webservice的几种验证方式(一)基于JAX-WS
来源:互联网 发布:天天p图软件 编辑:程序博客网 时间:2024/06/08 08:19
近年来,随着面向服务的平台的大规模开放,异构程序之间的通信的需求不断增多,随之而来的就是webservice的蓬勃发展。
Java中用来构建webservice的主流技术有Axis2,JAX-WS,CXF(主要对JAX-WS进行了一系列的封装)。
今天主要给大家介绍一些关于webservice的验证或者说是权限管理,本文主要针对JAX-WS进行说明,JAX-WS是基本适用于所有的的webservice调用,而且它主要依赖于JDK,额外需要的jar很少,我个人认为JAX-WS适用和灵活可以和很多框架结合适用,比如Spring,SSH,SpringMVC框架。只要能够掌握JAX-WS在平时的工作中使用就绰绰有余了。
回归正题还是来说webservice的验证,为什么要做webservice的验证,基本上都是为了数据安全考虑,当然也有特殊原因。
webservice的验证主要有一下几种验证方式:
1.在获取wsdl文件的时候验证
2.在soap head中验证
一、在获取wsdl文件的时候验证
1、基本原理:其实就是拦截特定的请求,例如我要获取wsdl的时候,对方提供wsdl路径是http://www.baidu.com/XXX/HelloServiceImplPort?wsdl,只要我门获取到这个地址在测试工具XMLSpy中输入这个地址时会弹出这个对话框,要求你输入用户名和密码。
2、实现方式
2.1服务器实现方式
这里我使用的是SSH框架,其实主要就是webservice和Spring的集成。我把关键的地方贴出来
a.在tomcat中配置用户名和密码
1.找到tomcat安装目录---->conf------>tomcat-users.xml,创建用户名和密码都为tomcat
2.客户端程序
</pre><pre name="code" class="html">这是一个接口
package com.webservice;
import java.util.List;import javax.jws.WebService;import com.xx.bean.Campaign;import com.xx.bean.Campaigntarget;@WebServicepublic interface CRM_CampaignService {public boolean addCampaign(List<Campaign> list);public boolean addCampaigntarget(List<Campaigntarget> list);}
这是接口实现方式,把方法中的代码都去掉了,这里涉及到和Spring整合
package com.webservice;import java.util.List;import javax.jws.HandlerChain;import javax.jws.WebService;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.springframework.beans.factory.annotation.Autowired;import com.xx.bean.Campaign;import com.xx.bean.Campaigntarget;@WebService(endpointInterface="com.webservice.CRM_CampaignService")public class CRM_CampaignServiceImpl implements CRM_CampaignService{@Autowiredprivate CampaignService campaignService;@Autowiredprivate CampaigntargetService campaigntargetService;@Autowiredprivate SessionFactory sessionFactory;@Overridepublic boolean addCampaign(List<Campaign> list) {}@Overridepublic boolean addCampaigntarget(List<Campaigntarget> list) {}}
这是web.xml配置
<description> JAX-WS endpoint - CRM_CampaignServiceImplService</description> <display-name>CRM_CampaignServiceImplService</display-name><servlet-name>CRM_CampaignServiceImplService</servlet-name> <servlet-class> com.sun.xml.ws.transport.http.servlet.WSSpringServlet </servlet-class> </servlet><servlet-mapping> <servlet-name>CRM_CampaignServiceImplService</servlet-name> <url-pattern>/CRM_CampaignServiceImplPort</url-pattern></servlet-mapping>
<security-role> <description>Normal operator user</description> <role-name>tomcat</role-name> </security-role> <security-constraint> <span style="white-space:pre"></span> <web-resource-collection> <span style="white-space:pre"></span> <web-resource-name>Operator Roles Security</web-resource-name> <span style="white-space:pre"></span> <span style="white-space:pre"></span><url-pattern>/CRM_CampaignServiceImplPort</url-pattern> <span style="white-space:pre"></span> </web-resource-collection> <span style="white-space:pre"></span><auth-constraint> <span style="white-space:pre"></span> <role-name>tomcat</role-name> <span style="white-space:pre"></span></auth-constraint> <user-data-constraint> <span style="white-space:pre"></span> <transport-guarantee>NONE</transport-guarantee> <pre name="code" class="html"><span style="white-space:pre"></span></user-data-constraint>
</security-constraint> <span style="font-family: Arial, Helvetica, sans-serif;"> </span>
<login-config> <auth-method>BASIC</auth-method> </login-config>
这是Spring配置文件,注意红线加粗的地方,这是要额外引入的
<?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:context="http://www.springframework.org/schema/context"<strong style="background-color: rgb(255, 102, 0);">xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"</strong> xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd<strong><span style="color:#ff0000;">http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd"</span></strong>default-autowire="byName" default-lazy-init="true">
<bean id="cRM_CampaignService" class="com.webservice.CRM_CampaignServiceImpl"/> <wss:binding url="/CRM_CampaignServiceImplPort"> <wss:service> <ws:service bean="#cRM_CampaignService" /> </wss:service> </wss:binding>
到这里服务端基本完成了,输入访问地址就会出来这个对话框
输入用户名和密码都是tomcat
然后就可以看到wsdl文件
在这里获取wsdl是需要的验证基本上就结束了,有什么错误还请大家斧正。
- webservice的几种验证方式(一)基于JAX-WS
- 基于Java的webservice创建与jax-ws方式调用
- webservice学习笔记(一) - 基于JAX-WS的入门示例
- webservice学习笔记(一) - 基于JAX-WS的入门示例
- WebService—快速实现一个基于JAX-WS的WebService项目(一)
- WebService—快速实现一个基于JAX-WS的WebService项目(一)
- WebService—快速实现一个基于JAX-WS的WebService项目(一)
- 基于Xfire SOAP Header的WebService安全验证(xfire服务端,jax-ws和xfire两种客户端)
- 基于JAX-WS规范的WebService实现
- 基于JAX-WS的webService开发实例
- webservice快速入门-使用JAX-WS注解的方式快速搭建ws服务端和客户端(一)
- webservice快速入门-使用JAX-WS注解的方式快速搭建ws服务端和客户端(一)
- webservice快速入门-使用JAX-WS注解的方式快速搭建ws服务端和客户端(一)
- webservice快速入门-使用JAX-WS注解的方式快速搭建ws服务端和客户端(一)
- webservice快速入门-使用JAX-WS注解的方式快速搭建ws服务端和客户端(一)
- 基于CXF的JAX-WS、JAX-RS(RESTful)的webService
- 基于CXF的JAX-WS、JAX-RS(RESTful)的webService
- 基于CXF的JAX-WS、JAX-RS(RESTful)的webService
- scrollView 与 Autolayout
- IOS开发优秀资源
- 第五章 BIRT文本类报表
- 常见的负载均衡的基本算法
- 删除单链表中重复的值
- webservice的几种验证方式(一)基于JAX-WS
- 右值引用,移动语义,完美转发
- Spark:一个高效的分布式计算系统
- 织梦DEDECMS网站搬家教程 数据库备份和还原教程
- Ubuntu14.04(64位) 安装ia32-libs
- 第六章 BIRT普通网格报表
- Linux——SSH 登录失败:Host key verification failed 的处理方法
- CSDN学院精品课程推荐
- js控制li标签排序问题 js调用php函数