cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amicha...@apache.org
Subject svn commit: r883205 - 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/resources/
Date Mon, 23 Nov 2009 00:55:52 GMT
Author: amichalec
Date: Mon Nov 23 00:55:51 2009
New Revision: 883205

URL: http://svn.apache.org/viewvc?rev=883205&view=rev
Log:
ATOM push-style converters for ATOM extension mode; fix of doubled nested content tags.

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryExtensionConverter.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryExtensionConverter.java
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryContentConverter.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryContentConverter.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/logging_atompush.properties

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryContentConverter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryContentConverter.java?rev=883205&r1=883204&r2=883205&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryContentConverter.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryContentConverter.java
Mon Nov 23 00:55:51 2009
@@ -35,7 +35,7 @@
 import org.apache.cxf.jaxrs.ext.logging.LogRecordsList;
 
 /**
- * Multiple entries in feed, each entry content with one log record from list.
+ * Multiple entries in feed, each entry with one log record from list embedded as XML content.
  */
 public class MultiEntryContentConverter implements Converter {
 
@@ -56,16 +56,13 @@
         for (LogRecord record : records) {
             Entry entry = factory.newEntry();
             feed.addEntry(entry);
-            Content content = factory.newContent();
-            content.setContentType(Content.Type.XML);
-            entry.setContent(content);
             StringWriter writer = new StringWriter();
             try {
                 marsh.marshal(record, writer);
             } catch (JAXBException e) {
                 throw new RuntimeException(e);
             }
-            content.setValue(writer.toString());
+            entry.setContent(writer.toString(), Content.Type.XML);
         }
         return feed;
     }

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryExtensionConverter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryExtensionConverter.java?rev=883205&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryExtensionConverter.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/MultiEntryExtensionConverter.java
Mon Nov 23 00:55:51 2009
@@ -0,0 +1,75 @@
+/**
+ * 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.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.ExtensibleElement;
+import org.apache.abdera.model.Feed;
+import org.apache.cxf.jaxrs.ext.logging.LogRecord;
+
+/**
+ * Multiple entries in feed, each entry with list of log records embedded as ATOM extension.
+ */
+public class MultiEntryExtensionConverter implements Converter {
+
+    private Factory factory = Abdera.getNewFactory();
+    private DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+
+    public Element convert(List<LogRecord> records) {
+        Feed feed = factory.newFeed();
+        for (LogRecord rec : records) {
+            Entry entry = factory.newEntry();
+            feed.addEntry(entry);
+            ExtensibleElement erec = entry.addExtension(qn("logRecord"));
+            String date = df.format(rec.getEventTimestamp());
+            // timezone in date does not have semicolon as XML Date requires
+            // e.g we have "2009-11-23T22:03:53.996+0100"
+            // instead of "2009-11-23T22:03:53.996+01:00"
+            date = date.substring(0, date.length() - 2) + ":" + date.substring(date.length()
- 2);
+            // forget about single line "addExtension().setText()" since
+            // javac failure "org.apache.abdera.model.Element cannot be dereferenced"
+            Element e = erec.addExtension(qn("eventTimestamp"));
+            e.setText(date);
+            e = erec.addExtension(qn("level"));
+            e.setText(rec.getLevel().toString());
+            e = erec.addExtension(qn("loggerName"));
+            e.setText(rec.getLoggerName());
+            e = erec.addExtension(qn("message"));
+            e.setText(rec.getMessage());
+            e = erec.addExtension(qn("threadName"));
+            e.setText(rec.getThreadName());
+            e = erec.addExtension(qn("throwable"));
+            e.setText(rec.getThrowable());
+        }
+        return feed;
+    }
+
+    private QName qn(String name) {
+        return new QName("http://cxf.apache.org/jaxrs/log", name, "log");
+    }
+}

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryContentConverter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryContentConverter.java?rev=883205&r1=883204&r2=883205&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryContentConverter.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryContentConverter.java
Mon Nov 23 00:55:51 2009
@@ -35,7 +35,7 @@
 import org.apache.cxf.jaxrs.ext.logging.LogRecordsList;
 
 /**
- * Single entry in feed with content set to list of log records.
+ * Single entry in feed with list of log records embedded as XML content.
  */
 public class SingleEntryContentConverter implements Converter {
 
@@ -55,9 +55,6 @@
         Feed feed = factory.newFeed();
         Entry entry = factory.newEntry();
         feed.addEntry(entry);
-        Content content = factory.newContent();
-        content.setContentType(Content.Type.XML);
-        entry.setContent(content);
         StringWriter writer = new StringWriter();
         LogRecordsList list = new LogRecordsList();
         list.setLogRecords(records);
@@ -66,7 +63,7 @@
         } catch (JAXBException e) {
             throw new RuntimeException(e);
         }
-        content.setValue(writer.toString());
+        entry.setContent(writer.toString(), Content.Type.XML);
         return feed;
     }
 

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryExtensionConverter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryExtensionConverter.java?rev=883205&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryExtensionConverter.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/SingleEntryExtensionConverter.java
Mon Nov 23 00:55:51 2009
@@ -0,0 +1,76 @@
+/**
+ * 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.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.ExtensibleElement;
+import org.apache.abdera.model.Feed;
+import org.apache.cxf.jaxrs.ext.logging.LogRecord;
+
+/**
+ * Single entry in feed with list of log records embedded as ATOM extension.
+ */
+public class SingleEntryExtensionConverter implements Converter {
+
+    private Factory factory = Abdera.getNewFactory();
+    private DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+
+    public Element convert(List<LogRecord> records) {
+        Feed feed = factory.newFeed();
+        Entry entry = factory.newEntry();
+        feed.addEntry(entry);
+        ExtensibleElement list = entry.addExtension(qn("logRecordsList"));
+        for (LogRecord rec : records) {
+            ExtensibleElement erec = list.addExtension(qn("logRecord"));
+            String date = df.format(rec.getEventTimestamp());
+            // timezone in date does not have semicolon as XML Date requires
+            // e.g we have "2009-11-23T22:03:53.996+0100"
+            // instead of "2009-11-23T22:03:53.996+01:00"
+            date = date.substring(0, date.length() - 2) + ":" + date.substring(date.length()
- 2);
+            // forget about single line "addExtension().setText()" since
+            // javac failure "org.apache.abdera.model.Element cannot be dereferenced"
+            Element e = erec.addExtension(qn("eventTimestamp"));
+            e.setText(date);
+            e = erec.addExtension(qn("level"));
+            e.setText(rec.getLevel().toString());
+            e = erec.addExtension(qn("loggerName"));
+            e.setText(rec.getLoggerName());
+            e = erec.addExtension(qn("message"));
+            e.setText(rec.getMessage());
+            e = erec.addExtension(qn("threadName"));
+            e.setText(rec.getThreadName());
+            e = erec.addExtension(qn("throwable"));
+            e.setText(rec.getThrowable());
+        }
+        return feed;
+    }
+
+    private QName qn(String name) {
+        return new QName("http://cxf.apache.org/jaxrs/log", name, "log");
+    }
+}

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/logging_atompush.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/logging_atompush.properties?rev=883205&r1=883204&r2=883205&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/logging_atompush.properties
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/logging_atompush.properties
Mon Nov 23 00:55:51 2009
@@ -25,7 +25,7 @@
 # Atom handler specific settings
 org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.url = http://localhost:9080
 org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.batchSize = 1
-#org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.converter = ContentSingleEntryConverter
+org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.converter = SingleEntryExtensionConverter
 #org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.deliverer = WebClientDeliverer
 
 #org.apache.cxf.jaxrs.ext.logging.atom.AtomPushHandler.retry.pause = linear



Mime
View raw message