pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alejandro Vilar" <alejandro.vi...@synacom.com.bo>
Subject RE: Help understanding classpaths/codebase with applets
Date Tue, 22 Jun 2010 22:44:14 GMT
>The question I have is - what do you do with the file after the GET? You'd
have to store it in the local file system and point Log4J to it >before your
app actually starts up.

The file was a suggestion and is not required to store it in some place, I
was thinking more in a BufferedStream or something to configure Log4j with
an InputStream, as John mentioned it's also possible using an URL.

>The problem here is that it requires the use of the codebase, which John is
trying to avoid (there are some unfortunate side effects of the >way the JDK
performs service lookups when running in an applet that doesn't disable
codebase lookup - I filed a bug on it, but Sun/Oracle >never responded).

With the codebase method you can compute an url for example
"/pivotapp/applet-log4j.xml":

/Tomcat
  /unique-log4j-config.xml (<-- the real config file)
  /pivotapp
     /index.html
     /my-pivot-app.jar
     /applet-log4j.xml    (<-- this file doesn't exists)

And use a servlet combined with a filter or something else like this:

public class Log4JFileServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException {
        OutputStream out = null;
        try {
            String path = request.getServletPath();
            Pattern pattern = Pattern.compile("/applet-log4j.xml");
            Matcher matcher = pattern.matcher(path);
            if (matcher.find()) {
                response.setContentType("text/xml;charset=UTF-8");
                out = response.getOutputStream();
                File uniqueFile = new File("path-to-the-real-config-file");
                InputStream is = new FileInputStream(uniqueFile);
                byte[] buf = new byte[2048];
                int len = 0;
                while ((len = is.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
            } else {
                //redirect to appropiate servlet or use a filter before this
servlet
                //with the pattern's logic
            }
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (Exception e) {
                }
            }
        }
    }
}

If the server app has control over the applet path and related resources I
don't see any problem with the codebase.

Alejandro

-----Original Message-----
From: Greg Brown [mailto:gkbrown@mac.com] 
Sent: Martes, 22 de Junio de 2010 05:58 p.m.
To: user@pivot.apache.org
Subject: Re: Help understanding classpaths/codebase with applets

> 1) Use one server app, to retrieve a unique file with an static and
> well-know url, put that url in all your applets and use a get method to
> retrieve an stream an setup log4j.

The question I have is - what do you do with the file after the GET? You'd
have to store it in the local file system and point Log4J to it before your
app actually starts up.

> 2) Write a file servlet in all your webApps, inside the applet use the
> codebase to create a relative url to an fictitious file, this file will be
> pulled from a unique path by each one of your web apps in the server side.

The problem here is that it requires the use of the codebase, which John is
trying to avoid (there are some unfortunate side effects of the way the JDK
performs service lookups when running in an applet that doesn't disable
codebase lookup - I filed a bug on it, but Sun/Oracle never responded).



Mime
View raw message