webservice的几种验证方式(一)基于JAX-WS
|
近年来,随着面向服务的平台的大规模开放,异构程序之间的通信的需求不断增多,随之而来的就是webservice的蓬勃发展。 </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;
@WebService
public 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{
@Autowired
private CampaignService campaignService;
@Autowired
private CampaigntargetService campaigntargetService;
@Autowired
private SessionFactory sessionFactory;
@Override
public boolean addCampaign(List<Campaign> list) {
}
@Override
public 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.xsd
http://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.xsd
http://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是需要的验证基本上就结束了,有什么错误还请大家斧正。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |


