title: Programmatically update certificates in tomcat 8 without server restart
body: <p>In order to update the certificate that I use for SSL for my server I have a code that does the import\export and validation that I need.</p>
  
  <p>It works well, but In order for the changes to take effect I have to restart the tomcat.<br>
  I wish to avoid the restart, and update it without using external tools (keytool for example).<br>
  I looked up for some similar questions, and found a solution - restarting the 443 connector. I'm able to do so, and the connector is stopping and starting, but the certificate was not updated. Only server restart actually updates it.  </p>
  
  <p>Is there some connector initialisation procedure that I'm missing?<br>
  Some system cache or objects that I should clear?</p>
  
  <p>This is the code that I use for restarting the connector:  </p>
  
  <pre><code>MBeanServer mbeanServer = null;
  ObjectName objectName = null;
  final ObjectName objectNameQuery = new ObjectName("*:type=Connector,port=443,*");
  for (final MBeanServer server : (ArrayList&lt;MBeanServer&gt;) MBeanServerFactory.findMBeanServer(null)) {
      if (server.queryNames(objectNameQuery, null).size() &gt; 0) {
          mbeanServer = server;
          objectName = (ObjectName) server.queryNames(objectNameQuery,null).toArray()[0];
          break;
      }
  }
  
  mbeanServer.invoke(objectName, "stop", null, null);
  Thread.sleep(1000);
  mbeanServer.invoke(objectName, "start", null, null);  
  </code></pre>
  
  <p>I see in the tomcat logs the following traces of the connector restart:<br>
      <code>23-Apr-2017 15:42:00.292 INFO [BG-Task RestartTomcatConnector] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-443"]</code><br>
      <code>23-Apr-2017 15:42:01.349 INFO [BG-Task RestartTomcatConnector] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-443"]</code></p>