cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r894615 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/resources/jaxrs_logging_atompull/ systests/jaxrs/src/test/res...
Date Wed, 30 Dec 2009 14:05:41 GMT
Author: sergeyb
Date: Wed Dec 30 14:05:41 2009
New Revision: 894615

URL: http://svn.apache.org/viewvc?rev=894615&view=rev
Log:
Prototyping an AtomPullServer for feeding log events, more to come

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullHandler.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
  (with props)
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
  (with props)
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml 
 (with props)
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/web.xml   (with
props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushEngineConfigurator.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java?rev=894615&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
Wed Dec 30 14:05:41 2009
@@ -0,0 +1,167 @@
+/**
+ * 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.jaxrs.ext.logging.atom;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.logging.Handler;
+import java.util.logging.Logger;
+
+import org.apache.commons.lang.Validate;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.ext.logging.LogLevel;
+
+
+public abstract class AbstractAtomBean {
+
+    private List<LoggerLevel> loggers = new ArrayList<LoggerLevel>();
+    private boolean initialized;
+
+    /**
+     * Creates unconfigured and uninitialized bean. To configure setters must be used, then
{@link #init()}
+     * must be called.
+     */
+    public AbstractAtomBean() {
+        initSingleLogger();
+    }
+
+    private void initSingleLogger() {
+        loggers = new ArrayList<LoggerLevel>();
+        loggers.add(new LoggerLevel("", "INFO"));
+    }
+
+
+    /**
+     * Set one or more loggers and levels descriptor. <br>
+     * Parsed input syntax is:
+     * 
+     * <pre>
+     * loggers   := &lt;logger&gt;(&lt;separator&gt;&lt;logger&gt;)*
+     * logger    := &lt;name&gt;[&quot;:&quot;&lt;level&gt;]
+     * separator := &quot;,&quot; | &quot; &quot; | &quot;\n&quot;
+     * </pre>
+     * 
+     * Examples:
+     * <p>
+     * Two loggers and two levels: <br>
+     * <tt>org.apache.cxf:INFO, org.apache.cxf.jaxrs:DEBUG</tt>
+     * <p>
+     * Three loggers, first with default "INFO" level: <br>
+     * <tt>org.apache.cxf, org.apache.cxf.jaxrs:DEBUG, namedLogger:ERROR</tt><br>
+     * <p>
+     * One logger with default "INFO" level: <br>
+     * <tt>org.apache.cxf</tt><br>
+     */
+    public void setLoggers(String loggers) {
+        checkInit();
+        Validate.notNull(loggers, "loggers is null");
+        parseLoggers(loggers);
+    }
+
+    /**
+     * Name of logger to associate with ATOM push handler; empty string for root logger.
+     */
+    public void setLogger(String logger) {
+        checkInit();
+        Validate.notNull(logger, "logger is null");
+        if (loggers.size() != 1) {
+            initSingleLogger();
+        }
+        loggers.get(0).setLogger(logger);
+    }
+
+    /**
+     * Name of level that logger will use publishing log events to ATOM push handler; empty
string for default
+     * "INFO" level.
+     */
+    public void setLevel(String level) {
+        checkInit();
+        Validate.notNull(level, "level is null");
+        if (loggers.size() != 1) {
+            initSingleLogger();
+        }
+        loggers.get(0).setLevel(level);
+    }
+
+
+    /**
+     * Initializes bean; creates ATOM push handler based on current properties state, and
attaches handler to
+     * logger(s).
+     */
+    public void init() {
+        checkInit();
+        initialized = true;
+        Handler h = createHandler();
+        for (int i = 0; i < loggers.size(); i++) {
+            Logger l = LogUtils.getL7dLogger(AbstractAtomBean.class, null, loggers.get(i).getLogger());
+            l.addHandler(h);
+            l.setLevel(LogLevel.toJUL(LogLevel.valueOf(loggers.get(i).getLevel())));
+        }
+    }
+
+    protected abstract Handler createHandler();
+    
+    protected void checkInit() {
+        if (initialized) {
+            throw new IllegalStateException("Bean is already initialized");
+        }
+    }
+
+    private void parseLoggers(String param) {
+        loggers = new ArrayList<LoggerLevel>();
+        StringTokenizer st1 = new StringTokenizer(param, ", \t\n\r\f");
+        while (st1.hasMoreTokens()) {
+            String tok = st1.nextToken();
+            int idx = tok.indexOf(":");
+            if (idx != -1) {
+                loggers.add(new LoggerLevel(tok.substring(0, idx), tok.substring(idx + 1,
tok.length())));
+            } else {
+                loggers.add(new LoggerLevel(tok, "INFO"));
+            }
+        }
+    }
+
+    private static class LoggerLevel {
+        private String logger;
+        private String level;
+
+        public LoggerLevel(String logger, String level) {
+            this.logger = logger;
+            this.level = level;
+        }
+
+        public String getLogger() {
+            return logger;
+        }
+
+        public void setLogger(String logger) {
+            this.logger = logger;
+        }
+
+        public String getLevel() {
+            return level;
+        }
+
+        public void setLevel(String level) {
+            this.level = level;
+        }
+
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullHandler.java?rev=894615&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullHandler.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullHandler.java
Wed Dec 30 14:05:41 2009
@@ -0,0 +1,53 @@
+/**
+ * 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.jaxrs.ext.logging.atom;
+
+import java.util.logging.Handler;
+
+import org.apache.cxf.jaxrs.ext.logging.LogRecord;
+
+
+public final class AtomPullHandler extends Handler {
+
+    private AtomPullServer engine;
+    /**
+     * Creates handler using (package private).
+     * 
+     * @param engine configured engine.
+     */
+    AtomPullHandler(AtomPullServer engine) {
+        this.engine = engine;
+    }
+
+    @Override
+    public void publish(java.util.logging.LogRecord record) {
+        LogRecord rec = LogRecord.fromJUL(record);
+        engine.publish(rec);
+    }
+
+    @Override
+    public synchronized void close() throws SecurityException {
+        engine.close();
+    }
+
+    @Override
+    public synchronized void flush() {
+        // no-op
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullHandler.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java?rev=894615&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
Wed Dec 30 14:05:41 2009
@@ -0,0 +1,69 @@
+/**
+ * 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.jaxrs.ext.logging.atom;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Handler;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Feed;
+import org.apache.cxf.jaxrs.ext.logging.LogRecord;
+import org.apache.cxf.jaxrs.ext.logging.atom.converter.StandardConverter;
+import org.apache.cxf.jaxrs.ext.logging.atom.converter.StandardConverter.Format;
+import org.apache.cxf.jaxrs.ext.logging.atom.converter.StandardConverter.Multiplicity;
+import org.apache.cxf.jaxrs.ext.logging.atom.converter.StandardConverter.Output;
+
+@Path("logs")
+public class AtomPullServer extends AbstractAtomBean {
+
+    private StandardConverter converter = 
+        new StandardConverter(Output.FEED, Multiplicity.MANY, Format.CONTENT);
+    private List<LogRecord> records = new LinkedList<LogRecord>();
+    
+    @GET
+    @Produces("application/atom+xml")
+    public Feed getAllRecords() {
+        //TODO: this is quite clumsy, think of something better
+        List<? extends Element> elements = null;
+        synchronized (records) {
+            elements = converter.convert(records);
+        }
+        return (Feed)(elements.get(0));
+    }
+
+    @Override
+    protected Handler createHandler() {
+        return new AtomPullHandler(this);
+    }
+    
+    public void publish(LogRecord record) {
+        synchronized (records) {
+            records.add(record);
+        }
+    }
+    
+    public void close() {
+        // save records somehow
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushBean.java?rev=894615&r1=894614&r2=894615&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushBean.java
Wed Dec 30 14:05:41 2009
@@ -18,15 +18,9 @@
  */
 package org.apache.cxf.jaxrs.ext.logging.atom;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.StringTokenizer;
 import java.util.logging.Handler;
-import java.util.logging.Logger;
 
 import org.apache.commons.lang.Validate;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.jaxrs.ext.logging.LogLevel;
 import org.apache.cxf.jaxrs.ext.logging.atom.converter.Converter;
 import org.apache.cxf.jaxrs.ext.logging.atom.deliverer.Deliverer;
 
@@ -83,23 +77,15 @@
  *   &lt;/bean&gt;
  * </pre>
  */
-public final class AtomPushBean {
+public final class AtomPushBean extends AbstractAtomBean {
 
     private AtomPushEngineConfigurator conf = new AtomPushEngineConfigurator();
-    private List<LoggerLevel> loggers = new ArrayList<LoggerLevel>();
-    private boolean initialized;
-
+    
     /**
      * Creates unconfigured and uninitialized bean. To configure setters must be used, then
{@link #init()}
      * must be called.
      */
     public AtomPushBean() {
-        initSingleLogger();
-    }
-
-    private void initSingleLogger() {
-        loggers = new ArrayList<LoggerLevel>();
-        loggers.add(new LoggerLevel("", "INFO"));
     }
 
     /**
@@ -128,59 +114,7 @@
         Validate.notNull(converter, "converter is null");
         conf.setConverter(converter);
     }
-
-    /**
-     * Set one or more loggers and levels descriptor. <br>
-     * Parsed input syntax is:
-     * 
-     * <pre>
-     * loggers   := &lt;logger&gt;(&lt;separator&gt;&lt;logger&gt;)*
-     * logger    := &lt;name&gt;[&quot;:&quot;&lt;level&gt;]
-     * separator := &quot;,&quot; | &quot; &quot; | &quot;\n&quot;
-     * </pre>
-     * 
-     * Examples:
-     * <p>
-     * Two loggers and two levels: <br>
-     * <tt>org.apache.cxf:INFO, org.apache.cxf.jaxrs:DEBUG</tt>
-     * <p>
-     * Three loggers, first with default "INFO" level: <br>
-     * <tt>org.apache.cxf, org.apache.cxf.jaxrs:DEBUG, namedLogger:ERROR</tt><br>
-     * <p>
-     * One logger with default "INFO" level: <br>
-     * <tt>org.apache.cxf</tt><br>
-     */
-    public void setLoggers(String loggers) {
-        checkInit();
-        Validate.notNull(loggers, "loggers is null");
-        parseLoggers(loggers);
-    }
-
-    /**
-     * Name of logger to associate with ATOM push handler; empty string for root logger.
-     */
-    public void setLogger(String logger) {
-        checkInit();
-        Validate.notNull(logger, "logger is null");
-        if (loggers.size() != 1) {
-            initSingleLogger();
-        }
-        loggers.get(0).setLogger(logger);
-    }
-
-    /**
-     * Name of level that logger will use publishing log events to ATOM push handler; empty
string for default
-     * "INFO" level.
-     */
-    public void setLevel(String level) {
-        checkInit();
-        Validate.notNull(level, "level is null");
-        if (loggers.size() != 1) {
-            initSingleLogger();
-        }
-        loggers.get(0).setLevel(level);
-    }
-
+    
     /**
      * Size of batch; empty string for default one element batch.
      */
@@ -253,65 +187,8 @@
         conf.setFormat(format);
     }
 
-    /**
-     * Initializes bean; creates ATOM push handler based on current properties state, and
attaches handler to
-     * logger(s).
-     */
-    public void init() {
-        checkInit();
-        initialized = true;
-        Handler h = new AtomPushHandler(conf.createEngine());
-        for (int i = 0; i < loggers.size(); i++) {
-            Logger l = LogUtils.getL7dLogger(AtomPushBean.class, null, loggers.get(i).getLogger());
-            l.addHandler(h);
-            l.setLevel(LogLevel.toJUL(LogLevel.valueOf(loggers.get(i).getLevel())));
-        }
-    }
-
-    private void checkInit() {
-        if (initialized) {
-            throw new IllegalStateException("Bean is already initialized");
-        }
-    }
-
-    private void parseLoggers(String param) {
-        loggers = new ArrayList<LoggerLevel>();
-        StringTokenizer st1 = new StringTokenizer(param, ", \t\n\r\f");
-        while (st1.hasMoreTokens()) {
-            String tok = st1.nextToken();
-            int idx = tok.indexOf(":");
-            if (idx != -1) {
-                loggers.add(new LoggerLevel(tok.substring(0, idx), tok.substring(idx + 1,
tok.length())));
-            } else {
-                loggers.add(new LoggerLevel(tok, "INFO"));
-            }
-        }
-    }
-
-    private static class LoggerLevel {
-        private String logger;
-        private String level;
-
-        public LoggerLevel(String logger, String level) {
-            this.logger = logger;
-            this.level = level;
-        }
-
-        public String getLogger() {
-            return logger;
-        }
-
-        public void setLogger(String logger) {
-            this.logger = logger;
-        }
-
-        public String getLevel() {
-            return level;
-        }
-
-        public void setLevel(String level) {
-            this.level = level;
-        }
-
+    protected Handler createHandler() {
+        return new AtomPushHandler(conf.createEngine());
     }
+
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushEngineConfigurator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushEngineConfigurator.java?rev=894615&r1=894614&r2=894615&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushEngineConfigurator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPushEngineConfigurator.java
Wed Dec 30 14:05:41 2009
@@ -123,11 +123,11 @@
             if (converterClass != null) {
                 c = createConverter(converterClass);
             } else {
-                Output out = parseEnum(output, Output.FEED);
+                Output out = parseEnum(output, Output.FEED, Output.class);
                 Multiplicity defaultMul = out == Output.FEED ? Multiplicity.MANY
                     : batch > 1 ? Multiplicity.MANY : Multiplicity.ONE; 
-                Multiplicity mul = parseEnum(multiplicity, defaultMul);
-                Format form = parseEnum(format, Format.CONTENT);
+                Multiplicity mul = parseEnum(multiplicity, defaultMul, Multiplicity.class);
+                Format form = parseEnum(format, Format.CONTENT, Format.class);
                 if (out == Output.FEED) {
                     c = new StandardConverter(out, mul, form);
                 } else {
@@ -201,12 +201,12 @@
     }
 
     @SuppressWarnings("unchecked")
-    private <T extends Enum<T>> T parseEnum(String value, T defaultValue) {
+    private <T extends Enum<T>> T parseEnum(String value, T defaultValue, Class<T>
enumClass) {
         if (value == null | "".equals(value)) {
             return defaultValue;
         }
         try {
-            return (T)Enum.valueOf(defaultValue.getClass(), value.toUpperCase());
+            return (T)Enum.valueOf(enumClass, value.toUpperCase());
         } catch (Exception e) {
             return defaultValue;
         }

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java?rev=894615&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
Wed Dec 30 14:05:41 2009
@@ -0,0 +1,163 @@
+/**
+ * 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.systest.jaxrs;
+
+import java.io.StringReader;
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.xml.bind.JAXBContext;
+
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.provider.AtomFeedProvider;
+import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JAXRSLoggingAtomPullSpringTest extends AbstractClientServerTestBase {
+
+    private JAXBContext context; 
+    private int fakyLogger;
+    private int namedLogger;
+    private int resourceLogger;
+    private int throwables;
+    
+    @BeforeClass
+    public static void beforeClass() throws Exception {
+        // must be 'in-process' to communicate with inner class in single JVM
+        // and to spawn class SpringServer w/o using main() method
+        launchServer(SpringServer.class, true);
+    }
+
+    @Ignore
+    public static class SpringServer extends AbstractSpringServer {
+        public SpringServer() {
+            super("/jaxrs_logging_atompull");
+        }
+    }
+
+    @Before
+    public void before() throws Exception {
+        context = JAXBContext.newInstance(org.apache.cxf.jaxrs.ext.logging.LogRecord.class);
+    }
+
+    @Test
+    public void testFeed() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:9080/resource/root");
+        wc.path("/log").get();
+        Thread.sleep(3000);
+        
+        WebClient wc2 = WebClient.create("http://localhost:9080/atom/logs",
+                                         Collections.singletonList(new AtomFeedProvider()));
+        Feed feed = wc2.accept("application/atom+xml").get(Feed.class);
+        feed.toString();
+        assertEquals(8, feed.getEntries().size());
+        
+        resetCounters();
+        for (Entry e : feed.getEntries()) {
+            updateCounters(readLogRecord(e.getContent()), "Resource");
+        }
+        
+        verifyCounters();
+    }
+    
+    
+    @Ignore
+    @Path("/root")
+    public static class Resource {
+        private static final Logger LOG1 = LogUtils.getL7dLogger(Resource.class);
+        private static final Logger LOG2 = LogUtils.getL7dLogger(Resource.class, null, "namedLogger");
+        
+        @GET
+        @Path("/log")
+        public void doLogging() {
+            doLog(LOG1, LOG2);
+        }
+
+    }
+    
+    
+    private static void doLog(Logger l1, Logger l2) {
+        l1.severe("severe message");
+        l1.warning("warning message");
+        l1.info("info message");
+        LogRecord r = new LogRecord(Level.FINE, "fine message");
+        r.setThrown(new IllegalArgumentException("tadaam"));
+        l1.log(r);
+        r = new LogRecord(Level.FINER, "finer message with {0} and {1}");
+        r.setParameters(new Object[] {
+            "param1", "param2"
+        });
+        r.setLoggerName("faky-logger");
+        l1.log(r);
+        l1.finest("finest message");
+
+        // for LOG2 only 'warning' and above messages should be logged
+        l2.severe("severe message");
+        l2.severe("severe message2");
+        l2.info("info message - should not pass!");
+        l2.finer("finer message - should not pass!");
+    }
+    
+    private org.apache.cxf.jaxrs.ext.logging.LogRecord readLogRecord(String value) throws
Exception {
+        return (org.apache.cxf.jaxrs.ext.logging.LogRecord)
+            context.createUnmarshaller().unmarshal(new StringReader(value));
+    }
+    
+    
+    private void updateCounters(org.apache.cxf.jaxrs.ext.logging.LogRecord record, String
clsName) {
+        String name = record.getLoggerName();
+        if (name != null && name.length() > 0) {
+            if (("org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$" + clsName).equals(name))
{
+                resourceLogger++;      
+            } else if ("namedLogger".equals(name)) {
+                namedLogger++;      
+            } else if ("faky-logger".equals(name)) {
+                fakyLogger++;      
+            }
+        } else {
+            assertNotNull(record.getThrowable());
+            throwables++;
+        }
+    }
+    
+    private void resetCounters() {
+        fakyLogger = 0;
+        namedLogger = 0;
+        resourceLogger = 0;
+        throwables = 0;
+    }
+    
+    private void verifyCounters() {
+        assertEquals(1, throwables);
+        assertEquals(4, resourceLogger);
+        assertEquals(2, namedLogger);
+        assertEquals(1, fakyLogger);
+    }
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml?rev=894615&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml (added)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml Wed
Dec 30 14:05:41 2009
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+	<!--
+		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.
+	-->
+	<!-- START SNIPPET: beans -->
+	<!--
+		beans xmlns="http://www.springframework.org/schema/beans"
+		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		xmlns:simple="http://cxf.apache.org/simple" xsi:schemaLocation="
+		http://www.springframework.org/schema/beans
+		http://www.springframework.org/schema/beans/spring-beans.xsd
+		http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd"
+	-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+	xmlns:util="http://www.springframework.org/schema/util"
+	xsi:schemaLocation="
+http://www.springframework.org/schema/beans 
+http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxrs 
+http://cxf.apache.org/schemas/jaxrs.xsd
+http://www.springframework.org/schema/util 
+http://www.springframework.org/schema/util/spring-util-2.0.xsd">
+
+	<import resource="classpath:META-INF/cxf/cxf.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
+	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
+
+	<bean id = "atomPullServer" class="org.apache.cxf.jaxrs.ext.logging.atom.AtomPullServer"

+	      init-method="init">
+	      <property name="loggers"
+			value="
+			org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource:ALL,
+			namedLogger:WARN" />
+	</bean>      
+
+	<bean id="feed" class="org.apache.cxf.jaxrs.provider.AtomFeedProvider">
+	    <property name="formattedOutput" value="true"/>
+	</bean>
+
+	<jaxrs:server id="resourceServer" address="/resource">
+		<jaxrs:serviceBeans>
+			<bean class="org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource"/>
+		</jaxrs:serviceBeans>
+		<jaxrs:providers>
+			<ref bean="feed" />
+		</jaxrs:providers>
+	</jaxrs:server>
+
+
+    <jaxrs:server id="atomServer" address="/atom">
+		<jaxrs:serviceBeans>
+			<ref bean="atomPullServer"/>
+		</jaxrs:serviceBeans>
+		<jaxrs:providers>
+			<ref bean="feed" />
+		</jaxrs:providers>
+	</jaxrs:server>
+
+</beans>
+<!-- END SNIPPET: beans -->
+

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/web.xml?rev=894615&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/web.xml (added)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/web.xml Wed
Dec 30 14:05:41 2009
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app
+    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+    "http://java.sun.com/dtd/web-app_2_3.dtd">
+<!--
+	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.
+-->
+<!-- START SNIPPET: webxml -->
+<web-app>
+	<context-param>
+		<param-name>contextConfigLocation</param-name>
+		<param-value>WEB-INF/beans.xml</param-value>
+	</context-param>
+
+	<listener>
+		<listener-class>
+			org.springframework.web.context.ContextLoaderListener
+		</listener-class>
+	</listener>
+
+	<servlet>
+		<servlet-name>CXFServlet</servlet-name>
+		<display-name>CXF Servlet</display-name>
+		<servlet-class>
+			org.apache.cxf.transport.servlet.CXFServlet
+		</servlet-class>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	
+	<servlet-mapping>
+		<servlet-name>CXFServlet</servlet-name>
+		<url-pattern>/*</url-pattern>
+	</servlet-mapping>
+	
+</web-app>
+<!-- END SNIPPET: webxml -->

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message