Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport to "maven artifacts" and result of "goJF" #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion OCPP-J/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependencies>
<dependency>
<groupId>eu.chargetime.ocpp</groupId>
<artifactId>common</artifactId>
<artifactId>ocpp-common</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -127,6 +127,7 @@
</execution>
</executions>
</plugin>
<!-- disable
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand All @@ -141,6 +142,7 @@
</execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down
39 changes: 21 additions & 18 deletions OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ public WebSocketListener(ISessionFactory sessionFactory, Draft... drafts) {
public void open(String hostname, int port, ListenerEvents handler) {
server =
new WebSocketServer(
new InetSocketAddress(hostname, port),
configuration.getParameter(JSONConfiguration.WEBSOCKET_WORKER_COUNT, DEFAULT_WEBSOCKET_WORKER_COUNT),
drafts) {
new InetSocketAddress(hostname, port),
configuration.getParameter(
JSONConfiguration.WEBSOCKET_WORKER_COUNT, DEFAULT_WEBSOCKET_WORKER_COUNT),
drafts) {
@Override
public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
logger.debug(
Expand Down Expand Up @@ -115,9 +116,9 @@ public void relay(String message) {
String proxiedAddress = clientHandshake.getFieldValue(HTTP_HEADER_PROXIED_ADDRESS);

logger.debug(
"New web-socket connection opened from address: {} proxied for: {}",
webSocket.getRemoteSocketAddress(),
proxiedAddress);
"New web-socket connection opened from address: {} proxied for: {}",
webSocket.getRemoteSocketAddress(),
proxiedAddress);

SessionInformation information =
new SessionInformation.Builder()
Expand All @@ -131,13 +132,14 @@ public void relay(String message) {
}

@Override
public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(WebSocket webSocket, Draft draft,
ClientHandshake clientHandshake) throws InvalidDataException {
public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
WebSocket webSocket, Draft draft, ClientHandshake clientHandshake)
throws InvalidDataException {
SessionInformation information =
new SessionInformation.Builder()
.Identifier(clientHandshake.getResourceDescriptor())
.InternetAddress(webSocket.getRemoteSocketAddress())
.build();
new SessionInformation.Builder()
.Identifier(clientHandshake.getResourceDescriptor())
.InternetAddress(webSocket.getRemoteSocketAddress())
.build();

String username = null;
byte[] password = null;
Expand All @@ -150,25 +152,26 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(WebSocket web
// split credentials on username and password
for (int i = 0; i < credDecoded.length; i++) {
if (credDecoded[i] == ':') {
username = new String(Arrays.copyOfRange(credDecoded, 0, i), StandardCharsets.UTF_8);
username =
new String(Arrays.copyOfRange(credDecoded, 0, i), StandardCharsets.UTF_8);
if (i + 1 < credDecoded.length) {
password = Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length);
}
break;
}
}
}
if (password == null || password.length < OCPPJ_CP_MIN_PASSWORD_LENGTH || password.length > OCPPJ_CP_MAX_PASSWORD_LENGTH)
if (password == null
|| password.length < OCPPJ_CP_MIN_PASSWORD_LENGTH
|| password.length > OCPPJ_CP_MAX_PASSWORD_LENGTH)
throw new InvalidDataException(401, "Invalid password length");
}

try {
handler.authenticateSession(information, username, password);
}
catch (AuthenticationException e) {
} catch (AuthenticationException e) {
throw new InvalidDataException(e.getErrorCode(), e.getMessage());
}
catch (Exception e) {
} catch (Exception e) {
throw new InvalidDataException(401, e.getMessage());
}
return super.onWebsocketHandshakeReceivedAsServer(webSocket, draft, clientHandshake);
Expand Down
4 changes: 3 additions & 1 deletion ocpp-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>eu.chargetime.ocpp</groupId>
<artifactId>common</artifactId>
<artifactId>ocpp-common</artifactId>
<version>1.0.1</version>

<name>Java-OCA-OCPP common</name>
Expand Down Expand Up @@ -128,6 +128,7 @@
</execution>
</executions>
</plugin>
<!-- disable
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand All @@ -142,6 +143,7 @@
</execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.model.SessionInformation;

public interface ListenerEvents {
void authenticateSession(SessionInformation information, String username, byte[] password) throws AuthenticationException;
void authenticateSession(SessionInformation information, String username, byte[] password)
throws AuthenticationException;

void newSession(ISession session, SessionInformation information);
}
133 changes: 68 additions & 65 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.feature.Feature;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.SessionInformation;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

import eu.chargetime.ocpp.model.SessionInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -83,76 +82,80 @@ public void open(String hostname, int port, ServerEvents serverEvents) {
new ListenerEvents() {

@Override
public void authenticateSession(SessionInformation information, String username, byte[] password) throws AuthenticationException {
public void authenticateSession(
SessionInformation information, String username, byte[] password)
throws AuthenticationException {
serverEvents.authenticateSession(information, username, password);
}

@Override
public void newSession(ISession session, SessionInformation information) {
session.accept(
new SessionEvents() {
@Override
public void handleConfirmation(String uniqueId, Confirmation confirmation) {

Optional<CompletableFuture<Confirmation>> promiseOptional =
promiseRepository.getPromise(uniqueId);
if (promiseOptional.isPresent()) {
promiseOptional.get().complete(confirmation);
promiseRepository.removePromise(uniqueId);
} else {
logger.debug("Promise not found for confirmation {}", confirmation);
}
}

@Override
public Confirmation handleRequest(Request request)
throws UnsupportedFeatureException {
Optional<Feature> featureOptional = featureRepository.findFeature(request);
if (featureOptional.isPresent()) {
Optional<UUID> sessionIdOptional = getSessionID(session);
if (sessionIdOptional.isPresent()) {
return featureOptional.get().handleRequest(sessionIdOptional.get(), request);
} else {
logger.error(
"Unable to handle request ({}), the active session was not found.",
request);
throw new IllegalStateException("Active session not found");
}
} else {
throw new UnsupportedFeatureException();
}
new SessionEvents() {
@Override
public void handleConfirmation(String uniqueId, Confirmation confirmation) {

Optional<CompletableFuture<Confirmation>> promiseOptional =
promiseRepository.getPromise(uniqueId);
if (promiseOptional.isPresent()) {
promiseOptional.get().complete(confirmation);
promiseRepository.removePromise(uniqueId);
} else {
logger.debug("Promise not found for confirmation {}", confirmation);
}
}

@Override
public Confirmation handleRequest(Request request)
throws UnsupportedFeatureException {
Optional<Feature> featureOptional = featureRepository.findFeature(request);
if (featureOptional.isPresent()) {
Optional<UUID> sessionIdOptional = getSessionID(session);
if (sessionIdOptional.isPresent()) {
return featureOptional
.get()
.handleRequest(sessionIdOptional.get(), request);
} else {
logger.error(
"Unable to handle request ({}), the active session was not found.",
request);
throw new IllegalStateException("Active session not found");
}

@Override
public void handleError(
String uniqueId, String errorCode, String errorDescription, Object payload) {
Optional<CompletableFuture<Confirmation>> promiseOptional =
promiseRepository.getPromise(uniqueId);
if (promiseOptional.isPresent()) {
promiseOptional
.get()
.completeExceptionally(
new CallErrorException(errorCode, errorDescription, payload));
promiseRepository.removePromise(uniqueId);
} else {
logger.debug("Promise not found for error {}", errorDescription);
}
}

@Override
public void handleConnectionClosed() {
Optional<UUID> sessionIdOptional = getSessionID(session);
if (sessionIdOptional.isPresent()) {
serverEvents.lostSession(sessionIdOptional.get());
sessions.remove(sessionIdOptional.get());
} else {
logger.warn("Active session not found");
}
}

@Override
public void handleConnectionOpened() {}
});
} else {
throw new UnsupportedFeatureException();
}
}

@Override
public void handleError(
String uniqueId, String errorCode, String errorDescription, Object payload) {
Optional<CompletableFuture<Confirmation>> promiseOptional =
promiseRepository.getPromise(uniqueId);
if (promiseOptional.isPresent()) {
promiseOptional
.get()
.completeExceptionally(
new CallErrorException(errorCode, errorDescription, payload));
promiseRepository.removePromise(uniqueId);
} else {
logger.debug("Promise not found for error {}", errorDescription);
}
}

@Override
public void handleConnectionClosed() {
Optional<UUID> sessionIdOptional = getSessionID(session);
if (sessionIdOptional.isPresent()) {
serverEvents.lostSession(sessionIdOptional.get());
sessions.remove(sessionIdOptional.get());
} else {
logger.warn("Active session not found");
}
}

@Override
public void handleConnectionOpened() {}
});

sessions.put(session.getSessionId(), session);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.UUID;

public interface ServerEvents {
default void authenticateSession(SessionInformation information, String username, byte[] password) throws AuthenticationException {}
default void authenticateSession(SessionInformation information, String username, byte[] password)
throws AuthenticationException {}

void newSession(UUID sessionIndex, SessionInformation information);

Expand Down
8 changes: 4 additions & 4 deletions ocpp-v1_6-example/json-client-implementation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<name>json-client-implementation</name>
<description>Demo project for a json client application, written in form of tests</description>
<properties>
<java.version>11</java.version>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -45,13 +45,13 @@
</dependency>
<dependency>
<groupId>eu.chargetime.ocpp</groupId>
<artifactId>v1_6</artifactId>
<version>1.0.1</version>
<artifactId>ocpp-v1_6</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<version>7.5</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
12 changes: 6 additions & 6 deletions ocpp-v1_6-example/json_server_example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>eu.chargetime.ocpp</groupId>
<artifactId>json-server-implementation </artifactId>
<artifactId>json-server-implementation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>json-server-implementation </name>
<description>Example Spring Application of a json server </description>
<description>Example Spring Application of a json server</description>
<properties>
<java.version>11</java.version>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -45,13 +45,13 @@
</dependency>
<dependency>
<groupId>eu.chargetime.ocpp</groupId>
<artifactId>v1_6</artifactId>
<version>1.0.1</version>
<artifactId>ocpp-v1_6</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<version>7.5</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Loading