Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to Kotlin 1.0.0-beta-4584. Fixed broken code, removed deprec… #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pom.xml - The Apache POM file that builds and packages the sample

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>0.12.1218</kotlin.version>
<kotlin.version>1.0.0-beta-4584</kotlin.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.picocontainer.DefaultPicoContainer
import org.picocontainer.MutablePicoContainer
import spark.servlet.SparkApplication
import kotlin.reflect.KClass
import kotlin.reflect.jvm.java

public class Application(
var composer: Composable = Noncomposer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ package com.nordicapis.kotlin_spark_sample
import org.slf4j.LoggerFactory
import spark.Request
import spark.Response
import kotlin.reflect.jvm.java

public class AuthorizeController : Controllable()
{
private val _logger = LoggerFactory.getLogger(javaClass<AuthorizeController>())
private val _logger = LoggerFactory.getLogger(AuthorizeController::class.java)

public override fun before(request: Request, response: Response): Boolean
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ ContainerComposer.kt - The composer that wires up the dependencies of this appli

package com.nordicapis.kotlin_spark_sample

import org.picocontainer.DefaultPicoContainer
import org.picocontainer.MutablePicoContainer
import kotlin.reflect.jvm.java

class ContainerComposer : Composable
{
public override fun composeApplication(appContainer: MutablePicoContainer)
{
appContainer.addComponent(javaClass<AuthorizeController>())
appContainer.addComponent(javaClass<TokenController>())
appContainer.addComponent(javaClass<LoginController>())
appContainer.addComponent(AuthorizeController::class.java)
appContainer.addComponent(TokenController::class.java)
appContainer.addComponent(LoginController::class.java)
}

public override fun composeRequest(container: MutablePicoContainer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package com.nordicapis.kotlin_spark_sample
import spark.Request
import spark.Response

SuppressWarnings("unused")
@SuppressWarnings("unused")
abstract class Controllable
{
public open fun before(request: Request, response: Response): Boolean = true
Expand Down
15 changes: 7 additions & 8 deletions src/main/kotlin/com/nordicapis/kotlin_spark_sample/Router.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,27 @@ import spark.*
import spark.Spark.halt
import spark.template.velocity.VelocityTemplateEngine
import java.util.*
import kotlin.reflect.jvm.java

class Router constructor() : SparkBase()
{
public fun <T : Controllable> routeTo(path: String, container: PicoContainer, controllerClass: Class<T>,
composer: Composable, template: String? = null)
{
for (classMethod in controllerClass.getDeclaredMethods())
for (classMethod in controllerClass.declaredMethods)
{
val methodName = classMethod.getName()
val methodName = classMethod.name

if (methodName == "before" || methodName == "after")
{
continue // We don't want to route after or before using Spark, so skip these.
}

// See if the controller class' method is overriding one of Controllable's
for (interfaceMethod in javaClass<Controllable>().getMethods())
for (interfaceMethod in Controllable::class.java.methods)
{
if (methodName == interfaceMethod.getName() && // method names match?
classMethod.getReturnType() == interfaceMethod.getReturnType() && // method return the same type?
Arrays.deepEquals(classMethod.getParameterTypes(), interfaceMethod.getParameterTypes())) // Params match?
if (methodName == interfaceMethod.name && // method names match?
classMethod.returnType == interfaceMethod.returnType && // method return the same type?
Arrays.deepEquals(classMethod.parameterTypes, interfaceMethod.parameterTypes)) // Params match?
{
if (template == null || template.isBlank())
{
Expand Down Expand Up @@ -103,7 +102,7 @@ class Router constructor() : SparkBase()
{
// Fire the controller's method depending on the HTTP method of the request
val httpMethod = request.requestMethod().toLowerCase()
val method = controllerClass.getMethod(httpMethod, javaClass<Request>(), javaClass<Response>())
val method = controllerClass.getMethod(httpMethod, Request::class.java, Response::class.java)
val result = method.invoke(controller, request, response)

if (result is ControllerResult && result.continueProcessing)
Expand Down