com.izivia.ocpp.soap15.Ocpp15SoapParser.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ocpp-1-5-soap Show documentation
Show all versions of ocpp-1-5-soap Show documentation
This module provides a SOAP parser for OCPP 1.5
package com.izivia.ocpp.soap15
import com.fasterxml.jackson.core.type.TypeReference
import com.izivia.ocpp.core15.Ocpp15ForcedFieldType
import com.izivia.ocpp.core15.Ocpp15IgnoredNullRestriction
import com.izivia.ocpp.core15.model.common.enumeration.Actions
import com.izivia.ocpp.soap.*
import com.izivia.ocpp.utils.*
import kotlin.reflect.full.memberProperties
class Ocpp15SoapParser(
override val ignoredNullRestrictions: List? = null,
override val forcedFieldTypes: List? = null,
) :
OcppSoapParserImpl(
ocppNs = OcppNs(
ocppCpNs = "urn://Ocpp/Cp/2012/06/",
ocppCsNs = "urn://Ocpp/Cs/2012/06/"
),
soapMapperInput = Ocpp15SoapMapperIn,
soapMapperOutput = Ocpp15SoapMapper
) {
override fun readToEnvelop(
soap: String,
warningHandler: (warnings: List) -> Unit
): SoapEnvelope<*> =
try {
soapMapperInput
.readTree(soap)
.apply {
applyDeserializerOptions(this, warningHandler)
}?.let {
soapMapperInput
.readerFor(object : TypeReference>() {})
.readValue(it)
}
} catch (e: Exception) {
parseSoapFaulted(soap, e) {
Ocpp15SoapBody(fault = it)
}
} as SoapEnvelope
private fun getRealBodyContent(envelope: SoapEnvelope): Any {
for (prop in Ocpp15SoapBody::class.memberProperties) {
prop.get(envelope.body)?.let { return it }
}
throw IllegalArgumentException("Unknown message operation. enveloppe = $envelope")
}
override fun getRequestBodyContent(envelope: SoapEnvelope<*>): Any =
getRealBodyContent(envelope as SoapEnvelope)
.isA { it.toFaultReq() }
override fun getResponseBodyContent(envelope: SoapEnvelope<*>): Any =
getRealBodyContent(envelope as SoapEnvelope)
override fun getOcppInitiator(action: String): OcppInitiator =
Actions.valueOf(action.uppercase()).initiatedBy
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy