-
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.
- Loading branch information
0 parents
commit a0dee75
Showing
5 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
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,10 @@ | ||
.DS_Store | ||
.idea | ||
.idea/workspace.xml | ||
csv/ | ||
/target/ | ||
.classpath | ||
.project | ||
.settings | ||
.gradle | ||
*.iml |
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,5 @@ | ||
# OpenNess Demo Consumer | ||
|
||
Demo Consumer Application for the OpenNess platform using the Java OpenNess Connector | ||
implementing a demo service interested to received traffic evente and interact with the demo | ||
TIS (Traffic Information System). |
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,113 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>it.unimore.dipi.openness.consumer</groupId> | ||
<artifactId>openness-consumer-demo</artifactId> | ||
<version>0.0.1</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<slf4j.version>1.7.26</slf4j.version> | ||
<jackson.version>2.9.8</jackson.version> | ||
<logback.version>1.2.3</logback.version> | ||
<openness.connector.version>0.0.3</openness.connector.version> | ||
<junit.version>4.13</junit.version> | ||
<apache-commons.version>3.9</apache-commons.version> | ||
<apache.httpclient>4.5.12</apache.httpclient> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>it.unimore.dipi</groupId> | ||
<artifactId>openness-connector</artifactId> | ||
<version>${openness.connector.version}</version> | ||
<type>jar</type> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>${apache-commons.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Jackson --> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>${jackson.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-yaml</artifactId> | ||
<version>${jackson.version}</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-codec</groupId> | ||
<artifactId>commons-codec</artifactId> | ||
<version>1.10</version> | ||
</dependency> | ||
|
||
<!-- CHANGE JAVA 1.9 --> | ||
<dependency> | ||
<groupId>javax.xml.bind</groupId> | ||
<artifactId>jaxb-api</artifactId> | ||
<version>2.3.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.xml.bind</groupId> | ||
<artifactId>jaxb-core</artifactId> | ||
<version>2.3.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.xml.bind</groupId> | ||
<artifactId>jaxb-impl</artifactId> | ||
<version>2.3.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.activation</groupId> | ||
<artifactId>activation</artifactId> | ||
<version>1.1.1</version> | ||
</dependency> | ||
<!-- CHANGE JAVA 1.9 --> | ||
|
||
<dependency> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>${apache.httpclient}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
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,32 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd' | ||
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> | ||
<profiles> | ||
<profile> | ||
<repositories> | ||
<repository> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
<id>bintray-smarianimore-openness-connector</id> | ||
<name>bintray</name> | ||
<url>https://dl.bintray.com/smarianimore/openness-connector</url> | ||
</repository> | ||
</repositories> | ||
<pluginRepositories> | ||
<pluginRepository> | ||
<snapshots> | ||
<enabled>false</enabled> | ||
</snapshots> | ||
<id>bintray-smarianimore-openness-connector</id> | ||
<name>bintray-plugins</name> | ||
<url>https://dl.bintray.com/smarianimore/openness-connector</url> | ||
</pluginRepository> | ||
</pluginRepositories> | ||
<id>bintray</id> | ||
</profile> | ||
</profiles> | ||
<activeProfiles> | ||
<activeProfile>bintray</activeProfile> | ||
</activeProfiles> | ||
</settings> |
84 changes: 84 additions & 0 deletions
84
src/main/java/it/unimore/dipi/openness/consumer/SimpleConsumerTester.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,84 @@ | ||
package it.unimore.dipi.openness.consumer; | ||
|
||
import it.unimore.dipi.iot.openness.config.AuthorizedApplicationConfiguration; | ||
import it.unimore.dipi.iot.openness.connector.EdgeApplicationAuthenticator; | ||
import it.unimore.dipi.iot.openness.connector.EdgeApplicationConnector; | ||
import it.unimore.dipi.iot.openness.dto.service.EdgeApplicationServiceDescriptor; | ||
import it.unimore.dipi.iot.openness.dto.service.EdgeApplicationServiceList; | ||
import it.unimore.dipi.iot.openness.exception.EdgeApplicationAuthenticatorException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* @author Marco Picone, Ph.D. - [email protected] | ||
* @project openness-consumer-demo | ||
* @created 02/11/2020 - 15:41 | ||
*/ | ||
public class SimpleConsumerTester { | ||
|
||
public static final Logger logger = LoggerFactory.getLogger(SimpleConsumerTester.class); | ||
|
||
private static final String OPENNESS_CONTROLLER_BASE_AUTH_URL = "http://eaa.openness:7080/"; | ||
|
||
private static final String OPENNESS_CONTROLLER_BASE_APP_URL = "https://eaa.openness:7443/"; | ||
|
||
private static final String OPENNESS_CONTROLLER_BASE_APP_WS_URL = "wss://eaa.openness:7443/"; | ||
|
||
private static final String APPLICATION_ID = "opennessConsumerDemo"; | ||
|
||
private static final String NAME_SPACE = "consumerdemo"; | ||
|
||
private static final String ORG_NAME = "DIPIUniMore"; | ||
|
||
public static void main(String[] args) { | ||
|
||
try { | ||
|
||
logger.info("Starting Simple Openness Consumer Tester ..."); | ||
|
||
AuthorizedApplicationConfiguration authorizedApplicationConfiguration = handleAuth(); | ||
|
||
logger.info("Application Correctly Authenticated ! AppId: {}", authorizedApplicationConfiguration.getApplicationId()); | ||
|
||
EdgeApplicationConnector edgeApplicationConnector = new EdgeApplicationConnector(OPENNESS_CONTROLLER_BASE_APP_URL, | ||
authorizedApplicationConfiguration, | ||
OPENNESS_CONTROLLER_BASE_APP_WS_URL); | ||
|
||
EdgeApplicationServiceList availableServices = edgeApplicationConnector.getAvailableServices(); | ||
|
||
if(availableServices != null && availableServices.getServiceList() != null){ | ||
for(EdgeApplicationServiceDescriptor edgeApplicationServiceDescriptor : availableServices.getServiceList()){ | ||
logger.info("Service URN: {} -> {}", edgeApplicationServiceDescriptor.getServiceUrn(), edgeApplicationServiceDescriptor); | ||
} | ||
} | ||
else | ||
logger.error("EdgeApplicationServiceList = NULL or ServiceList = NULL !"); | ||
|
||
}catch (Exception e){ | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
private static AuthorizedApplicationConfiguration handleAuth() throws EdgeApplicationAuthenticatorException { | ||
|
||
final AuthorizedApplicationConfiguration authorizedApplicationConfiguration; | ||
|
||
final EdgeApplicationAuthenticator edgeApplicationAuthenticator = new EdgeApplicationAuthenticator(OPENNESS_CONTROLLER_BASE_AUTH_URL); | ||
|
||
final Optional<AuthorizedApplicationConfiguration> storedConfiguration = edgeApplicationAuthenticator.loadExistingAuthorizedApplicationConfiguration(APPLICATION_ID, ORG_NAME); | ||
|
||
if(storedConfiguration.isPresent()) { | ||
logger.info("AuthorizedApplicationConfiguration Loaded Correctly !"); | ||
authorizedApplicationConfiguration = storedConfiguration.get(); | ||
} else { | ||
logger.info("AuthorizedApplicationConfiguration Not Available ! Authenticating the app ..."); | ||
authorizedApplicationConfiguration = edgeApplicationAuthenticator.authenticateApplication(NAME_SPACE, APPLICATION_ID, ORG_NAME); | ||
} | ||
|
||
return authorizedApplicationConfiguration; | ||
} | ||
|
||
} |