Skip to content

Commit

Permalink
moving web service messages to DEBUG level
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed May 31, 2017
1 parent 36b790e commit a9aa0aa
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.model.impl.util;

import org.apache.cxf.Bus;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.interceptor.AbstractLoggingInterceptor;
import org.apache.cxf.interceptor.InterceptorProvider;

import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
* Created by Viliam Repan (lazyman).
*/
public class LoggingFeature extends AbstractFeature {

public static final String MESSAGE_LOGGER = "org.apache.cxf.services.midpoint";

private static final Logger LOG = Logger.getLogger(MESSAGE_LOGGER);

private static final LoggingInInterceptor IN = new LoggingInInterceptor(AbstractLoggingInterceptor.DEFAULT_LIMIT);

private static final LoggingOutInterceptor OUT = new LoggingOutInterceptor(AbstractLoggingInterceptor.DEFAULT_LIMIT);

@Override
protected void initializeProvider(InterceptorProvider provider, Bus bus) {
provider.getInInterceptors().add(IN);
provider.getInFaultInterceptors().add(IN);
provider.getOutInterceptors().add(OUT);
provider.getOutFaultInterceptors().add(OUT);
}

private static void logMessage(Logger logger, String message) {
if (!logger.isLoggable(Level.FINE)) {
return;
}

LogRecord lr = new LogRecord(Level.FINE, message);
lr.setSourceClassName(logger.getName());
lr.setSourceMethodName(null);
lr.setLoggerName(logger.getName());
logger.log(lr);
}

public static class LoggingInInterceptor extends org.apache.cxf.interceptor.LoggingInInterceptor {

public LoggingInInterceptor(int lim) {
super(lim);
}

@Override
protected void log(Logger logger, String message) {
logMessage(logger, message);
}

@Override
protected Logger getLogger() {
return LOG;
}
}

public static class LoggingOutInterceptor extends org.apache.cxf.interceptor.LoggingOutInterceptor {

public LoggingOutInterceptor(int lim) {
super(lim);
}

@Override
protected void log(Logger logger, String message) {
logMessage(logger, message);
}

@Override
protected Logger getLogger() {
return LOG;
}
}
}
6 changes: 4 additions & 2 deletions model/model-impl/src/main/resources/ctx-model.xml
Expand Up @@ -390,6 +390,8 @@
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

<bean id="loggingFeature" class="com.evolveum.midpoint.model.impl.util.LoggingFeature"/>

<jaxws:endpoint id="modelWS"
address="/model-3"
wsdlLocation="classpath:xml/ns/public/model/model-3.wsdl"
Expand All @@ -416,7 +418,7 @@
</jaxws:properties>

<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature"/>
<ref bean="loggingFeature"/>
</jaxws:features>
</jaxws:endpoint>

Expand All @@ -431,7 +433,7 @@
<ref bean="restAuthenticationHandler"/>
</jaxrs:providers>
<jaxrs:features>
<bean class="org.apache.cxf.feature.LoggingFeature"/>
<ref bean="loggingFeature"/>
</jaxrs:features>
</jaxrs:server>

Expand Down

0 comments on commit a9aa0aa

Please sign in to comment.