Skip to content

Commit ab76007

Browse files
authored
Revert "Features/fix profile initialization (nulls and cross-over in FirmwareManagementProfiles)"
1 parent 37a922d commit ab76007

File tree

14 files changed

+114
-122
lines changed

14 files changed

+114
-122
lines changed

OCPP-J/src/main/java/eu/chargetime/ocpp/WebSocketListener.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ public WebSocketListener(ISessionFactory sessionFactory, Draft... drafts) {
8282
public void open(String hostname, int port, ListenerEvents handler) {
8383
server =
8484
new WebSocketServer(
85-
new InetSocketAddress(hostname, port),
86-
configuration.getParameter(
87-
JSONConfiguration.WEBSOCKET_WORKER_COUNT, DEFAULT_WEBSOCKET_WORKER_COUNT),
88-
drafts) {
85+
new InetSocketAddress(hostname, port),
86+
configuration.getParameter(JSONConfiguration.WEBSOCKET_WORKER_COUNT, DEFAULT_WEBSOCKET_WORKER_COUNT),
87+
drafts) {
8988
@Override
9089
public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
9190
logger.debug(
@@ -116,9 +115,9 @@ public void relay(String message) {
116115
String proxiedAddress = clientHandshake.getFieldValue(HTTP_HEADER_PROXIED_ADDRESS);
117116

118117
logger.debug(
119-
"New web-socket connection opened from address: {} proxied for: {}",
120-
webSocket.getRemoteSocketAddress(),
121-
proxiedAddress);
118+
"New web-socket connection opened from address: {} proxied for: {}",
119+
webSocket.getRemoteSocketAddress(),
120+
proxiedAddress);
122121

123122
SessionInformation information =
124123
new SessionInformation.Builder()
@@ -132,14 +131,13 @@ public void relay(String message) {
132131
}
133132

134133
@Override
135-
public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
136-
WebSocket webSocket, Draft draft, ClientHandshake clientHandshake)
137-
throws InvalidDataException {
134+
public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(WebSocket webSocket, Draft draft,
135+
ClientHandshake clientHandshake) throws InvalidDataException {
138136
SessionInformation information =
139-
new SessionInformation.Builder()
140-
.Identifier(clientHandshake.getResourceDescriptor())
141-
.InternetAddress(webSocket.getRemoteSocketAddress())
142-
.build();
137+
new SessionInformation.Builder()
138+
.Identifier(clientHandshake.getResourceDescriptor())
139+
.InternetAddress(webSocket.getRemoteSocketAddress())
140+
.build();
143141

144142
String username = null;
145143
byte[] password = null;
@@ -152,26 +150,25 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer(
152150
// split credentials on username and password
153151
for (int i = 0; i < credDecoded.length; i++) {
154152
if (credDecoded[i] == ':') {
155-
username =
156-
new String(Arrays.copyOfRange(credDecoded, 0, i), StandardCharsets.UTF_8);
153+
username = new String(Arrays.copyOfRange(credDecoded, 0, i), StandardCharsets.UTF_8);
157154
if (i + 1 < credDecoded.length) {
158155
password = Arrays.copyOfRange(credDecoded, i + 1, credDecoded.length);
159156
}
160157
break;
161158
}
162159
}
163160
}
164-
if (password == null
165-
|| password.length < OCPPJ_CP_MIN_PASSWORD_LENGTH
166-
|| password.length > OCPPJ_CP_MAX_PASSWORD_LENGTH)
161+
if (password == null || password.length < OCPPJ_CP_MIN_PASSWORD_LENGTH || password.length > OCPPJ_CP_MAX_PASSWORD_LENGTH)
167162
throw new InvalidDataException(401, "Invalid password length");
168163
}
169164

170165
try {
171166
handler.authenticateSession(information, username, password);
172-
} catch (AuthenticationException e) {
167+
}
168+
catch (AuthenticationException e) {
173169
throw new InvalidDataException(e.getErrorCode(), e.getMessage());
174-
} catch (Exception e) {
170+
}
171+
catch (Exception e) {
175172
throw new InvalidDataException(401, e.getMessage());
176173
}
177174
return super.onWebsocketHandshakeReceivedAsServer(webSocket, draft, clientHandshake);

ocpp-common/src/main/java/eu/chargetime/ocpp/ListenerEvents.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ of this software and associated documentation files (the "Software"), to deal
2828
import eu.chargetime.ocpp.model.SessionInformation;
2929

3030
public interface ListenerEvents {
31-
void authenticateSession(SessionInformation information, String username, byte[] password)
32-
throws AuthenticationException;
33-
31+
void authenticateSession(SessionInformation information, String username, byte[] password) throws AuthenticationException;
3432
void newSession(ISession session, SessionInformation information);
3533
}

ocpp-common/src/main/java/eu/chargetime/ocpp/Server.java

Lines changed: 65 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ of this software and associated documentation files (the "Software"), to deal
2828
import eu.chargetime.ocpp.feature.Feature;
2929
import eu.chargetime.ocpp.model.Confirmation;
3030
import eu.chargetime.ocpp.model.Request;
31-
import eu.chargetime.ocpp.model.SessionInformation;
3231
import java.util.Map;
3332
import java.util.Optional;
3433
import java.util.UUID;
3534
import java.util.concurrent.CompletableFuture;
3635
import java.util.concurrent.ConcurrentHashMap;
36+
37+
import eu.chargetime.ocpp.model.SessionInformation;
3738
import org.slf4j.Logger;
3839
import org.slf4j.LoggerFactory;
3940

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

8485
@Override
85-
public void authenticateSession(
86-
SessionInformation information, String username, byte[] password)
87-
throws AuthenticationException {
86+
public void authenticateSession(SessionInformation information, String username, byte[] password) throws AuthenticationException {
8887
serverEvents.authenticateSession(information, username, password);
8988
}
9089

9190
@Override
9291
public void newSession(ISession session, SessionInformation information) {
9392
session.accept(
94-
new SessionEvents() {
95-
@Override
96-
public void handleConfirmation(String uniqueId, Confirmation confirmation) {
97-
98-
Optional<CompletableFuture<Confirmation>> promiseOptional =
99-
promiseRepository.getPromise(uniqueId);
100-
if (promiseOptional.isPresent()) {
101-
promiseOptional.get().complete(confirmation);
102-
promiseRepository.removePromise(uniqueId);
103-
} else {
104-
logger.debug("Promise not found for confirmation {}", confirmation);
105-
}
106-
}
107-
108-
@Override
109-
public Confirmation handleRequest(Request request)
110-
throws UnsupportedFeatureException {
111-
Optional<Feature> featureOptional = featureRepository.findFeature(request);
112-
if (featureOptional.isPresent()) {
113-
Optional<UUID> sessionIdOptional = getSessionID(session);
114-
if (sessionIdOptional.isPresent()) {
115-
return featureOptional
116-
.get()
117-
.handleRequest(sessionIdOptional.get(), request);
118-
} else {
119-
logger.error(
120-
"Unable to handle request ({}), the active session was not found.",
121-
request);
122-
throw new IllegalStateException("Active session not found");
93+
new SessionEvents() {
94+
@Override
95+
public void handleConfirmation(String uniqueId, Confirmation confirmation) {
96+
97+
Optional<CompletableFuture<Confirmation>> promiseOptional =
98+
promiseRepository.getPromise(uniqueId);
99+
if (promiseOptional.isPresent()) {
100+
promiseOptional.get().complete(confirmation);
101+
promiseRepository.removePromise(uniqueId);
102+
} else {
103+
logger.debug("Promise not found for confirmation {}", confirmation);
104+
}
105+
}
106+
107+
@Override
108+
public Confirmation handleRequest(Request request)
109+
throws UnsupportedFeatureException {
110+
Optional<Feature> featureOptional = featureRepository.findFeature(request);
111+
if (featureOptional.isPresent()) {
112+
Optional<UUID> sessionIdOptional = getSessionID(session);
113+
if (sessionIdOptional.isPresent()) {
114+
return featureOptional.get().handleRequest(sessionIdOptional.get(), request);
115+
} else {
116+
logger.error(
117+
"Unable to handle request ({}), the active session was not found.",
118+
request);
119+
throw new IllegalStateException("Active session not found");
120+
}
121+
} else {
122+
throw new UnsupportedFeatureException();
123+
}
123124
}
124-
} else {
125-
throw new UnsupportedFeatureException();
126-
}
127-
}
128-
129-
@Override
130-
public void handleError(
131-
String uniqueId, String errorCode, String errorDescription, Object payload) {
132-
Optional<CompletableFuture<Confirmation>> promiseOptional =
133-
promiseRepository.getPromise(uniqueId);
134-
if (promiseOptional.isPresent()) {
135-
promiseOptional
136-
.get()
137-
.completeExceptionally(
138-
new CallErrorException(errorCode, errorDescription, payload));
139-
promiseRepository.removePromise(uniqueId);
140-
} else {
141-
logger.debug("Promise not found for error {}", errorDescription);
142-
}
143-
}
144-
145-
@Override
146-
public void handleConnectionClosed() {
147-
Optional<UUID> sessionIdOptional = getSessionID(session);
148-
if (sessionIdOptional.isPresent()) {
149-
serverEvents.lostSession(sessionIdOptional.get());
150-
sessions.remove(sessionIdOptional.get());
151-
} else {
152-
logger.warn("Active session not found");
153-
}
154-
}
155-
156-
@Override
157-
public void handleConnectionOpened() {}
158-
});
125+
126+
@Override
127+
public void handleError(
128+
String uniqueId, String errorCode, String errorDescription, Object payload) {
129+
Optional<CompletableFuture<Confirmation>> promiseOptional =
130+
promiseRepository.getPromise(uniqueId);
131+
if (promiseOptional.isPresent()) {
132+
promiseOptional
133+
.get()
134+
.completeExceptionally(
135+
new CallErrorException(errorCode, errorDescription, payload));
136+
promiseRepository.removePromise(uniqueId);
137+
} else {
138+
logger.debug("Promise not found for error {}", errorDescription);
139+
}
140+
}
141+
142+
@Override
143+
public void handleConnectionClosed() {
144+
Optional<UUID> sessionIdOptional = getSessionID(session);
145+
if (sessionIdOptional.isPresent()) {
146+
serverEvents.lostSession(sessionIdOptional.get());
147+
sessions.remove(sessionIdOptional.get());
148+
} else {
149+
logger.warn("Active session not found");
150+
}
151+
}
152+
153+
@Override
154+
public void handleConnectionOpened() {}
155+
});
159156

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

ocpp-common/src/main/java/eu/chargetime/ocpp/ServerEvents.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
2929
import java.util.UUID;
3030

3131
public interface ServerEvents {
32-
default void authenticateSession(SessionInformation information, String username, byte[] password)
33-
throws AuthenticationException {}
32+
default void authenticateSession(SessionInformation information, String username, byte[] password) throws AuthenticationException {}
3433

3534
void newSession(UUID sessionIndex, SessionInformation information);
3635

ocpp-common/src/main/java/eu/chargetime/ocpp/feature/ProfileFeature.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ public abstract class ProfileFeature implements Feature {
4040
* @param ownerProfile the {@link Profile} that owns the function.
4141
*/
4242
public ProfileFeature(Profile ownerProfile) {
43-
if (ownerProfile == null) {
44-
throw new IllegalArgumentException("need non-null profile");
45-
}
4643
profile = ownerProfile;
4744
}
4845

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientCoreProfile.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ public ClientCoreProfile(ClientCoreEventHandler handler) {
5555
features = new ArrayList<>();
5656
eventHandler = handler;
5757

58-
features.add(new AuthorizeFeature(this));
59-
features.add(new BootNotificationFeature(this));
58+
features.add(new AuthorizeFeature(null));
59+
features.add(new BootNotificationFeature(null));
6060
features.add(new ChangeAvailabilityFeature(this));
6161
features.add(new ChangeConfigurationFeature(this));
6262
features.add(new ClearCacheFeature(this));
6363
features.add(new DataTransferFeature(this));
6464
features.add(new GetConfigurationFeature(this));
65-
features.add(new HeartbeatFeature(this));
66-
features.add(new MeterValuesFeature(this));
65+
features.add(new HeartbeatFeature(null));
66+
features.add(new MeterValuesFeature(null));
6767
features.add(new RemoteStartTransactionFeature(this));
6868
features.add(new RemoteStopTransactionFeature(this));
6969
features.add(new ResetFeature(this));
70-
features.add(new StartTransactionFeature(this));
71-
features.add(new StatusNotificationFeature(this));
72-
features.add(new StopTransactionFeature(this));
70+
features.add(new StartTransactionFeature(null));
71+
features.add(new StatusNotificationFeature(null));
72+
features.add(new StopTransactionFeature(null));
7373
features.add(new UnlockConnectorFeature(this));
7474
}
7575

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ClientFirmwareManagementProfile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class ClientFirmwareManagementProfile implements Profile {
4141
public ClientFirmwareManagementProfile(ClientFirmwareManagementEventHandler eventHandler) {
4242
this.eventHandler = eventHandler;
4343
features = new HashSet<>();
44+
features.add(new DiagnosticsStatusNotificationFeature(null));
45+
features.add(new FirmwareStatusNotificationFeature(null));
4446
features.add(new GetDiagnosticsFeature(this));
4547
features.add(new UpdateFirmwareFeature(this));
4648
}

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerCoreProfile.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ public ServerCoreProfile(ServerCoreEventHandler handler) {
4444
features = new HashSet<>();
4545
features.add(new AuthorizeFeature(this));
4646
features.add(new BootNotificationFeature(this));
47-
features.add(new ChangeAvailabilityFeature(this));
48-
features.add(new ChangeConfigurationFeature(this));
49-
features.add(new ClearCacheFeature(this));
47+
features.add(new ChangeAvailabilityFeature(null));
48+
features.add(new ChangeConfigurationFeature(null));
49+
features.add(new ClearCacheFeature(null));
5050
features.add(new DataTransferFeature(this));
51-
features.add(new GetConfigurationFeature(this));
51+
features.add(new GetConfigurationFeature(null));
5252
features.add(new HeartbeatFeature(this));
5353
features.add(new MeterValuesFeature(this));
54-
features.add(new RemoteStartTransactionFeature(this));
55-
features.add(new RemoteStopTransactionFeature(this));
56-
features.add(new ResetFeature(this));
54+
features.add(new RemoteStartTransactionFeature(null));
55+
features.add(new RemoteStopTransactionFeature(null));
56+
features.add(new ResetFeature(null));
5757
features.add(new StartTransactionFeature(this));
5858
features.add(new StatusNotificationFeature(this));
5959
features.add(new StopTransactionFeature(this));
60-
features.add(new UnlockConnectorFeature(this));
60+
features.add(new UnlockConnectorFeature(null));
6161
}
6262

6363
@Override

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerFirmwareManagementProfile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public class ServerFirmwareManagementProfile implements Profile {
4545
public ServerFirmwareManagementProfile(ServerFirmwareManagementEventHandler eventHandler) {
4646
this.eventHandler = eventHandler;
4747
features = new HashSet<>();
48+
features.add(new GetDiagnosticsFeature(null));
4849
features.add(new DiagnosticsStatusNotificationFeature(this));
4950
features.add(new FirmwareStatusNotificationFeature(this));
51+
features.add(new UpdateFirmwareFeature(null));
5052
}
5153

5254
@Override

ocpp-v1_6/src/main/java/eu/chargetime/ocpp/feature/profile/ServerLocalAuthListProfile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class ServerLocalAuthListProfile implements Profile {
4242

4343
public ServerLocalAuthListProfile() {
4444
featureList = new HashSet<>();
45-
featureList.add(new GetLocalListVersionFeature(this));
46-
featureList.add(new SendLocalListFeature(this));
45+
featureList.add(new GetLocalListVersionFeature(null));
46+
featureList.add(new SendLocalListFeature(null));
4747
}
4848

4949
@Override

0 commit comments

Comments
 (0)