diff --git a/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/enumerations/GlobalValues.java b/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/enumerations/GlobalValues.java index ace7e56..bed4faf 100644 --- a/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/enumerations/GlobalValues.java +++ b/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/enumerations/GlobalValues.java @@ -57,6 +57,8 @@ public enum GlobalValues { // Schema information V2G_CI_MSG_DEF_NAMESPACE("urn:iso:15118:2:2013:MsgDef"), + V2G_CI_MSG_BODY_NAMESPACE("urn:iso:15118:2:2013:MsgBody"), + V2G_CI_XMLDSIG_NAMESPACE("http://www.w3.org/2000/09/xmldsig#"), SCHEMA_PATH_APP_PROTOCOL("/schemas/V2G_CI_AppProtocol.xsd"), SCHEMA_PATH_MSG_DEF("/schemas/V2G_CI_MsgDef.xsd"), SCHEMA_PATH_XMLDSIG("/schemas/xmldsig-core-schema.xsd"), @@ -142,6 +144,10 @@ public enum GlobalValues { return "version 1 (IS compliant)"; case V2G_CI_MSG_DEF_NAMESPACE: return "urn:iso:15118:2:2013:MsgDef"; + case V2G_CI_MSG_BODY_NAMESPACE: + return "urn:iso:15118:2:2013:MsgBody"; + case V2G_CI_XMLDSIG_NAMESPACE: + return "http://www.w3.org/2000/09/xmldsig#"; case SCHEMA_PATH_APP_PROTOCOL: return "/schemas/V2G_CI_AppProtocol.xsd"; case SCHEMA_PATH_MSG_DEF: diff --git a/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/exiCodec/ExiCodec.java b/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/exiCodec/ExiCodec.java index 602a83a..bd77a92 100644 --- a/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/exiCodec/ExiCodec.java +++ b/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/exiCodec/ExiCodec.java @@ -14,12 +14,16 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; + import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.bind.ValidationEvent; import javax.xml.bind.ValidationEventHandler; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.risev2g.shared.v2gMessages.appProtocol.SupportedAppProtocolReq; @@ -68,6 +72,24 @@ public abstract class ExiCodec { setInStream(new ByteArrayInputStream(baos.toByteArray())); baos.close(); + // For debugging purposes, you can view the XML representation of marshalled messages + StringWriter sw = new StringWriter(); + String className = ""; + + if (jaxbObject instanceof V2GMessage) { + className = ((V2GMessage) jaxbObject).getBody().getBodyElement().getName().getLocalPart(); + } else if (jaxbObject instanceof SupportedAppProtocolReq) { + className = "SupportedAppProtocolReq"; + } else if (jaxbObject instanceof SupportedAppProtocolRes) { + className = "SupportedAppProtocolRes"; + } else { + className = "marshalled JAXBElement"; + } + + getMarshaller().marshal(jaxbObject, sw); + getLogger().debug("XML representation of " + className + ":\n" + sw.toString()); + sw.close(); + return getInStream(); } catch (JAXBException | IOException e) { getLogger().error(e.getClass().getSimpleName() + " occurred while trying to marshal to InputStream from JAXBElement", e); diff --git a/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/utils/MiscUtils.java b/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/utils/MiscUtils.java index ae91d81..4ca9d41 100644 --- a/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/utils/MiscUtils.java +++ b/RISE-V2G-Shared/src/main/java/org/eclipse/risev2g/shared/utils/MiscUtils.java @@ -267,8 +267,8 @@ public final class MiscUtils { String messageName = messageOrField.getClass().getSimpleName().replace("Type", ""); String namespace = ""; - if (messageOrField instanceof SignedInfoType) namespace = "http://www.w3.org/2000/09/xmldsig#"; - else namespace = "urn:iso:15118:2:2013:MsgBody"; + if (messageOrField instanceof SignedInfoType) namespace = GlobalValues.V2G_CI_XMLDSIG_NAMESPACE.toString(); + else namespace = GlobalValues.V2G_CI_MSG_BODY_NAMESPACE.toString(); return new JAXBElement(new QName(namespace, messageName), messageOrField.getClass(),