spark-framework

Correct content-type for sending this AJAX Post data

谁说胖子不能爱 提交于 2020-01-04 09:39:29
问题 I am having problem sending base64 image data using ajax post I think I have the wrong value for Content-Type but have tried application/json , text/json and image/jpeg without any success Javascript function sendFormData(fD) { var urls = fD.get('urls'); console.log('urls', urls); var xhr = new XMLHttpRequest(); xhr.open('POST', '/editsongs.update_artwork'); alert(urls); xhr.setRequestHeader("Content-type", "image/jpeg"); xhr.send(urls); } Browser console shows ["data:image/jpeg;base64,/9j

Freemarker template error: null or missing

点点圈 提交于 2019-12-25 08:37:07
问题 public static void main(String[] args) throws IOException { port(8080); Configuration config = new Configuration(Configuration.VERSION_2_3_26); config.setDirectoryForTemplateLoading(new File("PATH_NAME")); get("/test", (req,res) ->{ StringWriter writer = new StringWriter(); Template temp = config.getTemplate("loginform.ftl"); temp.process(null, writer); return writer; }); post("/select", (req,res) -> { String city = req.queryParams("city"); String state = req.queryParams("state"); Map<String,

SSE implementation in Spark REST

拟墨画扇 提交于 2019-12-12 21:28:58
问题 Looking for a simple example of a GET rest api that produces text/event-stream. How do I keep a track of listeners, how to use emitter in spark? Basically, how do I achieve SSE using spark framework (Server side code) 来源: https://stackoverflow.com/questions/45826776/sse-implementation-in-spark-rest

Spark Framework: Listen for server stop

北战南征 提交于 2019-12-11 10:02:11
问题 Is there a way to listen for when Spark framework is shutting down, to run some cleanup? For example, I want to close out my ElasticSearch client. 回答1: One approach is to use Runtime.getRuntime().addShutdownHook() . This is a general Java mechanism for running code when the program exits. Since a Spark Framework web application is just a normal web application, this will work. See the Java documentation. However, this hook will not be run if the VM process is aborted using the SIGKILL signal

How would I return a Firebase custom token if the generation of the custom token is asynchronous?

我与影子孤独终老i 提交于 2019-12-11 07:54:29
问题 I'm using the Spark Framework hosted on Heroku and I have this in my main : method in my server post("/token", (request, response) -> "Hello World"); That's working fine, however, I want to actually send a custom token, and not just "Hello World". So, logically, I would need this: FirebaseAuth auth = FirebaseAuth.getInstance(); String uid = UUID.randomUUID().toString(); post("/token", (request, response) -> auth.createCustomToken(uid)); However, createCustomToken returns a Task<String> and