Skip to content

Commit a494935

Browse files
committed
Merge branch 'master' into patch-1
2 parents d0c52b8 + 55098b2 commit a494935

File tree

17 files changed

+586
-1
lines changed

17 files changed

+586
-1
lines changed

ocpp-v1_6-example/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
8+
.mvn/
9+
mvnw
10+
mvnw.cmd
11+
12+
### STS ###
13+
.apt_generated
14+
.classpath
15+
.factorypath
16+
.project
17+
.settings
18+
.springBeans
19+
.sts4-cache
20+
21+
### IntelliJ IDEA ###
22+
.idea
23+
*.iws
24+
*.iml
25+
*.ipr
26+
27+
### NetBeans ###
28+
/nbproject/private/
29+
/nbbuild/
30+
/dist/
31+
/nbdist/
32+
/.nb-gradle/
33+
build/
34+
35+
### VS Code ###
36+
.vscode/
37+
38+
*.DS_Store
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Json Server Example Spring Application
2+
=============
3+
4+
An example spring application which is implementing a JSON server.
5+
Running on port 8887 and accepts the jsons provided in the documentation here (OCPP 1.6)
6+
https://www.openchargealliance.org/downloads/
7+
8+
UT for the server implementation, as well as for a pretty simple authorization handler implementation is provided.
9+
For external a simple browser extention as simple web socket client can be used.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.5.6</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>eu.chargetime.ocpp</groupId>
12+
<artifactId>json-server-implementation </artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>json-server-implementation </name>
15+
<description>Example Spring Application of a json server </description>
16+
<properties>
17+
<java.version>11</java.version>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-test</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.projectlombok</groupId>
33+
<artifactId>lombok</artifactId>
34+
<optional>true</optional>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.java-websocket</groupId>
38+
<artifactId>Java-WebSocket</artifactId>
39+
<version>1.5.1</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.google.code.gson</groupId>
43+
<artifactId>gson</artifactId>
44+
<version>2.8.8</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>eu.chargetime.ocpp</groupId>
48+
<artifactId>v1_6</artifactId>
49+
<version>1.0.1</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.testng</groupId>
53+
<artifactId>testng</artifactId>
54+
<version>RELEASE</version>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>junit</groupId>
59+
<artifactId>junit</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-maven-plugin</artifactId>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package eu.chargetime.ocpp.jsonserverimplementation;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class JsonServerImplementationApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(JsonServerImplementationApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package eu.chargetime.ocpp.jsonserverimplementation.config;
2+
3+
import lombok.Getter;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
@Configuration
9+
@EnableConfigurationProperties
10+
@Getter
11+
public class ApplicationConfiguration {
12+
13+
@Value("${server.port}")
14+
private Integer serverPort;
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package eu.chargetime.ocpp.jsonserverimplementation.config;
2+
3+
import eu.chargetime.ocpp.JSONServer;
4+
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
@Configuration
10+
@Slf4j
11+
public class JsonServerConfig {
12+
13+
@Bean
14+
public JSONServer jsonServer(ServerCoreProfile core) {
15+
return new JSONServer(core);
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package eu.chargetime.ocpp.jsonserverimplementation.config;
2+
3+
import eu.chargetime.ocpp.feature.profile.ServerCoreEventHandler;
4+
import eu.chargetime.ocpp.feature.profile.ServerCoreProfile;
5+
import eu.chargetime.ocpp.model.core.*;
6+
import lombok.Getter;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
import java.time.ZonedDateTime;
12+
import java.util.UUID;
13+
14+
@Configuration
15+
@Getter
16+
@Slf4j
17+
public class ServerCoreProfileConfig {
18+
19+
@Bean
20+
public ServerCoreEventHandler getCoreEventHandler() {
21+
return new ServerCoreEventHandler() {
22+
@Override
23+
public AuthorizeConfirmation handleAuthorizeRequest(UUID sessionIndex, AuthorizeRequest request) {
24+
25+
System.out.println(request);
26+
// ... handle event
27+
IdTagInfo idTagInfo = new IdTagInfo();
28+
idTagInfo.setExpiryDate(ZonedDateTime.now());
29+
idTagInfo.setParentIdTag("test");
30+
idTagInfo.setStatus(AuthorizationStatus.Accepted);
31+
32+
return new AuthorizeConfirmation(idTagInfo);
33+
}
34+
35+
@Override
36+
public BootNotificationConfirmation handleBootNotificationRequest(UUID sessionIndex, BootNotificationRequest request) {
37+
38+
System.out.println(request);
39+
// ... handle event
40+
41+
return null; // returning null means unsupported feature
42+
}
43+
44+
@Override
45+
public DataTransferConfirmation handleDataTransferRequest(UUID sessionIndex, DataTransferRequest request) {
46+
47+
System.out.println(request);
48+
// ... handle event
49+
50+
return null; // returning null means unsupported feature
51+
}
52+
53+
@Override
54+
public HeartbeatConfirmation handleHeartbeatRequest(UUID sessionIndex, HeartbeatRequest request) {
55+
56+
System.out.println(request);
57+
// ... handle event
58+
59+
return null; // returning null means unsupported feature
60+
}
61+
62+
@Override
63+
public MeterValuesConfirmation handleMeterValuesRequest(UUID sessionIndex, MeterValuesRequest request) {
64+
65+
System.out.println(request);
66+
// ... handle event
67+
68+
return null; // returning null means unsupported feature
69+
}
70+
71+
@Override
72+
public StartTransactionConfirmation handleStartTransactionRequest(UUID sessionIndex, StartTransactionRequest request) {
73+
74+
System.out.println(request);
75+
// ... handle event
76+
77+
return null; // returning null means unsupported feature
78+
}
79+
80+
@Override
81+
public StatusNotificationConfirmation handleStatusNotificationRequest(UUID sessionIndex, StatusNotificationRequest request) {
82+
83+
System.out.println(request);
84+
// ... handle event
85+
86+
return null; // returning null means unsupported feature
87+
}
88+
89+
@Override
90+
public StopTransactionConfirmation handleStopTransactionRequest(UUID sessionIndex, StopTransactionRequest request) {
91+
92+
System.out.println(request);
93+
// ... handle event
94+
95+
return null; // returning null means unsupported feature
96+
}
97+
};
98+
}
99+
100+
@Bean
101+
public ServerCoreProfile createCore(ServerCoreEventHandler serverCoreEventHandler) {
102+
return new ServerCoreProfile(serverCoreEventHandler);
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package eu.chargetime.ocpp.jsonserverimplementation.config;
2+
3+
import eu.chargetime.ocpp.ServerEvents;
4+
import eu.chargetime.ocpp.model.SessionInformation;
5+
import lombok.Getter;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.Configuration;
9+
10+
import java.util.UUID;
11+
12+
@Configuration
13+
@Getter
14+
@Slf4j
15+
public class ServerEventConfig {
16+
17+
@Bean
18+
public ServerEvents createServerCoreImpl() {
19+
return getNewServerEventsImpl();
20+
}
21+
22+
private ServerEvents getNewServerEventsImpl() {
23+
return new ServerEvents() {
24+
25+
@Override
26+
public void newSession(UUID sessionIndex, SessionInformation information) {
27+
28+
// sessionIndex is used to send messages.
29+
System.out.println("New session " + sessionIndex + ": " + information.getIdentifier());
30+
}
31+
32+
@Override
33+
public void lostSession(UUID sessionIndex) {
34+
35+
System.out.println("Session " + sessionIndex + " lost connection");
36+
}
37+
};
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package eu.chargetime.ocpp.jsonserverimplementation.server;
2+
3+
import eu.chargetime.ocpp.JSONServer;
4+
import eu.chargetime.ocpp.ServerEvents;
5+
import eu.chargetime.ocpp.jsonserverimplementation.config.ApplicationConfiguration;
6+
import lombok.AllArgsConstructor;
7+
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.stereotype.Component;
9+
10+
import javax.annotation.PostConstruct;
11+
12+
@Slf4j
13+
@Component
14+
@AllArgsConstructor
15+
public class JsonServerImpl {
16+
17+
private final ServerEvents serverEvents;
18+
private final JSONServer server;
19+
private final ApplicationConfiguration applicationConfiguration;
20+
21+
@PostConstruct
22+
public void startServer() throws Exception {
23+
server.open("localhost", applicationConfiguration.getServerPort(), serverEvents);
24+
}
25+
}

0 commit comments

Comments
 (0)