Ignore:
Timestamp:
2014-05-01T02:34:43+02:00 (10 years ago)
Author:
Don-vip
Message:

see #8465 - global use of try-with-resources, according to

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpsServer.java

    r7004 r7033  
    5656               
    5757                // Load keystore
    58                 InputStream in = RemoteControlHttpsServer.class.getResourceAsStream(KEYSTORE_PATH);
    59                 if (in == null) {
    60                     Main.error(tr("Unable to find JOSM keystore at {0}. Remote control will not be available on HTTPS.", KEYSTORE_PATH));
    61                 } else {
    62                     try {
    63                         ks.load(in, password);
    64                     } finally {
    65                         Utils.close(in);
     58                try (InputStream in = RemoteControlHttpsServer.class.getResourceAsStream(KEYSTORE_PATH)) {
     59                    if (in == null) {
     60                        Main.error(tr("Unable to find JOSM keystore at {0}. Remote control will not be available on HTTPS.", KEYSTORE_PATH));
     61                    } else {
     62                        try {
     63                            ks.load(in, password);
     64                        } finally {
     65                            Utils.close(in);
     66                        }
     67                       
     68                        if (Main.isDebugEnabled()) {
     69                            for (Enumeration<String> aliases = ks.aliases(); aliases.hasMoreElements();) {
     70                                Main.debug("Alias in keystore: "+aliases.nextElement());
     71                            }
     72                        }
     73   
     74                        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
     75                        kmf.init(ks, password);
     76                       
     77                        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
     78                        tmf.init(ks);
     79                       
     80                        sslContext = SSLContext.getInstance("TLS");
     81                        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
     82                       
     83                        if (Main.isDebugEnabled()) {
     84                            Main.debug("SSL Context protocol: " + sslContext.getProtocol());
     85                            Main.debug("SSL Context provider: " + sslContext.getProvider());
     86                        }
     87                       
     88                        initOK = true;
    6689                    }
    67                    
    68                     if (Main.isDebugEnabled()) {
    69                         for (Enumeration<String> aliases = ks.aliases(); aliases.hasMoreElements();) {
    70                             Main.debug("Alias in keystore: "+aliases.nextElement());
    71                         }
    72                     }
    73 
    74                     KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    75                     kmf.init(ks, password);
    76                    
    77                     TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
    78                     tmf.init(ks);
    79                    
    80                     sslContext = SSLContext.getInstance("TLS");
    81                     sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    82                    
    83                     if (Main.isDebugEnabled()) {
    84                         Main.debug("SSL Context protocol: " + sslContext.getProtocol());
    85                         Main.debug("SSL Context provider: " + sslContext.getProvider());
    86                     }
    87                    
    88                     initOK = true;
    8990                }
    9091            } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException |
     
    175176             Integer.toString(server.getLocalPort()));
    176177        while (true) {
    177             try {
    178                 Socket request = server.accept();
     178            try (Socket request = server.accept()) {
    179179                if (Main.isDebugEnabled() && request instanceof SSLSocket) {
    180180                    SSLSocket sslSocket = (SSLSocket) request;
Note: See TracChangeset for help on using the changeset viewer.