From 97227d9ea8e351075e8c133d741df3081d7bd2c3 Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Mon, 22 Nov 2021 22:34:29 +0100 Subject: [PATCH 01/10] started with MQTT PubSub client skeleton --- application-skeleton-mqtt/pom.xml | 54 ++++++++++++++ .../pubsub/PubSubApplicationInitListener.java | 67 ++++++++++++++++++ .../skeleton/pubsub/PubSubMain.java | 20 ++++++ ...itional-spring-configuration-metadata.json | 32 +++++++++ .../src/main/resources/application.properties | 33 +++++++++ .../certificates/providerskeleton.p12 | Bin 0 -> 4355 bytes .../resources/certificates/truststore.p12 | Bin 0 -> 1162 bytes pom.xml | 1 + 8 files changed, 207 insertions(+) create mode 100644 application-skeleton-mqtt/pom.xml create mode 100644 application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java create mode 100644 application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubMain.java create mode 100644 application-skeleton-mqtt/src/main/resources/META-INF/additional-spring-configuration-metadata.json create mode 100644 application-skeleton-mqtt/src/main/resources/application.properties create mode 100644 application-skeleton-mqtt/src/main/resources/certificates/providerskeleton.p12 create mode 100644 application-skeleton-mqtt/src/main/resources/certificates/truststore.p12 diff --git a/application-skeleton-mqtt/pom.xml b/application-skeleton-mqtt/pom.xml new file mode 100644 index 0000000..8d01ed4 --- /dev/null +++ b/application-skeleton-mqtt/pom.xml @@ -0,0 +1,54 @@ + + 4.0.0 + + + eu.arrowhead + application-skeleton-java-spring + 4.4.0.0 + + + arrowhead-application-skeleton-mqtt + Arrowhead MQTT PubSub Skeleton + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + maven-resources-plugin + 3.1.0 + + + copy-resources + validate + + copy-resources + + + ${basedir}/target + + + src/main/resources + + application.properties + + + + + + + + + + + diff --git a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java new file mode 100644 index 0000000..a47ef5e --- /dev/null +++ b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java @@ -0,0 +1,67 @@ +package eu.arrowhead.application.skeleton.pubsub; + +import java.io.IOException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.cert.CertificateException; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +import ai.aitia.arrowhead.application.library.ArrowheadService; +import ai.aitia.arrowhead.application.library.config.ApplicationInitListener; +import ai.aitia.arrowhead.application.library.util.ApplicationCommonConstants; +//import eu.arrowhead.application.skeleton.provider.security.ProviderSecurityConfig; +import eu.arrowhead.common.CommonConstants; +import eu.arrowhead.common.Utilities; +import eu.arrowhead.common.core.CoreSystem; +import eu.arrowhead.common.exception.ArrowheadException; + +@Component +public class PubSubApplicationInitListener extends ApplicationInitListener { + + //================================================================================================= + // members + + @Autowired + private ArrowheadService arrowheadService; + + @Value(CommonConstants.$SERVER_SSL_ENABLED_WD) + private boolean sslEnabled; + + private final Logger logger = LogManager.getLogger(PubSubApplicationInitListener.class); + + //================================================================================================= + // methods + + //------------------------------------------------------------------------------------------------- + @Override + protected void customInit(final ContextRefreshedEvent event) { + + //Checking the availability of necessary core systems + //checkCoreSystemReachability(CoreSystem.SERVICEREGISTRY); + //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); + + //Initialize Arrowhead Context + //arrowheadService.updateCoreServiceURIs(CoreSystem.AUTHORIZATION); + + //TODO: implement here any custom behavior on application start up + } + + //------------------------------------------------------------------------------------------------- + @Override + public void customDestroy() { + //TODO: implement here any custom behavior on application shout down + } + + //================================================================================================= + // assistant methods + +} diff --git a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubMain.java b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubMain.java new file mode 100644 index 0000000..487fb17 --- /dev/null +++ b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubMain.java @@ -0,0 +1,20 @@ +package eu.arrowhead.application.skeleton.pubsub; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +import eu.arrowhead.common.CommonConstants; + +@SpringBootApplication +@ComponentScan(basePackages = {CommonConstants.BASE_PACKAGE, "ai.aitia"}) //TODO: add custom packages if any +public class PubSubMain { + + //================================================================================================= + // methods + + //------------------------------------------------------------------------------------------------- + public static void main(final String[] args) { + SpringApplication.run(PubSubMain.class, args); + } +} diff --git a/application-skeleton-mqtt/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/application-skeleton-mqtt/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 0000000..d1479ba --- /dev/null +++ b/application-skeleton-mqtt/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,32 @@ +{"properties": [ + { + "name": "client_system_name", + "type": "java.lang.String", + "description": "A description for 'client_system_name'" + }, + { + "name": "broker_address", + "type": "java.lang.String", + "description": "A description for 'broker_address'" + }, + { + "name": "broker_port", + "type": "java.lang.String", + "description": "A description for 'broker_port'" + }, + { + "name": "broker_username", + "type": "java.lang.String", + "description": "A description for 'broker_username'" + }, + { + "name": "broker_password", + "type": "java.lang.String", + "description": "A description for 'broker_password'" + }, + { + "name": "container.max_keep_alive_requests", + "type": "java.lang.Integer", + "description": "A description for 'container.max_keep_alive_requests'" + } +]} diff --git a/application-skeleton-mqtt/src/main/resources/application.properties b/application-skeleton-mqtt/src/main/resources/application.properties new file mode 100644 index 0000000..5fe1f4e --- /dev/null +++ b/application-skeleton-mqtt/src/main/resources/application.properties @@ -0,0 +1,33 @@ +############################################ +### CUSTOM PARAMETERS ### +############################################ + +# Name of the client system +application_system_name=PUBSUBSKELETON + +# Broker parameters +broker.address=127.0.0.1 +broker.port=1883 +broker.username=pubsub +broker.password=badpassword + + +############################################ +### SECURE MODE ### +############################################ + +# configure secure mode + +# Set this to false to disable mqtt(s) mode +server.ssl.enabled=true + + +server.ssl.key-store-type=PKCS12 +server.ssl.key-store=classpath:certificates/providerskeleton.p12 +server.ssl.key-store-password=123456 +server.ssl.key-alias=providerskeleton +server.ssl.key-password=123456 +server.ssl.client-auth=need +server.ssl.trust-store-type=PKCS12 +server.ssl.trust-store=classpath:certificates/truststore.p12 +server.ssl.trust-store-password=123456 diff --git a/application-skeleton-mqtt/src/main/resources/certificates/providerskeleton.p12 b/application-skeleton-mqtt/src/main/resources/certificates/providerskeleton.p12 new file mode 100644 index 0000000000000000000000000000000000000000..c5b579924f83f5fb044c814107ba501a18623b3e GIT binary patch literal 4355 zcmY+EWmFW7w#8?L8M;g96owvZXc=VSFAahqiYVP35<@tIbW5moOH1d_-6$a4GBij@ zUf)~q-Mj9Gz4lqZea`u~VQBJu5D*83CU3wc;0=8mdO-rj17@Mgi@|8}{J%IGhKBh4 zR|Ihcqan6`vE^Tx;u8Je6)_U8Nk%*;z~dgbbiZ^9nP3j zN_F2!@v~|W4xmdLj0X4HlAMp&xiO^|nR!&~)IU2U*_3D>u%(R4_V|&~jcEO6S;lQ~ z{;RK(bH>Z4B-CJ@$_G9RdM0Lfo<*q4793gFJ=48CxBCF z1R!HL{YI)#R@uC}JN_cA`(UcoZ(Nv?*4}GUo-%23>rhq#TkPSi9By|*hU4k=ZwEs;6)PUR6{N`;Hjjf8}0E&K9B*Q%j1^FKg3bT(@kAMQ2^woR+b z%@XEZUbCESJEbXc1Shk!wtS>|5%xo&6R)+hPuf73fZ}6*ZpYFZc1Z;#V`6KvD_P`7 zGfi-td5zTON*+k2P4rL#{ft_2pHoV{;)H}3(SJ`}ZH+M#qmFc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dlRs?MH~cvo3d zHlyrpX>%j3P9U%3S<(fcph}zVB(PH4$33Y9cXH7PXURkTi_HqtB zT&g=qFo+(2XAa1XC2Ey@u%_-?xC=92i7OXvdZ4Q)8fDqG82|wH_l==)xazFFUJ2+1 z4`2uNOKnlpx><1J=T)wczuRqD#Y)bms&=odjOP%=Ww6teD0%IVT_~|ZRM03Msb%FO z)ceySwpCJ6mmk?aNo3*%`g6uTg!W~IH-ImR&F1mt+0DxLj0q1Up+WIVzv+U%fPR)} zW8LV8$am@c3I8373OGB%4Ho=4bE0i?2{5y?e3c3{7SnQR&>f@T(fk5 z(08P7%ZJ`NZyTsXf>Gb-#v|@Syt0K8SBaNUc`RLs*CpY^9{L;~-7ql% zTfEDSgAMduUOueEvHHNzB~cQ%B^z6KV8WsH+jqHrj+ni;x^X4d*q=e6?3 zJPu;4u(80w@YnMx-tBPyUOL4^Jza=bZjmay? zX&zILY$J^QgXAC_x23Z*S}?oDQCj53@ z&%kN^wOS)7de}EeW3|ft++)7NDO><5C}BFef}oSev$fq=B^Dux>64!T7_%rkr*79EXojOyJ-Mg~Q9`^~K>>&&&Sxk^NWBl@F;=^p4gPmX#1 zx^CslA(YpYDm&*bb)|(1C=zF09$RXXq3~Qq>s3g|=5^_RBeeR@97J$vdf1O;%KR8| zZO-92jG26WVm?u;Vhtn(m_B;tN*Cd(PgKJWL#Y~F=|nL2h8b5>rhfM3qln*LvV_GqQ_n0IDgvMdcEcYH zYAO3w@y2GERGflRX}F2jBuO_m=097$UhWZibM6)ir#zpdQVFeHiCA7HbA9tVBjCF~hy69pzHkp_rz8<*QEA?GBsa?ZZkn4L-EXIDpJ60RogI;zCcA_| z!s6p7;*FL?Q*1h6k6~;u0$d0mDGrDp0svFH*J{+4#4zHCY4T65_^1?5G literal 0 HcmV?d00001 diff --git a/application-skeleton-mqtt/src/main/resources/certificates/truststore.p12 b/application-skeleton-mqtt/src/main/resources/certificates/truststore.p12 new file mode 100644 index 0000000000000000000000000000000000000000..6da7cd2d032a7f5616eb0fa1cb6af7757b79f6ae GIT binary patch literal 1162 zcmV;51aZ%2`Yw2hW8Bt2LUiC1_~;MNQUVie#xIu!wo#Sa)KD-Xk4QB8AcV}aBK<6W{yG=*Ik4y&-y->U2_4Q$Dnr zCauJ3Ukce$1d)$#|5fB8D1^syty5TRV#|}`VMuuACkKRJ-P3~KRD&PD-nW{6(#Z0+vGBy7WYOz<<;gEL0Ovq_P`EuN*=#rIPy z;I+Tm!-5FcSb=yyU#vT7wJ&SzhAgXseVzLnq0kV4POCKg1!l@PQ3Jy=H1Y?zVv6rU zt115AxuG=lwv78#zc<7JYP=nL{o#XCWEOieJ~N$cABq@EcPmO?xv;xEQMaL!>$ zV$TK3AiN$@(omV_ioYE^;ks5rqv@ae3CHDG>5pvz0t%a=+3CSUEU$A)n#!u$S|)x}*)IxGFH=r(=OdixR&9U#O|bHhZwlBH4hwER5riuq$dgEB z%_A%V=s!KvT1PgWCspA&^+T9*#pXgP>3+uK{{$Y{i8?Aqd$9(x3!-U)kN?q-H;)+< z$Ayj5@5rvON*`*#NqLk3Zw5>##r&X|LRpm@m^a2BRJwvK={E+x8application-skeleton-provider application-skeleton-subscriber application-skeleton-publisher + application-skeleton-mqtt From e906fd3932cc1e06700556e404ff9cdd4c684eb1 Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Tue, 23 Nov 2021 22:25:24 +0100 Subject: [PATCH 02/10] created MQTT skelenton that connects to a Broker and subscribes to a test topic --- .../pubsub/PubSubApplicationInitListener.java | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java index a47ef5e..0a3f611 100644 --- a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java +++ b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java @@ -18,14 +18,22 @@ import ai.aitia.arrowhead.application.library.ArrowheadService; import ai.aitia.arrowhead.application.library.config.ApplicationInitListener; import ai.aitia.arrowhead.application.library.util.ApplicationCommonConstants; -//import eu.arrowhead.application.skeleton.provider.security.ProviderSecurityConfig; import eu.arrowhead.common.CommonConstants; import eu.arrowhead.common.Utilities; import eu.arrowhead.common.core.CoreSystem; import eu.arrowhead.common.exception.ArrowheadException; +import org.eclipse.paho.client.mqttv3.MqttCallback; +import org.eclipse.paho.client.mqttv3.MqttClient; +import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.eclipse.paho.client.mqttv3.MqttConnectOptions; +import org.eclipse.paho.client.mqttv3.internal.security.SSLSocketFactoryFactory; +import org.eclipse.paho.client.mqttv3.MqttMessage; +import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; +import org.eclipse.paho.client.mqttv3.MqttException; + @Component -public class PubSubApplicationInitListener extends ApplicationInitListener { +public class PubSubApplicationInitListener extends ApplicationInitListener implements MqttCallback { //================================================================================================= // members @@ -36,6 +44,7 @@ public class PubSubApplicationInitListener extends ApplicationInitListener { @Value(CommonConstants.$SERVER_SSL_ENABLED_WD) private boolean sslEnabled; + MqttClient client = null; private final Logger logger = LogManager.getLogger(PubSubApplicationInitListener.class); //================================================================================================= @@ -47,20 +56,56 @@ protected void customInit(final ContextRefreshedEvent event) { //Checking the availability of necessary core systems //checkCoreSystemReachability(CoreSystem.SERVICEREGISTRY); - //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); + //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); //Initialize Arrowhead Context //arrowheadService.updateCoreServiceURIs(CoreSystem.AUTHORIZATION); //TODO: implement here any custom behavior on application start up + try { + client = arrowheadService.connectMQTTBroker(this, "127.0.0.1", 1883, "pubsub", "badpassword", "pubsub01"); + client.subscribe("ah/pubsub/messages"); + } catch (Exception e) { + throw new ArrowheadException("Could not connect to MQTT broker!\n" + e.toString()); + } } - + //------------------------------------------------------------------------------------------------- @Override public void customDestroy() { //TODO: implement here any custom behavior on application shout down + if (client != null) { + try { + arrowheadService.disconnectMQTTBroker(client); + arrowheadService.closeMQTTBroker(client); + } catch(Exception e) { + } + + client = null; + } } + //================================================================================================= + // MQTT callback methods + + @Override + public void connectionLost(Throwable t) { + System.out.println("connectionLost: " + t.toString()); + + //TODO: implement here any custom behavior on broker disconnect, typically a reconnect after a short timeout + } + + @Override + public void messageArrived(String topic, MqttMessage message) throws Exception { + System.out.println("topic - " + topic + ": " + new String(message.getPayload())); + + //TODO: implement here any custom behavior on incoming messages, filtered in topic + } + + @Override + public void deliveryComplete(IMqttDeliveryToken token) { + } + //================================================================================================= // assistant methods From dd66090892fdc061abae9ecf6780ea3ae7b44992 Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Tue, 23 Nov 2021 22:35:32 +0100 Subject: [PATCH 03/10] minor code improvements --- .../skeleton/pubsub/PubSubApplicationInitListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java index 0a3f611..1db3eb0 100644 --- a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java +++ b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java @@ -66,6 +66,7 @@ protected void customInit(final ContextRefreshedEvent event) { client = arrowheadService.connectMQTTBroker(this, "127.0.0.1", 1883, "pubsub", "badpassword", "pubsub01"); client.subscribe("ah/pubsub/messages"); } catch (Exception e) { + client = null; throw new ArrowheadException("Could not connect to MQTT broker!\n" + e.toString()); } } From fbdde9446ebcb74382fd77114a4e8b22c5d6c39c Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Tue, 23 Nov 2021 23:05:23 +0100 Subject: [PATCH 04/10] MQTT over TCP and TLS works! code is ok, but there are methods that should be implemeneted --- .../pubsub/PubSubApplicationInitListener.java | 33 ++++++++++++++----- .../src/main/resources/application.properties | 10 +++--- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java index 1db3eb0..cfe2997 100644 --- a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java +++ b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java @@ -40,7 +40,27 @@ public class PubSubApplicationInitListener extends ApplicationInitListener imple @Autowired private ArrowheadService arrowheadService; + + //@Value(CommonConstants.$APPLICATION_SYSTEM_NAME) + @Value("${application_system_name}") + private String systemName; + + //@Value(CommonConstants.$MQTT_BROKER_ADDRES) + @Value("${mqtt.broker.address}") + private String brokerAddress; + + //@Value(CommonConstants.$MQTT_BROKER_PORT) + @Value("${mqtt.broker.port}") + private int brokerPort; + + //@Value(CommonConstants.$MQTT_BROKER_USERNAME) + @Value("${mqtt.broker.username}") + private String brokerUsername; + //@Value(CommonConstants.$MQTT_BROKER_PASSWORD) + @Value("${mqtt.broker.password}") + private String brokerPassword; + @Value(CommonConstants.$SERVER_SSL_ENABLED_WD) private boolean sslEnabled; @@ -54,16 +74,13 @@ public class PubSubApplicationInitListener extends ApplicationInitListener imple @Override protected void customInit(final ContextRefreshedEvent event) { - //Checking the availability of necessary core systems - //checkCoreSystemReachability(CoreSystem.SERVICEREGISTRY); - //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); - - //Initialize Arrowhead Context - //arrowheadService.updateCoreServiceURIs(CoreSystem.AUTHORIZATION); - //TODO: implement here any custom behavior on application start up try { - client = arrowheadService.connectMQTTBroker(this, "127.0.0.1", 1883, "pubsub", "badpassword", "pubsub01"); + client = arrowheadService.connectMQTTBroker(this, brokerAddress, brokerPort, brokerUsername, brokerPassword, systemName); + + //Checking the availability of necessary core systems add MQTT support here as well + //checkCoreSystemReachability(CoreSystem.SERVICEREGISTRY); add MQTT support here as well + //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); add MQTT support here as well client.subscribe("ah/pubsub/messages"); } catch (Exception e) { client = null; diff --git a/application-skeleton-mqtt/src/main/resources/application.properties b/application-skeleton-mqtt/src/main/resources/application.properties index 5fe1f4e..4aecdd4 100644 --- a/application-skeleton-mqtt/src/main/resources/application.properties +++ b/application-skeleton-mqtt/src/main/resources/application.properties @@ -5,11 +5,11 @@ # Name of the client system application_system_name=PUBSUBSKELETON -# Broker parameters -broker.address=127.0.0.1 -broker.port=1883 -broker.username=pubsub -broker.password=badpassword +# MQTT Broker parameters +mqtt.broker.address=127.0.0.1 +mqtt.broker.port=1883 +mqtt.broker.username=pubsub +mqtt.broker.password=badpassword ############################################ From 7df1181659a8b79604a9ce36d2854535911d9408 Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Tue, 23 Nov 2021 23:10:00 +0100 Subject: [PATCH 05/10] updated to TLS port by default --- .../pubsub/PubSubApplicationInitListener.java | 12 ++++++------ .../src/main/resources/application.properties | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java index cfe2997..918e59f 100644 --- a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java +++ b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java @@ -45,7 +45,7 @@ public class PubSubApplicationInitListener extends ApplicationInitListener imple @Value("${application_system_name}") private String systemName; - //@Value(CommonConstants.$MQTT_BROKER_ADDRES) + //@Value(CommonConstants.$MQTT_BROKER_ADDRESS) @Value("${mqtt.broker.address}") private String brokerAddress; @@ -78,9 +78,9 @@ protected void customInit(final ContextRefreshedEvent event) { try { client = arrowheadService.connectMQTTBroker(this, brokerAddress, brokerPort, brokerUsername, brokerPassword, systemName); - //Checking the availability of necessary core systems add MQTT support here as well - //checkCoreSystemReachability(CoreSystem.SERVICEREGISTRY); add MQTT support here as well - //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); add MQTT support here as well + //Checking the availability of necessary core systems add MQTT support here as well? + //checkCoreSystemReachability(CoreSystem.SERVICEREGISTRY); add MQTT support here as well? + //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); add MQTT support here as well? client.subscribe("ah/pubsub/messages"); } catch (Exception e) { client = null; @@ -91,7 +91,7 @@ protected void customInit(final ContextRefreshedEvent event) { //------------------------------------------------------------------------------------------------- @Override public void customDestroy() { - //TODO: implement here any custom behavior on application shout down + //TODO: implement here any custom behavior on application shut down if (client != null) { try { arrowheadService.disconnectMQTTBroker(client); @@ -117,7 +117,7 @@ public void connectionLost(Throwable t) { public void messageArrived(String topic, MqttMessage message) throws Exception { System.out.println("topic - " + topic + ": " + new String(message.getPayload())); - //TODO: implement here any custom behavior on incoming messages, filtered in topic + //TODO: implement here any custom behavior on incoming messages, such as filtering in topics etc } @Override diff --git a/application-skeleton-mqtt/src/main/resources/application.properties b/application-skeleton-mqtt/src/main/resources/application.properties index 4aecdd4..d7c8e17 100644 --- a/application-skeleton-mqtt/src/main/resources/application.properties +++ b/application-skeleton-mqtt/src/main/resources/application.properties @@ -7,7 +7,7 @@ application_system_name=PUBSUBSKELETON # MQTT Broker parameters mqtt.broker.address=127.0.0.1 -mqtt.broker.port=1883 +mqtt.broker.port=8883 mqtt.broker.username=pubsub mqtt.broker.password=badpassword From 50b9281f8cfadc148c091e85af6c0af01e38ce53 Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Tue, 23 Nov 2021 23:27:23 +0100 Subject: [PATCH 06/10] Tomcat is disabled by default in MQTT mode --- .../src/main/resources/application.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/application-skeleton-mqtt/src/main/resources/application.properties b/application-skeleton-mqtt/src/main/resources/application.properties index d7c8e17..e4caadb 100644 --- a/application-skeleton-mqtt/src/main/resources/application.properties +++ b/application-skeleton-mqtt/src/main/resources/application.properties @@ -5,6 +5,9 @@ # Name of the client system application_system_name=PUBSUBSKELETON +# Disable Tomcat for MQTT only applications +spring.main.web-application-type=none + # MQTT Broker parameters mqtt.broker.address=127.0.0.1 mqtt.broker.port=8883 From 3e4c4f190fca5579751808c315dc7df02fa56729 Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Wed, 24 Nov 2021 13:40:48 +0100 Subject: [PATCH 07/10] changed certificate --- .../src/main/resources/application.properties | 2 +- .../resources/certificates/providerskeleton.p12 | Bin 4355 -> 0 bytes .../src/main/resources/certificates/pubsub.p12 | Bin 0 -> 4457 bytes 3 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 application-skeleton-mqtt/src/main/resources/certificates/providerskeleton.p12 create mode 100644 application-skeleton-mqtt/src/main/resources/certificates/pubsub.p12 diff --git a/application-skeleton-mqtt/src/main/resources/application.properties b/application-skeleton-mqtt/src/main/resources/application.properties index e4caadb..eebba8a 100644 --- a/application-skeleton-mqtt/src/main/resources/application.properties +++ b/application-skeleton-mqtt/src/main/resources/application.properties @@ -26,7 +26,7 @@ server.ssl.enabled=true server.ssl.key-store-type=PKCS12 -server.ssl.key-store=classpath:certificates/providerskeleton.p12 +server.ssl.key-store=classpath:certificates/pubsub.p12 server.ssl.key-store-password=123456 server.ssl.key-alias=providerskeleton server.ssl.key-password=123456 diff --git a/application-skeleton-mqtt/src/main/resources/certificates/providerskeleton.p12 b/application-skeleton-mqtt/src/main/resources/certificates/providerskeleton.p12 deleted file mode 100644 index c5b579924f83f5fb044c814107ba501a18623b3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001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@ z&%kN^wOS)7de}EeW3|ft++)7NDO><5C}BFef}oSev$fq=B^Dux>64!T7_%rkr*79EXojOyJ-Mg~Q9`^~K>>&&&Sxk^NWBl@F;=^p4gPmX#1 zx^CslA(YpYDm&*bb)|(1C=zF09$RXXq3~Qq>s3g|=5^_RBeeR@97J$vdf1O;%KR8| zZO-92jG26WVm?u;Vhtn(m_B;tN*Cd(PgKJWL#Y~F=|nL2h8b5>rhfM3qln*LvV_GqQ_n0IDgvMdcEcYH zYAO3w@y2GERGflRX}F2jBuO_m=097$UhWZibM6)ir#zpdQVFeHiCA7HbA9tVBjCF~hy69pzHkp_rz8<*QEA?GBsa?ZZkn4L-EXIDpJ60RogI;zCcA_| z!s6p7;*FL?Q*1h6k6~;u0$d0mDGrDp0svFH*J{+4#4zHCY4T65_^1?5G diff --git a/application-skeleton-mqtt/src/main/resources/certificates/pubsub.p12 b/application-skeleton-mqtt/src/main/resources/certificates/pubsub.p12 new file mode 100644 index 0000000000000000000000000000000000000000..603e7919d253ee09e6b3bbfe2b1fa4ef452a5eb1 GIT binary patch literal 4457 zcma)+XE+;Uf5Zxws*P0h6Sj8baVR$4_- zD~f;bbMN!}J@?hUFU~p7`Fzj!y!^t@R7gSq5Qe5=C4vY)>HoOMNC1R+XfXUQl!w{>;{e}=nZoY>yOO~KK{Q+7 z+df<2**+5VqX=n7s)u7K-j#%eyp)6hb{H8E@qd3Lgn$WPEJP6N2z3Aw2m%OzD8u(V zDCQ=ftkkO<&ML=lKq?y+3hd?X8+h+>;AC#r06S)O?$Uoe%O}u%@vV}}wZRb*q zujKJ56;9Q$J&V$BqS);u)FH-l%U=c3dJPW`R>tDoob9g+jxOs4G)(3CVT)ib0r91prXOeHf(3MRM7o)aLXw(UttARNlhSj*AQJEOU zR&}m~2){q>sG11gQmJ5tm9#vww)Ya;Fnh{9zL$+?D3Ln?%&roYb-j&Ltoi79Th1_x zf}LiG=3Y(eZ;Dup43qfvmNM7xqXIURfqi%Q8?j*bIv1B1uc?}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iN#f@_Ve(xfS%k4UZ^5pu0eTlR4fZNh<)*EA>$552>F?pO#{l&iMm9z-1nmdVjR z2ycD16>eJee2ibct`Bww=xM9{mEUNB3CUl3tKiA0D#i>j1TWi{3Kyo?Urmsy!a~iRoS$vMCZNindVHg)wA1Y=jvcw2}yTx zr9wca!C`pwiMEX@C(ZE3hJ~cwIIfMYWRybNFJ=9(2WxpYo<8xRC@bOZM>Jt)Ukcr7|dlSbx%BsNS1dq*xj@(**~s2grh5179yP0YUz4}92{#+Z`IKTOD<2JOgP4g9r z@icQLeSqY)D0HiSYHe#i-A@AG*EIh|CDTS+NM)TY#{eIr zeh{A2n20#i|LEbn>#{2m(xBrR1S0V*A`GhUR|qMju;9@Sif1GjZHh7! z+V8m`?F$G$iti$Ud!{+l$7;UpBj_va4VhR4y(0c?-54s$SDTi`Q&BO{Gc9Q3v^sFI zYJ8l}l6ehKiijiFvGr=$n@<{m9vn)E9s)V0PhGKjlaX>AFJs6xOw@lrOLA?mM9mpt zHn-op@uRv&sg57_x@-tS?DuoaGqiB_9ms> z>KOCRE|tk_Gtj#@ij8s_#DyggRjP@pIF3fl_?B`ZD&V06t|>rdQFLAVMRcF6P;cN0 zk<$f%cJ}u%I+y~C0|p@i3z7o~8Nmb~ni7S3@MAPG<;<05uf~#`+c(g36GYQvb!><@ YZ!d`T2%NEF^FDv@ Date: Wed, 24 Nov 2021 13:52:13 +0100 Subject: [PATCH 08/10] fixed indentation --- .../pubsub/PubSubApplicationInitListener.java | 89 +++++++++---------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java index 918e59f..8b9f701 100644 --- a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java +++ b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java @@ -41,30 +41,30 @@ public class PubSubApplicationInitListener extends ApplicationInitListener imple @Autowired private ArrowheadService arrowheadService; - //@Value(CommonConstants.$APPLICATION_SYSTEM_NAME) - @Value("${application_system_name}") + //@Value(CommonConstants.$APPLICATION_SYSTEM_NAME) + @Value("${application_system_name}") private String systemName; - //@Value(CommonConstants.$MQTT_BROKER_ADDRESS) - @Value("${mqtt.broker.address}") + //@Value(CommonConstants.$MQTT_BROKER_ADDRESS) + @Value("${mqtt.broker.address}") private String brokerAddress; - //@Value(CommonConstants.$MQTT_BROKER_PORT) - @Value("${mqtt.broker.port}") + //@Value(CommonConstants.$MQTT_BROKER_PORT) + @Value("${mqtt.broker.port}") private int brokerPort; - //@Value(CommonConstants.$MQTT_BROKER_USERNAME) - @Value("${mqtt.broker.username}") + //@Value(CommonConstants.$MQTT_BROKER_USERNAME) + @Value("${mqtt.broker.username}") private String brokerUsername; - //@Value(CommonConstants.$MQTT_BROKER_PASSWORD) - @Value("${mqtt.broker.password}") + //@Value(CommonConstants.$MQTT_BROKER_PASSWORD) + @Value("${mqtt.broker.password}") private String brokerPassword; @Value(CommonConstants.$SERVER_SSL_ENABLED_WD) private boolean sslEnabled; - MqttClient client = null; + MqttClient client = null; private final Logger logger = LogManager.getLogger(PubSubApplicationInitListener.class); //================================================================================================= @@ -74,55 +74,52 @@ public class PubSubApplicationInitListener extends ApplicationInitListener imple @Override protected void customInit(final ContextRefreshedEvent event) { - //TODO: implement here any custom behavior on application start up - try { - client = arrowheadService.connectMQTTBroker(this, brokerAddress, brokerPort, brokerUsername, brokerPassword, systemName); - - //Checking the availability of necessary core systems add MQTT support here as well? - //checkCoreSystemReachability(CoreSystem.SERVICEREGISTRY); add MQTT support here as well? - //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); add MQTT support here as well? - client.subscribe("ah/pubsub/messages"); - } catch (Exception e) { - client = null; - throw new ArrowheadException("Could not connect to MQTT broker!\n" + e.toString()); - } + //TODO: implement here any custom behavior on application start up + try { + client = arrowheadService.connectMQTTBroker(this, brokerAddress, brokerPort, brokerUsername, brokerPassword, systemName); + + //Checking the availability of necessary core systems add MQTT support here as well? + //checkCoreSystemReachability(CoreSystem.SERVICEREGISTRY); add MQTT support here as well? + //checkCoreSystemReachability(CoreSystem.AUTHORIZATION); add MQTT support here as well? + client.subscribe("ah/pubsub/messages"); + } catch (Exception e) { + client = null; + throw new ArrowheadException("Could not connect to MQTT broker!\n" + e.toString()); + } } //------------------------------------------------------------------------------------------------- @Override public void customDestroy() { - //TODO: implement here any custom behavior on application shut down - if (client != null) { - try { - arrowheadService.disconnectMQTTBroker(client); - arrowheadService.closeMQTTBroker(client); - } catch(Exception e) { - } - - client = null; + //TODO: implement here any custom behavior on application shut down + if (client != null) { + try { + arrowheadService.disconnectMQTTBroker(client); + arrowheadService.closeMQTTBroker(client); + } catch(Exception e) { + } + client = null; + } } - } //================================================================================================= // MQTT callback methods - @Override - public void connectionLost(Throwable t) { - System.out.println("connectionLost: " + t.toString()); + @Override + public void connectionLost(Throwable t) { - //TODO: implement here any custom behavior on broker disconnect, typically a reconnect after a short timeout - } + //TODO: implement here any custom behavior on broker disconnect, typically a reconnect after a short timeout + } - @Override - public void messageArrived(String topic, MqttMessage message) throws Exception { - System.out.println("topic - " + topic + ": " + new String(message.getPayload())); + @Override + public void messageArrived(String topic, MqttMessage message) throws Exception { - //TODO: implement here any custom behavior on incoming messages, such as filtering in topics etc - } + //TODO: implement here any custom behavior on incoming messages, such as filtering in topics etc + } - @Override - public void deliveryComplete(IMqttDeliveryToken token) { - } + @Override + public void deliveryComplete(IMqttDeliveryToken token) { + } //================================================================================================= // assistant methods From 73100defc0a9bfa59437a15607faefe844137702 Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Mon, 29 Nov 2021 09:19:02 +0100 Subject: [PATCH 09/10] updated meta description --- ...itional-spring-configuration-metadata.json | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/application-skeleton-mqtt/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/application-skeleton-mqtt/src/main/resources/META-INF/additional-spring-configuration-metadata.json index d1479ba..97b8897 100644 --- a/application-skeleton-mqtt/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/application-skeleton-mqtt/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -1,28 +1,28 @@ {"properties": [ { - "name": "client_system_name", + "name": "application_system_name", "type": "java.lang.String", - "description": "A description for 'client_system_name'" + "description": "A description for 'application_system_name'" }, { - "name": "broker_address", + "name": "broker.address", "type": "java.lang.String", - "description": "A description for 'broker_address'" + "description": "A description for 'broker.address'" }, { - "name": "broker_port", - "type": "java.lang.String", - "description": "A description for 'broker_port'" + "name": "broker.port", + "type": "java.lang.Integer", + "description": "A description for 'broker.port'" }, { - "name": "broker_username", + "name": "broker.username", "type": "java.lang.String", - "description": "A description for 'broker_username'" + "description": "A description for 'broker.username'" }, { - "name": "broker_password", + "name": "broker.password", "type": "java.lang.String", - "description": "A description for 'broker_password'" + "description": "A description for 'broker.password'" }, { "name": "container.max_keep_alive_requests", From e7067884956b86f1f7322809204384483af5942b Mon Sep 17 00:00:00 2001 From: Jens Eliasson Date: Mon, 29 Nov 2021 11:36:35 +0100 Subject: [PATCH 10/10] removed unused imports --- .../skeleton/pubsub/PubSubApplicationInitListener.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java index 8b9f701..f2b257b 100644 --- a/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java +++ b/application-skeleton-mqtt/src/main/java/eu/arrowhead/application/skeleton/pubsub/PubSubApplicationInitListener.java @@ -1,13 +1,5 @@ package eu.arrowhead.application.skeleton.pubsub; -import java.io.IOException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.cert.CertificateException; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired;