Skip to content

Commit

Permalink
removed hard-code urls
Browse files Browse the repository at this point in the history
  • Loading branch information
smarianimore committed Nov 12, 2020
1 parent 7b17317 commit 9424530
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM adoptopenjdk/maven-openjdk11

ENV MAVEN_OPTS -Xms64m -Xmx128m

RUN mkdir -p /usr/local/src/mvnapp
WORKDIR /usr/local/src/mvnapp
ADD . /usr/local/src/mvnapp

RUN mvn --settings settings.xml -Dmaven.test.skip=true clean install dependency:copy-dependencies

WORKDIR /usr/local/src/mvnapp
RUN chmod +x run.sh


CMD ./run.sh it.unimore.dipi.openness.consumer.SimpleConsumerTester

10 changes: 10 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Build Classpath
export CLASSPATH="./target/classes"
for file in `ls target/*.jar` ; do export CLASSPATH=$CLASSPATH':'./target/$file; done
for file in `ls target/dependency` ; do export CLASSPATH=$CLASSPATH':'./target/dependency/$file; done

# Pass all arguments to java run
java -classpath $CLASSPATH "$@"

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import it.unimore.dipi.iot.openness.exception.EdgeApplicationConnectorException;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.util.Optional;
import java.util.Properties;

/**
* @author Marco Picone, Ph.D. - [email protected]
Expand All @@ -26,12 +28,6 @@ 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";
Expand All @@ -42,16 +38,24 @@ public static void main(String[] args) {

try {

final String rootPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
final String appConfigPath = rootPath + "urls.properties";
final Properties appProps = new Properties();
appProps.load(new FileInputStream(appConfigPath));
final String authUrl = appProps.getProperty("myAuth");
final String apiUrl = appProps.getProperty("myApi");
final String wsUrl = appProps.getProperty("myWs");

logger.info("Starting Simple Openness Consumer Tester ...");

AuthorizedApplicationConfiguration authorizedApplicationConfiguration = handleAuth();
AuthorizedApplicationConfiguration authorizedApplicationConfiguration = handleAuth(authUrl);

logger.info("Application Correctly Authenticated ! AppId: {}", authorizedApplicationConfiguration.getApplicationId());

EdgeApplicationConnector edgeApplicationConnector = new EdgeApplicationConnector(
OPENNESS_CONTROLLER_BASE_APP_URL,
apiUrl,
authorizedApplicationConfiguration,
OPENNESS_CONTROLLER_BASE_APP_WS_URL);
wsUrl);

//Activate Notification Channel
ConsumerNotificationsHandler myNotificationsHandler = new ConsumerNotificationsHandler();
Expand Down Expand Up @@ -103,11 +107,11 @@ private static void getEvents(final String endpoint) throws EdgeApplicationConne
}
}

private static AuthorizedApplicationConfiguration handleAuth() throws EdgeApplicationAuthenticatorException {
private static AuthorizedApplicationConfiguration handleAuth(final String authUrl) throws EdgeApplicationAuthenticatorException {

final AuthorizedApplicationConfiguration authorizedApplicationConfiguration;

final EdgeApplicationAuthenticator edgeApplicationAuthenticator = new EdgeApplicationAuthenticator(OPENNESS_CONTROLLER_BASE_AUTH_URL);
final EdgeApplicationAuthenticator edgeApplicationAuthenticator = new EdgeApplicationAuthenticator(authUrl);

final Optional<AuthorizedApplicationConfiguration> storedConfiguration = edgeApplicationAuthenticator.loadExistingAuthorizedApplicationConfiguration(APPLICATION_ID, ORG_NAME);

Expand Down
3 changes: 3 additions & 0 deletions urls.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
myAuth=http://eaa.openness:7080/
myApi=https://eaa.openness:7443/
myWs=wss://eaa.openness:7443/

0 comments on commit 9424530

Please sign in to comment.