forked from usdot-jpo-ode/jpo-s3-deposit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updates with API connection and kafka testing
- Loading branch information
1 parent
0bd0323
commit fc74fad
Showing
18 changed files
with
311 additions
and
382 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
jpo-s3-depositor/src/main/java/us/dot/its/jpo/ode/s3/depositor/gen/FullOdeBsmData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package us.dot.its.jpo.ode.s3.depositor.gen; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.As; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; | ||
|
||
import us.dot.its.jpo.ode.model.OdeBsmData; | ||
import us.dot.its.jpo.ode.model.OdeBsmMetadata; | ||
import us.dot.its.jpo.ode.model.OdeBsmPayload; | ||
import us.dot.its.jpo.ode.model.OdeData; | ||
import us.dot.its.jpo.ode.model.OdeMsgMetadata; | ||
import us.dot.its.jpo.ode.model.OdeMsgPayload; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonTypeInfo.*; | ||
|
||
public class FullOdeBsmData extends OdeData { | ||
|
||
private static final long serialVersionUID = 4944935387116447760L; | ||
|
||
public FullOdeBsmData() { | ||
super(); | ||
} | ||
|
||
public FullOdeBsmData(OdeBsmMetadata metadata, OdeBsmPayload payload) { | ||
super(metadata, payload); | ||
} | ||
|
||
@Override | ||
@JsonTypeInfo(use = Id.CLASS, include = As.EXISTING_PROPERTY, defaultImpl = OdeBsmMetadata.class) | ||
public void setMetadata(OdeMsgMetadata metadata) { | ||
super.setMetadata(metadata); | ||
} | ||
|
||
@Override | ||
@JsonTypeInfo(use = Id.CLASS, include = As.EXISTING_PROPERTY, defaultImpl = OdeBsmPayload.class) | ||
public void setPayload(OdeMsgPayload payload) { | ||
super.setPayload(payload); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
jpo-s3-depositor/src/main/java/us/dot/its/jpo/ode/s3/depositor/gen/GenOdeSchemas.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package us.dot.its.jpo.ode.s3.depositor.gen; | ||
|
||
import org.springframework.stereotype.Controller; | ||
|
||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import us.dot.its.jpo.ode.model.OdeBsmData; | ||
|
||
@Controller | ||
public class GenOdeSchemas { | ||
|
||
// @PostConstruct | ||
// public void generateSchema() { | ||
// HyperSchemaFactoryWrapper bsm = new HyperSchemaFactoryWrapper(); | ||
// ObjectMapper mapper = new ObjectMapper(); | ||
// try { | ||
// mapper.acceptJsonFormatVisitor(FullOdeBsmData.class, bsm); | ||
// JsonSchema bsmSchema = bsm.finalSchema(); | ||
// String schemaJson = | ||
// mapper.writerWithDefaultPrettyPrinter().writeValueAsString(bsmSchema); | ||
// System.out.println(schemaJson); | ||
// } catch (JsonMappingException e) { | ||
// e.printStackTrace(); | ||
// } catch (Exception e) { | ||
// e.printStackTrace(); | ||
// } | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
jpo-s3-depositor/src/main/java/us/dot/its/jpo/ode/s3/depositor/imp/ImpMqttService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package us.dot.its.jpo.ode.s3.depositor.imp; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
|
||
import javax.net.ssl.SSLSocketFactory; | ||
import javax.net.ssl.X509ExtendedKeyManager; | ||
import javax.net.ssl.X509ExtendedTrustManager; | ||
|
||
import org.eclipse.paho.client.mqttv3.MqttClient; | ||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions; | ||
import org.eclipse.paho.client.mqttv3.MqttException; | ||
import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
import nl.altindag.ssl.SSLFactory; | ||
import nl.altindag.ssl.pem.util.PemUtils; | ||
import us.dot.its.jpo.ode.s3.depositor.DepositorProperties; | ||
import us.dot.its.jpo.ode.s3.depositor.models.imp.ConfigData; | ||
import us.dot.its.jpo.ode.s3.depositor.utils.CommonUtils; | ||
|
||
@Service | ||
public class ImpMqttService { | ||
private static final Logger logger = LoggerFactory.getLogger(ImpMqttService.class); | ||
private MqttClient client; | ||
|
||
public ImpMqttService(DepositorProperties properties) throws MqttException { | ||
ConfigData impConfig = CommonUtils.readConfigFile(properties.getImpCertPath() + "/config.json"); | ||
|
||
String uri = impConfig.getImpMqttUri().toString().replace("mqtt://", "ssl://"); | ||
|
||
client = new MqttClient(uri, impConfig.getDeviceID()); | ||
MqttConnectOptions options = new MqttConnectOptions(); | ||
options.setCleanSession(true); | ||
options.setSocketFactory(createSocketFactory(impConfig.getCaCertPath(), impConfig.getClientCertPath(), | ||
impConfig.getKeyFilePath())); | ||
client.connect(options); | ||
} | ||
|
||
public static SSLSocketFactory createSocketFactory(String caCertPath, String clientCertPath, | ||
String privateKeyPath) { | ||
// Convert to absolute paths | ||
String absoluteCaCertPath = Paths.get(caCertPath).toAbsolutePath().toString(); | ||
String absoluteClientCertPath = Paths.get(clientCertPath).toAbsolutePath().toString(); | ||
String absolutePrivateKeyPath = Paths.get(privateKeyPath).toAbsolutePath().toString(); | ||
|
||
logger.info("CA Cert Path: {}", absoluteCaCertPath); | ||
logger.info("Client Cert Path: {}", absoluteClientCertPath); | ||
logger.info("Private Key Path: {}", absolutePrivateKeyPath); | ||
|
||
// Check if files exist | ||
if (!new File(absoluteCaCertPath).exists()) { | ||
throw new IllegalArgumentException("CA Certificate file not found at path: " + absoluteCaCertPath); | ||
} | ||
if (!new File(absoluteClientCertPath).exists()) { | ||
throw new IllegalArgumentException("Client Certificate file not found at path: " + absoluteClientCertPath); | ||
} | ||
if (!new File(absolutePrivateKeyPath).exists()) { | ||
throw new IllegalArgumentException("Private Key file not found at path: " + absolutePrivateKeyPath); | ||
} | ||
|
||
X509ExtendedKeyManager keyManager = PemUtils.loadIdentityMaterial(Paths.get(absoluteClientCertPath), | ||
Paths.get(absolutePrivateKeyPath)); | ||
X509ExtendedTrustManager trustManager = PemUtils.loadTrustMaterial(Paths.get(absoluteCaCertPath)); | ||
|
||
var sslFactory = SSLFactory.builder().withIdentityMaterial(keyManager).withTrustMaterial(trustManager).build(); | ||
|
||
var sslSocketFactory = sslFactory.getSslSocketFactory(); | ||
return sslSocketFactory; | ||
} | ||
|
||
public void publish(String topic, String messageContent) throws MqttException { | ||
MqttMessage message = new MqttMessage(); | ||
message.setPayload(messageContent.getBytes()); | ||
client.publish(topic, message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 17 additions & 10 deletions
27
jpo-s3-depositor/src/main/java/us/dot/its/jpo/ode/s3/depositor/imp/ImpUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package us.dot.its.jpo.ode.s3.depositor.imp; | ||
// package us.dot.its.jpo.ode.s3.depositor.imp; | ||
|
||
import us.dot.its.jpo.ode.depositor.GeoRoutedMsg; | ||
// import com.google.protobuf.ByteString; | ||
|
||
public class ImpUtil { | ||
// import us.dot.its.jpo.ode.depositor.GeoRoutedMsg; | ||
// import us.dot.its.jpo.ode.depositor.GeoRoutedMsgOrBuilder; | ||
|
||
public GeoRoutedMsg getGeoRoutedMsg(String asn1String, String odeReceivedAt, ) { | ||
|
||
byte[] asn1 = pojo1.getMetadata().getAsn1().getBytes(); | ||
ByteString asn1ByteString = ByteString.copyFrom(asn1); | ||
// public class ImpUtil { | ||
|
||
GeoRoutedMsgOrBuilder geoRoutedMsg = GeoRoutedMsg.newBuilder().setMsgBytes(asn1ByteString).set; | ||
} | ||
} | ||
// public GeoRoutedMsg getGeoRoutedMsg(String asn1String, String odeReceivedAt) | ||
// { | ||
|
||
// // byte[] asn1 = pojo1.getMetadata().getAsn1().getBytes(); | ||
// ByteString asn1ByteString = ByteString.copyFrom(asn1String.getBytes()); | ||
|
||
// GeoRoutedMsg geoRoutedMsg = | ||
// GeoRoutedMsg.newBuilder().setMsgBytes(asn1ByteString).build(); | ||
|
||
// return geoRoutedMsg; | ||
// } | ||
// } |
Oops, something went wrong.