Abandoned

Note: This blog has been abandoned, any future updates will be found here: https://phillipgreenii.github.io/

Tuesday, April 3, 2012

Specifying ProjectStage in JNDI with WebLogic

Note: This blog has been abandoned, any future updates will be found here: https://phillipgreenii.github.io/specifying-projectstage-in-jndi-with/

Starting in JSF 2.0 (JSR-314) a feature was added called ProjectStage.  This is an attribute that signifies the stage where the project is running: DevelopmentUnitTest, SystemTest, or Production.  The idea is that if the code knows where it is running, it can plan better.  As an example, in a production environment certain optimizations could occur during startup that would cause better overal performance. However, these optimizations during start up is a problem during development because during development there is a lot more shutting down and starting up of the server.

There are two ways to specify the ProjectStage: web.xml and JNDI.  The problem with using web.xml is that you need to update or override it as you go move from one environment to the next.  JNDI is configured on the application server, so it is the ideal place to configure ProjectStage.

In WebLogic (11g), you can not add custom resources to JNDI.  So, out of the box, you can not specify ProjectStage in JNDI.

In a previous post, I described Weblogic JNDI Custom Resource Configuration, which is a project where I configure JNDI in WebLogic using Startup Classes.

Adding ProjectStage to JNDI

Follow the documentation at Weblogic JNDI Custom Resource Configuration to install it.  Use the following configuration:


Name:jsf-stage
Class Name:com.idmworks.weblogic.jndiconfiguration.StringInitializer
Arguments:jsf/master/ProjectStage=Development
Failure is Fatalunticked
Run Before Application Deploymentsunticked
Run Before Application Activationsticked

This will configure jsf/master/ProjectStage to store the value of "Development"

Add Resource to web.xml

In the previous step, "Development" was added to the global name space as jsf/master/ProjectStage.  The JSF JSR Documentation states that it looks for the ProjectStage at java:comp/env/jsf/ProjectStage which is the local namespace.  In order to define it in the local name space, we need to specify it in web.xml.
<web-app version="2.5" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <!-- ... other configuration removed ... -->
  <resource-ref>
    <res-ref-name>jsf/ProjectStage</res-ref-name>
    <res-type>java.lang.String</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
  <!-- ... other configuration removed ... -->
</web-app>

Add Resource to weblogic.xml

In the previous step, we allocated the place holder for java:comp/env/jsf/ProjectStage, we now need to map the global location to the local place holder:
<weblogic-web-app xmlns:j2ee="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.bea.com/ns/weblogic/90" xsi:schemalocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
  <!-- ... other configuration removed ... -->
  <resource-description>
    <res-ref-name>jsf/ProjectStage</res-ref-name>
    <jndi-name>jsf/master/ProjectStage</jndi-name>
  </resource-description>
</weblogic-web-app>

Verify ProjectStage

Below is a small snippet of code that you can add to any facelet to check what the current projectStage is set to
Stage: #{facesContext.application.projectStage}

References

15 comments:

  1. Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
    Weblogic Training in Chennai

    ReplyDelete
  2. They are becomes a more and more interesting from the starting lines until the end.


    weblogic tutorial

    ReplyDelete
  3. Thanks For Clearing All My Doubts Through Your Website Post.You Cleared All My Doubts.Coming To Our Self We Provide Commercial Kitchen Equipment Parts Through Out US At Very Affordable Prices And Also We Offer Same Day Shipping In US.We Offer Only Genuine Products.Really Thanks For Posting.

    ReplyDelete
  4. This Blog is very helpful and useful,came to know that i should be strong in my basics and this blog helps me to improve it,Urgent Care Centers Services Provided by Us.Thanks For Posting.I Am refereed by my friend to this blog and i also want to refer my other friends to this blog.

    ReplyDelete
  5. Good article. It is very useful for me to learn and understand easily USMLE Thanks for posting.

    ReplyDelete
  6. This Blog Provides Very Useful and Important Information. I just Want to share this blog with my friends and family members. Tibco Certification Training

    ReplyDelete
  7. In Love With This Blog Which is providing Such an Important and useful Information...

    Visakhapatnam Real Estate

    ReplyDelete

  8. Excellent blog. Lots of useful information here, thanks for your effort!
    Real Estate Plots in Vizag

    ReplyDelete

  9. Very Informative blog thank you for sharing. Keep sharing.

    Best software training institute in Chennai. Make your career development the best by learning software courses.

    devops training in chennai
    cloud computing courses in chennai
    Docker classes in Chennai

    ReplyDelete
  10. I believe there are many more pleasurable opportunities ahead for
    individuals that looked at your site.
    dba course in chennai
    java training institute in chennai

    ReplyDelete
  11. Very Informative blog thank you for sharing. Keep sharing, It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.

    ReplyDelete