How to use getCertificate method of com.testsigma.agent.ws.server.AgentWebServer class

Best Testsigma code snippet using com.testsigma.agent.ws.server.AgentWebServer.getCertificate

Source:AgentWebServer.java Github

copy

Full Screen

...73 AgentWebServerConfigDTO agentWebServerConfigDTO = agentWebServerService.getWebServerCertificate();74 if (agentWebServerConfigDTO == null) {75 throw new Exception("Could not fetch agent web server config from Testsigma cloud...");76 }77 this.certificate = getCertificate(agentWebServerConfigDTO);78 this.key = agentWebServerConfigDTO.getKey();79 this.isCertificateFetched = true;80 }81 }82 private void startDefaultHttpConnector() {83 log.info("Starting agent HTTP connector at port - " + this.defaultHttpPort);84 }85 private void startDefaultHttpsConnector() throws Exception {86 this.defaultHttpsServerConnector = this.startHttpsConnector(Integer.parseInt(this.defaultHttpsPort));87 }88 private void stopDefaultHttpConnector() {89 log.info("Stopping agent HTTP connector running on port - " + this.defaultHttpPort);90 }91 private void stopDefaultHttpsConnector() throws Exception {92 if ((this.defaultHttpsServerConnector != null) && (this.defaultHttpsServerConnector.isRunning())) {93 log.info("Stopping agent HTTP connector running on port - " + this.defaultHttpsPort);94 this.defaultHttpsServerConnector.stop();95 }96 this.defaultHttpsServerConnector = null;97 }98 private ServerConnector startHttpsConnector(int httpsPort) throws Exception {99 log.info("Starting agent HTTPS connector at port - " + httpsPort);100 ServerConnector serverConnector;101 SslContextFactory.Server context = new SslContextFactory.Server();102 KeyStore keyStore = KeyStore.getInstance("PKCS12");103 try (ByteArrayInputStream certificateStream = new ByteArrayInputStream(this.certificate)) {104 keyStore.load(certificateStream, new String(this.key, StandardCharsets.UTF_8).toCharArray());105 }106 context.setKeyStore(keyStore);107 context.setKeyStorePassword(new String(this.key, StandardCharsets.UTF_8));108 serverConnector = new ServerConnector(this.server, context);109 serverConnector.setPort(httpsPort);110 serverConnector.start();111 this.server.addConnector(serverConnector);112 return serverConnector;113 }114 private byte[] getCertificate(AgentWebServerConfigDTO agentWebServerConfigDTO) {115 try {116 if (agentWebServerConfigDTO.getCertificatePresignedURL() != null) {117 String fileName = FilenameUtils.getName(agentWebServerConfigDTO.getCertificatePresignedURL().getPath());118 File destinationFile = Paths.get(FileUtils.getTempDirectory().toString(), fileName).toFile();119 FileUtils.copyURLToFile(agentWebServerConfigDTO.getCertificatePresignedURL(), destinationFile, (60 * 1000), (60 * 1000));120 if (destinationFile.exists()) {121 return FileUtils.readFileToByteArray(destinationFile);122 } else {123 log.error("Couldn't not fetch certificate from - " + agentWebServerConfigDTO.getCertificatePresignedURL());124 }125 }126 } catch (Exception e) {127 log.error(e.getMessage());128 }129 return agentWebServerConfigDTO.getCertificate();130 }131}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful