diff --git a/OCPP-J/pom.xml b/OCPP-J/pom.xml index f3d0e848a..9b979debf 100644 --- a/OCPP-J/pom.xml +++ b/OCPP-J/pom.xml @@ -49,7 +49,7 @@ eu.chargetime.ocpp - common + ocpp-common 1.0.1 @@ -127,6 +127,7 @@ + org.sonatype.plugins nexus-staging-maven-plugin diff --git a/OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java b/OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java index 588b645a3..341abd52b 100644 --- a/OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java +++ b/OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java @@ -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( @@ -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() @@ -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; @@ -150,7 +152,8 @@ 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); } @@ -158,17 +161,17 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(WebSocket web } } } - 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); diff --git a/ocpp-common/pom.xml b/ocpp-common/pom.xml index 01bfaee62..5628cf35b 100644 --- a/ocpp-common/pom.xml +++ b/ocpp-common/pom.xml @@ -5,7 +5,7 @@ 4.0.0 eu.chargetime.ocpp - common + ocpp-common 1.0.1 Java-OCA-OCPP common @@ -128,6 +128,7 @@ + org.sonatype.plugins nexus-staging-maven-plugin diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/ListenerEvents.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/ListenerEvents.java index 81eb7c01a..3e8be78d0 100644 --- a/ocpp-common/src/main/java/eu/chargetime/ocpp/ListenerEvents.java +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/ListenerEvents.java @@ -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); } diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java index 1e4f60cb8..78071eb4a 100644 --- a/ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java @@ -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; @@ -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> 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 featureOptional = featureRepository.findFeature(request); - if (featureOptional.isPresent()) { - Optional 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> 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 featureOptional = featureRepository.findFeature(request); + if (featureOptional.isPresent()) { + Optional 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> 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 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> 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 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); diff --git a/ocpp-common/src/main/java/eu/chargetime/ocpp/ServerEvents.java b/ocpp-common/src/main/java/eu/chargetime/ocpp/ServerEvents.java index 4d8a5d0b4..7e4168f2d 100644 --- a/ocpp-common/src/main/java/eu/chargetime/ocpp/ServerEvents.java +++ b/ocpp-common/src/main/java/eu/chargetime/ocpp/ServerEvents.java @@ -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); diff --git a/ocpp-v1_6-example/json-client-implementation/pom.xml b/ocpp-v1_6-example/json-client-implementation/pom.xml index b73e036cd..eafe61cb0 100644 --- a/ocpp-v1_6-example/json-client-implementation/pom.xml +++ b/ocpp-v1_6-example/json-client-implementation/pom.xml @@ -14,7 +14,7 @@ json-client-implementation Demo project for a json client application, written in form of tests - 11 + 8 @@ -45,13 +45,13 @@ eu.chargetime.ocpp - v1_6 - 1.0.1 + ocpp-v1_6 + 1.0.2 org.testng testng - RELEASE + 7.5 test diff --git a/ocpp-v1_6-example/json_server_example/pom.xml b/ocpp-v1_6-example/json_server_example/pom.xml index e06aee797..bd7186c07 100644 --- a/ocpp-v1_6-example/json_server_example/pom.xml +++ b/ocpp-v1_6-example/json_server_example/pom.xml @@ -9,12 +9,12 @@ eu.chargetime.ocpp - json-server-implementation + json-server-implementation 0.0.1-SNAPSHOT json-server-implementation - Example Spring Application of a json server + Example Spring Application of a json server - 11 + 8 @@ -45,13 +45,13 @@ eu.chargetime.ocpp - v1_6 - 1.0.1 + ocpp-v1_6 + 1.0.2 org.testng testng - RELEASE + 7.5 test diff --git a/ocpp-v1_6-test/pom.xml b/ocpp-v1_6-test/pom.xml index 38137f4e1..3ffb7ea47 100644 --- a/ocpp-v1_6-test/pom.xml +++ b/ocpp-v1_6-test/pom.xml @@ -5,7 +5,7 @@ 4.0.0 eu.chargetime.ocpp - v1_6-test + ocpp-v1_6-test 1.0.2 Java-OCA-OCPP v1.6 - Integration test @@ -48,12 +48,12 @@ eu.chargetime.ocpp - common + ocpp-common 1.0.1 eu.chargetime.ocpp - v1_6 + ocpp-v1_6 1.0.2 @@ -99,7 +99,7 @@ org.codehaus.gmavenplus gmavenplus-plugin - 1.6 + 1.13.1 diff --git a/ocpp-v1_6/pom.xml b/ocpp-v1_6/pom.xml index 950dd1c94..4c775e691 100644 --- a/ocpp-v1_6/pom.xml +++ b/ocpp-v1_6/pom.xml @@ -5,7 +5,7 @@ 4.0.0 eu.chargetime.ocpp - v1_6 + ocpp-v1_6 1.0.2 jar @@ -49,7 +49,7 @@ eu.chargetime.ocpp - common + ocpp-common 1.0.1 @@ -126,6 +126,7 @@ + org.sonatype.plugins nexus-staging-maven-plugin diff --git a/ocpp-v2_0-test/pom.xml b/ocpp-v2_0-test/pom.xml index 9c613b670..fad4d5d8b 100644 --- a/ocpp-v2_0-test/pom.xml +++ b/ocpp-v2_0-test/pom.xml @@ -5,7 +5,7 @@ 4.0.0 eu.chargetime.ocpp - v2_0-test + ocpp-v2_0-test 1.0.2 jar @@ -49,12 +49,12 @@ eu.chargetime.ocpp - common + ocpp-common 1.0.1 eu.chargetime.ocpp - v2_0 + ocpp-v2_0 1.0.2 @@ -100,7 +100,7 @@ org.codehaus.gmavenplus gmavenplus-plugin - 1.6 + 1.13.1 diff --git a/ocpp-v2_0/pom.xml b/ocpp-v2_0/pom.xml index c5f2ec545..9290952ab 100644 --- a/ocpp-v2_0/pom.xml +++ b/ocpp-v2_0/pom.xml @@ -5,7 +5,7 @@ 4.0.0 eu.chargetime.ocpp - v2_0 + ocpp-v2_0 1.0.2 jar @@ -49,7 +49,7 @@ eu.chargetime.ocpp - common + ocpp-common 1.0.1 diff --git a/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/features/basic/StatusNotificationFeature.java b/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/features/basic/StatusNotificationFeature.java index 478ca7ea1..68321d83a 100644 --- a/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/features/basic/StatusNotificationFeature.java +++ b/ocpp-v2_0/src/main/java/eu/chargetime/ocpp/features/basic/StatusNotificationFeature.java @@ -43,8 +43,8 @@ public StatusNotificationFeature(IServerStatusNotificationRequestHandler handler @Override public Confirmation handleRequest(UUID sessionIndex, Request request) { - return handler.handleStatusNotificationRequest(sessionIndex, - (StatusNotificationRequest) request); + return handler.handleStatusNotificationRequest( + sessionIndex, (StatusNotificationRequest) request); } @Override diff --git a/pom.xml b/pom.xml index 5930bd322..41f132e98 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 eu.chargetime.ocpp - all + parent 1.0 pom @@ -40,6 +40,10 @@ OCPP-J ocpp-v1_6 ocpp-v1_6-test + ocpp-v2_0 ocpp-v2_0-test