Apache CFX Custom LoggingInInterceptor未覆盖

时间:2017-06-20 08:43:26

标签: java apache logging spring-boot

我正在尝试创建自定义LoggingInInterceptor,但代码根本不是自定义部分。我的样本SOP @@@@@@@@ handleMessage甚至没有打印。我使用Apache CFX和SpringBoot应用程序来使用SOAP所以我们试着自定义logger的请求和响应。请帮助找到问题。

自定义拦截器:

@Component
public class CustomLoggingInterceptor extends LoggingInInterceptor{     

    @Override
    public void handleMessage(Message message) throws Fault {
        System.out.println("@@@@@@@@handleMessage"+this.getClass().getName());
        Logger logger = getCustomMessageLogger(message);
        if (logger != null && (writer != null || logger.isLoggable(Level.INFO))) {
            logging(logger, message);
        }
    }

        Logger getCustomMessageLogger(Message message) {
        if (isLoggingDisabledNow(message)) {
            return null; 
        }
        Endpoint ep = message.getExchange().getEndpoint();
        if (ep == null || ep.getEndpointInfo() == null) {
            return getLogger();
        }
        EndpointInfo endpoint = ep.getEndpointInfo();
        if (endpoint.getService() == null) {
            return getLogger();
        }
        Logger logger = endpoint.getProperty("MessageLogger", Logger.class);
        if (logger == null) {
            String logName = "org.apache.cxf.services." ;
            logger = LogUtils.getL7dLogger(this.getClass(), null, logName);
            endpoint.setProperty("MessageLogger", logger);
        }
        return logger;
    }
}

服务电话: -

    UserService service = getUserServiceForEndpoint("URL");
    Client client = ClientProxy.getClient(service);
    Endpoint endpoint = client.getEndpoint();

    endpoint.getOutInterceptors().add(wssOutInterceptor);
    endpoint.getOutInterceptors().add(loggingOutInterceptor);
    endpoint.getOutFaultInterceptors().add(loggingOutInterceptor);

    endpoint.getInInterceptors().add(customLoggingInterceptor );
    endpoint.getInFaultInterceptors().add(customLoggingInterceptor);

1 个答案:

答案 0 :(得分:1)

通过自定义LoggingOutInterceptor我的问题解决如下,

@Component
public class CredentialMaskingLoggingOutInterceptor extends LoggingOutInterceptor{

    @Autowired
    ApplicationProperties appProps;

    /**
     * To mask user credentials from the logging so that which will not be misused.
     */
    @Override
    protected String formatLoggingMessage(LoggingMessage buffer) {
        return buffer.toString().replace(appProps.getUsername(), "SOAP_USERNAME").replace(appProps.getPassword(), "SOAP_PASSWORD");
    }
}

更新了日志摘要:

<wsse:UsernameToken wsu:Id="UsernameToken"><wsse:Username>SOAP_USERNAME</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">SOAP_PASSWORD</wsse:Password></wsse:UsernameToken>