【노트】WebService CXF와 SSM 통합, 실명 인증 시뮬레이션

9139 단어 WebService
앞서 쓴 한 학우망 프로젝트 중의 실명 인증 기능은 학교의 학적 시스템 인터페이스를 호출하여 자동 실명 심사 기능을 실현해야 한다.
1. 인터페이스 개발
【web.xml】
  <servlet>  
    <servlet-name>CXFServletservlet-name>  
    <servlet-class>org.apache.cxf.transport.servlet.CXFServletservlet-class>  
  servlet>  

  <servlet-mapping>  
    <servlet-name>CXFServletservlet-name>  
    <url-pattern>/webservice/*url-pattern>  
  servlet-mapping>

【spring-webservice.xml】
    
<beans xmlns="http://www.springframework.org/schema/beans"    
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    xmlns:p="http://www.springframework.org/schema/p"  
    xmlns:aop="http://www.springframework.org/schema/aop"   
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:jee="http://www.springframework.org/schema/jee"  
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">    

    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

    
    <context:component-scan base-package="com.jul_11th.*" />

    
    <jaxws:endpoint implementor="#myWebServiceImpl" address="/MyWebService"/>

beans>

【서비스 인터페이스】
package com.jul_11th.webservice;

import javax.jws.WebService;

@WebService
public interface MyWebService {
    /**
     *       
     */
    boolean  Authentication(String realName,String id);
}

[서비스 인터페이스 구현 클래스]
package com.jul_11th.webservice;

import javax.annotation.Resource;
import javax.jws.WebService;

import org.springframework.stereotype.Component;

import com.jul_11th.service.IUserService;

@Component("myWebServiceImpl")
@WebService
public class MyWebServiceImpl implements MyWebService {

    @Resource(name = "userService")
    private IUserService userService;

    public boolean Authentication(String realName, String id) {
        return userService.Authentication(realName, id);
    }

}

2. 서비스 요청, 크로스 플랫폼 인터페이스 호출
【Client】
package com.jul_11th.client;

//import org.apache.cxf.frontend.ClientProxy;

import com.jul_11th.webservice.MyWebService;
import com.jul_11th.webservice.MyWebServiceImplService;

public class Client {

    public static void main(String[] args) {
        MyWebServiceImplService service = new MyWebServiceImplService();
        MyWebService hw = service.getMyWebServiceImplPort();
        //org.apache.cxf.endpoint.Client client=ClientProxy.getClient(hw);
        //client.getOutInterceptors().add(new AddHeaderInterceptor("admin","admin"));
        System.out.println(hw.authentication("   ", "410423199400000000"));
    }

}

【콘솔 출력】
   07, 2017 10:18:24    org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
  : Creating Service {http://webservice.jul_11th.com/}MyWebServiceImplService from WSDL: http://localhost:8080/SSM/webservice/MyWebService?wsdl
true

좋은 웹페이지 즐겨찾기