src/share/classes/java/util/logging/SocketHandler.java

Print this page

        

*** 26,35 **** --- 26,37 ---- package java.util.logging; import java.io.*; import java.net.*; + import java.security.AccessController; + import java.security.PrivilegedAction; /** * Simple network logging <tt>Handler</tt>. * <p> * <tt>LogRecords</tt> are published to a network stream connection. By default
*** 81,96 **** public class SocketHandler extends StreamHandler { private Socket sock; private String host; private int port; ! // Private method to configure a SocketHandler from LogManager // properties and/or default values as specified in the class // javadoc. ! private void configure() { LogManager manager = LogManager.getLogManager(); ! String cname = getClass().getName(); setLevel(manager.getLevelProperty(cname +".level", Level.ALL)); setFilter(manager.getFilterProperty(cname +".filter", null)); setFormatter(manager.getFormatterProperty(cname +".formatter", new XMLFormatter())); try { --- 83,100 ---- public class SocketHandler extends StreamHandler { private Socket sock; private String host; private int port; ! // Private PrivilegedAction to configure a SocketHandler from LogManager // properties and/or default values as specified in the class // javadoc. ! private class ConfigureAction implements PrivilegedAction<Void> { ! @Override ! public Void run() { LogManager manager = LogManager.getLogManager(); ! String cname = SocketHandler.this.getClass().getName(); setLevel(manager.getLevelProperty(cname +".level", Level.ALL)); setFilter(manager.getFilterProperty(cname +".filter", null)); setFormatter(manager.getFormatterProperty(cname +".formatter", new XMLFormatter())); try {
*** 103,114 **** // assert false; } } port = manager.getIntProperty(cname + ".port", 0); host = manager.getStringProperty(cname + ".host", null); } - /** * Create a <tt>SocketHandler</tt>, using only <tt>LogManager</tt> properties * (or their defaults). * @throws IllegalArgumentException if the host or port are invalid or --- 107,119 ---- // assert false; } } port = manager.getIntProperty(cname + ".port", 0); host = manager.getStringProperty(cname + ".host", null); + return null; + } } /** * Create a <tt>SocketHandler</tt>, using only <tt>LogManager</tt> properties * (or their defaults). * @throws IllegalArgumentException if the host or port are invalid or
*** 116,135 **** * @throws IOException if we are unable to connect to the target * host and port. */ public SocketHandler() throws IOException { // We are going to use the logging defaults. ! sealed = false; ! configure(); ! try { connect(); ! } catch (IOException ix) { System.err.println("SocketHandler: connect failed to " + host + ":" + port); ! throw ix; } - sealed = true; } /** * Construct a <tt>SocketHandler</tt> using a specified host and port. * --- 121,147 ---- * @throws IOException if we are unable to connect to the target * host and port. */ public SocketHandler() throws IOException { // We are going to use the logging defaults. ! try { ! AccessController.doPrivileged(new ConfigureAction() { ! @Override ! public Void run() { ! super.run(); try { connect(); ! } catch (IOException ioe) { ! throw new UncheckedIOException(ioe); ! } ! return null; ! } ! }, null, LogManager.controlPermission); ! } catch (UncheckedIOException uioe) { System.err.println("SocketHandler: connect failed to " + host + ":" + port); ! throw uioe.getCause(); } } /** * Construct a <tt>SocketHandler</tt> using a specified host and port. *
*** 144,156 **** * @throws IllegalArgumentException if the host or port are invalid. * @throws IOException if we are unable to connect to the target * host and port. */ public SocketHandler(String host, int port) throws IOException { ! sealed = false; ! configure(); ! sealed = true; this.port = port; this.host = host; connect(); } --- 156,166 ---- * @throws IllegalArgumentException if the host or port are invalid. * @throws IOException if we are unable to connect to the target * host and port. */ public SocketHandler(String host, int port) throws IOException { ! AccessController.doPrivileged(new ConfigureAction(), null, LogManager.controlPermission); this.port = port; this.host = host; connect(); }