Home » geronimo-2.2-source-release » org.apache.geronimo.monitoring.console » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    *  http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   
   21   package org.apache.geronimo.monitoring.console;
   22   
   23   import java.io.IOException;
   24   
   25   import javax.servlet.GenericServlet;
   26   import javax.servlet.ServletRequest;
   27   import javax.servlet.ServletResponse;
   28   import javax.servlet.ServletException;
   29   import javax.servlet.ServletConfig;
   30   import javax.servlet.RequestDispatcher;
   31   import javax.annotation.Resource;
   32   import javax.transaction.UserTransaction;
   33   import javax.persistence.PersistenceContext;
   34   import javax.persistence.EntityManager;
   35   import javax.portlet.RenderRequest;
   36   import javax.portlet.PortletException;
   37   
   38   import org.apache.geronimo.monitoring.console.data.Graph;
   39   
   40   /**
   41    * @version $Rev: 720024 $ $Date: 2008-11-23 10:32:00 -0800 (Sun, 23 Nov 2008) $
   42    */
   43   public class PopUpGraphServlet extends GenericServlet {
   44       @Resource
   45       UserTransaction userTransaction;
   46   
   47       @PersistenceContext
   48       EntityManager entityManager;
   49   
   50       private RequestDispatcher jspDispatcher;
   51   
   52       /**
   53        * Called by the servlet container to indicate to a servlet that the
   54        * servlet is being placed into service.  See {@link javax.servlet.Servlet#init}.
   55        * <p/>
   56        * <p>This implementation stores the {@link javax.servlet.ServletConfig}
   57        * object it receives from the servlet container for later use.
   58        * When overriding this form of the method, call
   59        * <code>super.init(config)</code>.
   60        *
   61        * @param config the <code>ServletConfig</code> object
   62        *               that contains configutation
   63        *               information for this servlet
   64        * @throws javax.servlet.ServletException if an exception occurs that
   65        *                                        interrupts the servlet's normal
   66        *                                        operation
   67        * @see javax.servlet.UnavailableException
   68        */
   69   
   70       @Override
   71       public void init(ServletConfig config) throws ServletException {
   72           jspDispatcher = config.getServletContext().getRequestDispatcher("/monitoringPopUpGraph.jsp");
   73       }
   74   
   75       /**
   76        * Called by the servlet container to allow the servlet to respond to
   77        * a request.  See {@link javax.servlet.Servlet#service}.
   78        * <p/>
   79        * <p>This method is declared abstract so subclasses, such as
   80        * <code>HttpServlet</code>, must override it.
   81        *
   82        * @param req the <code>ServletRequest</code> object
   83        *            that contains the client's request
   84        * @param res the <code>ServletResponse</code> object
   85        *            that will contain the servlet's response
   86        * @throws javax.servlet.ServletException if an exception occurs that
   87        *                                        interferes with the servlet's
   88        *                                        normal operation occurred
   89        * @throws java.io.IOException            if an input or output
   90        *                                        exception occurs
   91        */
   92   
   93       public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
   94           addGraphAttribute(req);
   95           jspDispatcher.forward(req, res);
   96       }
   97   
   98       private void addGraphAttribute(ServletRequest request) throws ServletException {
   99           try {
  100               userTransaction.begin();
  101               try {
  102                   String graphIdString = request.getParameter("graph_id");
  103                   int graphId = Integer.parseInt(graphIdString);
  104                   Graph graph = (Graph) entityManager.createNamedQuery("graphById").setParameter("id", graphId).getSingleResult();
  105                   StatsGraph statsGraph = new GraphsBuilder().getStatsGraph(graph);
  106                   request.setAttribute("statsGraph", statsGraph);
  107               } finally {
  108                   userTransaction.commit();
  109               }
  110           } catch (Exception e) {
  111               throw new ServletException(e);
  112           }
  113       }
  114   
  115   }

Home » geronimo-2.2-source-release » org.apache.geronimo.monitoring.console » [javadoc | source]