Skip to content

Commit

Permalink
Add some logs: send and recv events.
Browse files Browse the repository at this point in the history
Add some hashCode(), equals() and toString().
  • Loading branch information
sumlin committed Aug 31, 2018
1 parent ad6905e commit 05cc027
Show file tree
Hide file tree
Showing 109 changed files with 2,099 additions and 350 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class CallErrorException extends Exception {
* @param payload raw payload send from the other end.
*/
public CallErrorException(String errorCode, String errorDescription, Object payload) {
super("errorCode='" + errorCode + '\'' +
", errorDescription='" + errorDescription + '\'' +
", payload=" + payload);
this.errorCode = errorCode;
this.errorDescription = errorDescription;
this.payload = payload;
Expand Down
8 changes: 6 additions & 2 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,15 @@ public void disconnect()
*/
public CompletableFuture<Confirmation> send(Request request) throws UnsupportedFeatureException, OccurenceConstraintException {
Optional<Feature> featureOptional = featureRepository.findFeature(request);
if (!featureOptional.isPresent())
if (!featureOptional.isPresent()) {
logger.error("Can't send request: unsupported feature. Payload: {}", request);
throw new UnsupportedFeatureException();
}

if (!request.validate())
if (!request.validate()) {
logger.error("Can't send request: not validated. Payload {}: ", request);
throw new OccurenceConstraintException();
}

String id = session.storeRequest(request);
CompletableFuture<Confirmation> promise = promiseRepository.createPromise(id);
Expand Down
23 changes: 23 additions & 0 deletions ocpp-common/src/main/java/eu/chargetime/ocpp/Communicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ of this software and associated documentation files (the "Software"), to deal
*/

import eu.chargetime.ocpp.model.*;
import eu.chargetime.ocpp.utilities.SugarUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;

import javax.xml.soap.SOAPMessage;
import java.util.ArrayDeque;

/**
Expand Down Expand Up @@ -153,6 +156,16 @@ public void accept(CommunicatorEvents events) {
*/
synchronized public void sendCall(String uniqueId, String action, Request request) {
Object call = makeCall(uniqueId, action, packPayload(request));

if (call != null) {
logger.warn(call.getClass().getCanonicalName());
if (call instanceof SOAPMessage) {
logger.trace("Send a message: {}", SugarUtil.soapMessageToString((SOAPMessage) call));
} else {
logger.trace("Send a message: {}", call);
}
}

try {
if(radio.isClosed()) {
if (request.transactionRelated()) {
Expand Down Expand Up @@ -201,6 +214,8 @@ public void sendCallResult(String uniqueId, String action, Confirmation confirma
* @param errorDescription a associated error description.
*/
public void sendCallError(String uniqueId, String action, String errorCode, String errorDescription) {
logger.error("An error occurred. Sending this information: uniqueId {}: action: {}, errorCore: {}, errorDescription: {}",
uniqueId, action, errorCode, errorDescription);
try {
radio.send(makeCallError(uniqueId, action, errorCode, errorDescription));
} catch (NotConnectedException ex) {
Expand Down Expand Up @@ -242,6 +257,14 @@ public void connected() {
@Override
public void receivedMessage(Object input) {
Message message = parse(input);
if (message != null) {
Object payload = message.getPayload();
if (payload instanceof Document) {
logger.trace("Receive a message: {}", SugarUtil.docToString((Document) payload));
} else {
logger.trace("Receive a message: {}", message);
}
}
if (message instanceof CallResultMessage) {
events.onCallResult(message.getId(), message.getAction(), message.getPayload());
} else if (message instanceof CallErrorMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import org.w3c.dom.Document;

import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Calendar;
import java.text.SimpleDateFormat;

Expand All @@ -36,4 +47,27 @@ public static String calendarToString(Calendar calendar) {
return "";
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(calendar.getTime());
}

public static String docToString(Document doc) {
try {
StringWriter sw = new StringWriter();
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(new DOMSource(doc), new StreamResult(sw));
return sw.toString();
} catch (Exception ex) {
throw new RuntimeException("Error converting to String", ex);
}
}

public static String soapMessageToString(SOAPMessage message) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
message.writeTo(out);
} catch (SOAPException | IOException e) {
return "";
}
return new String(out.toByteArray());
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.AuthorizeConfirmation;
import eu.chargetime.ocpp.model.core.AuthorizeRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Copyright (C) 2015-2016 Thomas Volden <tv@chargetime.eu>
Expand All @@ -32,6 +26,14 @@ of this software and associated documentation files (the "Software"), to deal
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.AuthorizeConfirmation;
import eu.chargetime.ocpp.model.core.AuthorizeRequest;


public class AuthorizeFeature extends Feature {

public AuthorizeFeature(Profile ownerProfile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.BootNotificationConfirmation;
import eu.chargetime.ocpp.model.core.BootNotificationRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Copyright (C) 2015-2016 Thomas Volden <tv@chargetime.eu>
Expand All @@ -32,6 +26,14 @@ of this software and associated documentation files (the "Software"), to deal
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.BootNotificationConfirmation;
import eu.chargetime.ocpp.model.core.BootNotificationRequest;


public class BootNotificationFeature extends Feature {

public BootNotificationFeature(Profile ownerProfile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.reservation.CancelReservationConfirmation;
import eu.chargetime.ocpp.model.reservation.CancelReservationRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Expand Down Expand Up @@ -33,6 +27,13 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.reservation.CancelReservationConfirmation;
import eu.chargetime.ocpp.model.reservation.CancelReservationRequest;


public class CancelReservationFeature extends Feature {

public CancelReservationFeature(Profile ownerProfile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.ChangeAvailabilityConfirmation;
import eu.chargetime.ocpp.model.core.ChangeAvailabilityRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Copyright (C) 2015-2016 Thomas Volden <tv@chargetime.eu>
Expand All @@ -32,6 +26,14 @@ of this software and associated documentation files (the "Software"), to deal
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.ChangeAvailabilityConfirmation;
import eu.chargetime.ocpp.model.core.ChangeAvailabilityRequest;


public class ChangeAvailabilityFeature extends Feature {
public ChangeAvailabilityFeature(Profile ownerProfile) {
super(ownerProfile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.ChangeConfigurationConfirmation;
import eu.chargetime.ocpp.model.core.ChangeConfigurationRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Copyright (C) 2015-2016 Thomas Volden <tv@chargetime.eu>
Expand All @@ -32,6 +26,14 @@ of this software and associated documentation files (the "Software"), to deal
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.ChangeConfigurationConfirmation;
import eu.chargetime.ocpp.model.core.ChangeConfigurationRequest;


public class ChangeConfigurationFeature extends Feature {
public ChangeConfigurationFeature(Profile ownerProfile) {
super(ownerProfile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.ClearCacheConfirmation;
import eu.chargetime.ocpp.model.core.ClearCacheRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Copyright (C) 2015-2016 Thomas Volden <tv@chargetime.eu>
Expand All @@ -32,6 +26,14 @@ of this software and associated documentation files (the "Software"), to deal
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.ClearCacheConfirmation;
import eu.chargetime.ocpp.model.core.ClearCacheRequest;


public class ClearCacheFeature extends Feature{
public ClearCacheFeature(Profile ownerProfile) {
super(ownerProfile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.DataTransferConfirmation;
import eu.chargetime.ocpp.model.core.DataTransferRequest;

/*
* ChargeTime.eu - Java-OCA-OCPP
*
Expand All @@ -31,6 +24,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.DataTransferConfirmation;
import eu.chargetime.ocpp.model.core.DataTransferRequest;


public class DataTransferFeature extends Feature {

public DataTransferFeature(Profile ownerProfile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Expand Down Expand Up @@ -33,6 +27,13 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.DiagnosticsStatusNotificationRequest;


public class DiagnosticsStatusNotificationFeature extends Feature {

public DiagnosticsStatusNotificationFeature(Profile ownerProfile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Copyright (C) 2015-2016 Thomas Volden <tv@chargetime.eu>
Expand Down Expand Up @@ -34,6 +28,13 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationConfirmation;
import eu.chargetime.ocpp.model.firmware.FirmwareStatusNotificationRequest;


public class FirmwareStatusNotificationFeature extends Feature {

public FirmwareStatusNotificationFeature(Profile ownerProfile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
package eu.chargetime.ocpp.feature;

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.GetConfigurationConfirmation;
import eu.chargetime.ocpp.model.core.GetConfigurationRequest;

/*
ChargeTime.eu - Java-OCA-OCPP
Copyright (C) 2015-2016 Thomas Volden <tv@chargetime.eu>
Expand All @@ -32,6 +25,14 @@ of this software and associated documentation files (the "Software"), to deal
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

import eu.chargetime.ocpp.feature.profile.Profile;
import eu.chargetime.ocpp.model.Confirmation;
import eu.chargetime.ocpp.model.Request;
import eu.chargetime.ocpp.model.core.GetConfigurationConfirmation;
import eu.chargetime.ocpp.model.core.GetConfigurationRequest;


public class GetConfigurationFeature extends Feature {
public GetConfigurationFeature(Profile ownerProfile) {
super(ownerProfile);
Expand Down
Loading

0 comments on commit 05cc027

Please sign in to comment.