Catching exception in a filter.
I have maven GWT 1.5 project split into few parts. One of them is WAR with client side and other is WAR with server side included in some EAR application. There is also some JAR wich is proxy between client and server, i mean client and server do not see each other, but they are dependent of this JAR so all common classes and f.e. RPC interfaces are defined there. I defined SecurityException in this JAR: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package pl.fizzycomp.client.common; import com.google.gwt.user.client.rpc.IsSerializable; import java.util.ArrayList; import java.util.List; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package pl.fizzycomp.client.common; import com.google.gwt.user.client.rpc.IsSerializable; import java.util.ArrayList; import java.util.List; public class SecurityException extends Exception implements IsSerializable { //CONSTRUCTORS HERE /** * User name of user that didn't have persmission */ private String userName; /** * Set of examined and not found roles */ private List rolesExamined = new ArrayList(); /** * Adds role to @see rolesExamined * @param roleName role to add */ public void addRole(String roleName){ rolesExamined.add(roleName); } /** * Adds roles to @see rolesExamined * @param roleName list of roles to add */ public void addRoles(List roleNames){ rolesExamined.addAll(roleNames); } /** * @return @see rolesExamined as a String */ public String getRolesExamined() { return rolesExamined.toString(); } /** * @return @see userName */ public String getUserName() { return userName; } /** * Sets @see userName to given value * @param userName value */ public void setUserName(String userName) { this.userName = userName; } /** * Returns message of the exception and values of @see userName and @see rolesExamined * @return */ public String toString() { return super.toString() + "; user: " + userName + ", examined roles: " + rolesExamined.toString(); } } All RPC methods that throws SecurityException and their synchronous interfaces declare this fact in the throws phrase. This exception I wanna catch and service (by writing info to the log and database table) in an aspect manner on the server side before it reaches client side and is silenced by the one trying to break security policy. So I declared in web.xml on the server WAR: SecurityExceptionFilter pl.xxx.server.filter.SecurityExceptionFilter SecurityExceptionFilter /services/* And the code of the filter: public class SecurityExceptionFilter implements Filter { private FilterConfig filterConfig = null; private static Logger log = Logger.getLogger (SecurityExceptionFilter.class); @EJB private ErrorCodesFacadeLocal errorCodesFacade; @Override public void init(FilterConfig config) throws ServletException { this.filterConfig = config; } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (filterConfig == null){ return; } try { System.out.println("+++ SecurityExceptionFilter"); System.out.println(request.toString()); System.out.println ("---"); System.out.println(response.toString()); System.out.println("++ +"); chain.doFilter(request, response); } catch (Throwable t){ log.fatal("Security violation attempt occured. Event will be written to ERROR_CODES table.", t); //TODO - database stuff } } /* private SecurityException examineSecurityException(final Throwable t){ Throwable temp = t; while (temp != null){ if (temp instanceof SecurityException){ return (SecurityException) temp; } temp = temp.getCause(); } return null; } */ @Override public void destroy() { this.filterConfig = null; } } Then I declared RPC method: public List doAdvancedPersonSearch (IAdvancedPersonSearchParameter apsp) throws SecurityException { if (true){ SecurityException e = new SecurityException ("testsecurityex"); e.setUserName("username"); e.addRole("role1");e.addRole("role2"); throw e; } } I built and deployed application, pushed the button that calls this RPC service and this is output: +++ SecurityExceptionFilter uri: /nserver//services/memberPersonService method: POST Que
Re: @EJB annotation during junit testing doesn't work
The problem is: - when running hosted mode manually I can specify -noserver mode with address of server where my server side is deployed instead of embedded Tomcat - TestRunner fires hosted mode without this option and I haven't found how can I make it to call hosted mode with additional parameters. Does anybody know how to do that? On Dec 1, 12:24 pm, jolero <[EMAIL PROTECTED]> wrote: > Hello > Thanks for your reply > > The thing is when I run hosted mode everything works fine. > Hosted mode runs gwt embedded instance of tomcat, so does GWTTestCase. > This is why I believed it was connected with GWT. > > Anyway, in this situation, how can I run tests in the container? > > On Nov 30, 12:37 am, medgey <[EMAIL PROTECTED]> wrote: > > > If you are running outside of a container then you will need to > > instantiate your EJBs yourself ('new"). This is unrelated to GWT. > > > On Nov 27, 7:53 am, jolero <[EMAIL PROTECTED]> wrote: > > > > Hello everybody. > > > > While developing junit tests in GWT app I have stucked on a problem > > > that I cannot solve for couple of days now. > > > In normal runtime I can normally call RPC services that use JPA > > > (Toplink and Glassfish Appserver) for data access purposes, but during > > > Junit tests (My tests extends GWTTestCase and use delayTestFinish and > > > finishTest for asynchronous calls as described in GWT documentation) > > > RPC methods that use injected objects are failing with > > > NullPointerException. In other words @EJB annotatnion doesn't work, > > > Beans are not injected and references to them are nulls. > > > > Have anybody had that issue? Does anybody know a solution? Thx in > > > advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
Re: @EJB annotation during junit testing doesn't work
Hello Thanks for your reply The thing is when I run hosted mode everything works fine. Hosted mode runs gwt embedded instance of tomcat, so does GWTTestCase. This is why I believed it was connected with GWT. Anyway, in this situation, how can I run tests in the container? On Nov 30, 12:37 am, medgey <[EMAIL PROTECTED]> wrote: > If you are running outside of a container then you will need to > instantiate your EJBs yourself ('new"). This is unrelated to GWT. > > On Nov 27, 7:53 am, jolero <[EMAIL PROTECTED]> wrote: > > > Hello everybody. > > > While developing junit tests in GWT app I have stucked on a problem > > that I cannot solve for couple of days now. > > In normal runtime I can normally call RPC services that use JPA > > (Toplink and Glassfish Appserver) for data access purposes, but during > > Junit tests (My tests extends GWTTestCase and use delayTestFinish and > > finishTest for asynchronous calls as described in GWT documentation) > > RPC methods that use injected objects are failing with > > NullPointerException. In other words @EJB annotatnion doesn't work, > > Beans are not injected and references to them are nulls. > > > Have anybody had that issue? Does anybody know a solution? Thx in > > advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---
@EJB annotation during junit testing doesn't work
Hello everybody. While developing junit tests in GWT app I have stucked on a problem that I cannot solve for couple of days now. In normal runtime I can normally call RPC services that use JPA (Toplink and Glassfish Appserver) for data access purposes, but during Junit tests (My tests extends GWTTestCase and use delayTestFinish and finishTest for asynchronous calls as described in GWT documentation) RPC methods that use injected objects are failing with NullPointerException. In other words @EJB annotatnion doesn't work, Beans are not injected and references to them are nulls. Have anybody had that issue? Does anybody know a solution? Thx in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to Google-Web-Toolkit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~--~~~~--~~--~--~---