You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/08/31 09:02:02 UTC

svn commit: r690649 - /incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedFilter.java

Author: etnu
Date: Sun Aug 31 00:02:01 2008
New Revision: 690649

URL: http://svn.apache.org/viewvc?rev=690649&view=rev
Log:
Added an InjectedFilter to compliment InjectedServlet.


Added:
    incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedFilter.java

Added: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedFilter.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedFilter.java?rev=690649&view=auto
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedFilter.java (added)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/servlet/InjectedFilter.java Sun Aug 31 00:02:01 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.shindig.common.servlet;
+
+import com.google.inject.Injector;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+
+/**
+ * A Filter that can use Guice for injecting. Compliments InjectedServlet.
+ */
+public abstract class InjectedFilter implements Filter {
+  protected Injector injector;
+
+  public void init(FilterConfig config) throws ServletException {
+    ServletContext context = config.getServletContext();
+    injector = (Injector) context.getAttribute(GuiceServletContextListener.INJECTOR_ATTRIBUTE);
+    if (injector == null) {
+      throw new UnavailableException(
+          "Guice Injector not found! Make sure you registered " +
+          GuiceServletContextListener.class.getName() + " as a listener");
+    }
+    injector.injectMembers(this);
+  }
+}