Author: sergeyb
Date: Fri Jan 22 15:02:28 2010
New Revision: 902109
URL: http://svn.apache.org/viewvc?rev=902109&view=rev
Log:
Finishing the initial support for Atom pull-style logging
Added:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadWriteLogStorage.java
(with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadableLogStorage.java
(with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/LogRecord.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/LogRecord.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/LogRecord.java?rev=902109&r1=902108&r2=902109&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/LogRecord.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/LogRecord.java
Fri Jan 22 15:02:28 2010
@@ -49,6 +49,19 @@
private String threadName = "";
private String throwable = "";
+ public LogRecord() {
+
+ }
+
+ public LogRecord(LogRecord copy) {
+ this.eventTimestamp = copy.getEventTimestamp();
+ this.level = copy.getLevel();
+ this.message = copy.getMessage();
+ this.loggerName = copy.getLoggerName();
+ this.threadName = copy.getThreadName();
+ this.throwable = copy.getThrowable();
+ }
+
/**
* Creates this object from JUL LogRecord. Most attributes are copied,
others are converted as follows:
* raw {...@link java.util.logging.LogRecord#getMessage() message} is
formatted with
@@ -164,4 +177,6 @@
public String toString() {
return ToStringBuilder.reflectionToString(this,
ToStringStyle.SHORT_PREFIX_STYLE);
}
+
+
}
Added:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadWriteLogStorage.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadWriteLogStorage.java?rev=902109&view=auto
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadWriteLogStorage.java
(added)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadWriteLogStorage.java
Fri Jan 22 15:02:28 2010
@@ -0,0 +1,40 @@
+/**
+ * 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;
+
+import java.util.List;
+
+/**
+ * Can be used by pull-style loggers to offload/save the records to some
external storage
+ *
+ */
+public interface ReadWriteLogStorage extends ReadableLogStorage {
+
+ /**
+ * Save the records
+ * @param records log records to save
+ */
+ void save(List<LogRecord> records);
+
+ /**
+ * Clear the storage
+ */
+ void clear();
+
+}
Propchange:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadWriteLogStorage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadWriteLogStorage.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadableLogStorage.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadableLogStorage.java?rev=902109&view=auto
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadableLogStorage.java
(added)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadableLogStorage.java
Fri Jan 22 15:02:28 2010
@@ -0,0 +1,56 @@
+/**
+ * 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;
+
+import java.util.List;
+
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+
+/**
+ * Can be used by pull-style loggers to read the records from some external
storage
+ *
+ */
+public interface ReadableLogStorage {
+
+
+ /**
+ * Read the records and load them into a provided list
+ * @param list the list saved records should be added to
+ * @param condition the condition loaded records must meet, can be null
+ * @param loadFrom the initial index of the storage to have records loaded
from
+ * @param int maxNumberOfRecords the max number of records to load from
the storage
+ */
+ void load(List<LogRecord> list,
+ SearchCondition<LogRecord> condition,
+ int loadFrom,
+ int maxNumberOfRecords);
+
+
+ /**
+ * Get the size of storage (in records)
+ * @param the size, -1 if not known, for ex, when reading from an open
file containing log entries
+ */
+ int getSize();
+
+
+ /**
+ * Close the storage
+ */
+ void close();
+}
Propchange:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadableLogStorage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/ReadableLogStorage.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
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=902109&r1=902108&r2=902109&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AbstractAtomBean.java
Fri Jan 22 15:02:28 2010
@@ -102,7 +102,7 @@
/**
- * Initializes bean; creates ATOM push handler based on current properties
state, and attaches handler to
+ * Initializes bean; creates ATOM handler based on current properties
state, and attaches handler to
* logger(s).
*/
public void init() {
@@ -138,7 +138,11 @@
}
}
- private static class LoggerLevel {
+ protected List<LoggerLevel> getLoggers() {
+ return loggers;
+ }
+
+ protected static class LoggerLevel {
private String logger;
private String level;
Modified:
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=902109&r1=902108&r2=902109&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/logging/atom/AtomPullServer.java
Fri Jan 22 15:02:28 2010
@@ -28,14 +28,19 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
-import org.apache.abdera.model.Element;
import org.apache.abdera.model.Feed;
import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.ext.logging.LogLevel;
import org.apache.cxf.jaxrs.ext.logging.LogRecord;
+import org.apache.cxf.jaxrs.ext.logging.ReadWriteLogStorage;
+import org.apache.cxf.jaxrs.ext.logging.ReadableLogStorage;
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;
+import org.apache.cxf.jaxrs.ext.search.ConditionType;
+import org.apache.cxf.jaxrs.ext.search.OrSearchCondition;
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
@Path("logs")
public class AtomPullServer extends AbstractAtomBean {
@@ -44,16 +49,57 @@
new StandardConverter(Output.FEED, Multiplicity.MANY, Format.CONTENT);
private List<LogRecord> records = new LinkedList<LogRecord>();
private WeakHashMap<Integer, Feed> feeds = new WeakHashMap<Integer,
Feed>();
+ private ReadableLogStorage storage;
private int pageSize = 20;
+ private int maxInMemorySize = 500;
private boolean useArchivedFeeds;
-
+ private int recordsSize;
+ private volatile boolean alreadyClosed;
+ private SearchCondition<LogRecord> condition;
+
@Context
private MessageContext context;
+ @Override
+ public void init() {
+ // the storage might've been used to save previous records or it might
+ // point to a file log entries are added to
+ if (storage != null) {
+ //-1 can be returned by read-only storage if it does not know in
advance
+ // a number of records it may contain
+ recordsSize = storage.getSize();
+ }
+
+ if (storage == null || storage instanceof ReadWriteLogStorage) {
+ super.init();
+ } else {
+ // super.init() results in the additional Handler being created
and publish()
+ // method being called as a result. If the storage is read-only it
is assumed it points to
+ // the external source of log records thus no need to get the
publish events here
+
+ // instead we create a SearchCondition the external storage will
check against when
+ // loading the matching records on request
+
+ List<SearchCondition<LogRecord>> list = new
LinkedList<SearchCondition<LogRecord>>();
+ for (LoggerLevel l : super.getLoggers()) {
+ LogRecord r = new LogRecord();
+ r.setLoggerName(l.getLogger());
+ r.setLevel(LogLevel.valueOf(l.getLevel()));
+ list.add(new SearchConditionImpl(r));
+ }
+ condition = new OrSearchCondition<LogRecord>(list);
+ }
+
+ }
+
@GET
@Produces("application/atom+xml")
public Feed getRecords() {
int page = getPageValue();
+
+ // lets check if the Atom reader is asking for a set of records which
has already been
+ // converted to Feed
+
synchronized (feeds) {
Feed f = feeds.get(page);
if (f != null) {
@@ -61,45 +107,89 @@
}
}
- List<? extends Element> elements = null;
+ Feed feed = null;
synchronized (records) {
List<LogRecord> list = getSubList(page);
- elements = converter.convert(list);
+ feed = (Feed)converter.convert(list).get(0);
+ setFeedPageProperties(feed, page);
}
- Feed feed = (Feed)(elements.get(0));
- setFeedPageProperties(feed, page);
- synchronized (feeds) {
- feeds.put(page, feed);
+ // if at the moment we've converted n < pageSize number of records
only and
+ // persist a Feed keyed by a page then another reader requesting the
same page
+ // may miss latest records which might've been added since the
original request
+ if (feed.getEntries().size() == pageSize) {
+ synchronized (feeds) {
+ feeds.put(page, feed);
+ }
}
return feed;
}
+ @GET
+ @Path("records")
+ @Produces("text/plain")
+ public int getNumberOfAvaiableRecords() {
+ return recordsSize;
+ }
+
+
protected List<LogRecord> getSubList(int page) {
- if (records.size() == 0) {
+
+ if (recordsSize == -1) {
+ // let the external storage load the records it knows about
+ List<LogRecord> list = new LinkedList<LogRecord>();
+ storage.load(list, condition, page == 1 ? 0 : (page - 1) *
pageSize, pageSize);
+ return list;
+ }
+
+ if (recordsSize == 0) {
return records;
}
+ int fromIndex = 0;
+ int toIndex = 0;
+ // see
http://tools.ietf.org/html/draft-nottingham-atompub-feed-history-07
if (!useArchivedFeeds) {
-
- int fromIndex = page == 1 ? 0 : (page - 1) * pageSize;
- if (fromIndex > records.size()) {
+ fromIndex = page == 1 ? 0 : (page - 1) * pageSize;
+ if (fromIndex > recordsSize) {
// this should not happen really
page = 1;
fromIndex = 0;
}
- int toIndex = page == 1 ? pageSize : fromIndex + pageSize;
- if (toIndex > records.size()) {
- toIndex = records.size();
+ toIndex = page == 1 ? pageSize : fromIndex + pageSize;
+ if (toIndex > recordsSize) {
+ toIndex = recordsSize;
}
- return records.subList(fromIndex, toIndex);
} else {
- int fromIndex = records.size() - pageSize * page;
+ fromIndex = recordsSize - pageSize * page;
if (fromIndex < 0) {
fromIndex = 0;
}
- int toIndex = pageSize < records.size() ? records.size() :
pageSize;
- return records.subList(fromIndex, toIndex);
+ toIndex = pageSize < recordsSize ? recordsSize : pageSize;
}
+
+ // if we have the storage then try to load from it
+ if (storage != null) {
+ if (fromIndex < storage.getSize()) {
+ int storageSize = storage.getSize();
+ int maxQuantityToLoad = toIndex > storageSize ? toIndex -
storageSize : toIndex - fromIndex;
+ List<LogRecord> list = new LinkedList<LogRecord>();
+ storage.load(list, condition, fromIndex, maxQuantityToLoad);
+ int totalQuantity = toIndex - fromIndex;
+ if (list.size() < totalQuantity) {
+ int remaining = totalQuantity - list.size();
+ if (remaining > records.size()) {
+ remaining = records.size();
+ }
+ list.addAll(records.subList(0, remaining));
+ }
+ return list;
+ } else {
+ fromIndex -= storage.getSize();
+ toIndex -= storage.getSize();
+ }
+ }
+ return records.subList(fromIndex, toIndex);
+
}
protected void setFeedPageProperties(Feed feed, int page) {
@@ -109,19 +199,21 @@
String uri = context.getUriInfo().getAbsolutePath().toString();
if (!useArchivedFeeds) {
-
- if (page > 2) {
- feed.addLink(uri, "first");
- }
-
- if (page * pageSize < records.size()) {
+ if (recordsSize != -1) {
+ if (page > 2) {
+ feed.addLink(uri, "first");
+ }
+
+ if (page * pageSize < recordsSize) {
+ feed.addLink(uri + "?page=" + (page + 1), "next");
+ }
+
+ if (page * (pageSize + 1) < recordsSize) {
+ feed.addLink(uri + "?page=" + (recordsSize / pageSize +
1), "last");
+ }
+ } else if (feed.getEntries().size() == pageSize) {
feed.addLink(uri + "?page=" + (page + 1), "next");
}
-
- if (page * (pageSize + 1) < records.size()) {
- feed.addLink(uri + "?page=" + (records.size() / pageSize + 1),
"last");
- }
-
if (page > 1) {
uri = page > 2 ? uri + "?page=" + (page - 1) : uri;
feed.addLink(uri, "previous");
@@ -156,16 +248,80 @@
}
public void publish(LogRecord record) {
+ if (alreadyClosed) {
+ System.err.println("AtomPullServer has been closed, the following
log record can not be saved : "
+ + record.toString());
+ return;
+ }
synchronized (records) {
+ if (records.size() == maxInMemorySize) {
+ if (storage instanceof ReadWriteLogStorage) {
+ ((ReadWriteLogStorage)storage).save(records);
+ records.clear();
+ } else {
+ LogRecord oldRecord = records.remove(0);
+ System.err.println("The oldest log record is removed : " +
oldRecord.toString());
+ }
+ }
records.add(record);
+ ++recordsSize;
}
}
+ public void setPageSize(int size) {
+ pageSize = size;
+ }
+
+ public void setMaxInMemorySize(int maxInMemorySize) {
+ this.maxInMemorySize = maxInMemorySize;
+ }
+
+ public void setStorage(ReadableLogStorage storage) {
+ this.storage = storage;
+ }
+
public void close() {
-
+ if (alreadyClosed) {
+ return;
+ }
+ alreadyClosed = true;
+ if (storage instanceof ReadWriteLogStorage) {
+ ((ReadWriteLogStorage)storage).save(records);
+ }
}
- public void setPageSize(int size) {
- pageSize = size;
+ private static class SearchConditionImpl implements
SearchCondition<LogRecord> {
+ private LogRecord template;
+
+ public SearchConditionImpl(LogRecord l) {
+ this.template = l;
+ }
+
+ public boolean isMet(LogRecord pojo) {
+
+ return (template.getLevel() == LogLevel.ALL
+ || pojo.getLevel().compareTo(template.getLevel()) <= 0)
+ && template.getLoggerName().equals(pojo.getLoggerName());
+ }
+
+ public LogRecord getCondition() {
+ return new LogRecord(template);
+ }
+
+ public ConditionType getConditionType() {
+ return ConditionType.CUSTOM;
+ }
+
+ public List<SearchCondition<LogRecord>> getConditions() {
+ return null;
+ }
+
+ public List<LogRecord> findAll(List<LogRecord> pojos) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
}
+
}
Modified:
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=902109&r1=902108&r2=902109&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
(original)
+++
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLoggingAtomPullSpringTest.java
Fri Jan 22 15:02:28 2010
@@ -21,6 +21,7 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.LogRecord;
@@ -35,8 +36,13 @@
import org.apache.abdera.model.Link;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.ext.logging.LogLevel;
+import org.apache.cxf.jaxrs.ext.logging.ReadWriteLogStorage;
+import org.apache.cxf.jaxrs.ext.logging.ReadableLogStorage;
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
import org.apache.cxf.jaxrs.provider.AtomFeedProvider;
import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
+import org.apache.cxf.transport.http.HTTPConduit;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -68,6 +74,7 @@
@Before
public void before() throws Exception {
context =
JAXBContext.newInstance(org.apache.cxf.jaxrs.ext.logging.LogRecord.class);
+ Storage.clearRecords();
}
@Test
@@ -93,11 +100,58 @@
wc.path("/log").get();
Thread.sleep(3000);
- verifyPages("http://localhost:9080/atom2/logs", "next", 3, 2);
- verifyPages("http://localhost:9080/atom2/logs?page=3", "previous", 2,
3);
+ verifyPages("http://localhost:9080/atom2/logs", "next", 3, 2,
"theNamedLogger");
+ verifyPages("http://localhost:9080/atom2/logs?page=3", "previous", 2,
3, "theNamedLogger");
}
- private void verifyPages(String startAddress, String rel, int firstValue,
int lastValue)
+ @Test
+ public void testPagedFeedWithReadWriteStorage() throws Exception {
+ WebClient wc =
WebClient.create("http://localhost:9080/resource3/storage");
+ HTTPConduit conduit = WebClient.getConfig(wc).getHttpConduit();
+ conduit.getClient().setReceiveTimeout(1000000);
+ conduit.getClient().setConnectionTimeout(1000000);
+ wc.path("/log").get();
+ Thread.sleep(3000);
+
+ verifyStoragePages("http://localhost:9080/atom3/logs", "next",
"Resource3", "theStorageLogger");
+ List<org.apache.cxf.jaxrs.ext.logging.LogRecord> list =
Storage.getRecords();
+ assertEquals(4, list.size());
+ verifyStoragePages("http://localhost:9080/atom3/logs", "next",
"Resource3", "theStorageLogger");
+ verifyStoragePages("http://localhost:9080/atom3/logs?page=2",
"previous", "Resource3",
+ "theStorageLogger");
+ }
+
+ @Test
+ public void testPagedFeedWithReadOnlyStorage() throws Exception {
+ verifyStoragePages("http://localhost:9080/atom4/logs", "next",
"Resource4", "readOnlyStorageLogger");
+ verifyStoragePages("http://localhost:9080/atom4/logs?page=2",
"previous", "Resource4",
+ "readOnlyStorageLogger");
+ }
+
+ private void verifyStoragePages(String startAddress, String rel,
+ String resourceName, String nLogger)
+ throws Exception {
+ List<Entry> entries = new ArrayList<Entry>();
+ String href1 = fillPagedEntries(entries, startAddress, 4, rel, true);
+ assertNull(fillPagedEntries(entries, href1, 4, rel, false));
+ assertEquals(8, entries.size());
+
+ resetCounters();
+ for (Entry e : entries) {
+ updateCounters(readLogRecord(e.getContent()), resourceName,
nLogger);
+ }
+ if ("Resource4".equals(resourceName)) {
+ assertEquals(1, throwables);
+ assertEquals(6, resourceLogger);
+ assertEquals(2, namedLogger);
+ assertEquals(0, fakyLogger);
+ } else {
+ verifyCounters();
+ }
+ }
+
+ private void verifyPages(String startAddress, String rel,
+ int firstValue, int lastValue, String nLogger)
throws Exception {
List<Entry> entries = new ArrayList<Entry>();
String href1 = fillPagedEntries(entries, startAddress,
@@ -108,7 +162,7 @@
resetCounters();
for (Entry e : entries) {
- updateCounters(readLogRecord(e.getContent()), "Resource2",
"theNamedLogger");
+ updateCounters(readLogRecord(e.getContent()), "Resource2",
nLogger);
}
verifyCounters();
}
@@ -131,6 +185,9 @@
private Feed getFeed(String address) {
WebClient wc = WebClient.create(address,
Collections.singletonList(new
AtomFeedProvider()));
+ HTTPConduit conduit = WebClient.getConfig(wc).getHttpConduit();
+ conduit.getClient().setReceiveTimeout(1000000);
+ conduit.getClient().setConnectionTimeout(1000000);
Feed feed = wc.accept("application/atom+xml").get(Feed.class);
feed.toString();
return feed;
@@ -164,12 +221,121 @@
}
+ @Ignore
+ @Path("/storage")
+ public static class Resource3 {
+ private static final Logger LOG1 =
LogUtils.getL7dLogger(Resource3.class);
+ private static final Logger LOG2 =
LogUtils.getL7dLogger(Resource3.class, null, "theStorageLogger");
+
+ @GET
+ @Path("/log")
+ public void doLogging() {
+ doLog(Resource3.LOG1, Resource3.LOG2);
+ }
+
+ }
+
+ @Ignore
+ public static class ExternalStorage implements ReadableLogStorage {
+
+ private List<org.apache.cxf.jaxrs.ext.logging.LogRecord> records =
+ new LinkedList<org.apache.cxf.jaxrs.ext.logging.LogRecord>();
+
+ public ExternalStorage() {
+
addRecord("org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource4",
+ Level.SEVERE, null);
+
addRecord("org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource4",
+ Level.WARNING, null);
+
addRecord("org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource4",
+ Level.INFO, null);
+
addRecord("org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource4",
+ Level.FINE, new IllegalArgumentException());
+
addRecord("org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource4",
+ Level.FINEST, null);
+
addRecord("org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource4",
+ Level.FINER, null);
+ addRecord("readOnlyStorageLogger", Level.SEVERE, null);
+ addRecord("readOnlyStorageLogger", Level.SEVERE, null);
+ }
+
+ private void addRecord(String loggerName, Level level, Throwable t) {
+ org.apache.cxf.jaxrs.ext.logging.LogRecord lr =
+ new org.apache.cxf.jaxrs.ext.logging.LogRecord();
+ lr.setLoggerName(loggerName);
+ lr.setLevel(LogLevel.fromJUL(level));
+ if (t != null) {
+ lr.setThrowable(t);
+ }
+ records.add(lr);
+ }
+
+ public void close() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public int getSize() {
+ // this storage is getting the records from a file log entries are
added to
+ return -1;
+ }
+
+ public void load(List<org.apache.cxf.jaxrs.ext.logging.LogRecord>
list,
+
SearchCondition<org.apache.cxf.jaxrs.ext.logging.LogRecord> condition,
+ int loadFrom,
+ int maxNumberOfRecords) {
+ int limit = loadFrom + maxNumberOfRecords;
+ for (int i = loadFrom; i < limit; i++) {
+ if (condition.isMet(records.get(i))) {
+ list.add(records.get(i));
+ }
+ }
+ }
+
+ }
+
+ @Ignore
+ public static class Storage implements ReadWriteLogStorage {
+ private static List<org.apache.cxf.jaxrs.ext.logging.LogRecord>
records =
+ new LinkedList<org.apache.cxf.jaxrs.ext.logging.LogRecord>();
+
+ public void load(List<org.apache.cxf.jaxrs.ext.logging.LogRecord> list,
+
SearchCondition<org.apache.cxf.jaxrs.ext.logging.LogRecord> sc,
+ int from, int quantity) {
+ list.addAll(records.subList(from, from + quantity));
+ }
+
+ public void save(List<org.apache.cxf.jaxrs.ext.logging.LogRecord>
list) {
+ records.addAll(list);
+ }
+
+ public void clear() {
+ }
+
+ public void close() {
+ }
+
+ public int getSize() {
+ return records.size();
+ }
+
+ public static List<org.apache.cxf.jaxrs.ext.logging.LogRecord>
getRecords() {
+ return records;
+ }
+
+ public static void clearRecords() {
+ records.clear();
+ }
+ }
+
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");
+ if ("Resource4".equals(l1.getName())) {
+ r.setLoggerName(l1.getName());
+ }
r.setThrown(new IllegalArgumentException("tadaam"));
l1.log(r);
r = new LogRecord(Level.FINER, "finer message with {0} and {1}");
@@ -206,8 +372,9 @@
} else if ("faky-logger".equals(name)) {
fakyLogger++;
}
- } else {
- assertNotNull(record.getThrowable());
+ }
+
+ if (record.getThrowable().length() > 0) {
throwables++;
}
}
Modified:
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=902109&r1=902108&r2=902109&view=diff
==============================================================================
---
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml
(original)
+++
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_logging_atompull/WEB-INF/beans.xml
Fri Jan 22 15:02:28 2010
@@ -54,8 +54,36 @@
theNamedLogger:WARN" />
<property name="pageSize" value="3"/>
+ </bean>
+
+ <bean id = "atomPullServer3"
class="org.apache.cxf.jaxrs.ext.logging.atom.AtomPullServer"
+ init-method="init">
+ <property name="loggers"
+ value="
+
org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource3:ALL,
+ theStorageLogger:WARN" />
+ <property name="pageSize" value="4"/>
+ <property name="maxInMemorySize" value="4"/>
+ <property name="storage">
+ <ref bean="storage" />
+ </property>
+ </bean>
+
+ <bean id = "atomPullServer4"
class="org.apache.cxf.jaxrs.ext.logging.atom.AtomPullServer"
+ init-method="init">
+ <property name="loggers"
+ value="
+
org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource4:ALL,
+ readOnlyStorageLogger:WARN" />
+ <property name="pageSize" value="4"/>
+ <property name="storage">
+ <ref bean="storage2" />
+ </property>
</bean>
+ <bean id="storage"
class="org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Storage"/>
+ <bean id="storage2"
class="org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$ExternalStorage"/>
+
<bean id="feed" class="org.apache.cxf.jaxrs.provider.AtomFeedProvider">
<property name="formattedOutput" value="true"/>
</bean>
@@ -77,7 +105,15 @@
<ref bean="feed" />
</jaxrs:providers>
</jaxrs:server>
-
+
+ <jaxrs:server id="resource3Server" address="/resource3">
+ <jaxrs:serviceBeans>
+ <bean
class="org.apache.cxf.systest.jaxrs.JAXRSLoggingAtomPullSpringTest$Resource3"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <ref bean="feed" />
+ </jaxrs:providers>
+ </jaxrs:server>
<jaxrs:server id="atomServer" address="/atom">
<jaxrs:serviceBeans>
@@ -96,7 +132,25 @@
<ref bean="feed" />
</jaxrs:providers>
</jaxrs:server>
+
+ <jaxrs:server id="atomServer3" address="/atom3">
+ <jaxrs:serviceBeans>
+ <ref bean="atomPullServer3"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <ref bean="feed" />
+ </jaxrs:providers>
+ </jaxrs:server>
+ <jaxrs:server id="atomServer4" address="/atom4">
+ <jaxrs:serviceBeans>
+ <ref bean="atomPullServer4"/>
+ </jaxrs:serviceBeans>
+ <jaxrs:providers>
+ <ref bean="feed" />
+ </jaxrs:providers>
+ </jaxrs:server>
+
</beans>
<!-- END SNIPPET: beans -->