Question
GovCIO
US
Last activity: 17 Jan 2020 14:52 EST
Unable to pass the keystore file data in Kafka integration using java code in V722
Hi,
We are using V722 in our application. We have a requirement to push the message to Kafka topic. As we don't have DataSet in our Pega version, we are using Java, Avro schema to connect Kafka. For that, we are writing a java code initially and will leverage the same in the Pega function. We have schema ready and we have all necessary jars imported in our system. While passing the message to Kafka, we need to add the SSL configuration given by the Kafka team. For that, we have created Keystore instances and added the jks files accordingly. Now we need to pass this information as a part of java code to call KafkaProducer(props) before writing the message on Topic. I am not sure how to send the Keystore files data in the below mentioned java code but what I did is like I have stored these files into ServicePath directory and passing the file with the password int he below java code but somehow system is not picking up this jks file and is throwing exception. Please help me on how to resolve this issue.
===================================================================
java.util.Properties props = new java.util.Properties();
props.put(org.apache.kafka.clients.producer.ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"server:port");
String tempPath = tools.getProperty("pxProcess.pxServiceExportPath").getStringValue();
Hi,
We are using V722 in our application. We have a requirement to push the message to Kafka topic. As we don't have DataSet in our Pega version, we are using Java, Avro schema to connect Kafka. For that, we are writing a java code initially and will leverage the same in the Pega function. We have schema ready and we have all necessary jars imported in our system. While passing the message to Kafka, we need to add the SSL configuration given by the Kafka team. For that, we have created Keystore instances and added the jks files accordingly. Now we need to pass this information as a part of java code to call KafkaProducer(props) before writing the message on Topic. I am not sure how to send the Keystore files data in the below mentioned java code but what I did is like I have stored these files into ServicePath directory and passing the file with the password int he below java code but somehow system is not picking up this jks file and is throwing exception. Please help me on how to resolve this issue.
===================================================================
java.util.Properties props = new java.util.Properties();
props.put(org.apache.kafka.clients.producer.ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"server:port");
String tempPath = tools.getProperty("pxProcess.pxServiceExportPath").getStringValue();
//configure the following three settings for SSL Encryption
props.put(org.apache.kafka.clients.CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL");
props.put(org.apache.kafka.common.config.SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG,tempPath+"/keystotre1.jks");
props.put(org.apache.kafka.common.config.SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG,"password");
//oLog.infoForced("Step1");
// configure the following three settings for SSL Authentication
//props.put(org.apache.kafka.common.config.SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG,tempPath+"/keystotre2.jks");
//props.put(org.apache.kafka.common.config.SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG,"password");
//props.put(org.apache.kafka.common.config.SslConfigs.SSL_KEY_PASSWORD_CONFIG,"password");
//oLog.infoForced("Step2");
props.put(org.apache.kafka.clients.producer.ProducerConfig.RETRIES_CONFIG, 0);
props.put(org.apache.kafka.clients.producer.ProducerConfig.ACKS_CONFIG, "all");
props.put(org.apache.kafka.clients.producer.ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, org.apache.kafka.common.serialization.StringSerializer.class);
props.put(org.apache.kafka.clients.producer.ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, org.apache.kafka.common.serialization.ByteArraySerializer.class);
/* oLog.error(props); */
oLog.infoForced("All properties values"+props);
try{
org.apache.kafka.clients.producer.Producer producer = new org.apache.kafka.clients.producer.KafkaProducer(props);
oLog.infoForced("**5");
org.apache.kafka.clients.producer.ProducerRecord prodRecord = new org.apache.kafka.clients.producer.ProducerRecord(Topic, out.toByteArray());
//oLog.infoForced("**Pushing data"+out.toByteArray());
//oLog.infoForced("Properties:"+props);
producer.send(prodRecord);
producer.flush();
producer.close();
}
catch(Exception e)
{
java.io.StringWriter stringWriter = new java.io.StringWriter();
java.io.PrintWriter exceptionPrinter = new java.io.PrintWriter(stringWriter);
e.printStackTrace(exceptionPrinter);
String sStackTrace = stringWriter.toString();
String[] lines = sStackTrace.split("\n\r|\r|\n");
for (int i = 0; i < lines.length; i++) {
oLog.infoForced("** Stack Trace Is: " + lines[i]);}
//oLog.infoForced("** Stack Trace Is: " + sStackTrace);
//oLog.infoForced("**Exception"+e);
return false;
}
========================================================
The highlighted portion is throwing exception in my case and not sure how to resolve it. Here is the java exception from log statement. Why there is a missing "/" after "file:" from the log statement given below. Not sure.
*********************
** Stack Trace Is: Caused by: org.apache.kafka.common.KafkaException: java.io.FileNotFoundException: file:/web:/StaticContent/global/ServiceExport/keystore1.jks (No such file or directory)
**********************
Thanks,
Ravi Kumar.
***Edited by Moderator Marissa to update platform capability tags****