Skip to content

Commit

Permalink
Merge pull request #18 from emilm/identity-ip-address
Browse files Browse the repository at this point in the history
Added IP address
  • Loading branch information
TVolden committed May 22, 2017
2 parents cd22d8d + 9ece605 commit cc9fa1a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,40 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import java.net.InetSocketAddress;

public class SessionInformation {

private String identifier;
private InetSocketAddress address;

public String getIdentifier() {
return identifier;
}
public InetSocketAddress getAddress() { return address; }

public static class Builder {

private String identifier;
private InetSocketAddress address;

public Builder Identifier(String identifier) {
this.identifier = identifier;
return this;
}

public Builder InternetAddress(InetSocketAddress address) {
this.address = address;
return this;
}

public SessionInformation build() {
SessionInformation sessionInformation = new SessionInformation();
sessionInformation.identifier = this.identifier;
sessionInformation.address = this.address;
return sessionInformation;
}


}
}
2 changes: 1 addition & 1 deletion ocpp-v1_6/src/main/java/eu/chargetime/ocpp/SOAPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void openWS() {
server.createContext("/", new WSHttpHandler(WSDL_CHARGE_POINT, message -> {
SOAPMessage soapMessage = null;
try {
soapMessage = transmitter.relay(message).get();
soapMessage = transmitter.relay(message.getMessage()).get();
} catch (InterruptedException e) {
//e.printStackTrace();
} catch (ExecutionException e) {
Expand Down
25 changes: 25 additions & 0 deletions ocpp-v1_6/src/main/java/eu/chargetime/ocpp/SOAPMessageInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package eu.chargetime.ocpp;

import javax.xml.soap.SOAPMessage;
import java.net.InetSocketAddress;

/**
* Created by emil on 21.05.2017.
*/
public class SOAPMessageInfo {
private final InetSocketAddress address;
private final SOAPMessage message;

public SOAPMessageInfo(InetSocketAddress address, SOAPMessage message) {
this.address = address;
this.message = message;
}

public InetSocketAddress getAddress() {
return address;
}

public SOAPMessage getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void handle(HttpExchange httpExchange) throws IOException {
sendWSDL(httpExchange);
} else {
SOAPMessage request = parse(httpExchange.getRequestBody());
SOAPMessage confirmation = events.incomingRequest(request);
SOAPMessage confirmation = events.incomingRequest(new SOAPMessageInfo(httpExchange.getRemoteAddress(), request));
OutputStream responseStream = httpExchange.getResponseBody();
try {
httpExchange.getResponseHeaders().add("Content-Type", "application/soap+xml; charset=utf-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ of this software and associated documentation files (the "Software"), to deal
import javax.xml.soap.SOAPMessage;

public interface WSHttpHandlerEvents {
SOAPMessage incomingRequest(SOAPMessage message);
SOAPMessage incomingRequest(SOAPMessageInfo messageInfo);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ private void removeChargebox(String identity) {
}

@Override
public SOAPMessage incomingRequest(SOAPMessage message) {
public SOAPMessage incomingRequest(SOAPMessageInfo messageInfo) {
SOAPMessage message = messageInfo.getMessage();
String identity = SOAPSyncHelper.getHeaderValue(message, "chargeBoxIdentity");
if (!chargeBoxes.containsKey(identity)) {
String toUrl = SOAPSyncHelper.getHeaderValue(message, "From");
Expand All @@ -99,7 +100,7 @@ public SOAPMessage incomingRequest(SOAPMessage message) {
chargeBoxes.remove(identity);
}));

SessionInformation information = new SessionInformation.Builder().Identifier(identity).build();
SessionInformation information = new SessionInformation.Builder().Identifier(identity).InternetAddress(messageInfo.getAddress()).build();
events.newSession(session, information);
chargeBoxes.put(identity, webServiceReceiver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public void open(String hostname, int port, ListenerEvents handler) {
public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
WebSocketReceiver receiver = new WebSocketReceiver(message -> webSocket.send(message));
sockets.put(webSocket, receiver);
SessionInformation information = new SessionInformation.Builder().Identifier(clientHandshake.getResourceDescriptor()).build();
SessionInformation information = new SessionInformation.Builder()
.Identifier(clientHandshake.getResourceDescriptor())
.InternetAddress(webSocket.getRemoteSocketAddress()).build();

handler.newSession(new Session(new JSONCommunicator(receiver), new Queue(), handleRequestAsync), information);
}

Expand Down

0 comments on commit cc9fa1a

Please sign in to comment.