From 7633b904ec6cf6922513d672fed5e19c8e82ca1e Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Wed, 13 Jul 2016 12:58:56 +0100 Subject: [PATCH] Continued to add static serving endpoint --- .../com/r3corda/demos/api/InterestRateSwapAPI.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt b/src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt index 150cd17d52..468a6ef7dd 100644 --- a/src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt +++ b/src/main/kotlin/com/r3corda/demos/api/InterestRateSwapAPI.kt @@ -8,12 +8,14 @@ import com.r3corda.core.utilities.loggerFor import com.r3corda.demos.protocols.AutoOfferProtocol import com.r3corda.demos.protocols.ExitServerProtocol import com.r3corda.demos.protocols.UpdateBusinessDayProtocol +import org.apache.commons.io.IOUtils import java.net.URI import java.time.LocalDate import java.time.LocalDateTime import javax.ws.rs.* import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response +import java.nio.channels.* /** * This provides a simplified API, currently for demonstration use only. @@ -116,17 +118,14 @@ class InterestRateSwapAPI(val services: ServiceHub) { @Path("web") @Produces(MediaType.TEXT_HTML) fun serveWeb() : Response { - try - { + try { val resourcePath = "/web/index.html" val resource = javaClass.getResourceAsStream(resourcePath) - println(resource); - return Response.ok(resource, MediaType.TEXT_HTML_TYPE).build() - } - catch(ex: Exception) - { + val responseContent = IOUtils.toString(resource) + return Response.ok(responseContent, MediaType.TEXT_HTML_TYPE).build() + } catch(ex: Exception) { + println(ex) return Response.status(Response.Status.NOT_FOUND).build() } - } }