-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update handling of hte @logging annotation to use the new logging cap…
…abilities if available
- Loading branch information
Showing
9 changed files
with
293 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
core/src/main/java/org/apache/cxf/service/factory/OldLoggingFactoryBeanListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.cxf.service.factory; | ||
|
||
|
||
import java.util.logging.Logger; | ||
|
||
import org.apache.cxf.Bus; | ||
import org.apache.cxf.annotations.Logging; | ||
import org.apache.cxf.common.logging.LogUtils; | ||
import org.apache.cxf.endpoint.Endpoint; | ||
import org.apache.cxf.endpoint.Server; | ||
|
||
/** | ||
* | ||
*/ | ||
public class OldLoggingFactoryBeanListener implements FactoryBeanListener { | ||
static final Logger LOG = LogUtils.getL7dLogger(OldLoggingFactoryBeanListener.class); | ||
|
||
/** {@inheritDoc}*/ | ||
public void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object... args) { | ||
switch (ev) { | ||
case ENDPOINT_SELECTED: { | ||
Class<?> cls = (Class<?>)args[2]; | ||
Endpoint ep = (Endpoint)args[1]; | ||
Bus bus = factory.getBus(); | ||
// To avoid the NPE | ||
if (cls == null) { | ||
return; | ||
} | ||
addLoggingSupport(ep, bus, cls.getAnnotation(Logging.class)); | ||
break; | ||
} | ||
case SERVER_CREATED: { | ||
Class<?> cls = (Class<?>)args[2]; | ||
if (cls == null) { | ||
return; | ||
} | ||
Server server = (Server)args[0]; | ||
Bus bus = factory.getBus(); | ||
addLoggingSupport(server.getEndpoint(), bus, cls.getAnnotation(Logging.class)); | ||
break; | ||
} | ||
default: | ||
//do nothing | ||
} | ||
} | ||
|
||
|
||
private void addLoggingSupport(Endpoint endpoint, Bus bus, Logging annotation) { | ||
if (annotation != null) { | ||
@SuppressWarnings("deprecation") | ||
org.apache.cxf.feature.LoggingFeature lf = new org.apache.cxf.feature.LoggingFeature(annotation); | ||
LOG.warning("Deprecated logging interceptors being used, switch to cxf-rt-ext-logging based logging."); | ||
lf.initialize(endpoint, bus); | ||
} | ||
} | ||
|
||
|
||
} |
83 changes: 83 additions & 0 deletions
83
...eatures/logging/src/main/java/org/apache/cxf/ext/logging/LoggingBusLifecycleListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.cxf.ext.logging; | ||
|
||
import org.apache.cxf.Bus; | ||
import org.apache.cxf.buslifecycle.BusLifeCycleListener; | ||
import org.apache.cxf.buslifecycle.BusLifeCycleManager; | ||
|
||
/** | ||
* | ||
*/ | ||
public class LoggingBusLifecycleListener implements BusLifeCycleListener { | ||
|
||
static final boolean FORCE_LOGGING; | ||
static final boolean FORCE_PRETTY; | ||
static { | ||
boolean b = false; | ||
boolean pretty = false; | ||
try { | ||
String prop = System.getProperty("org.apache.cxf.logging.enabled", "false"); | ||
if ("pretty".equals(prop)) { | ||
b = true; | ||
pretty = true; | ||
} else { | ||
b = Boolean.parseBoolean(prop); | ||
//treat these all the same | ||
b |= Boolean.getBoolean("com.sun.xml.ws.transport.local.LocalTransportPipe.dump"); | ||
b |= Boolean.getBoolean("com.sun.xml.ws.util.pipe.StandaloneTubeAssembler.dump"); | ||
b |= Boolean.getBoolean("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump"); | ||
b |= Boolean.getBoolean("com.sun.xml.ws.transport.http.HttpAdapter.dump"); | ||
} | ||
} catch (Throwable t) { | ||
//ignore | ||
} | ||
FORCE_LOGGING = b; | ||
FORCE_PRETTY = pretty; | ||
} | ||
|
||
private final Bus bus; | ||
public LoggingBusLifecycleListener(Bus b) { | ||
bus = b; | ||
bus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this); | ||
} | ||
|
||
/** {@inheritDoc}*/ | ||
@Override | ||
public void initComplete() { | ||
if (FORCE_LOGGING) { | ||
LoggingFeature feature = new LoggingFeature(); | ||
feature.setPrettyLogging(FORCE_PRETTY); | ||
bus.getFeatures().add(feature); | ||
feature.initialize(bus); | ||
} | ||
} | ||
|
||
/** {@inheritDoc}*/ | ||
@Override | ||
public void preShutdown() { | ||
} | ||
|
||
/** {@inheritDoc}*/ | ||
@Override | ||
public void postShutdown() { | ||
} | ||
|
||
} |
106 changes: 106 additions & 0 deletions
106
rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFactoryBeanListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.cxf.ext.logging; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.PrintWriter; | ||
import java.net.URI; | ||
|
||
import org.apache.cxf.Bus; | ||
|
||
import org.apache.cxf.annotations.Logging; | ||
|
||
import org.apache.cxf.endpoint.Endpoint; | ||
import org.apache.cxf.endpoint.Server; | ||
import org.apache.cxf.ext.logging.event.PrintWriterEventSender; | ||
import org.apache.cxf.service.factory.AbstractServiceFactoryBean; | ||
import org.apache.cxf.service.factory.FactoryBeanListener; | ||
import org.apache.cxf.service.factory.FactoryBeanListenerManager; | ||
|
||
/** | ||
* | ||
*/ | ||
public class LoggingFactoryBeanListener implements FactoryBeanListener { | ||
|
||
public LoggingFactoryBeanListener(Bus b) { | ||
FactoryBeanListenerManager m = b.getExtension(FactoryBeanListenerManager.class); | ||
for (FactoryBeanListener f : m.getListeners()) { | ||
if (f.getClass().getSimpleName().equals("OldLoggingFactoryBeanListener")) { | ||
m.removeListener(f); | ||
} | ||
} | ||
} | ||
|
||
/** {@inheritDoc}*/ | ||
public void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object... args) { | ||
switch (ev) { | ||
case ENDPOINT_SELECTED: { | ||
Class<?> cls = (Class<?>)args[2]; | ||
Endpoint ep = (Endpoint)args[1]; | ||
Bus bus = factory.getBus(); | ||
// To avoid the NPE | ||
if (cls == null) { | ||
return; | ||
} | ||
addLoggingSupport(ep, bus, cls.getAnnotation(Logging.class)); | ||
break; | ||
} | ||
case SERVER_CREATED: { | ||
Class<?> cls = (Class<?>)args[2]; | ||
if (cls == null) { | ||
return; | ||
} | ||
Server server = (Server)args[0]; | ||
Bus bus = factory.getBus(); | ||
addLoggingSupport(server.getEndpoint(), bus, cls.getAnnotation(Logging.class)); | ||
break; | ||
} | ||
default: | ||
//do nothing | ||
} | ||
} | ||
|
||
private void addLoggingSupport(Endpoint endpoint, Bus bus, Logging annotation) { | ||
if (annotation != null) { | ||
LoggingFeature lf = new LoggingFeature(); | ||
lf.setPrettyLogging(annotation.pretty()); | ||
lf.setLimit(annotation.limit()); | ||
lf.setLogBinary(annotation.showBinary()); | ||
|
||
if ("<stdout>".equals(annotation.outLocation())) { | ||
lf.setOutSender(new PrintWriterEventSender(System.out)); | ||
} else if ("<stderr>".equals(annotation.outLocation())) { | ||
lf.setOutSender(new PrintWriterEventSender(System.err)); | ||
} else if (annotation.outLocation().startsWith("file:")) { | ||
try { | ||
URI uri = new URI(annotation.outLocation()); | ||
File file = new File(uri); | ||
PrintWriter writer = new PrintWriter(new FileWriter(file, true), true); | ||
lf.setOutSender(new PrintWriterEventSender(writer)); | ||
} catch (Exception ex) { | ||
//stick with default | ||
} | ||
} | ||
lf.initialize(endpoint, bus); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.