removed hardcoded namespace from function getJaxbElement() in shared.utils.MiscUtils.java and added global values in shared.enumerations.GlobalValues.java
This commit is contained in:
parent
c3605af549
commit
9ee2d21472
|
@ -57,6 +57,8 @@ public enum GlobalValues {
|
||||||
|
|
||||||
// Schema information
|
// Schema information
|
||||||
V2G_CI_MSG_DEF_NAMESPACE("urn:iso:15118:2:2013:MsgDef"),
|
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_APP_PROTOCOL("/schemas/V2G_CI_AppProtocol.xsd"),
|
||||||
SCHEMA_PATH_MSG_DEF("/schemas/V2G_CI_MsgDef.xsd"),
|
SCHEMA_PATH_MSG_DEF("/schemas/V2G_CI_MsgDef.xsd"),
|
||||||
SCHEMA_PATH_XMLDSIG("/schemas/xmldsig-core-schema.xsd"),
|
SCHEMA_PATH_XMLDSIG("/schemas/xmldsig-core-schema.xsd"),
|
||||||
|
@ -142,6 +144,10 @@ public enum GlobalValues {
|
||||||
return "version 1 (IS compliant)";
|
return "version 1 (IS compliant)";
|
||||||
case V2G_CI_MSG_DEF_NAMESPACE:
|
case V2G_CI_MSG_DEF_NAMESPACE:
|
||||||
return "urn:iso:15118:2:2013:MsgDef";
|
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:
|
case SCHEMA_PATH_APP_PROTOCOL:
|
||||||
return "/schemas/V2G_CI_AppProtocol.xsd";
|
return "/schemas/V2G_CI_AppProtocol.xsd";
|
||||||
case SCHEMA_PATH_MSG_DEF:
|
case SCHEMA_PATH_MSG_DEF:
|
||||||
|
|
|
@ -14,12 +14,16 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBElement;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
import javax.xml.bind.ValidationEvent;
|
import javax.xml.bind.ValidationEvent;
|
||||||
import javax.xml.bind.ValidationEventHandler;
|
import javax.xml.bind.ValidationEventHandler;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.eclipse.risev2g.shared.v2gMessages.appProtocol.SupportedAppProtocolReq;
|
import org.eclipse.risev2g.shared.v2gMessages.appProtocol.SupportedAppProtocolReq;
|
||||||
|
@ -68,6 +72,24 @@ public abstract class ExiCodec {
|
||||||
setInStream(new ByteArrayInputStream(baos.toByteArray()));
|
setInStream(new ByteArrayInputStream(baos.toByteArray()));
|
||||||
baos.close();
|
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();
|
return getInStream();
|
||||||
} catch (JAXBException | IOException e) {
|
} catch (JAXBException | IOException e) {
|
||||||
getLogger().error(e.getClass().getSimpleName() + " occurred while trying to marshal to InputStream from JAXBElement", e);
|
getLogger().error(e.getClass().getSimpleName() + " occurred while trying to marshal to InputStream from JAXBElement", e);
|
||||||
|
|
|
@ -267,8 +267,8 @@ public final class MiscUtils {
|
||||||
String messageName = messageOrField.getClass().getSimpleName().replace("Type", "");
|
String messageName = messageOrField.getClass().getSimpleName().replace("Type", "");
|
||||||
String namespace = "";
|
String namespace = "";
|
||||||
|
|
||||||
if (messageOrField instanceof SignedInfoType) namespace = "http://www.w3.org/2000/09/xmldsig#";
|
if (messageOrField instanceof SignedInfoType) namespace = GlobalValues.V2G_CI_XMLDSIG_NAMESPACE.toString();
|
||||||
else namespace = "urn:iso:15118:2:2013:MsgBody";
|
else namespace = GlobalValues.V2G_CI_MSG_BODY_NAMESPACE.toString();
|
||||||
|
|
||||||
return new JAXBElement(new QName(namespace, messageName),
|
return new JAXBElement(new QName(namespace, messageName),
|
||||||
messageOrField.getClass(),
|
messageOrField.getClass(),
|
||||||
|
|
Loading…
Reference in New Issue