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();
+ }
}
}
}
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.
} 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;
}
BufferedReader clientReader;
PrintWriter clientWriter;
+ Socket server = null;
+
try {
//Connect to SMTP Server host
String servername = ApplicationProperties.getSmtpServerHost();
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();
//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
+ }
+ }
}
}