Access of JSF Beans from Servlet Filter

Is there any way how can I access session JSF beans from servlet filter?
I need to check certain value of JSF bean stored in session scope in my filter.
Thanks
ferdo

Frank,
I am not sure about phase listener, this is the whole situation:
as I am not using Container Managed Security with my JSF, after I do sucessfull login into application, I need to store some information into the session scope (user etc) and in the servlet filter I need to find out if the user is connected.
I was trying to put such info into Servlet Session directly in my bean via External Context and reading the info in Filter.
This is working fine when my application is running locally (jdev oc4j) but once deployed into Application server, when user login first time, user information is somehow removed from the session, and cannot figure out why.
So I was thinking to try another approach, to find out from servlet filter if JSF bean value is set or not.
Any other suggestions? Do not want to swicth to Container Manages Security now.
ferdo
null

Similar Messages

  • Accessing Managed Session Bean in Servlet Filter

    I wrote a Servlet Filter to handle user authentication. Now I'm trying to access my Managed Session Bean in the filter in order to save the current user. Unfortunately the Session Bean is created after the Filter executes for the first time.
    I'm trying to access the Session Bean in this way:
    (SessionBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("sessionBean");
    In this case getExternalContext() is equals null.
    Is there any way to create the Session bean before the filter executes or any other ideas how to handle this?
    I already searched around the internet but couldnt figure out something.
    Thanks guys,
    Paul

    Ok, fixed it like this. Works perfect. JSF finds and uses the handmade Session Bean as well.
    if(request.getSession().getAttribute(BeanNames.SESSION_SCOPE_BEAN) == null) {
         SessionBean sessionBean = new SessionBean();
         request.getSession().setAttribute(BeanNames.SESSION_SCOPE_BEAN, sessionBean);
    }Thanks,
    Paul

  • Accessing a JSF element from a back bean method

    Hi,
    short question, can I access the JSF element from a back bean method?
    So, for example, if I have the following JSF code:
    <h:panelGroup id="test1" rendered="#{bean.someMethod}">...</h:panelGroup>
    <h:panelGroup id="test2" rendered="#{bean.someMethod}">...</h:panelGroup>
    <h:panelGroup id="test3" rendered="#{bean.someMethod}">...</h:panelGroup>
    Can I found out in some way, which element (esp. which ID) calls the someMethod-method?
    Kind regards
    Matthias

    There are more possibilities as well. If you depend it on for example the User's rights/groups, then you can also do for example:
    rendered="#{user.admin}" // getter = public boolean isAdmin()
    rendered="#{user.groupName == 'admin'}" // getter = public String getGroupName()
    rendered="#{user.groupId > 1}" // getter = public int getGroupId()
    rendered="#{fn:contains(user.groups, 'admin')}" // getter = public String[] getGroups() or public List<String> getGroups()
    etc..I think it's after all just a matter of learning about the capabilities of EL a bit more.

  • Managed session bean in servlet filter

    Hi,
    Is there a way to get hold of a managed bean with session scope in a servlet filter? The code below throws an error due to the fact that the faces context is null.
    FacesContext facesContext = FacesContext.getCurrentInstance();
    System.out.println("facesContext: " + facesContext); // shows that facesContext is null
    ApplicationFactory appFactory = ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    Application app = appFactory.getApplication();
    Object obj = app.createValueBinding("user").getValue(facesContext); //throws the error due to the null parameter
    Object obj2 = app.createValueBinding("user"); //results in a valid ValueBindingHere is the faces-config snippet for the managed bean:
    <managed-bean>
        <managed-bean-name>user</managed-bean-name>
        <managed-bean-class>biz.libereco.skemo.info.asl.beans.User</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>For the record, I am using JSF 1.0 Final.
    Thank you,
    Marcel

    wynton_0 wrote:
    Yes, there is a way to get hold of a managed bean with session scope in a servlet filter.
    See here:
    [http://wiki.apache.org/myfaces/AccessFacesContextFromServlet]
    and here:
    [how to access faces context and backing beans in a servlet filter|http://www.thoughtsabout.net/blog/archives/000033.html]
    This makes no utter sense. A JSF session scoped managed bean is under the hood just put as a HttpSession attribute with the managed bean name as key. Guess what, you can just access the HttpSession in Filter by ((HttpServletRequest) request).getSession() and then just call getAttribute() on it. If it isn't there yet, then just do a setAttribute() with a new instance.
    After I get User bean in my Servlet filter, I populate value to this bean, for example:
    user.setLanguage(request.getParameter("locale"));
    The User bean is in session scope. The User bean's language attribute suppose to be same in the whole session scope, but later on, I got null. My question is:
    how to keep this value in session scope?The the session was apparently invalidated/renewed or you manually removed the bean or replaced it by null.
    In the future, please don't resurrect old topics, just start a new topic for each independent problem/question.

  • Exception while accessing a com port from servlet

    I am trying to access communication port from a Servlet using java communications api's.
    But Following exception was thrown
    Caught java.lang.NullPointerException:name can't be null while loading driver com.sun.comm.Win32Driver
    The SecurityManager do not allow that opeartion.
    java.security AccessControlException:access denied (java.io.FilePermission c:\j2sdk1.4.1\jre\lib\javax.comm.properties delete)
    at java.security.AccessControlContext.java:270) at java.security.AccessController.checkPermission(SecurityManager.java)
    at java.lang.SecurityManager.checkDelete()
    at java.comm.CommPortIdentifier.getPortIdentifiers(CommportIdentifier.java)
    Please help me.Tell me what to do.how to successfully access a communication port from a Servlet.

    Solved!!. Just make sure u r placing neccessary files (comm.jar, win32com.dll and javax.comm.properties)onto the right JVM folders. Since JVM may be installed in many different location in your PC, U might want to do some search around looking for java.exe elsewhere in the system. Good luck!

  • Access session scope variables from a filter

    I have a filter I am using to check if 2 people are loged in with the same user name.
    When my web app loads I store the user name in a class that has session scope.
    Is there a way for me to access this class from the Filter class?
    How do I access the session instance from this class?
    How do I pass parameters to the Filter class?
    Thank you,
    Al

    http://forum.java.sun.com/thread.jspa?threadID=5122925&tstart=0

  • Accessing BI graph bean from JClient

    We've been trying to work with the graph bean from JClient from within JDeveloper. (The "Panel with Graph" option in File/new/Client tier/Swing/JClient for BC4j)
    It looks like there is nothing in place beyond the simple graph wizard. Documentation is superficial. We can't even get axis labels to show.
    The question is: where can reasonable documentation be found and if it does not exist, is it safe to use this charting product at all?

    Thanks, I've also found http://otn.oracle.com/bibeans903/help/ a few minutes after posting the question. That solved the trouble for now.

  • Accessing BI graph bean from JDeveloper/JClient

    We've been trying to work with the graph bean from JClient from within JDeveloper. (The "Panel with Graph" option in File/new/Client tier/Swing/JClient for BC4j)
    It looks like there is nothing in place beyond the simple graph wizard. Documentation is superficial. We can't even get axis labels to show.
    The question is: where can reasonable documentation be found and if it does not exist, is it safe to use this charting product at all?

    I am not sure what the BC4J team exposed for Help in the release you are using. For 9.0.5 the Graph integration has been greatly improved. You may want to post this message in the JDeveloper or BC4J forums so someone on their team can better assist you.

  • How do I lookup an EJB 3.0 Session bean from servlet or JSP?

    Does anyone knows how can I invoke an EJB from a servlet or JSP ?
    I deployed a simple EJB on a Oracle Application Server 10g release 10.1.3 and I'm working with JDeveloper 10.1.3. I deployed the files via JDeveloper, and I didn´t specify any orion-ejb-jar.xml or ejb-jar.xml file
    After deployment, the orion-ejb-jar.xml look like this in the server:
    <?xml version="1.0" encoding="utf-8"?>
    <orion-ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-ejb-jar-10_0.xsd" deployment-version="10.1.3.0.0" deployment-time="10b49516c8f" schema-major-version="10" schema-minor-version="0" >
    <enterprise-beans>
    <session-deployment name="HolaMundoEJB" location="HolaMundoEJB" local-location="HolaMundoEJB_HolaMundoEJBLocal" local-wrapper-name="HolaMundoEJBLocal_StatelessSessionBeanWrapper6" remote-wrapper-name="HolaMundoEJB_StatelessSessionBeanWrapper7" persistence-filename="HolaMundoEJB.home_default_group_1">
    </session-deployment>
    </enterprise-beans>
    <assembly-descriptor>
    <default-method-access>
    <security-role-mapping name="<default-ejb-caller-role>" impliesAll="true" />
    </default-method-access>
    </assembly-descriptor>
    </orion-ejb-jar>
    I'm trying to invoke the ejb in a servlet by doing the following:
    public void doGet(HttpServletRequest request, ....
    Context context = new InitialContext();
    HolaMundoEJB helloWorld =
    (HolaMundoEJB)context.lookup("java:com/env/ejb/HolaMundoEJB");
    String respuesta = helloWorld.sayHello("David");
    When i invoke the servlet I catch a NamingException whose message says something
    like this ....java:com/env/ejb/HolaMundoEJB not found in webLlamaEJB
    I tried different paths for the lookup but nothing....
    Can anyone help me with this topic? Thank you.

    Please try the following code:
    HelloEJBBean.java:
    @Stateless(name="Hello")
    @Remote(value={Hello.class})
    public class HelloEJBBean implements Hello {  ... }
    hello.jsp:
    Context ctx = new InitialContext();
    Hello h = (Hello)ctx.lookup("ejb/Hello");
    web.xml:
    <ejb-ref>
    <ejb-ref-name>ejb/Hello</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <remote>fi.kronodoc.test.model.Hello</remote>
    </ejb-ref>
    i think you should also define jndi mappings for the references in orion-ejb-jar.xml and orion-web.xml but for some reason it seems to be working also without these.

  • Strange behaviour when accessing Oracle 8i table from servlet

    Hi there,
    First a little background, I've got a 2 column table in an Oracle 8i DB that holds a very simple code to word map. There are no strange characters. Both columns are varchar.
    From my desktop machine, when I execute the the following:
    <SNIP>
                OracleDataSource ods = new OracleDataSource();
                ods.setDriverType("thin");
                ods.setServerName("DBserver.db");
                ods.setDatabaseName("DB");
                ods.setPortNumber(1527);
                ods.setUser("user");
                ods.setPassword("password");
                Connection connection = ods.getConnection();
                Statement stmt = connection.createStatement();
                ResultSet res = stmt.executeQuery(SQL);
                CachedRowSet crs = new CachedRowSetImpl();
                crs.populate(res);
                while (crs.next()) {
                    System.out.println("ID: " + crs.getString(1) +
                                       ",  Name: " + crs.getString(2));
                }<SNIP>
    Everything works fine, and I get the results I expect (both return values for getString(1) and getString(2) are exactly as they are stored in the table)
    HOWEVER:
    When I execute the same exact code in a servlet sitting on a Tomcat server (I'm using a simple applet servlet model to access the table and return a response to the applet), crs.getString(int) returns strings like: 0x53, 0x54, 0x4E and so on.
    I am unsure what this means, and would be grateful for any assistance. I am wondering where to start to troubleshoot the problem.

    I suggest you use the name of the field in your getString() so you can be sure what field its getting.
    Example:
    from:
    crs.getString(1)
    to:
    crs.getString("first_name");
    Also, I suggest you get a connection, use it, and close it (along with closing the resultSet and statement) all within a try/catch/finally block. You have to close the connection when you are done with it or you may run out of connections.
    Also, I suggest replacing this:
    CachedRowSet crs = new CachedRowSetImpl();
    crs.populate(res);
    while (crs.next()) {
    System.out.println("ID: " + crs.getString(1) +
    ", Name: " + crs.getString(2));
    with something like this:
    while(resultSet.next()){
    System.out.println("ID"
    System.out.println("ID: " + resultSet.getString("first_name") +
    ", Name: " + resultSet.getString("last_name"));
    }

  • How to pass Bean from servlet to jsp

    I had fetched record from my database to my servlet and passed it to bean.
    how should i pass that bean to my jsp to display the record values in their corresponding textboxes??

    leozeo write: I had fetched record from my database to my servlet and passed it to bean.
    how should i pass that bean to my jsp to display the record values in their corresponding textboxes?? Post the code

  • Calling Stateless Session bean from Servlet

    Dear Friends,
    A help will be Appreciated...
    I created a EJB (Stateless Session Bean) using WebSphere Application Developer with its Business logic in Main bean. Its working perfectly fine using UTC (Standalone Test Client). But when i use a servlet to communicate with this EJB, its giving me error as follows:
    Error Stack:
    java.lang.NoClassDefFoundError: package name/DemoHome
    at java.lang.Class.newInstance0(Native Method)
    at java.lang.Class.newInstance(Class.java:254)
    at java.beans.Beans.instantiate(Beans.java:213)
    at java.beans.Beans.instantiate(Beans.java:57)
    at com.ibm.servlet.engine.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:148)
    at com.ibm.servlet.engine.webapp.WebAppServletManager.getServletReference(WebAppServletManager.java:287)
    at com.ibm.servlet.engine.webapp.WebApp.getServletReference(WebApp.java:354)
    at com.ibm.servlet.engine.webapp.WebAppRequestDispatcherInfo.calculateInfo(WebAppRequestDispatcherInfo.java:167)
    at com.ibm.servlet.engine.webapp.WebAppRequestDispatcherInfo.<init>(WebAppRequestDispatcherInfo.java:51)
    at com.ibm.servlet.engine.webapp.WebApp.getRequestDispatcher(WebApp.java:1145)
    at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:179)
    at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
    at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:122)
    at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
    at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
    at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:323)
    at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:252)
    at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
    For more Info let me provide the snipets of how i used the Sevlet:
    Client.java
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import packagename.*; //package name of imported ear file which is in
    //classpath
    public class Client extends HttpServlet {
    public void doGet(
    javax.servlet.http.HttpServletRequest request,
    javax.servlet.http.HttpServletResponse response)
    throws javax.servlet.ServletException, java.io.IOException {
    PrintWriter out=response.getWriter();
    Properties p = new Properties();
    p.put(javax.naming.Context.PROVIDER_URL, "iiop:///");
    p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
    try {
    InitialContext initial = new InitialContext(p);
    Object objref = initial.lookup("JDemo");
    DemoHome home = (DemoHome)PortableRemoteObject.narrow(objref,DemoHome.class);
    Demo demo = home.create();
    int r=demo.testBean(4);
    out.println("EJB RESULT= "+r);
    } catch (Exception ex) {
    System.err.println("Caught an unexpected exception!");
    ex.printStackTrace();
    Kindly provide ur solution to this problem. Urgent solution will be helpful as its a part of our present project.
    Thanking you for ur esteemed help.
    regards,
    Arun.

    Perhaps you webserver can't see your package jar file.
    Try putting it in WEB-INF\lib directory of your app and restart your server.

  • Can't get x509 from servlet filter?

    i have a filter and a jsp. currently, both the filter and the jsp attempt to pull the X509 certificate from the request and log it (eventually the filter will perform authentication and the jsp will be a web service). however...the filter is unable to get the certificate, whereas the jsp gets the certificate without problems. why is this? some code below:
    **** filter ****
    doFilter(...) {
    HttpServletRequest request = (HttpServletRequest)servletRequest;
    X509Certificate[] obj = (X509Certificate[]) request.getAttribute("java.security.cert.X509Certificate");
    but obj is always null. (i even enumerate the attributes - always empty)...
    **** jsp ****
    essentially the same X509Cert line as above, but obj contains the certificate.
    any ideas? i'm using oracle's app server, which uses a modified Apache HTTP server, if that makes a difference.
    thanks
    chris

    http://forum.java.sun.com/thread.jsp?forum=33&thread=346827&start=0&range=15#1436379

  • Access ApplicationBean from servlet

    My project uses both JSF generated pages as well as servlets. I would like to be able to access an Application Bean from a servlet in the same project. The java files for the servlet are in the same directory as the package that holds the generated java page files. The Application bean should be accessible to both the generated classes as well as the servlets. Can anyone suggest how to set this up?

    Hi Jim,
    I am not sure I understand completely the problem you are facing, but I shall try to answer to the best of my knowledge and from what I have understood.
    Since the JSF generated pages and the servlets are in the same folder all you would require to do is create an instance of the application bean and it should be accessible.
    Hope this is what you were looking for.
    Cheers
    Giri :-)
    Creator Team

  • How to use the same bean from Jsp and Servlet

    I want to use the same bean instance from both the servlet and jsp.
    for eg. if a create a bean using the jsp:useBean in servlet and if a modify some values, that values should be reflected while i access the same bean from the servlet. But instead of that the servlet is creating a new instance of the bean.
    is it possible?
    Thanks in advance

    Hi,
    When you call jsp:useBean you inform a scope (session, request, page...)
    This means the bean instance will be stored in that scope.
    So, if the informed scope is session, then, in the servlet you could get the bean instance back from the session, this way:
    HttpSession session = request.getSession();
    Bean b = (Bean) session.getAttribute("bean_id");
    Regards,
    Filipe Fedalto

Maybe you are looking for

  • Error in Process chain execution.

    Pls, i'm getting the following error with my process chain. Error TEXT : *************** From HERE *********** WARNING 914 ***  EEWO0914W An internal error has occurred. Either the joblog or the job protocol for the following job does not exist: Job

  • Files won't open on PS3

    Files won't open on PS3 but are not corrupt. The open file when placed on flash drive and opened on another device.

  • I'm getting no error using float in cldc1.0 with wtk2.2?

    I'm getting no error using float in cldc1.0 with wtk2.2?

  • HT4436 I GET A SYNC ERROR MESSAGE WITH OUTLOOK

    I CAN NOT SYNC WITH MY OUTLOOK INSTALLED IN MY LAPTOP RUNNING WINDOWS 7 I GET THE FOLLOWING MESSAGE: Task 'Synchronizing subscribed folders for *********.' reported error (0x800CCC0E) : 'Outlook cannot synchronize subscribed folders for***********. E

  • Multi-page pdf downloads???

    How do i download multipage pdfs within the Adobe illustrator program?  I know it is some sort of module within scrips...any ideas and feedback would be greatly appreciated.