Takuya Ono
takuy****@users*****
2005年 2月 22日 (火) 01:11:06 JST
Index: BetaProject/src/org/jent/checksmtp/LDAPSearch.java diff -u BetaProject/src/org/jent/checksmtp/LDAPSearch.java:1.1.1.1 BetaProject/src/org/jent/checksmtp/LDAPSearch.java:1.2 --- BetaProject/src/org/jent/checksmtp/LDAPSearch.java:1.1.1.1 Mon Feb 21 08:44:03 2005 +++ BetaProject/src/org/jent/checksmtp/LDAPSearch.java Tue Feb 22 01:11:06 2005 @@ -21,20 +21,25 @@ private LDAPSearch() { } - static private void init() { - if ( !ApplicationProperties.getLdap() ) { - //InitialDirContext - lastProviderUrl = ApplicationProperties.getLdapProviderURL(); - Properties env = new Properties(); - env.setProperty(Context.INITIAL_CONTEXT_FACTORY, - "com.sun.jndi.ldap.LdapCtxFactory"); - env.put(Context.PROVIDER_URL, lastProviderUrl); - - try { - ctx = new InitialDirContext(env); - } catch (NamingException e) { - System.err.println("LDAPSearch init error."); - e.printStackTrace(); + static synchronized private void init() { + if ( ApplicationProperties.getLdap() ) { + //not initialized ctx or LDAP Provider URL was changed. + if ( ctx==null + || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { + try { + if ( ctx != null ) { ctx.close(); } + //InitialDirContext + lastProviderUrl = ApplicationProperties.getLdapProviderURL(); + Properties env = new Properties(); + env.setProperty(Context.INITIAL_CONTEXT_FACTORY, + "com.sun.jndi.ldap.LdapCtxFactory"); + env.put(Context.PROVIDER_URL, lastProviderUrl); + + ctx = new InitialDirContext(env); + } catch (NamingException e) { + System.err.println("LDAPSearch init error."); + e.printStackTrace(); + } } } } @@ -45,12 +50,9 @@ if (!ApplicationProperties.getLdap()) { return ans; } - synchronized (LDAPSearch.class ) { - //not initialized ctx or LDAP Provider URL was changed. - if ( ctx==null - || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { - init(); - } + if ( ctx==null + || (!lastProviderUrl.equals(ApplicationProperties.getLdapProviderURL())) ) { + init(); } Pattern pattern = Pattern.compile("[ \t]+"); //Attributes separate by space. @@ -95,11 +97,22 @@ } catch (NamingException e) { System.err.println("LDAP Search Error."); e.printStackTrace(); + //ctx reflesh + try { + ctx.close(); + } catch (NamingException nEx) { + //IGNORE Exception + } + ctx = null; } catch (UnsupportedEncodingException ueEx) { UnsupportedEncodingException e = ueEx; System.err.println("LDAP SJIS Error."); e.printStackTrace(); - } + } catch (NullPointerException npEx) { //for failsafe. + NullPointerException e = npEx; + System.err.println("LDAP Unexpected Error."); + e.printStackTrace(); + } return ans; } Index: BetaProject/src/org/jent/checksmtp/Processer.java diff -u BetaProject/src/org/jent/checksmtp/Processer.java:1.1.1.1 BetaProject/src/org/jent/checksmtp/Processer.java:1.2 --- BetaProject/src/org/jent/checksmtp/Processer.java:1.1.1.1 Mon Feb 21 08:44:03 2005 +++ BetaProject/src/org/jent/checksmtp/Processer.java Tue Feb 22 01:11:06 2005 @@ -57,6 +57,8 @@ BufferedReader clientReader; PrintWriter clientWriter; + Socket server = null; + try { //Connect to SMTP Server host String servername = ApplicationProperties.getSmtpServerHost(); @@ -65,7 +67,7 @@ int serverport = ApplicationProperties.getSmtpServerPort(); //Connection to true SMTP server. - Socket server = new Socket(servername, serverport); + server = new Socket(servername, serverport); serverInput = server.getInputStream(); serverOutput = server.getOutputStream(); clientInput = client.getInputStream(); @@ -92,10 +94,28 @@ //forServerThread.start(); ////Use this ThreadforClientThread.run(); server.close(); + server = null; client.close(); + client = null; } catch (IOException e) { System.err.println("Execption occurred in Processer."); e.printStackTrace(); + } finally { + //for failsafe Socket close. + if (server != null) { + try { + server.close(); + } catch (IOException ioEx ) { + //IGNORE close Exception + } + } + if (client != null) { + try { + client.close(); + } catch (IOException ioEx ) { + //IGNORE close Exception + } + } } }