Verity's Daily Logs_

[SOAP]Web Service - Clien side Logging 출력 본문

Spring Framework/Project

[SOAP]Web Service - Clien side Logging 출력

johye0 2022. 2. 24. 21:07
반응형

 

 

SOAP Web Service Client 로직 실행 시 요청에 대한 응답 원문을 확인하는 것이 개발이나 유지보수(이력 및 오류 처리) 에 필요할 것이다. 이에 Client 요청 시 요청과 응답에 대한 SOAP Body 데이터를 콘솔로 출력하는 기능까지 추가로 개발한다.

 

<요청 로그 예시>

<응답 로그 예시>

 

 

4. Logging

4-1. Dependency 추가


<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-features-logging</artifactId>
			<version>3.5.0</version>
</dependency>

 

4-2. LoggingFeature 추가


<기존코드>

package com.happy.webservice.cxf.config;

import com.happy.cxf.ws.UserService;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CxfClientConfig {

    @Value("${server.serviceUrl}")
    private String serviceUrl;

    @Bean
    public UserService userService() throws Exception {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setServiceClass(UserService.class);
        jaxWsProxyFactoryBean.setAddress(serviceUrl);

        UserService userService = (UserService) jaxWsProxyFactoryBean.create();
        return userService;
    }
}

 

<수정코드>

package com.happy.webservice.cxf.config;

import com.happy.cxf.ws.UserService;
import org.apache.cxf.ext.logging.LoggingFeature;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CxfClientConfig {

    @Value("${server.serviceUrl}")
    private String serviceUrl;  // <http://localhost:8088/ws/user>

    @Bean
    public LoggingFeature loggingFeature() {
        LoggingFeature loggingFeature = new LoggingFeature();
        loggingFeature.setPrettyLogging(true);
        return loggingFeature;
    }

    @Bean
    public UserService userService(@Autowired LoggingFeature loggingFeature) throws Exception {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        jaxWsProxyFactoryBean.setServiceClass(UserService.class);
        jaxWsProxyFactoryBean.setAddress(serviceUrl);
        jaxWsProxyFactoryBean.getFeatures().add(loggingFeature);

        return (UserService) jaxWsProxyFactoryBean.create();
    }
}

 

4-3. application.yml 설정 추가


logging:
  level:
    org:
      apache:
        cxf:
          services: INFO

 

4-4. 로그 결과


 

반응형

'Spring Framework > Project' 카테고리의 다른 글

[SOAP]Web Service - Clien side 생성  (0) 2022.02.17
[SOAP]Web Service - Server side 생성  (2) 2022.02.16
[SOAP]Web Service Project 개요  (0) 2022.02.14
[SOAP]프로젝트 생성 방법  (0) 2022.02.14
[SOAP]Web Service (SOAP, REST)  (0) 2022.02.09
Comments