001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.samples.daytrader.web; 018 019 import java.io.IOException; 020 import javax.servlet.*; 021 import javax.servlet.http.*; 022 023 import org.apache.geronimo.samples.daytrader.soap.*; 024 import org.apache.geronimo.samples.daytrader.util.*; 025 026 import org.apache.geronimo.samples.daytrader.*; 027 028 public class OrdersAlertFilter implements Filter { 029 030 /** 031 * Constructor for CompletedOrdersAlertFilter 032 */ 033 public OrdersAlertFilter() { 034 super(); 035 } 036 037 /** 038 * @see Filter#init(FilterConfig) 039 */ 040 private FilterConfig filterConfig = null; 041 public void init(FilterConfig filterConfig) throws ServletException { 042 this.filterConfig = filterConfig; 043 } 044 045 /** 046 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) 047 */ 048 public void doFilter( 049 ServletRequest req, 050 ServletResponse resp, 051 FilterChain chain) 052 throws IOException, ServletException { 053 if (filterConfig == null) 054 return; 055 056 try 057 { 058 String action = req.getParameter("action"); 059 if ( action != null ) 060 { 061 action = action.trim(); 062 if ( (action.length() > 0) && (!action.equals("logout")) ) 063 { 064 String userID; 065 if ( action.equals("login") ) 066 userID = req.getParameter("uid"); 067 else 068 userID = (String) ((HttpServletRequest) req).getSession().getAttribute("uidBean"); 069 if ( (userID != null) && (userID.trim().length()>0) ) 070 { 071 TradeServices tAction=null; 072 if(TradeConfig.getAccessMode() == TradeConfig.STANDARD) 073 tAction = new TradeAction(); 074 else if(TradeConfig.getAccessMode() == TradeConfig.WEBSERVICES) 075 tAction = new TradeWebSoapProxy(); 076 java.util.Collection closedOrders = tAction.getClosedOrders(userID); 077 if ( (closedOrders!=null) && (closedOrders.size() > 0) ) 078 req.setAttribute("closedOrders", closedOrders); 079 if (Log.doTrace()) Log.printCollection("OrderAlertFilter: userID="+userID+" closedOrders=", closedOrders); 080 } 081 } 082 } 083 } 084 catch (Exception e) 085 { 086 Log.error(e, "OrdersAlertFilter - Error checking for closedOrders"); 087 } 088 089 ServletContext sc = filterConfig.getServletContext(); 090 //String xyz = (String) sc.getAttribute("hitCounter"); 091 chain.doFilter(req, resp/*wrapper*/); 092 093 } 094 095 /** 096 * @see Filter#destroy() 097 */ 098 public void destroy() { 099 this.filterConfig = null; 100 } 101 102 } 103