Skip to content

Commit

Permalink
Use mqttTestClient with no authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Dec 25, 2024
1 parent e51c6a1 commit b487424
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,26 @@ public ProtobufMqttClient(Mqtt3BlockingClient sampleClient) {
}

public static void main(String[] args) {

Mqtt3SimpleAuth simpleAuth = Mqtt3SimpleAuth.builder().username(broker_username)
.password(broker_password.getBytes()).build();
Mqtt3BlockingClient sampleClient = Mqtt3Client.builder()
.serverHost(broker_host)
.serverPort(broker_port)
.identifier(client_id)
.simpleAuth(simpleAuth)
.sslWithDefaultConfig()
.buildBlocking();
Mqtt3BlockingClient sampleClient;
if (broker_username == null || broker_username.isEmpty() ||
broker_password == null || broker_password.isEmpty()) {
sampleClient = Mqtt3Client.builder()
.serverHost(broker_host)
.serverPort(broker_port)
.identifier(client_id)
.sslWithDefaultConfig()
.buildBlocking();
} else {
Mqtt3SimpleAuth simpleAuth = Mqtt3SimpleAuth.builder().username(broker_username)
.password(broker_password.getBytes()).build();
sampleClient = Mqtt3Client.builder()
.serverHost(broker_host)
.serverPort(broker_port)
.identifier(client_id)
.simpleAuth(simpleAuth)
.sslWithDefaultConfig()
.buildBlocking();
}
ProtobufMqttClient client = new ProtobufMqttClient(sampleClient);
client.testSendEvent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ public interface InternalCustomAlarmOrBuilder extends
* Protobuf type {@code processor.protobuf.InternalCustomAlarm}
*/
public static final class InternalCustomAlarm extends
com.google.protobuf.GeneratedMessageV3 implements
com.google.protobuf.GeneratedMessage implements
// @@protoc_insertion_point(message_implements:processor.protobuf.InternalCustomAlarm)
InternalCustomAlarmOrBuilder {
private static final long serialVersionUID = 0L;
// Use InternalCustomAlarm.newBuilder() to construct.
private InternalCustomAlarm(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
private InternalCustomAlarm(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
super(builder);
}
private InternalCustomAlarm() {
Expand Down Expand Up @@ -156,7 +156,7 @@ protected java.lang.Object newInstance(
}

@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return InternalCustomAlarmOuter.internal_static_processor_protobuf_InternalCustomAlarm_fieldAccessorTable
.ensureFieldAccessorsInitialized(
Expand Down Expand Up @@ -419,23 +419,23 @@ public void writeTo(com.google.protobuf.CodedOutputStream output)
if (timestamp_ != 0L) {
output.writeInt64(1, timestamp_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(txt_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 2, txt_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(txt_)) {
com.google.protobuf.GeneratedMessage.writeString(output, 2, txt_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(unit_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 3, unit_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(unit_)) {
com.google.protobuf.GeneratedMessage.writeString(output, 3, unit_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(externalIdType_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 4, externalIdType_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(externalIdType_)) {
com.google.protobuf.GeneratedMessage.writeString(output, 4, externalIdType_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(externalId_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 5, externalId_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(externalId_)) {
com.google.protobuf.GeneratedMessage.writeString(output, 5, externalId_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(alarmType_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 6, alarmType_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(alarmType_)) {
com.google.protobuf.GeneratedMessage.writeString(output, 6, alarmType_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(severity_)) {
com.google.protobuf.GeneratedMessageV3.writeString(output, 7, severity_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(severity_)) {
com.google.protobuf.GeneratedMessage.writeString(output, 7, severity_);
}
getUnknownFields().writeTo(output);
}
Expand All @@ -450,23 +450,23 @@ public int getSerializedSize() {
size += com.google.protobuf.CodedOutputStream
.computeInt64Size(1, timestamp_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(txt_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, txt_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(txt_)) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(2, txt_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(unit_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, unit_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(unit_)) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(3, unit_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(externalIdType_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, externalIdType_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(externalIdType_)) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(4, externalIdType_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(externalId_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, externalId_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(externalId_)) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(5, externalId_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(alarmType_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, alarmType_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(alarmType_)) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(6, alarmType_);
}
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(severity_)) {
size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, severity_);
if (!com.google.protobuf.GeneratedMessage.isStringEmpty(severity_)) {
size += com.google.protobuf.GeneratedMessage.computeStringSize(7, severity_);
}
size += getUnknownFields().getSerializedSize();
memoizedSize = size;
Expand Down Expand Up @@ -562,39 +562,39 @@ public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom(
}
public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input);
}
public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input, extensionRegistry);
}
public static InternalCustomAlarmOuter.InternalCustomAlarm parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
return com.google.protobuf.GeneratedMessage
.parseDelimitedWithIOException(PARSER, input);
}
public static InternalCustomAlarmOuter.InternalCustomAlarm parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
return com.google.protobuf.GeneratedMessage
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
}
public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input);
}
public static InternalCustomAlarmOuter.InternalCustomAlarm parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return com.google.protobuf.GeneratedMessageV3
return com.google.protobuf.GeneratedMessage
.parseWithIOException(PARSER, input, extensionRegistry);
}

Expand All @@ -614,15 +614,15 @@ public Builder toBuilder() {

@java.lang.Override
protected Builder newBuilderForType(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
Builder builder = new Builder(parent);
return builder;
}
/**
* Protobuf type {@code processor.protobuf.InternalCustomAlarm}
*/
public static final class Builder extends
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
com.google.protobuf.GeneratedMessage.Builder<Builder> implements
// @@protoc_insertion_point(builder_implements:processor.protobuf.InternalCustomAlarm)
InternalCustomAlarmOuter.InternalCustomAlarmOrBuilder {
public static final com.google.protobuf.Descriptors.Descriptor
Expand All @@ -631,7 +631,7 @@ public static final class Builder extends
}

@java.lang.Override
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
internalGetFieldAccessorTable() {
return InternalCustomAlarmOuter.internal_static_processor_protobuf_InternalCustomAlarm_fieldAccessorTable
.ensureFieldAccessorsInitialized(
Expand All @@ -644,7 +644,7 @@ private Builder() {
}

private Builder(
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
super(parent);

}
Expand Down Expand Up @@ -1403,7 +1403,7 @@ public InternalCustomAlarmOuter.InternalCustomAlarm getDefaultInstanceForType()
private static final com.google.protobuf.Descriptors.Descriptor
internal_static_processor_protobuf_InternalCustomAlarm_descriptor;
private static final
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
com.google.protobuf.GeneratedMessage.FieldAccessorTable
internal_static_processor_protobuf_InternalCustomAlarm_fieldAccessorTable;

public static com.google.protobuf.Descriptors.FileDescriptor
Expand All @@ -1429,7 +1429,7 @@ public InternalCustomAlarmOuter.InternalCustomAlarm getDefaultInstanceForType()
internal_static_processor_protobuf_InternalCustomAlarm_descriptor =
getDescriptor().getMessageTypes().get(0);
internal_static_processor_protobuf_InternalCustomAlarm_fieldAccessorTable = new
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_processor_protobuf_InternalCustomAlarm_descriptor,
new java.lang.String[] { "Timestamp", "Txt", "Unit", "ExternalIdType", "ExternalId", "AlarmType", "Severity", });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void extractFromSource(ProcessingContext<byte[]> context)
.getAlarmType(),
MappingSubstitution.SubstituteValue.TYPE.TEXTUAL,
RepairStrategy.DEFAULT))));
postProcessingCache.put(context.getMapping().targetAPI.identifier,
postProcessingCache.put(context.getMapping().getGenericDeviceIdentifier(),
new ArrayList<MappingSubstitution.SubstituteValue>(Arrays.asList(
new MappingSubstitution.SubstituteValue(
payloadProtobuf.getExternalId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void substituteInTargetAndSend(ProcessingContext<T> context) {
int countMaxEntries = postProcessingCache.get(entryWithMaxSubstitutes).size();

List<String> pathsTargetForDeviceIdentifiers;
if (mapping.extension == null || MappingType.PROTOBUF_STATIC.equals(mapping.getMappingType())) {
if (mapping.extension != null || MappingType.PROTOBUF_STATIC.equals(mapping.getMappingType())) {
pathsTargetForDeviceIdentifiers = new ArrayList<>(Arrays.asList(mapping.getGenericDeviceIdentifier()));
} else {
pathsTargetForDeviceIdentifiers = getPathTargetForDeviceIdentifiers(mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public class ProcessingContext<O> {

private String sourceId;

private String targetPathIdentifier;

public static final String SOURCE_ID = "source.id";

public boolean hasError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,29 @@ public ProtobufMqttClient(Mqtt3BlockingClient sampleClient) {
}

public static void main(String[] args) {

Mqtt3BlockingClient sampleClient;
if (broker_username == null || broker_username.isEmpty() ||
broker_password == null || broker_password.isEmpty()) {
Mqtt3BlockingClient sampleClient = Mqtt3Client.builder()
sampleClient = Mqtt3Client.builder()
.serverHost(broker_host)
.serverPort(broker_port)
.identifier(client_id)
.sslWithDefaultConfig()
.buildBlocking();
ProtobufMqttClient client = new ProtobufMqttClient(sampleClient);
client.testSendMeasurement();
client.testSendAlarm();
} else {
Mqtt3SimpleAuth simpleAuth = Mqtt3SimpleAuth.builder().username(broker_username)
.password(broker_password.getBytes()).build();
Mqtt3BlockingClient sampleClient = Mqtt3Client.builder()
sampleClient = Mqtt3Client.builder()
.serverHost(broker_host)
.serverPort(broker_port)
.identifier(client_id)
.simpleAuth(simpleAuth)
.sslWithDefaultConfig()
.buildBlocking();
ProtobufMqttClient client = new ProtobufMqttClient(sampleClient);
client.testSendMeasurement();
client.testSendAlarm();
}
ProtobufMqttClient client = new ProtobufMqttClient(sampleClient);
client.testSendMeasurement();
client.testSendAlarm();

}

Expand Down

0 comments on commit b487424

Please sign in to comment.