Skip to content

Commit 213c2de

Browse files
committed
improve OCPP WS/JSON implementation
pull exception handling from outgoing pipeline into invoker, to catch exceptions earlier, since invoker might also throw exceptions
1 parent add41f7 commit 213c2de

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/main/java/de/rwth/idsg/steve/ocpp/ws/AbstractChargePointServiceInvoker.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall;
1010
import de.rwth.idsg.steve.ocpp.ws.pipeline.OutgoingPipeline;
1111
import lombok.Setter;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214
import org.springframework.beans.factory.annotation.Autowired;
1315

1416
import java.util.UUID;
@@ -18,13 +20,30 @@
1820
* @since 20.03.2015
1921
*/
2022
public abstract class AbstractChargePointServiceInvoker {
23+
private final Logger log = LoggerFactory.getLogger(getClass());
2124

2225
@Autowired private OutgoingPipeline outgoingPipeline;
2326

2427
@Setter private TypeStore typeStore;
2528
@Setter private AbstractWebSocketEndpoint endpoint;
2629

30+
/**
31+
* Just a wrapper to make try-catch block and exception handling stand out
32+
*/
2733
public void runPipeline(String chargeBoxId, RequestType request, OcppResponseHandler handler) {
34+
try {
35+
run(chargeBoxId, request, handler);
36+
} catch (Exception e) {
37+
log.error("Exception occurred", e);
38+
// Outgoing call failed due to technical problems. Pass the exception to handler to inform the user
39+
handler.handleException(e);
40+
}
41+
}
42+
43+
/**
44+
* Actual processing
45+
*/
46+
private void run(String chargeBoxId, RequestType request, OcppResponseHandler handler) {
2847
String messageId = UUID.randomUUID().toString();
2948
ActionResponsePair pair = typeStore.findActionResponse(request);
3049
if (pair == null) {

src/main/java/de/rwth/idsg/steve/ocpp/ws/pipeline/OutgoingPipeline.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,8 @@ public class OutgoingPipeline implements Pipeline {
2222

2323
@Override
2424
public void run(CommunicationContext context) {
25-
try {
26-
serializer.process(context);
27-
sender.process(context);
28-
29-
} catch (Exception e) {
30-
log.error("Exception occurred", e);
31-
// Outgoing call failed due to technical problems. Pass the exception to handler to inform the user.
32-
context.getFutureResponseContext().getHandler().handleException(e);
33-
return;
34-
}
25+
serializer.process(context);
26+
sender.process(context);
3527

3628
// All went well, and the call is sent. Store the response context for later lookup.
3729
futureResponseContextStore.add(context.getSession(),

0 commit comments

Comments
 (0)