You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2014/03/10 17:06:20 UTC

svn commit: r1575987 - in /webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto: WSProviderConfig.java WSS4JResourceBundle.java

Author: coheigea
Date: Mon Mar 10 16:06:20 2014
New Revision: 1575987

URL: http://svn.apache.org/r1575987
Log:
Fixing the Santuario ResourceBundle when used with a non-US Locale

Added:
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSS4JResourceBundle.java
Modified:
    webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java

Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java?rev=1575987&r1=1575986&r2=1575987&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java (original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSProviderConfig.java Mon Mar 10 16:06:20 2014
@@ -25,12 +25,8 @@ import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
 import java.security.Provider;
 import java.security.Security;
-import java.util.Enumeration;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
 
 import org.apache.wss4j.common.util.Loader;
-import org.apache.xml.security.utils.Constants;
 import org.apache.xml.security.utils.I18n;
 import org.apache.xml.security.utils.XMLUtils;
 
@@ -133,33 +129,7 @@ public final class WSProviderConfig {
     }
 
     private static void initializeResourceBundles() {
-
-        ResourceBundle resourceBundle = new ResourceBundle() {
-
-            private final ResourceBundle wss4jSecResourceBundle = ResourceBundle.getBundle("messages.wss4j_errors");
-            private final ResourceBundle xmlSecResourceBundle = ResourceBundle.getBundle(Constants.exceptionMessagesResourceBundleBase);
-
-            @Override
-            protected Object handleGetObject(String key) {
-                Object value = null;
-                try {
-                    value = wss4jSecResourceBundle.getObject(key);
-                } catch (MissingResourceException e) {
-                    try {
-                        value = xmlSecResourceBundle.getObject(key);
-                    } catch (MissingResourceException ex) { //NOPMD
-                        //ignore
-                    }
-                }
-                return value;
-            }
-
-            @Override
-            public Enumeration<String> getKeys() {
-                throw new UnsupportedOperationException("getKeys not supported");
-            }
-        };
-        I18n.init(resourceBundle);
+        I18n.init(new WSS4JResourceBundle());
     }
 
     /**

Added: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSS4JResourceBundle.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSS4JResourceBundle.java?rev=1575987&view=auto
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSS4JResourceBundle.java (added)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/crypto/WSS4JResourceBundle.java Mon Mar 10 16:06:20 2014
@@ -0,0 +1,79 @@
+/**
+ * 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.wss4j.common.crypto;
+
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.apache.xml.security.utils.Constants;
+
+/**
+ * ResourceBundle for WSS4J
+ */
+public class WSS4JResourceBundle extends ResourceBundle {
+    
+    private static final org.slf4j.Logger LOG = 
+        org.slf4j.LoggerFactory.getLogger(WSS4JResourceBundle.class);
+    
+    private final ResourceBundle wss4jSecResourceBundle;
+    private final ResourceBundle xmlSecResourceBundle;
+    
+    public WSS4JResourceBundle() {
+        wss4jSecResourceBundle = ResourceBundle.getBundle("messages.wss4j_errors");
+        
+        ResourceBundle tmpResourceBundle;
+        try {
+            tmpResourceBundle = 
+                ResourceBundle.getBundle(Constants.exceptionMessagesResourceBundleBase);
+        } catch (MissingResourceException ex) {
+            // Using a Locale of which there is no properties file.
+            LOG.debug(ex.getMessage());
+            // Default to en/US
+            tmpResourceBundle = 
+                ResourceBundle.getBundle(Constants.exceptionMessagesResourceBundleBase,
+                                         new Locale("en", "US"));
+        }
+        xmlSecResourceBundle = tmpResourceBundle;
+    }
+
+    @Override
+    protected Object handleGetObject(String key) {
+        Object value = null;
+        try {
+            value = wss4jSecResourceBundle.getObject(key);
+        } catch (MissingResourceException e) {
+            try {
+                value = xmlSecResourceBundle.getObject(key);
+            } catch (MissingResourceException ex) { //NOPMD
+                //ignore
+            }
+        }
+        return value;
+    }
+
+    @Override
+    public Enumeration<String> getKeys() {
+        throw new UnsupportedOperationException("getKeys not supported");
+    }
+    
+    
+}