Skip to content

Commit fb2b115

Browse files
committed
Added action to response calls. This is needed for SOAP implementation.
Experimenting with a Web Service listener.
1 parent 13a1849 commit fb2b115

File tree

17 files changed

+128
-41
lines changed

17 files changed

+128
-41
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ public abstract class Communicator {
7070
* Create a call result envelope to transmit.
7171
*
7272
* @param uniqueId the id the receiver expects.
73+
* @param action action name of the feature.
7374
* @param payload packed payload.
7475
* @return a fully packed message ready to send.
7576
*/
76-
protected abstract Object makeCallResult(String uniqueId, Object payload);
77+
protected abstract Object makeCallResult(String uniqueId, String action, Object payload);
7778

7879
/**
7980
* Create a call envelope to transmit to the server.
@@ -172,9 +173,9 @@ public void sendCall(String uniqueId, String action, Request request) {
172173
* @param uniqueId the id the receiver expects.
173174
* @param confirmation the outgoing {@link Confirmation}
174175
*/
175-
public void sendCallResult(String uniqueId, Confirmation confirmation) {
176+
public void sendCallResult(String uniqueId, String action, Confirmation confirmation) {
176177
try {
177-
radio.send(makeCallResult(uniqueId, packPayload(confirmation)));
178+
radio.send(makeCallResult(uniqueId, action, packPayload(confirmation)));
178179
} catch (NotConnectedException e) {
179180
e.printStackTrace();
180181
events.onError(uniqueId, "Not connected", "The confirmation couldn't be send due to the lack of connection", confirmation);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ of this software and associated documentation files (the "Software"), to deal
3030
import eu.chargetime.ocpp.model.Request;
3131

3232
import java.util.ArrayList;
33+
import java.util.Collections;
3334
import java.util.HashMap;
3435
import java.util.concurrent.CompletableFuture;
3536

@@ -51,8 +52,7 @@ public abstract class FeatureHandler {
5152
*/
5253
public void addFeatureProfile(Profile profile) {
5354
Feature[] features = profile.getFeatureList();
54-
for (Feature feature : features)
55-
featureList.add(feature);
55+
Collections.addAll(featureList, features);
5656
}
5757

5858
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ of this software and associated documentation files (the "Software"), to deal
2626
*/
2727

2828
public interface Listener {
29-
void open(String hostname, int port, ListenerEvents listenerEvents);
29+
void open(String hostname, int port, String path, ListenerEvents listenerEvents);
3030

3131
void close();
3232
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public Server(Listener listener) {
6060
* @param serverEvents Callback handler for server specific events.
6161
*/
6262
public void open(String hostname, int port, ServerEvents serverEvents) {
63-
listener.open(hostname, port, session -> {
63+
64+
listener.open(hostname, port, null, session -> {
6465
session.accept(new SessionEvents() {
6566
@Override
6667
public Feature findFeatureByAction(String action) {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public String sendRequest(String action, Request payload) {
7474
* @param uniqueId the unique identification the receiver expects.
7575
* @param confirmation the {@link Confirmation} payload to send.
7676
*/
77-
public void sendConfirmation(String uniqueId, Confirmation confirmation) {
78-
communicator.sendCallResult(uniqueId, confirmation);
77+
public void sendConfirmation(String uniqueId, String action, Confirmation confirmation) {
78+
communicator.sendCallResult(uniqueId, action, confirmation);
7979
}
8080

8181

@@ -144,7 +144,7 @@ public void onCall(String id, String action, String payload) {
144144
Request request = communicator.unpackPayload(payload, feature.getRequestType());
145145
if (request.validate()) {
146146
CompletableFuture<Confirmation> promise = handleIncomingRequest(request);
147-
promise.whenComplete(new ConfirmationHandler(id, communicator));
147+
promise.whenComplete(new ConfirmationHandler(id, action, communicator));
148148
} else {
149149
communicator.sendCallError(id, "OccurenceConstraintViolation", "Payload for Action is syntactically correct but at least one of the fields violates occurence constraints");
150150
}
@@ -193,11 +193,13 @@ private CompletableFuture<Confirmation> handleIncomingRequest(Request request) {
193193
class ConfirmationHandler implements BiConsumer<Confirmation, Throwable> {
194194

195195
private String id;
196+
private String action;
196197
private Communicator communicator;
197198

198-
public ConfirmationHandler(String id, Communicator communicator) {
199+
public ConfirmationHandler(String id, String action, Communicator communicator) {
199200

200201
this.id = id;
202+
this.action = action;
201203
this.communicator = communicator;
202204
}
203205

@@ -208,7 +210,7 @@ public void accept(Confirmation confirmation, Throwable throwable) {
208210
} else if (confirmation == null) {
209211
communicator.sendCallError(id, "NotSupported", "Requested Action is recognized but not supported by the receiver");
210212
} else {
211-
communicator.sendCallResult(id, confirmation);
213+
communicator.sendCallResult(id, action, confirmation);
212214
}
213215
}
214216
}

ocpp-common/src/test/java/eu/chargetime/ocpp/test/CommunicatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Object packPayload(Object payload) {
6868
}
6969

7070
@Override
71-
protected Object makeCallResult(String uniqueId, Object payload) {
71+
protected Object makeCallResult(String uniqueId, String action, Object payload) {
7272
return null;
7373
}
7474

ocpp-common/src/test/java/eu/chargetime/ocpp/test/ServerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void setup() {
6666
doReturn(request.getClass()).when(feature).getRequestType();
6767
doReturn(TestConfirmation.class).when(feature).getConfirmationType();
6868
when(feature.getAction()).thenReturn(null);
69-
doAnswer(invocation -> listenerEvents = invocation.getArgumentAt(2, ListenerEvents.class)).when(listener).open(anyString(), anyInt(), any());
69+
doAnswer(invocation -> listenerEvents = invocation.getArgumentAt(3, ListenerEvents.class)).when(listener).open(anyString(), anyInt(), any(), any());
7070
doAnswer(invocation -> sessionEvents = invocation.getArgumentAt(0, SessionEvents.class)).when(session).accept(any());
7171

7272
server = new Server(listener) {

ocpp-common/src/test/java/eu/chargetime/ocpp/test/SessionTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@ public void sendConfirmation_sendsConfirmationToCommunicator() {
115115
// Given
116116
Confirmation conf = () -> false;
117117
String someUniqueId = "Some id";
118+
String action = "Some action";
118119

119120
// When
120-
session.sendConfirmation(someUniqueId, conf);
121+
session.sendConfirmation(someUniqueId, action, conf);
121122

122123
// Then
123-
verify(communicator, times(1)).sendCallResult(eq(someUniqueId), eq(conf));
124+
verify(communicator, times(1)).sendCallResult(eq(someUniqueId), eq(action), eq(conf));
124125
}
125126

126127
@Test
@@ -168,7 +169,7 @@ public boolean validate() {
168169
try { Thread.sleep(10); } catch (Exception ex) {} // TODO make async invoker injectable
169170

170171
// then
171-
verify(communicator, times(1)).sendCallResult(anyString(), eq(aConfirmation));
172+
verify(communicator, times(1)).sendCallResult(anyString(), anyString(), eq(aConfirmation));
172173
}
173174

174175
@Test

ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeCentralSystem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public BootNotificationConfirmation handleBootNotificationRequest(int sessionInd
9797
try {
9898
confirmation.setInterval(1);
9999
} catch (Exception e) {
100+
e.printStackTrace();
100101
}
101102
confirmation.setCurrentTime(Calendar.getInstance());
102103
confirmation.setStatus(RegistrationStatus.Accepted);

ocpp-v1_6-test/src/main/java/eu/chargetime/ocpp/test/FakeChargePoint.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import eu.chargetime.ocpp.model.Request;
88
import eu.chargetime.ocpp.model.core.*;
99

10+
import java.net.MalformedURLException;
11+
import java.net.URL;
1012
import java.util.Calendar;
1113

1214
/*
@@ -43,15 +45,15 @@ public class FakeChargePoint
4345
private ClientCoreProfile core;
4446
private Throwable receivedException;
4547

46-
public FakeChargePoint() {
48+
public FakeChargePoint() throws MalformedURLException {
4749
this(clientType.JSON);
4850
}
4951

5052
public enum clientType {
5153
JSON, SOAP
5254
}
5355

54-
public FakeChargePoint(clientType type) {
56+
public FakeChargePoint(clientType type) throws MalformedURLException {
5557
core = new ClientCoreProfile(new ClientCoreEventHandler() {
5658
@Override
5759
public ChangeAvailabilityConfirmation handleChangeAvailabilityRequest(ChangeAvailabilityRequest request) {
@@ -119,7 +121,7 @@ public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorR
119121
client = new JSONClient(core);
120122
break;
121123
case SOAP:
122-
client = new SOAPClient("me", "http://localhost:8889", core);
124+
client = new SOAPClient("me", new URL("http://localhost:8889"), core);
123125
break;
124126
}
125127
}

0 commit comments

Comments
 (0)