CordaX500Name JAX-RS parameter converter (#1571)

This commit is contained in:
Maksymilian Pawlak 2017-09-21 10:19:42 +01:00 committed by josecoll
parent c93b0284ef
commit fd9c79659d
2 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package net.corda.webserver.converters
import net.corda.core.identity.CordaX500Name
import java.lang.reflect.Type
import javax.ws.rs.ext.ParamConverter
import javax.ws.rs.ext.ParamConverterProvider
import javax.ws.rs.ext.Provider
object CordaX500NameConverter : ParamConverter<CordaX500Name> {
override fun toString(value: CordaX500Name) = value.toString()
override fun fromString(value: String) = CordaX500Name.parse(value)
}
@Provider
object CordaConverterProvider : ParamConverterProvider {
override fun <T : Any> getConverter(rawType: Class<T>, genericType: Type?, annotations: Array<out Annotation>?): ParamConverter<T>? {
if (rawType == CordaX500Name::class.java) {
@Suppress("UNCHECKED_CAST")
return CordaX500NameConverter as ParamConverter<T>
}
return null
}
}

View File

@ -7,6 +7,7 @@ import net.corda.core.messaging.CordaRPCOps
import net.corda.core.utilities.loggerFor
import net.corda.nodeapi.ArtemisMessagingComponent
import net.corda.webserver.WebServerConfig
import net.corda.webserver.converters.CordaConverterProvider
import net.corda.webserver.services.WebServerPluginRegistry
import net.corda.webserver.servlets.*
import org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException
@ -136,6 +137,7 @@ class NodeWebServer(val config: WebServerConfig) {
val resourceConfig = ResourceConfig()
.register(ObjectMapperConfig(rpcObjectMapper))
.register(ResponseFilter())
.register(CordaConverterProvider)
.register(APIServerImpl(localRpc))
val webAPIsOnClasspath = pluginRegistries.flatMap { x -> x.webApis }