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

Fixes for compatibility and cleanup issues #69

Merged
merged 3 commits into from
Jun 29, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ public void clientLost() {
}

public void started() throws Exception {
final String host = "127.0.0.1";

if (!isStarted) {
int port = 8890;
if (server instanceof JSONTestServer) {
port = 8887;
}

server.open("127.0.0.1", port, dummyHandlers.generateServerEventsHandler());
logger.info("Server started on port: {}", port);
server.open(host, port, dummyHandlers.generateServerEventsHandler());
logger.info("Server started on host: {}, port: {}", host, port);
isStarted = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract class JSONBaseSpec extends Specification {
FakeChargePoint chargePoint = new FakeChargePoint()

def setupSpec() {
def conditions = new PollingConditions(timeout: 10)
def conditions = new PollingConditions(timeout: 11)

// When a Central System is running
centralSystem.started()
Expand All @@ -36,7 +36,7 @@ abstract class JSONBaseSpec extends Specification {
}

def cleanupSpec() {
def conditions = new PollingConditions(timeout: 10)
def conditions = new PollingConditions(timeout: 11)

centralSystem.stopped()

Expand Down
10 changes: 8 additions & 2 deletions ocpp-v1_6/src/main/java/eu/chargetime/ocpp/JSONServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ of this software and associated documentation files (the "Software"), to deal
import eu.chargetime.ocpp.wss.WssFactoryBuilder;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.protocols.IProtocol;
import org.java_websocket.protocols.Protocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.CompletionStage;
Expand All @@ -63,8 +65,12 @@ public class JSONServer implements IServerAPI {
public JSONServer(ServerCoreProfile coreProfile, JSONConfiguration configuration) {
featureRepository = new FeatureRepository();
SessionFactory sessionFactory = new SessionFactory(featureRepository);
draftOcppOnly = new Draft_6455(Collections.emptyList(),
Collections.singletonList(new Protocol("ocpp1.6")));

ArrayList<IProtocol> protocols = new ArrayList<>();
protocols.add(new Protocol("ocpp1.6"));
protocols.add(new Protocol(""));
draftOcppOnly = new Draft_6455(Collections.emptyList(), protocols);

this.listener = new WebSocketListener(sessionFactory, configuration, draftOcppOnly);
server = new Server(this.listener, featureRepository, new PromiseRepository());
featureRepository.addFeatureProfile(coreProfile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ public void relay(String message) {
public void onClose(WebSocket webSocket, int code, String reason, boolean remote) {
logger.debug("On connection close (resource descriptor: {}, code: {}, reason: {}, remote: {})", webSocket.getResourceDescriptor(), code, reason, remote);

sockets.get(webSocket).disconnect();
sockets.remove(webSocket);
WebSocketReceiver receiver = sockets.get(webSocket);
if(receiver != null) {
receiver.disconnect();
sockets.remove(webSocket);
} else {
logger.debug("Receiver for socket not found: {}", webSocket);
}
}

@Override
Expand Down Expand Up @@ -167,8 +172,8 @@ public void close() {
}

try {
sockets.clear();
server.stop(TIMEOUT_IN_MILLIS);
sockets.clear();
} catch (InterruptedException e) {
// Do second try
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public void onError(Exception ex) {
}

configure();

logger.debug("Trying to connect to: {}", resource);

try {
client.connectBlocking();
closed = false;
Expand Down