[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ with Servlets on Tomcat 5.x

I've included my ControllerServlet and my LogAspect files.

Thanks for all.
package com.gmsoft;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.*;

/**
 * Servlet implementation class for Servlet: Controller
 * @web.servlet
 *   name="Controller"
 *   display-name="Controlador"
 *   description="Controlador de tota l'aplicació Web - MVC"
 * @web.servlet-mapping
 *   url-pattern="/Controller"  
 */
 public class ControllerServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public ControllerServlet() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().print("Get");
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer action = (Integer)request.getAttribute("action");
		request.getSession().getServletContext().log("action ----->" + action);
		
		if (action != null) {
			switch (action.intValue()) {
				case com.gmsoft.enumerates.ActionsEnum.LOGIN:
					com.gmsoft.utils.UtilsModelFacade facade = (com.gmsoft.utils.UtilsModelFacade)request.getSession().getAttribute("ModelFacade");
					//Identificació del client en front al sistema.
					if (facade.validate(request.getAttribute("user").toString(), request.getAttribute("password").toString())) {
						//Obtenció del role del client.
						facade.getRole(1,false);
					}
					break;
			
				case com.gmsoft.enumerates.ActionsEnum.CHANGE_LANGUAGE:
					request.getSession().setAttribute("language", request.getAttribute("language"));
					request.getSession().getServletContext().log(request.getRequestURL().toString());
					break;
				
				default:
					response.getWriter().print("Post");
					request.getSession().getServletContext().log("default");
			}
		}else{
			response.getWriter().write("bull");
		}
	}
	
	public void setName(String name) {
		System.out.println("merda");
	}
}
package com.gmsoft.aspects;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public aspect LogAspect {
	pointcut doPostMethod (com.gmsoft.ControllerServlet controller, HttpServletRequest request, HttpServletResponse response) : call (void com.gmsoft.ControllerServlet.doPost(HttpServletRequest request, HttpServletResponse response)) && target(controller) && args(request,response);
	pointcut sets (com.gmsoft.ControllerServlet controller, String name) : call (void com.gmsoft.ControllerServlet.set* (String)) && target(controller) && args(name);
	
	before (com.gmsoft.ControllerServlet controller, HttpServletRequest request, HttpServletResponse response) : doPostMethod(controller,request,response) {
		System.out.println("merda");
		request.getSession().getServletContext().log("merda");
		try {
			response.getWriter().write("aspect");
		}catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	before (com.gmsoft.ControllerServlet controller, String name) : sets(controller, name) {
		System.out.println(name);
	}
}