You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Henning Schmiedehausen (JIRA)" <de...@velocity.apache.org> on 2007/03/08 01:10:39 UTC

[jira] Closed: (VELOCITY-145) VelocityServlet::loadConfiguration() may not load from war file

     [ https://issues.apache.org/jira/browse/VELOCITY-145?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henning Schmiedehausen closed VELOCITY-145.
-------------------------------------------


> VelocityServlet::loadConfiguration() may not load from war file
> ---------------------------------------------------------------
>
>                 Key: VELOCITY-145
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-145
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.3-rc1
>         Environment: Operating System: All
> Platform: All
>            Reporter: Mike Janson
>         Assigned To: Mike Janson
>            Priority: Minor
>
> VelocityServlet::loadConfiguration() may not load from a war file since it 
> calls getServletContext().getRealPath(), the behavior of which is undefined in 
> this case, and returns null from some containers (Tomcat).
> Patch is:
> --- VelocityServlet.java	2003-02-26 13:50:17.000000000 -0800
> +++ VelocityServlet.java.fixed	2003-02-26 13:48:34.000000000 -0800
> @@ -60,11 +60,14 @@
>  import java.io.Writer;
>  import java.io.BufferedWriter;
>  import java.io.OutputStreamWriter;
> +import java.io.InputStream;
>  import java.io.FileInputStream;
>  import java.io.FileNotFoundException;
>  import java.io.IOException;
>  import java.io.UnsupportedEncodingException;
>  
> +import java.net.URL;
> +
>  import java.util.Properties;
>  
>  import javax.servlet.ServletConfig;
> @@ -341,13 +344,25 @@
>          if ( propsFile != null )
>          {
>              String realPath = getServletContext().getRealPath(propsFile);
> -        
> +
> +            InputStream propsIStream = null;
>              if ( realPath != null )
>              {
>                  propsFile = realPath;
> +            } else {
> +                // assume we're here because getRealPath() returned null
> +                // try loading from URL instead
> +                URL configURL = getServletContext().getResource("/" + 
> propsFile);
> +                if (configURL != null)
> +                    propsIStream = configURL.openStream();
>              }
>  
> -            p.load( new FileInputStream(propsFile) );
> +            if (propsIStream == null)
> +            {
> +               propsIStream = new FileInputStream(propsFile);
> +            }
> +	    
> +            p.load(propsIStream);
>          }
>  
>          return p;

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


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