加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice详解(CXF)

发布时间:2020-12-16 22:25:02 所属栏目:安全 来源:网络整理
导读:闲话少说: 1.web.xml添加配置 !--add cxf config-- servlet descriptionApache CXF Endpoint/description display-namecxf/display-name servlet-namecxf/servlet-name servlet-classorg.apache.cxf.transport.servlet.CXFServlet/servlet-class load-on-st

闲话少说:

1.web.xml添加配置

 <!--add cxf config-->
    <servlet>
        <description>Apache CXF Endpoint</description>
        <display-name>cxf</display-name>
        <servlet-name>cxf</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>cxf</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping> 

2.新建cx-servlet.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:soap="http://cxf.apache.org/bindings/soap" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://cxf.apache.org/bindings/soap 
                        http://cxf.apache.org/schemas/configuration/soap.xsd
                        http://cxf.apache.org/jaxws 
                        http://cxf.apache.org/schemas/jaxws.xsd
                        http://cxf.apache.org/jaxrs 
                        http://cxf.apache.org/schemas/jaxrs.xsd
                        
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                        ">	
    
   
    <!-- 带有接口的发布 -->
    <!-- 
        id:唯一标识
        address:访问url
        serviceClass:接口类型
     -->
   <jaxws:server id="aop" address="/external"
        serviceClass="*.*.*.*.*.service.*" >
        <jaxws:serviceBean>
<!-- 			提供服务的实现类 -->
            <bean class="*.*.*.*.*.service.impl.*Impl"></bean>
        </jaxws:serviceBean>
<!-- 			加入消息拦截器  -->
        <jaxws:inInterceptors>
            <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
        </jaxws:inInterceptors>
        <jaxws:outInterceptors>
            <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
        </jaxws:outInterceptors>
    </jaxws:server>

    <!-- 配置restful方式的web服务 -->
    <bean id="ps" class="*.*.*.*.*.service.impl.*Impl"></bean>
    <jaxrs:server id="get" address="/getMethod">
        <jaxrs:serviceBeans>
            <ref bean="ps"/>
        </jaxrs:serviceBeans>
        <jaxrs:inInterceptors>
            <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
        </jaxrs:inInterceptors>
        <jaxrs:outInterceptors>
            <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
        </jaxrs:outInterceptors>
    </jaxrs:server> 
    
     <import resource="classpath:META-INF/cxf/cxf.xml" />
     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />    
</beans>

3.webService的接口与实现类

3.1普通的

@WebService
public interface *Service {

	/**
	 * 
	 * 
	 * @param orderId
	 * @param tmsState
	 */
	@WebMethod(operationName = "orderChange")
	@WebResult(name = "result")
	JSONResponse orderChange(@WebParam(name = "key") String key,@WebParam(name = "orderId") String orderId,@WebParam(name = "tmsState") String tmsState);

调用测试方式:eclipse有自带的一种测试方式,很简单,就不多说了




3.2? restful形式的,可以直接通过网址调用

@Produces({ MediaType.APPLICATION_JSON })
public interface CarriageChangeService extends Serializable {
/**
 * TMS运单状态变更
 * 
 * @param key
 * @param orderId
 * @param tmsState
 * @throws UnsupportedEncodingException
 */
@GET
@Path("/carriageChange/{key}/{orderId}/{tmsState}")
public String carriageChange(@PathParam("key") String key,@PathParam("orderId") String orderId,@PathParam("tmsState") String tmsState)
throws UnsupportedEncodingException;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读