I'm trying to write a java program that takes the XML file generated by a nifi-api url and generates an email if the queue size of the nifi flow exceeds a certain threshold. But the problem is that since SSL is enabled, the XML file is not being accessed and it gives me the below error:
java.net.SocketException: Unexpected end of file from server at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678) at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:848) at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474) at java.net.URL.openStream(URL.java:1045) at ReadXMLFile.main(ReadXMLFile.java:21)
When I manually try to access the link I had to select a certificate and I think that is the problem in accessing the XML file from code. Can someone tell me how to sign or select a certificate through java code?
If you are using client certificates as an authentication mechanism, you will need to provide a valid client certificate in the Java invocation of the API. You can do this by loading a Java Keystore (*.jks) file containing the private key of the client certificate and presenting that. An example of the code to do so (using Apache httpclient and JRE variables) is here. You can also do this explicitly by writing code to parse an arbitrary keystore and load a key via SSLContext and SSLSockets (see here).