Return-Path: Delivered-To: apmail-incubator-cxf-commits-archive@locus.apache.org Received: (qmail 69306 invoked from network); 20 Feb 2008 16:56:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Feb 2008 16:56:24 -0000 Received: (qmail 29088 invoked by uid 500); 20 Feb 2008 16:56:18 -0000 Delivered-To: apmail-incubator-cxf-commits-archive@incubator.apache.org Received: (qmail 29030 invoked by uid 500); 20 Feb 2008 16:56:18 -0000 Mailing-List: contact cxf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-commits@incubator.apache.org Received: (qmail 29021 invoked by uid 99); 20 Feb 2008 16:56:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Feb 2008 08:56:18 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Feb 2008 16:55:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 41B7C1A9832; Wed, 20 Feb 2008 08:56:03 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r629533 - in /incubator/cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/common/i18n/ common/common/src/main/java/org/apache/cxf/common/logging/ common/common/src/test/java/org/apache/cxf/common/i18n/ common/common/sr... Date: Wed, 20 Feb 2008 16:56:01 -0000 To: cxf-commits@incubator.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080220165603.41B7C1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Wed Feb 20 08:55:58 2008 New Revision: 629533 URL: http://svn.apache.org/viewvc?rev=629533&view=rev Log: Merged revisions 629531 via svnmerge from https://svn.apache.org/repos/asf/incubator/cxf/trunk ........ r629531 | dkulp | 2008-02-20 11:49:30 -0500 (Wed, 20 Feb 2008) | 2 lines [CXF-1432, CXF-1420] Make Message objects serializable, fix issues if message cannot be formatted, just log as is. ........ Modified: incubator/cxf/branches/2.0.x-fixes/ (props changed) incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/i18n/Message.java incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/i18n/MessageTest.java incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java Propchange: incubator/cxf/branches/2.0.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/i18n/Message.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/i18n/Message.java?rev=629533&r1=629532&r2=629533&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/i18n/Message.java (original) +++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/i18n/Message.java Wed Feb 20 08:55:58 2008 @@ -19,16 +19,20 @@ package org.apache.cxf.common.i18n; +import java.io.IOException; +import java.io.Serializable; import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.logging.Logger; -public class Message { - String code; - Object[] parameters; - ResourceBundle bundle; +public class Message implements Serializable { + private static final long serialVersionUID = 42L; + transient String code; + transient Object[] parameters; + transient ResourceBundle bundle; + /** * Constructor. * @@ -72,5 +76,16 @@ public Object[] getParameters() { return parameters; + } + + private void writeObject(java.io.ObjectOutputStream out) + throws IOException { + out.writeUTF(toString()); + } + private void readObject(java.io.ObjectInputStream in) + throws IOException, ClassNotFoundException { + code = in.readUTF(); + bundle = null; + parameters = null; } } Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java?rev=629533&r1=629532&r2=629533&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java (original) +++ incubator/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/common/logging/LogUtils.java Wed Feb 20 08:55:58 2008 @@ -252,12 +252,7 @@ public static void log(Logger logger, Level level, String message) { - if (logger.isLoggable(level)) { - final String formattedMessage = - MessageFormat.format(localize(logger, message), NO_PARAMETERS); - doLog(logger, level, formattedMessage, null); - } - + log(logger, level, message, NO_PARAMETERS); } /** @@ -303,11 +298,14 @@ String message, Object[] parameters) { if (logger.isLoggable(level)) { - final String formattedMessage = - MessageFormat.format(localize(logger, message), parameters); - doLog(logger, level, formattedMessage, null); - } - + String msg = localize(logger, message); + try { + msg = MessageFormat.format(msg, parameters); + } catch (IllegalArgumentException ex) { + //ignore, log as is + } + doLog(logger, level, msg, null); + } } private static void doLog(Logger log, Level level, String msg, Throwable t) { @@ -345,7 +343,12 @@ */ private static String localize(Logger logger, String message) { ResourceBundle bundle = logger.getResourceBundle(); - return bundle != null ? bundle.getString(message) : message; + try { + return bundle != null ? bundle.getString(message) : message; + } catch (MissingResourceException ex) { + //string not in the bundle + return message; + } } } Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/i18n/MessageTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/i18n/MessageTest.java?rev=629533&r1=629532&r2=629533&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/i18n/MessageTest.java (original) +++ incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/i18n/MessageTest.java Wed Feb 20 08:55:58 2008 @@ -19,6 +19,10 @@ package org.apache.cxf.common.i18n; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.util.ResourceBundle; import java.util.logging.Logger; @@ -49,5 +53,24 @@ assertEquals("unexpected message string", "subbed in 4 & 3", msg.toString()); + } + + @Test + public void testExceptionIO() throws java.lang.Exception { + ResourceBundle bundle = BundleUtils.getBundle(getClass()); + UncheckedException ex = new UncheckedException(new Message("SUB2_EXC", + bundle, + new Object[] {3, 4})); + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(bout); + out.writeObject(ex); + + ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bin); + Object o = in.readObject(); + assertTrue(o instanceof UncheckedException); + UncheckedException ex2 = (UncheckedException)o; + assertEquals("subbed in 4 & 3", ex2.getMessage()); + } } Modified: incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java?rev=629533&r1=629532&r2=629533&view=diff ============================================================================== --- incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java (original) +++ incubator/cxf/branches/2.0.x-fixes/common/common/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java Wed Feb 20 08:55:58 2008 @@ -125,7 +125,10 @@ EasyMock.verify(handler); LOG.removeHandler(handler); } - + @Test + public void testCXF1420() throws Exception { + LogUtils.log(LOG, Level.SEVERE, "SQLException for SQL [{call FOO.ping(?, ?)}]"); + } @Test public void testClassMethodNames() throws Exception { TestLogHandler handler = new TestLogHandler();