river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtra...@apache.org
Subject svn commit: r1306882 - in /river/jtsk/skunk/surrogate: docs/ src/org/apache/river/container/ src/org/apache/river/container/classloading/ src/org/apache/river/container/codebase/
Date Thu, 29 Mar 2012 14:37:15 GMT
Author: gtrasuk
Date: Thu Mar 29 14:37:14 2012
New Revision: 1306882

URL: http://svn.apache.org/viewvc?rev=1306882&view=rev
Log:
Internationalized the ClassServer messages.
Altered classpath parser to log its symbols at the FINEST level, so as to remove some noise
from the startup logs.

Added:
    river/jtsk/skunk/surrogate/docs/Todo.txt
Modified:
    river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
    river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
    river/jtsk/skunk/surrogate/src/org/apache/river/container/classloading/ClasspathExpressionParser.jjt
    river/jtsk/skunk/surrogate/src/org/apache/river/container/codebase/ClassServer.java

Added: river/jtsk/skunk/surrogate/docs/Todo.txt
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/docs/Todo.txt?rev=1306882&view=auto
==============================================================================
--- river/jtsk/skunk/surrogate/docs/Todo.txt (added)
+++ river/jtsk/skunk/surrogate/docs/Todo.txt Thu Mar 29 14:37:14 2012
@@ -0,0 +1,4 @@
+
+TODO 20120329 ClassServer comes up with address 0.0.0.0:8080 instead of hostname or IP.
+TODO 20120329 Add security manager setup.
+TODO 20120329 Add remote deployment capability (will require privileged application infrastructure).

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java?rev=1306882&r1=1306881&r2=1306882&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java (original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java Thu Mar 29
14:37:14 2012
@@ -51,10 +51,18 @@ public class MessageNames {
             CANT_CONVERT_EXCEPTION="cantConvertException",
             CANT_READ_START_PROPERTIES="cantReadStartProperties",
             CLASSLOADER_IS="classLoaderIs",
+            CLASS_SERVER_BAD_REQUEST="classServerBadRequest",
+            CLASS_SERVER_ERROR_ACCEPTING_CONNECTIONS="classServerErrorAcceptingConnections",
+            CLASS_SERVER_ESTABLISHED="classServerEstablished",
+            CLASS_SERVER_EXCEPTION_DURING_SHUTDOWN="classServerExceptionDuringShutdown",
+            CLASS_SERVER_EXCEPTION_GETTING_BYTES="classServerExceptionGettingBytes",
+            CLASS_SERVER_EXCEPTION_WRITING_RESPONSE="classServerExceptionWritingResponse",
             CLASS_SERVER_INIT_FAILED="classServerInitFailed",
+            CLASS_SERVER_NO_CONTENT_FOUND="classServerNoContentFound",
             CLASS_SERVER_RECEIVED_REQUEST="classServerReceivedRequest",
             CLASS_SERVER_RECEIVED_PROBE="classServerReceivedProbe",    
             CLASS_SERVER_REJECTED_PATH="classServerRejectedPath",
+            CLASS_SERVER_TERMINATED="classServerTerminated",
             CODESOURCE_IS="codeSourceIs",
             COMPLETED_SERVICE_DEPLOYMENT="completedServiceDeployment",
             CONFIG_FILE="configFile",

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties?rev=1306882&r1=1306881&r2=1306882&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties (original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties Thu Mar
29 14:37:14 2012
@@ -30,10 +30,18 @@ callingMain=Calling main method on class
 cantConvertException=Can''t convert type ''{0}'' to ''{1}''.
 cantReadStartProperties=Can''t read starter configuration file ''{0}'' in ''{1}''.
 classLoaderIs=ClassLoader for class {0} is {1}.
+classServerBadRequest=bad request \"{0}\" from {1}:{2}
+classServerErrorAcceptingConnections=Class Server was terminated due to IOException while
accepting connections.
+classServerEstablished=Class Server established on host {0} port {1}.
+classServerExceptionDuringShutdown=Class Server caught an exception during shutdown, which
was ignored.
+classServerExceptionGettingBytes=Class Server caught an exception while getting bytes to
serve the request.
+classServerExceptionWritingResponse=Class Server caught an exception writing the response,
so terminated the response.
 classServerInitFailed=Class Server initialization failed.
+classServerNoContentFound=Class Server has no content for path ''{0}''.
 classServerRejectedPath=Rejected request for path ''{0}'' (returning 404).
 classServerReceivedProbe={0} probed from {1}:{2}
 classServerReceivedRequest={0} requested from {1}:{2}
+classServerTerminated=Class Server terminated as part of normal shutdown on host {0} port
{1}.
 codeSourceIs=CodeSource for service in ''{0}'' is ''{1}''.
 completedServiceDeployment=Completed deployment of service in {0}.
 configFile=Configuration file is ''{0}''.

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/classloading/ClasspathExpressionParser.jjt
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/classloading/ClasspathExpressionParser.jjt?rev=1306882&r1=1306881&r2=1306882&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/classloading/ClasspathExpressionParser.jjt
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/classloading/ClasspathExpressionParser.jjt
Thu Mar 29 14:37:14 2012
@@ -92,7 +92,7 @@ TOKEN :
 
 void cpExpression() #cpExpression:
 {
-    log.fine("cpExpression()");
+    log.finest("cpExpression()");
 }
 {
     cpClause() ( <COLON> cpClause())*
@@ -100,7 +100,7 @@ void cpExpression() #cpExpression:
 
 void cpClause() #cpClause:
 {
-    log.fine("cpClause()");
+    log.finest("cpClause()");
 }
 {
     symbol() [ <LPAREN> filterExpression() <RPAREN>]
@@ -108,7 +108,7 @@ void cpClause() #cpClause:
 
 void filterExpression():
 {
-    log.fine("filterExpression()");
+    log.finest("filterExpression()");
 }
 {
     filterClause() ( <COMMA> filterClause())*
@@ -116,7 +116,7 @@ void filterExpression():
 
 void filterClause():
 {
-    log.fine("filterClause()");
+    log.finest("filterClause()");
 }
 {
     symbol() | stringLiteral()
@@ -125,7 +125,7 @@ void filterClause():
 
 void symbol() #symbol:
 {
-        log.fine("symbol()");
+        log.finest("symbol()");
         Token t=null;
 }
 {
@@ -136,7 +136,7 @@ void symbol() #symbol:
 
 void stringLiteral() #stringLiteral:
 {
-        log.fine("stringLiteral()");
+        log.finest("stringLiteral()");
         Token t=null;
 }
 {

Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/codebase/ClassServer.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/codebase/ClassServer.java?rev=1306882&r1=1306881&r2=1306882&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/codebase/ClassServer.java (original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/codebase/ClassServer.java Thu
Mar 29 14:37:14 2012
@@ -15,8 +15,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
 
-Originally taken from com.sun.jini.tool.ClassServer, then refactored to
-plug into the surrogate container.
+ Originally taken from com.sun.jini.tool.ClassServer, then refactored to
+ plug into the surrogate container.
  */
 package org.apache.river.container.codebase;
 
@@ -50,61 +50,29 @@ import org.apache.river.container.work.T
 import org.apache.river.container.work.WorkManager;
 
 /**
- * A simple HTTP server, for serving up JAR and class files.
- * <p>
- * The following items are discussed below:
- * <ul>
- * <li>{@linkplain #main Command line options}
- * <li><a href="#logging">Logging</a>
- * <li><a href="#running">Examples for running ClassServer</a>
- * </ul>
- * <p>
- * <a name="logging"><h3>Logging</h3></a>
- * <p>
+ * A simple HTTP server, for serving up JAR and class files. <p> The following
+ * items are discussed below: <ul> <li>{@linkplain #main Command line options}
+ * <li><a href="#logging">Logging</a> <li><a href="#running">Examples
for
+ * running ClassServer</a> </ul> <p> <a name="logging"><h3>Logging</h3></a>
<p>
  *
  * This implementation uses the {@link Logger} named
  * <code>com.sun.jini.tool.ClassServer</code> to log information at the
- * following logging levels:
- * <p>
- * <table border="1" cellpadding="5"
- *         summary="Describes logging performed by ClassServer at different
- *	   logging levels">
- * <caption halign="center" valign="top"><b><code>
+ * following logging levels: <p> <table border="1" cellpadding="5"
+ * summary="Describes logging performed by ClassServer at different logging
+ * levels"> <caption halign="center" valign="top"><b><code>
  *    com.sun.jini.tool.ClassServer</code></b></caption>
  *
- * <tr> <th scope="col">Level</th> <th scope="col">Description</th>
</tr>
- * <tr>
- *   <td>{@link Level#SEVERE SEVERE}</td>
- *   <td>failure to accept an incoming connection</td>
- * </tr>
- * <tr>
- *   <td>{@link Level#WARNING WARNING}</td>
- *   <td>failure to read the contents of a requested file,
- *       failure to find the message resource bundle, failure while
- *       executing the <code>-stop</code> option
- *   </td>
- * </tr>
- * <tr>
- *   <td>{@link Level#INFO INFO}</td>
- *   <td>server startup and termination</td>
- * </tr>
- * <tr>
- *   <td>{@link Level#CONFIG CONFIG}</td>
- *   <td>the JAR files being used for <code>-trees</code></td>
- * </tr>
- * <tr>
- *   <td>{@link Levels#HANDLED HANDLED}</td>
- *   <td>failure reading an HTTP request or writing a response</td>
- * </tr>
- * <tr>
- *   <td>{@link Level#FINE FINE}</td>
- *   <td>bad HTTP requests, HTTP requests for nonexistent files</td>
- * </tr>
- * <tr>
- *   <td>{@link Level#FINER FINER}</td>
- *   <td>good HTTP requests</td>
- * </tr>
- * </table>
+ * <tr> <th scope="col">Level</th> <th scope="col">Description</th>
</tr> <tr> <td>{@link Level#SEVERE SEVERE}</td>
+ * <td>failure to accept an incoming connection</td> </tr> <tr> <td>{@link
Level#WARNING WARNING}</td>
+ * <td>failure to read the contents of a requested file, failure to find the
+ * message resource bundle, failure while executing the
+ * <code>-stop</code> option </td> </tr> <tr> <td>{@link
Level#INFO INFO}</td>
+ * <td>server startup and termination</td> </tr> <tr> <td>{@link
Level#CONFIG CONFIG}</td>
+ * <td>the JAR files being used for
+ * <code>-trees</code></td> </tr> <tr> <td>{@link Levels#HANDLED
HANDLED}</td>
+ * <td>failure reading an HTTP request or writing a response</td> </tr>
<tr> <td>{@link Level#FINE FINE}</td>
+ * <td>bad HTTP requests, HTTP requests for nonexistent files</td> </tr>
<tr> <td>{@link Level#FINER FINER}</td>
+ * <td>good HTTP requests</td> </tr> </table>
  *
  *
  */
@@ -112,7 +80,9 @@ public class ClassServer implements Code
 
     private static final Logger logger =
             Logger.getLogger(ClassServer.class.getName(), MessageNames.BUNDLE_NAME);
-    /** Server socket to accept connections on */
+    /**
+     * Server socket to accept connections on
+     */
     private ServerSocket server;
     @Injected(style = InjectionStyle.BY_TYPE)
     private WorkManager workManager = null;
@@ -155,23 +125,29 @@ public class ClassServer implements Code
         int initialPort = Integer.parseInt(initialPortStr);
         try {
             server.bind(new InetSocketAddress(initialPort));
+            logger.log(Level.INFO, MessageNames.CLASS_SERVER_ESTABLISHED,
+                    new Object[]{server.getLocalSocketAddress(),
+                        server.getLocalPort()});
         } catch (BindException be) {
             IOException ioe = new IOException("failure to bind to port: " + initialPort,
be);
             throw ioe;
         }
     }
 
-    /** Just keep looping, spawning a new thread for each incoming request. 
-    It's tempting here to have the last operation queue another accept() task
-    rather than setup a loop.  Wonder what the ramifications would be?
-    We'd have more opportunities to end the service task, but possibly more 
-    development effort.
+    /**
+     * Just keep looping, spawning a new thread for each incoming request. It's
+     * tempting here to have the last operation queue another accept() task
+     * rather than setup a loop. Wonder what the ramifications would be? We'd
+     * have more opportunities to end the service task, but possibly more
+     * development effort.
      */
     public void run() {
         try {
             while (true) {
                 final Socket connectedSocket = server.accept();
-                /* Boy, would this be a nice spot to have closures! */
+                /*
+                 * Boy, would this be a nice spot to have closures!
+                 */
                 workManager.queueTask(TaskClass.SYSTEM_TASK,
                         Thread.currentThread().getContextClassLoader(),
                         new Runnable() {
@@ -185,38 +161,47 @@ public class ClassServer implements Code
         } catch (IOException e) {
             synchronized (this) {
                 if (!server.isClosed()) {
-                    logger.log(Level.SEVERE, "accepting connection", e);
+                    logger.log(Level.SEVERE, MessageNames.CLASS_SERVER_ERROR_ACCEPTING_CONNECTIONS,
e);
                 }
                 terminate();
             }
         }
     }
 
-    /** Close the server socket, causing the thread to terminate. */
+    /**
+     * Close the server socket, causing the thread to terminate.
+     */
     @Shutdown
     public synchronized void terminate() {
         try {
             server.close();
         } catch (IOException e) {
+            logger.log(Level.FINE, MessageNames.CLASS_SERVER_EXCEPTION_DURING_SHUTDOWN, e);
         }
-        logger.log(Level.INFO, "ClassServer terminated [port {0}]",
-                Integer.toString(getPort()));
+        logger.log(Level.INFO, MessageNames.CLASS_SERVER_TERMINATED,
+                new Object[]{server.getLocalSocketAddress(),
+                    server.getLocalPort()});
     }
 
-    /** Returns the port on which this server is listening. */
+    /**
+     * Returns the port on which this server is listening.
+     */
     public int getPort() {
         return server.getLocalPort();
     }
 
     /**
-    Returns the hostname that the server is listening to.
-    @return 
-    */
+     * Returns the hostname that the server is listening to.
+     *
+     * @return
+     */
     public String getHost() {
         return server.getInetAddress().getHostAddress();
     }
-    
-    /** Read up to CRLF, return false if EOF */
+
+    /**
+     * Read up to CRLF, return false if EOF
+     */
     private static boolean readLine(InputStream in, StringBuffer buf)
             throws IOException {
         while (true) {
@@ -224,6 +209,10 @@ public class ClassServer implements Code
             if (c < 0) {
                 return buf.length() > 0;
             }
+            /*
+             * The characters below are part of the http protocol and not
+             * localizable, so we're OK with character literals.
+             */
             if (c == '\r') {
                 in.mark(1);
                 c = in.read();
@@ -239,12 +228,16 @@ public class ClassServer implements Code
         }
     }
 
-    /** Parse % HEX HEX from s starting at i */
+    /**
+     * Parse % HEX HEX from s starting at i
+     */
     private static char decode(String s, int i) {
         return (char) Integer.parseInt(s.substring(i + 1, i + 3), 16);
     }
 
-    /** Decode escape sequences */
+    /**
+     * Decode escape sequences
+     */
     private static String decode(String path) {
         try {
             for (int i = path.indexOf('%');
@@ -278,7 +271,9 @@ public class ClassServer implements Code
         return path;
     }
 
-    /** Read the request/response and return the initial line. */
+    /**
+     * Read the request/response and return the initial line.
+     */
     private static String getInput(Socket sock, boolean isRequest)
             throws IOException {
         BufferedInputStream in =
@@ -309,12 +304,14 @@ public class ClassServer implements Code
     public void destroyContext(CodebaseContext context) {
         // Remove all the jar mappings.
         //destroy the context.
-        contexts.remove((ClassServerCodebaseContext) context);
+        contexts.remove(context.getAppId());
     }
     private static ResourceBundle resources;
     private static boolean resinit = false;
 
-    /** Canonicalize the path */
+    /**
+     * Canonicalize the path
+     */
     private String canon(String path) {
         if (path.regionMatches(true, 0, "http://", 0, 7)) {
             int i = path.indexOf('/', 7);
@@ -342,32 +339,36 @@ public class ClassServer implements Code
     }
 
     private boolean processBadRequest(String[] args, DataOutputStream out) throws IOException
{
-        logger.log(Level.FINE,
-                "bad request \"{0}\" from {1}:{2}", args);
+        logger.log(Level.FINE, MessageNames.CLASS_SERVER_BAD_REQUEST,
+                args);
         out.writeBytes("HTTP/1.0 400 Bad Request\r\n\r\n");
         out.flush();
         return true;
     }
 
-    /** Read specified number of bytes and always close the stream. */
+    /**
+     * Read specified number of bytes and always close the stream.
+     */
     private byte[] getBytes(FileObject fo)
             throws IOException {
-        ByteArrayOutputStream out=new ByteArrayOutputStream();
-        byte[] buffer=new byte[1024];
-        
-        InputStream in=fo.getContent().getInputStream();
-        int bytesRead=in.read(buffer);
-        while (bytesRead >0) {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        byte[] buffer = new byte[1024];
+
+        InputStream in = fo.getContent().getInputStream();
+        int bytesRead = in.read(buffer);
+        while (bytesRead > 0) {
             out.write(buffer, 0, bytesRead);
-            bytesRead=in.read(buffer);
+            bytesRead = in.read(buffer);
         }
-        byte[] bytes=out.toByteArray();
+        byte[] bytes = out.toByteArray();
         out.close();
         in.close();
         return bytes;
     }
 
-    /** Return the bytes of the requested file, or null if not found. */
+    /**
+     * Return the bytes of the requested file, or null if not found.
+     */
     private byte[] getBytes(String path) throws IOException {
         FileObject fo = findFileObjectForPath(path);
         if (fo == null) {
@@ -377,7 +378,9 @@ public class ClassServer implements Code
     }
 
     FileObject findFileObjectForPath(String path) {
-        /* First path segment is appid. */
+        /*
+         * First path segment is appid.
+         */
         StringTokenizer tok = new StringTokenizer(path, Strings.SLASH, false);
         FileObject ret = null;
         try {
@@ -424,9 +427,9 @@ public class ClassServer implements Code
             if (args != null) {
                 args[0] = path;
             }
-            args[1]=sock.getInetAddress().getHostName();
-            args[2]=Integer.toString(sock.getPort());
-            
+            args[1] = sock.getInetAddress().getHostName();
+            args[2] = Integer.toString(sock.getPort());
+
             logger.log(Level.FINER,
                     get
                     ? MessageNames.CLASS_SERVER_RECEIVED_REQUEST
@@ -436,13 +439,13 @@ public class ClassServer implements Code
             try {
                 bytes = getBytes(path);
             } catch (Exception e) {
-                logger.log(Level.WARNING, "getting bytes", e);
+                logger.log(Level.WARNING, MessageNames.CLASS_SERVER_EXCEPTION_GETTING_BYTES,
e);
                 out.writeBytes("HTTP/1.0 500 Internal Error\r\n\r\n");
                 out.flush();
                 return true;
             }
             if (bytes == null) {
-                logger.log(Level.FINE, "{0} not found", path);
+                logger.log(Level.FINE, MessageNames.CLASS_SERVER_NO_CONTENT_FOUND, path);
                 out.writeBytes("HTTP/1.0 404 Not Found\r\n\r\n");
                 out.flush();
                 return true;
@@ -454,7 +457,7 @@ public class ClassServer implements Code
             out.flush();
             return false;
         } catch (Exception e) {
-            logger.log(Level.FINE, "writing response", e);
+            logger.log(Level.FINE, MessageNames.CLASS_SERVER_EXCEPTION_WRITING_RESPONSE,
e);
         } finally {
             try {
                 sock.close();



Mime
View raw message