java - Global filter in WebSphere -


i want add filter adds new parameter header of each request on websphere. found global filter web applications , configuring global filter in websphere 8.5 , tried create global context listener adds filter. however, attempts end exception says cannot add filter programmatically added listener.

[9/21/15 9:39:29:646 cest] 00000000 containerhelp e   wsvr0501e: error creating component com.ibm.ws.runtime.component.compositionunitmgrimpl@a344950a com.ibm.ws.exception.runtimewarning: com.ibm.ws.webcontainer.exception.webappnotloadedexception: failed load webapp: failed load webapp: srve8011e: operation cannot executed programmatically added listener.     @ com.ibm.ws.webcontainer.component.webcontainerimpl.install(webcontainerimpl.java:428)     @ com.ibm.ws.webcontainer.component.webcontainerimpl.start(webcontainerimpl.java:714)     @ com.ibm.ws.runtime.component.applicationmgrimpl.start(applicationmgrimpl.java:1165)     @ com.ibm.ws.runtime.component.deployedapplicationimpl.firedeployedobjectstart(deployedapplicationimpl.java:1369)     @ com.ibm.ws.runtime.component.deployedmoduleimpl.start(deployedmoduleimpl.java:639)     @ com.ibm.ws.runtime.component.deployedapplicationimpl.start(deployedapplicationimpl.java:967)     @ com.ibm.ws.runtime.component.applicationmgrimpl.startapplication(applicationmgrimpl.java:771)     @ com.ibm.ws.runtime.component.compositionunitmgrimpl$cuinitializer$1.run(compositionunitmgrimpl.java:945)     @ com.ibm.ws.security.auth.contextmanagerimpl.runas(contextmanagerimpl.java:5468)     @ com.ibm.ws.security.auth.contextmanagerimpl.runassystem(contextmanagerimpl.java:5594)     @ com.ibm.ws.security.core.securitycontext.runassystem(securitycontext.java:255)     @ com.ibm.ws.runtime.component.compositionunitmgrimpl$cuinitializer.run(compositionunitmgrimpl.java:950)     @ com.ibm.wsspi.runtime.component.wscomponentimpl$_asynchinitializer.run(wscomponentimpl.java:496)     @ com.ibm.ws.util.threadpool$worker.run(threadpool.java:1702) 

listener class:

@weblistener public class requestlistener implements servletcontextlistener {          @override     public void contextinitialized(servletcontextevent sce) {                    servletcontext context = sce.getservletcontext();         try {             simplefilter f = context.createfilter(simplefilter.class);               filterregistration fr = context.addfilter("simplefilter", f);             fr.addmappingforurlpatterns(null, false, "/*");                      } catch (illegalstateexception e) {             system.out.println("filter not added: " + e.getmessage());             e.printstacktrace();         } catch (servletexception e) {             e.printstacktrace();         }     }      } 

filter class:

public class simplefilter implements filter {        public void dofilter(servletrequest servletrequest, servletresponse servletresponse,             filterchain filterchain) throws ioexception, servletexception {                      httpservletresponse httpservletresponse = (httpservletresponse)servletresponse;                 httpservletresponse.setheader("via", servername.getdisplayname());         filterchain.dofilter(servletrequest, httpservletresponse);              }     } 

is there way make work?

thanks


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -