knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject [1/2] KNOX-47: Replace all System.out.println and e.printStackTrace with localizable messages and resources.
Date Tue, 21 May 2013 13:11:32 GMT
Updated Branches:
  refs/heads/master 9ed2c0246 -> 5cd1567c3


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/5cd1567c/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
index fcf74bd..744784a 100644
--- a/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
+++ b/gateway-server/src/main/java/org/apache/hadoop/gateway/topology/file/FileTopologyProvider.java
@@ -95,9 +95,11 @@ public class FileTopologyProvider implements TopologyProvider, TopologyMonitor,
           try {
             map.put( file.getName(), loadTopology( file ) );
           } catch( IOException e ) {
-            e.printStackTrace();
+            // Maybe it makes sense to throw exception
+            log.failedToLoadTopology( file.getName().getFriendlyURI(), e );
           } catch( SAXException e ) {
-            e.printStackTrace();
+            // Maybe it makes sense to throw exception
+            log.failedToLoadTopology( file.getName().getFriendlyURI(), e );
           }
         }
       }
@@ -115,7 +117,8 @@ public class FileTopologyProvider implements TopologyProvider, TopologyMonitor,
         notifyChangeListeners( events );
       }
     } catch( FileSystemException e ) {
-      e.printStackTrace();
+      // Maybe it makes sense to throw exception
+      log.failedToReloadTopologies( e );
     }
   }
 
@@ -149,7 +152,7 @@ public class FileTopologyProvider implements TopologyProvider, TopologyMonitor,
       try {
         listener.handleTopologyEvent( events );
       } catch( RuntimeException e ) {
-        e.printStackTrace();
+        log.failedToHandleTopologyEvents( e );
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/5cd1567c/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/AbstractGatewayFilter.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/AbstractGatewayFilter.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/AbstractGatewayFilter.java
index b31336e..83dfb6f 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/AbstractGatewayFilter.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/AbstractGatewayFilter.java
@@ -25,6 +25,10 @@ import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import org.apache.hadoop.gateway.i18n.GatewaySpiMessages;
+import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
+
 import java.io.IOException;
 
 /**
@@ -35,6 +39,7 @@ public abstract class AbstractGatewayFilter implements Filter {
   public static final String SOURCE_REQUEST_URL_ATTRIBUTE_NAME = "sourceRequestUrl";
   public static final String TARGET_REQUEST_URL_ATTRIBUTE_NAME = "targetRequestUrl";
 //  public static final String RESPONSE_STREAMER_ATTRIBUTE_NAME = "responseStreamer";
+  private static final GatewaySpiMessages LOG = MessagesFactory.get( GatewaySpiMessages.class
);
 
   private FilterConfig config;
 
@@ -53,13 +58,13 @@ public abstract class AbstractGatewayFilter implements Filter {
     try {
       doFilter( (HttpServletRequest)request, (HttpServletResponse)response, chain );
     } catch( IOException e ) {
-      e.printStackTrace();
+      LOG.failedToExecuteFilter( e );
       throw e;
     } catch( ServletException e ) {
-      e.printStackTrace();
+      LOG.failedToExecuteFilter( e );
       throw e;
     } catch( Throwable t ) {
-      t.printStackTrace();
+      LOG.failedToExecuteFilter( t );
       throw new ServletException( t );
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/5cd1567c/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/security/AbstractIdentityAssertionFilter.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/security/AbstractIdentityAssertionFilter.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/security/AbstractIdentityAssertionFilter.java
index 4e4a5ed..5adaf8c 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/security/AbstractIdentityAssertionFilter.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/filter/security/AbstractIdentityAssertionFilter.java
@@ -25,6 +25,8 @@ import javax.servlet.Filter;
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletException;
 
+import org.apache.hadoop.gateway.i18n.GatewaySpiMessages;
+import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 import org.apache.hadoop.gateway.security.PrimaryPrincipal;
 import org.apache.hadoop.gateway.security.principal.PrincipalMapper;
 import org.apache.hadoop.gateway.security.principal.PrincipalMappingException;
@@ -32,6 +34,7 @@ import org.apache.hadoop.gateway.security.principal.SimplePrincipalMapper;
 
 public abstract class AbstractIdentityAssertionFilter implements Filter {
 
+  private static final GatewaySpiMessages LOG = MessagesFactory.get( GatewaySpiMessages.class
);
   protected PrincipalMapper mapper = new SimplePrincipalMapper();
 
   public AbstractIdentityAssertionFilter() {
@@ -45,8 +48,7 @@ public abstract class AbstractIdentityAssertionFilter implements Filter
{
         mapper.loadMappingTable(principalMapping);
       }
       catch (PrincipalMappingException pme) {
-        // TODO: log this appropriately
-        pme.printStackTrace();
+        LOG.failedToLoadPrincipalMappingTable( pme );
       }
     }
   }
@@ -87,4 +89,4 @@ public abstract class AbstractIdentityAssertionFilter implements Filter
{
     
   }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/5cd1567c/gateway-spi/src/main/java/org/apache/hadoop/gateway/i18n/GatewaySpiMessages.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/i18n/GatewaySpiMessages.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/i18n/GatewaySpiMessages.java
new file mode 100644
index 0000000..835194d
--- /dev/null
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/i18n/GatewaySpiMessages.java
@@ -0,0 +1,33 @@
+/**
+ * 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.hadoop.gateway.i18n;
+
+import org.apache.hadoop.gateway.i18n.messages.Message;
+import org.apache.hadoop.gateway.i18n.messages.MessageLevel;
+import org.apache.hadoop.gateway.i18n.messages.Messages;
+import org.apache.hadoop.gateway.i18n.messages.StackTrace;
+
+@Messages(logger="org.apache.hadoop.gateway")
+public interface GatewaySpiMessages {
+
+  @Message( level = MessageLevel.ERROR, text = "Failed to load the internal principal mapping
table: {0}" )
+  void failedToLoadPrincipalMappingTable( @StackTrace( level = MessageLevel.DEBUG ) Exception
e );
+
+  @Message( level = MessageLevel.ERROR, text = "Failed to execute filter: {0}" )
+  void failedToExecuteFilter( @StackTrace( level = MessageLevel.DEBUG ) Throwable t );
+}

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/5cd1567c/gateway-util-common/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-util-common/pom.xml b/gateway-util-common/pom.xml
index cda8702..1a17255 100644
--- a/gateway-util-common/pom.xml
+++ b/gateway-util-common/pom.xml
@@ -62,7 +62,10 @@
             <artifactId>gateway-test-utils</artifactId>
             <scope>test</scope>
         </dependency>
-
+        <dependency>
+            <groupId>${gateway-group}</groupId>
+            <artifactId>gateway-i18n</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.hamcrest</groupId>
             <artifactId>hamcrest-core</artifactId>
@@ -89,4 +92,4 @@
 
     </dependencies>
 
-</project>
\ No newline at end of file
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/5cd1567c/gateway-util-common/src/main/java/org/apache/hadoop/gateway/i18n/GatewayUtilCommonMessages.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/i18n/GatewayUtilCommonMessages.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/i18n/GatewayUtilCommonMessages.java
new file mode 100644
index 0000000..491be9b
--- /dev/null
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/i18n/GatewayUtilCommonMessages.java
@@ -0,0 +1,36 @@
+/**
+ * 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.hadoop.gateway.i18n;
+
+import java.util.Map;
+
+import org.apache.hadoop.gateway.i18n.messages.Message;
+import org.apache.hadoop.gateway.i18n.messages.MessageLevel;
+import org.apache.hadoop.gateway.i18n.messages.Messages;
+import org.apache.hadoop.gateway.i18n.messages.StackTrace;
+
+@Messages(logger="org.apache.hadoop.gateway")
+public interface GatewayUtilCommonMessages {
+
+  @Message( level = MessageLevel.ERROR, text = "Failed to serialize map to Json string {0}:
{1}" )
+  void failedToSerializeMapToJSON( Map<String, Object> map, @StackTrace( level = MessageLevel.DEBUG
) Exception e );
+
+  @Message( level = MessageLevel.ERROR, text = "Failed to get map from Json string {0}: {1}"
)
+  void failedToGetMapFromJsonString( String json, @StackTrace( level = MessageLevel.DEBUG
) Exception e );
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/5cd1567c/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
index 82b4478..1982ab9 100644
--- a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
@@ -21,9 +21,12 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.hadoop.gateway.i18n.GatewayUtilCommonMessages;
+import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
+
 import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonGenerationException;
 import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -31,6 +34,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class JsonUtils {
   
+  private static final GatewayUtilCommonMessages LOG = MessagesFactory.get( GatewayUtilCommonMessages.class
);
+
   public static String renderAsJsonString(Map<String, Object> map) {
     String json = null;
     ObjectMapper mapper = new ObjectMapper();
@@ -38,13 +43,9 @@ public class JsonUtils {
     try {
       // write JSON to a file
       json = mapper.writeValueAsString((Object)map);
-   
-    } catch (JsonGenerationException e) {
-      e.printStackTrace();
-    } catch (JsonMappingException e) {
-      e.printStackTrace();
-    } catch (IOException e) {
-      e.printStackTrace();
+    
+    } catch ( JsonProcessingException e ) {
+      LOG.failedToSerializeMapToJSON( map, e );
     }
     return json;
   }
@@ -58,14 +59,11 @@ public class JsonUtils {
     try {
       map = mapper.readValue(json, typeRef);
     } catch (JsonParseException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
+      LOG.failedToGetMapFromJsonString( json, e );
     } catch (JsonMappingException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
+      LOG.failedToGetMapFromJsonString( json, e );
     } catch (IOException e) {
-      // TODO Auto-generated catch block
-      e.printStackTrace();
+      LOG.failedToGetMapFromJsonString( json, e );
     } 
     return map;
   }   

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/5cd1567c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 26dcca3..eb8124a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -792,4 +792,4 @@
         </dependencies>
     </dependencyManagement>
 
-</project>
\ No newline at end of file
+</project>


Mime
View raw message