헤르메스 LIFE

CXF 2.3.11 설정 본문

Core Java

CXF 2.3.11 설정

헤르메스의날개 2022. 8. 11. 20:56
728x90

SimpleWebService.zip
8.16MB

2016년에 테스트했던 내용을 이번에 참조하면서 테스트 봤습니다.


Windows 환경변수 추가

Windows 시스템 변수추가

Lib 추가

cxf-2.6.2.jar
neethi-3.0.2.jar
wsdl4j-1.6.2.jar
xmlschema-core-2.0.3.jar

web.xml 수정 ( Wildfly 에서는 삭제해야 함. )

    <!-- SOAP를 이용한 Web Service를 위해 cxf 설정한다. -->
    <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>
Server Runtime 환경
Eclipse > Windows > Preferences > Server > Runtime Environment
CXF 설정
Eclipse > Windows > Preferences > Server > Runtime Environment

Web Service > Server and Runtime 확인

[Eclipse 프로젝트] > Properties > Project Facets 설정

[Eclipse 프로젝트] > Properties > Java Compiler > Annotation Processing

Enable project specific settings 에 체크를 합니다.

Service 소스 작성

package soap.cxf.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import soap.cxf.service.dao.JCommonDAO;
import soap.cxf.service.exception.ValidationException;
import soap.cxf.service.vo.SMSIF_101;
import soap.cxf.service.vo.ServiceRtn;

@WebService(targetNamespace = "http://service.cxf.hermeswing.com/", portName = "SmsServicePort", serviceName = "SmsServiceService")
public class JService extends JCommonDAO {
	public JService() {
	}

	@WebMethod(operationName = "MY_SMS_IF101", action = "urn:MY_SMS_IF101")
	public List<SMSIF_101> SMSIF_101(@WebParam(name = "system_id") String system_id,
			@WebParam(name = "passwd") String passwd, @WebParam(name = "msg_type") String msg_type,
			@WebParam(name = "dstaddr") String dstaddr, @WebParam(name = "callback") String callback,
			@WebParam(name = "stat") String stat, @WebParam(name = "text") String text,
			@WebParam(name = "request_time") String request_time, @WebParam(name = "opt_id") String opt_id,
			@WebParam(name = "opt_cmp") String opt_cmp, @WebParam(name = "opt_name") String opt_name)
			throws SQLException {
		int err_cd = 0;
		String err_msg = "";
		ServiceRtn rtn = new ServiceRtn(err_cd, err_msg);

		List<SMSIF_101> result = new ArrayList<>();

		try {
			if ((system_id == null) || (system_id.equals(""))) {
				throw new ValidationException("시스템ID(system_id)는 필수입력값입니다.");
			}
			if ((passwd == null) || (passwd.equals(""))) {
				throw new ValidationException("패스워드(passwd)는 필수입력값입니다.");
			}
			if ((msg_type == null) || (msg_type.equals(""))) {
				msg_type = "1";
			}
			if ((dstaddr == null) || (dstaddr.equals(""))) {
				throw new ValidationException("발신번호(dstaddr)는 필수 입력값입니다.");
			}
			if ((callback == null) || (callback.equals(""))) {
				throw new ValidationException("수신번호(callback)는 필수 입력값입니다.");
			}
			if ((stat == null) || (stat.equals(""))) {
				stat = "0";
			}
			if ((opt_id == null) || (opt_id.equals(""))) {
				throw new ValidationException("시스템id(opt_id)는 필수 입력값입니다.");
			}
			if ((opt_cmp == null) || (opt_cmp.equals(""))) {
				throw new ValidationException("회사코드(opt_cmp)는 필수 입력값입니다.");
			}

			SMSIF_101 param = new SMSIF_101();
			param.setSystem_id(system_id);
			param.setPasswd(passwd);

			param.setMsg_type(msg_type);
			param.setDstaddr(dstaddr);
			param.setCallback(callback);
			param.setStat(stat);
			param.setText(text);
			param.setRequest_time(request_time);
			param.setOpt_id(opt_id);
			param.setOpt_cmp(opt_cmp);
			param.setOpt_name(opt_name);

			result.add(param);

			return result;
		} catch (ValidationException e) {
			result.add(new SMSIF_101(2, e.getMessage(), "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
					"", "", "", "", "", "", "", "", "", "", "", "", "",
					""));
		} catch (SQLException e) {
			result.add(new SMSIF_101(3, e.toString(), "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
					"", "", "", "", "", "", "", "", "", "", "", "", "",
					""));
		}

		return result;
	}

}

주의....

web.xml 파일이 변경됨.백업 해두기를 권함... ㅡㅡ;;

소스에 오른쪽 마우스 버튼 클릭

Web Service 설정.
1. Web Service runtime 수정
2. Service 배포단계까지만...

설정이 완료되면..
1. webapp 아래 \wsdl 폴더가 생성됩니다.
2. /WEB-INF 폴더아래 cxf-beans.xml 파일 생성됩니다.
   생성된 파일을 web.xml 파일에 설정 추가
   설정을 추가 하지 않으면 cxf 의 BEANS가 설정되어 있는데 정의 되지 않았다는 메시지가 뜹니다.
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cxf' is defined

context-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:jaxrs="http://cxf.apache.org/jaxrs"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:cxf="http://cxf.apache.org/core"
	xsi:schemaLocation="
		http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
		http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.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.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">

	<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" />
	<jaxws:endpoint id="jservice"
		implementor="soap.cxf.service.JService"
		wsdlLocation="wsdl/jservice.wsdl" address="/jservice">
		<jaxws:features>
			<bean class="org.apache.cxf.feature.LoggingFeature" />
		</jaxws:features>
	</jaxws:endpoint>
</beans>

생성된 cxf-beans.xml 파일의 내용을 복사해서 추가해 넣습니다.

cxf-beans.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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.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-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	<jaxws:endpoint id="jservice"
		implementor="soap.cxf.service.JService"
		wsdlLocation="wsdl/jservice.wsdl" address="/jservice">
		<jaxws:features>
			<bean class="org.apache.cxf.feature.LoggingFeature" />
		</jaxws:features>
	</jaxws:endpoint>
</beans>

해당 부분을 추가해 넣으면 됩니다.

	<jaxws:endpoint id="jservice"
		implementor="soap.cxf.service.JService"
		wsdlLocation="wsdl/jservice.wsdl" address="/jservice">
		<jaxws:features>
			<bean class="org.apache.cxf.feature.LoggingFeature" />
		</jaxws:features>
	</jaxws:endpoint>

3. 확인

4. wsdl 파일 확인

5. jservice.wsdl 파일 일부

  <wsdl:service name="SmsServiceService">
    <wsdl:port name="SmsServicePort" binding="tns:SmsServiceServiceSoapBinding">
      <soap:address location="http://localhost:9090/SmsServicePort"/>
    </wsdl:port>
  </wsdl:service>
을 실제 주소로 변경합니다.
  <wsdl:service name="SmsServiceService">
    <wsdl:port name="SmsServicePort" binding="tns:SmsServiceServiceSoapBinding">
      <soap:address location="http://localhost:8080/services/jservice"/>
    </wsdl:port>
  </wsdl:service>
이제 Client 에 wsdl 파일과 xsd 파일만을 배포하게 됩니다.

 

Client의 개발

1. 배포받은 wsdl 파일과 xsd 파일을 폴더에 넣습니다.

2. Client 소스 생성

jservice.wsdl 파일 > 오른쪽 마우스 클릭

3. 소스가 생성되었습니다.

4. JService_SmsServicePort_Client.java 파일 실행

 

728x90