2016-07-27 6 views
1

Umwelt: JDK 7, WebLogic Server 12.1.3.0 (Patch 3) Maven System bautWebservice-Handler in der zweiten Modul verhindern log4j2 Konfiguration

Aufbauend auf Maven, habe ich ein Webservice IST-Modul in Abhängigkeit von einem zweites JAR-Modul, das Webservice-Handler definiert. Das Webservice-Modul verfügt über einen Kontexte-Listener, der log4j2 später aus der Datenbank initialisieren soll (zyklisch). Es gibt kein log4j2.xml, das irgendwo definiert ist, noch gewünscht.

Das Problem besteht darin, dass die Konfiguration von log4j2 beschädigt wird, wenn Handler mithilfe der @HandlerChain-Annotation auf dem Webservice-Endpunkt aktiviert werden, bevor der Web-Service-Kontext-Listener sie initialisieren kann.

Modul DemoWebService:

@WebService(endpointInterface = "demo.IDemoWebService") 
@HandlerChain(file = "handlers.xml") 
public class DemoWebService implements IDemoWebService { 
... 
} 

public class DemoServletContextListener implements ServletContextListener { 

    /** Status Logger */ 
    private static final Logger LOG = StatusLogger.getLogger(); 

    @Override 
    public void contextInitialized(ServletContextEvent event) { 
     System.out.println("Demo listener context intialized"); 
     System.out.println(LOG.getLevel() + " - " + LOG.isDebugEnabled() + " - " + LOG.isInfoEnabled() + " - " + LOG.isWarnEnabled()); 

     LOG.info("LOG Demo listener context intialized"); 
    } 

    @Override 
    public void contextDestroyed(ServletContextEvent event) { 
     System.out.println("Demo listener context destroyed"); 
     LOG.info("LOG Demo listener context destroyed"); 
    } 
} 

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> 

    <display-name>DemoWebService</display-name> 

    <!-- log4j2 configuration --> 
    <context-param> 
     <param-name>isLog4jAutoInitializationDisabled</param-name> 
     <param-value>true</param-value> 
    </context-param> 

    <listener> 
     <listener-class>demo.DemoServletContextListener</listener-class> 
    </listener> 

    ... 
</web-app> 

handlers.xml

<?xml version="1.0" encoding="UTF-8"?> 
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee"> 
    <handler-chain> 
     <handler> 
      <handler-name>Performance</handler-name> 
      <handler-class>demo.wshandler.WebServiceDemoHandler</handler-class> 
     </handler> 
    </handler-chain> 
</handler-chains> 

Modul WSHandler:

public class WebServiceDemoHandler { 

    private static Logger log = LogManager.getLogger(WebServiceDemoHandler.class); 

    @Override 

    public boolean handleMessage(SOAPMessageContext context) { 
     log.info("something"); 
     return true; 
    } 

    @Override 
    public boolean handlingNotRequired() { 
     return false; // this handler always handles the message 
    } 
} 

Nun, wenn ich Serverprotokolle während des Einsatzes einmal vergleichen, wenn @HandlerChain (file = „handlers.xml“) aktiv ist und einmal, als Kommentar gesetzt, der Unterschied im Protokoll ist grundsätzlich die folgenden Zeilen:

Handler Kette nicht aktiv:

Demo listener context intialized 
TRACE - true - true - true 
INFO StatusLogger LOG Demo listener context intialized 

Handler-Kette aktiv:

DEBUG StatusLogger Loaded Provider Provider[priority=10, className=org.apache.logging.log4j.core.impl.Log4jContextFactory, url=zip:C:wl_homeSer_projectsdomainsbase_domain/tmp/_WL_user/DemoWebService-1.0-SNAPSHOT/3or6mr/war/WEB-INF/lib/log4j-core-2.6.jar!/META-INF/log4j-provider.properties, [email protected]2883f04f] 
DEBUG StatusLogger Loaded Provider Provider[priority=10, className=org.apache.logging.log4j.core.impl.Log4jContextFactory, url=zip:C:wl_homeSer_projectsdomainsbase_domain/tmp/_WL_user/DemoWebService-1.0-SNAPSHOT/3or6mr/war/WEB-INF/lib/log4j-core-2.6.jar!/META-INF/log4j-provider.properties, [email protected]d5bfc18 finder: [email protected] annotation: [email protected]] 
DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry 
DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry 
DEBUG StatusLogger Took 0,086401 seconds to load 184 plugins from [email protected] 
DEBUG StatusLogger PluginManager 'Converter' found 41 plugins 
DEBUG StatusLogger Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream 
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false-1 
DEBUG StatusLogger Starting LoggerContext[name=7d5bfc18, [email protected]]... 
DEBUG StatusLogger Reconfiguration started for context[name=7d5bfc18] at URI null ([email protected]) with optional ClassLoader: null 
DEBUG StatusLogger PluginManager 'ConfigurationFactory' found 4 plugins 
DEBUG StatusLogger Missing dependencies for Yaml support 
DEBUG StatusLogger Missing dependencies for Json support 
DEBUG StatusLogger Using configurationFactory or[email protected]83bf63b 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.properties] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.properties] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.properties] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.properties] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.yml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.yml] using [email protected] finder: weblogic.utils.classloaders.CodeGenC[email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.yml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.yml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.yaml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.yaml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.yaml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.yaml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.json] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.json] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.json] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.json] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.jsn] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.jsn] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.jsn] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.jsn] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.xml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.xml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.xml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test7d5bfc18.xml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test.properties] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test.properties] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.properties] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.properties] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test.yml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test.yml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.yml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.yml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test.yaml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test.yaml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.yaml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.yaml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test.json] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test.json] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.json] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.json] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test.jsn] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test.jsn] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.jsn] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.jsn] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2-test.xml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2-test.xml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.xml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2-test.xml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j27d5bfc18.properties] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j27d5bfc18.properties] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.properties] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.properties] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j27d5bfc18.yml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j27d5bfc18.yml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.yml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.yml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j27d5bfc18.yaml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j27d5bfc18.yaml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.yaml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.yaml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j27d5bfc18.json] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j27d5bfc18.json] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.json] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.json] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j27d5bfc18.jsn] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j27d5bfc18.jsn] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.jsn] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.jsn] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j27d5bfc18.xml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j27d5bfc18.xml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.xml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j27d5bfc18.xml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2.properties] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2.properties] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.properties] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.properties] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2.yml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2.yml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.yml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.yml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2.yaml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2.yaml] using weblogic.util[email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.yaml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.yaml] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2.json] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2.json] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.json] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.json] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2.jsn] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2.jsn] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.jsn] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.jsn] using ClassLoader.getSystemResource(). 
TRACE StatusLogger Trying to find [log4j2.xml] using context class loader [email protected] 
TRACE StatusLogger Trying to find [log4j2.xml] using [email protected] finder: [email protected] annotation: [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.xml] using [email protected] class loader. 
TRACE StatusLogger Trying to find [log4j2.xml] using ClassLoader.getSystemResource(). 
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. 
DEBUG StatusLogger PluginManager 'Converter' found 41 plugins 
DEBUG StatusLogger Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream 
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false-2 
DEBUG StatusLogger Initializing configuration [email protected]b3 
DEBUG StatusLogger Installed script engines 
DEBUG StatusLogger juel Version: 1.0, Language: JSP 2.1 EL, Threading: MULTITHREADED, Compile: false, Names: {juel} 
DEBUG StatusLogger Oracle Nashorn Version: 1.8.0_71, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript} 
DEBUG StatusLogger Groovy Scripting Engine Version: 2.0, Language: Groovy, Threading: MULTITHREADED, Compile: true, Names: {groovy, Groovy} 
DEBUG StatusLogger PluginManager 'Core' found 100 plugins 
DEBUG StatusLogger PluginManager 'Level' found 0 plugins 
DEBUG StatusLogger Configuration [email protected]b3 initialized 
DEBUG StatusLogger Starting configuration [email protected]b3 
DEBUG StatusLogger Started configuration [email protected]b3 OK. 
TRACE StatusLogger Stopping [email protected]09... 
TRACE StatusLogger DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped. 
TRACE StatusLogger DefaultConfiguration stopping root LoggerConfig. 
TRACE StatusLogger DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped. 
TRACE StatusLogger DefaultConfiguration stopping remaining Appenders. 
DEBUG StatusLogger Shutting down OutputStreamManager SYSTEM_OUT.false-1 
TRACE StatusLogger DefaultConfiguration stopped 1 remaining Appenders. 
TRACE StatusLogger DefaultConfiguration cleaning Appenders from 1 LoggerConfigs. 
DEBUG StatusLogger Stopped [email protected]09 OK 
TRACE StatusLogger Reregistering MBeans after reconfigure. Selector=or[email protected]44387dfb 
TRACE StatusLogger Reregistering context (1/1): '7d5bfc18' [email protected] 
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=7d5bfc18' 
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=7d5bfc18,component=StatusLogger' 
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=7d5bfc18,component=ContextSelector' 
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=7d5bfc18,component=Loggers,name=*' 
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=7d5bfc18,component=Appenders,name=*' 
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=7d5bfc18,component=AsyncAppenders,name=*' 
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=7d5bfc18,component=AsyncLoggerRingBuffer' 
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=7d5bfc18,component=Loggers,name=*,subtype=RingBuffer' 
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=7d5bfc18 
Demo listener context intialized 
TRACE - false - false - true 

Was hier geschieht, ist, ich denke, Java Classloader vor dem Webkontext Zuhörer aktiv wird und löst dann die Initialisierung von log4j2, unerwünscht. Dies führt zu einer nicht wiederherstellbaren beschädigten log4j2-Konfiguration und alle weiteren Protokolle gehen verloren.

Antwort

2

Die Antwort auf die Frage gepostet ist einfach in die Klasse DemoServletContextListener die Linie

StatusLogger.getLogger().reset(); 

und der StatusLogger funktioniert wieder aufzunehmen. Allerdings kann die gebrochene Gesamtlogj4-Konfiguration nicht so gelöst werden. Doch der Initialisierungscode wurde hier weggelassen und ist daher höchstens Thema einer anderen Post-

+0

oder möglicherweise, wenn Sie Log4j nicht in Handler selbst verwenden, zu früh wahrscheinlich –

1

Haben Sie versucht, das LOG StatusLogger-Feld in als nicht statisch zu deklarieren? Durch das Laden dieser Klasse wird Log4j2 initialisiert.

Wenn Sie die Log4j2-Initialisierung verschieben möchten, bis WebServiceDemoHandler geladen ist, sollten Sie den StatusLogger wahrscheinlich nicht in verwenden.

Die ersten beiden Zeilen, die vom Statuslogger ausgegeben werden, gibt es außerdem zwei Klassenladeprogramme, und der erste ([email protected]) beginnt, Log4j2 zu initialisieren.

Es gibt auch einen [email protected] finder: [email protected] annotation: [email protected] Klassenlader, der anscheinend nicht ins Spiel kommt. Basierend auf dem Namen, ist dieser zweite Classloader für die Webanwendung. Ich denke, dass Log4j2 von diesem 2. Classloader initialisiert werden soll.Ich bin mir nicht sicher, wo der erste Classloader herkommt, aber das könnte ein guter Anhaltspunkt für weitere Untersuchungen sein.

+0

Hallo Remko! Vielen Dank für die kompetente Antwort. Ja, ich habe das ausprobiert und den Logger in WebServiceDemoHandler als nicht statisch definiert. Es hat nicht geholfen. Was nur geholfen hat war, log4j2 im zweiten Modul wshandler überhaupt nicht zu benutzen. Ich könnte den StatusLogger wieder in DemoServletContextListener arbeiten, indem Sie die folgende Zeile hinzufügen StatusLogger.getLogger(). Reset(); Die Gesamtprotokollkonfiguration, die im Kontext-Listener stattfinden sollte, kann jedoch nicht gespeichert werden. (Der Code für die Protokollierungsinitialisierung im Kontext-Listener wurde aus Platzgründen weggelassen.) –

+0

Gern geschehen! Hoffe es hilft das Rätsel zu lösen. –

+0

Upvotes immer willkommen! ;-P –

Verwandte Themen