mirror of
https://github.com/corda/corda.git
synced 2025-02-06 11:09:18 +00:00
More specific message when a corda service fails to instantiate. (#901)
This commit is contained in:
parent
48bb191ea2
commit
5233c50098
@ -65,6 +65,7 @@ import org.jetbrains.exposed.sql.Database
|
|||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.lang.reflect.InvocationTargetException
|
||||||
import java.lang.reflect.Modifier.*
|
import java.lang.reflect.Modifier.*
|
||||||
import java.net.JarURLConnection
|
import java.net.JarURLConnection
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
@ -273,6 +274,8 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class ServiceInstantiationException(cause: Throwable?) : Exception(cause)
|
||||||
|
|
||||||
private fun installCordaServices(scanResult: ScanResult) {
|
private fun installCordaServices(scanResult: ScanResult) {
|
||||||
fun getServiceType(clazz: Class<*>): ServiceType? {
|
fun getServiceType(clazz: Class<*>): ServiceType? {
|
||||||
return try {
|
return try {
|
||||||
@ -300,6 +303,8 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
} catch (e: NoSuchMethodException) {
|
} catch (e: NoSuchMethodException) {
|
||||||
log.error("${it.name}, as a Corda service, must have a constructor with a single parameter " +
|
log.error("${it.name}, as a Corda service, must have a constructor with a single parameter " +
|
||||||
"of type ${PluginServiceHub::class.java.name}")
|
"of type ${PluginServiceHub::class.java.name}")
|
||||||
|
} catch (e: ServiceInstantiationException) {
|
||||||
|
log.error("Corda service ${it.name} failed to instantiate", e.cause)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
log.error("Unable to install Corda service ${it.name}", e)
|
log.error("Unable to install Corda service ${it.name}", e)
|
||||||
}
|
}
|
||||||
@ -310,13 +315,17 @@ abstract class AbstractNode(open val configuration: NodeConfiguration,
|
|||||||
* Use this method to install your Corda services in your tests. This is automatically done by the node when it
|
* Use this method to install your Corda services in your tests. This is automatically done by the node when it
|
||||||
* starts up for all classes it finds which are annotated with [CordaService].
|
* starts up for all classes it finds which are annotated with [CordaService].
|
||||||
*/
|
*/
|
||||||
fun <T : SerializeAsToken> installCordaService(clazz: Class<T>): T {
|
fun <T : SerializeAsToken> installCordaService(serviceClass: Class<T>): T {
|
||||||
clazz.requireAnnotation<CordaService>()
|
serviceClass.requireAnnotation<CordaService>()
|
||||||
val ctor = clazz.getDeclaredConstructor(PluginServiceHub::class.java).apply { isAccessible = true }
|
val constructor = serviceClass.getDeclaredConstructor(PluginServiceHub::class.java).apply { isAccessible = true }
|
||||||
val service = ctor.newInstance(services)
|
val service = try {
|
||||||
cordappServices.putInstance(clazz, service)
|
constructor.newInstance(services)
|
||||||
|
} catch (e: InvocationTargetException) {
|
||||||
|
throw ServiceInstantiationException(e.cause)
|
||||||
|
}
|
||||||
|
cordappServices.putInstance(serviceClass, service)
|
||||||
smm.tokenizableServices += service
|
smm.tokenizableServices += service
|
||||||
log.info("Installed ${clazz.name} Corda service")
|
log.info("Installed ${serviceClass.name} Corda service")
|
||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user