Continued to add static serving endpoint

This commit is contained in:
Clinton Alexander 2016-07-13 12:58:56 +01:00
parent d41ae4528e
commit 7633b904ec

View File

@ -8,12 +8,14 @@ import com.r3corda.core.utilities.loggerFor
import com.r3corda.demos.protocols.AutoOfferProtocol import com.r3corda.demos.protocols.AutoOfferProtocol
import com.r3corda.demos.protocols.ExitServerProtocol import com.r3corda.demos.protocols.ExitServerProtocol
import com.r3corda.demos.protocols.UpdateBusinessDayProtocol import com.r3corda.demos.protocols.UpdateBusinessDayProtocol
import org.apache.commons.io.IOUtils
import java.net.URI import java.net.URI
import java.time.LocalDate import java.time.LocalDate
import java.time.LocalDateTime import java.time.LocalDateTime
import javax.ws.rs.* import javax.ws.rs.*
import javax.ws.rs.core.MediaType import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response import javax.ws.rs.core.Response
import java.nio.channels.*
/** /**
* This provides a simplified API, currently for demonstration use only. * This provides a simplified API, currently for demonstration use only.
@ -116,17 +118,14 @@ class InterestRateSwapAPI(val services: ServiceHub) {
@Path("web") @Path("web")
@Produces(MediaType.TEXT_HTML) @Produces(MediaType.TEXT_HTML)
fun serveWeb() : Response { fun serveWeb() : Response {
try try {
{
val resourcePath = "/web/index.html" val resourcePath = "/web/index.html"
val resource = javaClass.getResourceAsStream(resourcePath) val resource = javaClass.getResourceAsStream(resourcePath)
println(resource); val responseContent = IOUtils.toString(resource)
return Response.ok(resource, MediaType.TEXT_HTML_TYPE).build() return Response.ok(responseContent, MediaType.TEXT_HTML_TYPE).build()
} } catch(ex: Exception) {
catch(ex: Exception) println(ex)
{
return Response.status(Response.Status.NOT_FOUND).build() return Response.status(Response.Status.NOT_FOUND).build()
} }
} }
} }