Created
February 21, 2015 08:28
-
-
Save hhariri/f3968146fc24064a444c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.somanyfeeds.application | |
import javax.servlet.annotation.WebServlet | |
import javax.servlet.http.* | |
import java.io.InputStream | |
import java.io.BufferedReader | |
import java.io.Writer | |
import java.io.InputStreamReader | |
WebServlet(name = "SoManyFeeds", value = array("/*")) | |
public class SoManyFeedsServlet : HttpServlet() { | |
private val resourceLoader = ResourceLoader() | |
override public fun doGet(req: HttpServletRequest, resp: HttpServletResponse) { | |
val respWriter = resp.getWriter() | |
val path = req.getPathInfo() | |
val resourceName = if (path.equals("/")) "index.html" else path.substring(1) | |
resourceLoader.load("/public/$resourceName")?.let { | |
this.writeResource(respWriter, resourceStream) | |
return | |
} | |
// TODO build JSON API from here. | |
respWriter.write("Welcome to SoManyFeeds!") | |
} | |
fun writeResource(writer: Writer, resourceStream: InputStream) { | |
val reader = BufferedReader(InputStreamReader(resourceStream)); | |
var line: String? = reader.readLine(); | |
while (line != null) { | |
writer.write(line); | |
line = reader.readLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment