You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Ken nashua <nh...@hotmail.com> on 2006/10/27 15:36:41 UTC

TACOS DEMO getServletContext().getRealPath("/") returns NULL ?

Hi Folks,

I thought it proper to integrate ConfigurationServlet to my webapp just like 
the tacosdemo does.. just to initialize log4j

web.xml below...

--->HERE IS THE OUTPUT FROM TOMCAT CONSOLE:
java.io.FileNotFoundException: null\WEB-INF\log4j.properties (The system 
cannot
find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)

--->HERE IS THE CODE:
public class ConfigurationServlet extends ApplicationServlet implements 
ServletContextListener {

    /** Comment for <code>serialVersionUID</code> */
    private static final long serialVersionUID = 3257005471045858873L;
    /* Logger */
    private static final Logger LOG = 
Logger.getLogger(ConfigurationServlet.class);

    /**
     * @see javax.servlet.GenericServlet#init()
     */
    public void init() {
        try {
            // Use basic logging configuration until Log4j is properly 
configured
            
PropertyConfigurator.configure(getServletContext().getRealPath("/")
                    + "/WEB-INF/log4j.properties");
            super.init();
        } catch (Throwable t) {
            t.printStackTrace();
            LOG.fatal("Error configuring CIMS", t);
        }
    }

    /**
     * @see javax.servlet.Servlet#destroy()
     */
    public void destroy()
    {
        super.destroy();
        org.apache.log4j.LogManager.shutdown();
    }

    /**
     * @see 
javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0)
    {
        org.apache.log4j.LogManager.shutdown();
    }

    /**
     * {@inheritDoc}
     */
    public void contextInitialized(ServletContextEvent arg0)
    {
    }
}

--->HERE IS WEB.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <display-name>tap.proto-1.0</display-name>

    <filter>
        <filter-name>redirect</filter-name>
        <filter-class>org.apache.tapestry.RedirectFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>redirect</filter-name>
        <url-pattern>/</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>tap.proto-1.0</servlet-name>
        <servlet-class>proto.servlet.ConfigurationServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- SERVLET-MAPPINGS -->
    <servlet-mapping>
        <servlet-name>tap.proto-1.0</servlet-name>
        <url-pattern>/app</url-pattern>
    </servlet-mapping>

    <!-- Boiler Plate HiveMind Services -->
    <servlet-mapping>
        <servlet-name>tap.proto-1.0</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>tap.proto-1.0</servlet-name>
        <url-pattern>*.direct</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>tap.proto-1.0</servlet-name>
        <url-pattern>*.sdirect</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>tap.proto-1.0</servlet-name>
        <url-pattern>/assets/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>tap.proto-1.0</servlet-name>
        <url-pattern>*.svc</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>tap.proto-1.0</servlet-name>
        <url-pattern>*.ajax</url-pattern>
    </servlet-mapping>


    <session-config>
        <session-timeout >10</session-timeout> <!-- minutes -->
    </session-config>

    <resource-ref>
        <res-ref-name>MySQLDataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
    <resource-ref>
        <res-ref-name>OracleDataSource</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

</web-app>

_________________________________________________________________
Try Search Survival Kits: Fix up your home and better handle your cash with 
Live Search! 
http://imagine-windowslive.com/search/kits/default.aspx?kit=improve&locale=en-US&source=hmtagline


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: TACOS DEMO getServletContext().getRealPath("/") returns NULL ?

Posted by Konstantin Ignatyev <kg...@yahoo.com>.
Place all the resources into classpath and it shall
work.
It means that log4j.properties should be in
WEB-INF/classes and it will be picked up
autoamagically.

If yu need something then
this.getClass().getClassloader().getResource*


--- Ken nashua <nh...@hotmail.com> wrote:

> Hi Folks,
> 
> I thought it proper to integrate
> ConfigurationServlet to my webapp just like 
> the tacosdemo does.. just to initialize log4j
> 
> web.xml below...
> 
> --->HERE IS THE OUTPUT FROM TOMCAT CONSOLE:
> java.io.FileNotFoundException:
> null\WEB-INF\log4j.properties (The system 
> cannot
> find the path specified)
>         at java.io.FileInputStream.open(Native
> Method)
>         at
>
java.io.FileInputStream.<init>(FileInputStream.java:106)
>         at
>
java.io.FileInputStream.<init>(FileInputStream.java:66)
> 
> --->HERE IS THE CODE:
> public class ConfigurationServlet extends
> ApplicationServlet implements 
> ServletContextListener {
> 
>     /** Comment for <code>serialVersionUID</code> */
>     private static final long serialVersionUID =
> 3257005471045858873L;
>     /* Logger */
>     private static final Logger LOG = 
> Logger.getLogger(ConfigurationServlet.class);
> 
>     /**
>      * @see javax.servlet.GenericServlet#init()
>      */
>     public void init() {
>         try {
>             // Use basic logging configuration until
> Log4j is properly 
> configured
>             
>
PropertyConfigurator.configure(getServletContext().getRealPath("/")
>                     + "/WEB-INF/log4j.properties");
>             super.init();
>         } catch (Throwable t) {
>             t.printStackTrace();
>             LOG.fatal("Error configuring CIMS", t);
>         }
>     }
> 
>     /**
>      * @see javax.servlet.Servlet#destroy()
>      */
>     public void destroy()
>     {
>         super.destroy();
>         org.apache.log4j.LogManager.shutdown();
>     }
> 
>     /**
>      * @see 
>
javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
>      */
>     public void contextDestroyed(ServletContextEvent
> arg0)
>     {
>         org.apache.log4j.LogManager.shutdown();
>     }
> 
>     /**
>      * {@inheritDoc}
>      */
>     public void
> contextInitialized(ServletContextEvent arg0)
>     {
>     }
> }
> 
> --->HERE IS WEB.XML
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app
>         PUBLIC "-//Sun Microsystems, Inc.//DTD Web
> Application 2.3//EN"
>         "http://java.sun.com/dtd/web-app_2_3.dtd">
> 
> <web-app>
>     <display-name>tap.proto-1.0</display-name>
> 
>     <filter>
>         <filter-name>redirect</filter-name>
>        
>
<filter-class>org.apache.tapestry.RedirectFilter</filter-class>
>     </filter>
>     <filter-mapping>
>         <filter-name>redirect</filter-name>
>         <url-pattern>/</url-pattern>
>     </filter-mapping>
> 
>     <servlet>
>         <servlet-name>tap.proto-1.0</servlet-name>
>        
>
<servlet-class>proto.servlet.ConfigurationServlet</servlet-class>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
> 
>     <!-- SERVLET-MAPPINGS -->
>     <servlet-mapping>
>         <servlet-name>tap.proto-1.0</servlet-name>
>         <url-pattern>/app</url-pattern>
>     </servlet-mapping>
> 
>     <!-- Boiler Plate HiveMind Services -->
>     <servlet-mapping>
>         <servlet-name>tap.proto-1.0</servlet-name>
>         <url-pattern>*.html</url-pattern>
>     </servlet-mapping>
>     <servlet-mapping>
>         <servlet-name>tap.proto-1.0</servlet-name>
>         <url-pattern>*.direct</url-pattern>
>     </servlet-mapping>
>     <servlet-mapping>
>         <servlet-name>tap.proto-1.0</servlet-name>
>         <url-pattern>*.sdirect</url-pattern>
>     </servlet-mapping>
>     <servlet-mapping>
>         <servlet-name>tap.proto-1.0</servlet-name>
>         <url-pattern>/assets/*</url-pattern>
>     </servlet-mapping>
>     <servlet-mapping>
>         <servlet-name>tap.proto-1.0</servlet-name>
>         <url-pattern>*.svc</url-pattern>
>     </servlet-mapping>
>     <servlet-mapping>
>         <servlet-name>tap.proto-1.0</servlet-name>
>         <url-pattern>*.ajax</url-pattern>
>     </servlet-mapping>
> 
> 
>     <session-config>
>         <session-timeout >10</session-timeout> <!--
> minutes -->
>     </session-config>
> 
>     <resource-ref>
>         <res-ref-name>MySQLDataSource</res-ref-name>
>         <res-type>javax.sql.DataSource</res-type>
>         <res-auth>Container</res-auth>
>     </resource-ref>
>     <resource-ref>
>        
> <res-ref-name>OracleDataSource</res-ref-name>
>         <res-type>javax.sql.DataSource</res-type>
>         <res-auth>Container</res-auth>
>     </resource-ref>
> 
> </web-app>
> 
>
_________________________________________________________________
> Try Search Survival Kits: Fix up your home and
> better handle your cash with 
> Live Search! 
>
http://imagine-windowslive.com/search/kits/default.aspx?kit=improve&locale=en-US&source=hmtagline
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail:
> users-help@tapestry.apache.org
> 
> 


Konstantin Ignatyev




PS: If this is a typical day on planet earth, humans will add fifteen million tons of carbon to the atmosphere, destroy 115 square miles of tropical rainforest, create seventy-two miles of desert, eliminate between forty to one hundred species, erode seventy-one million tons of topsoil, add 2,700 tons of CFCs to the stratosphere, and increase their population by 263,000

Bowers, C.A.  The Culture of Denial:  Why the Environmental Movement Needs a Strategy for Reforming Universities and Public Schools.  New York:  State University of New York Press, 1997: (4) (5) (p.206)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org