天道酬勤,学无止境

spark-framework

Freemarker template error: null or missing

Question 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, Object> data = new HashMap<>(); data.put("Hello", "Your not null!"); StringWriter writer =

2022-02-16 02:04:21    分类:技术分享    java   rest   templates   freemarker   spark-framework

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

Question 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 not a String. So, I have to do: auth.createCustomToken(uid).addOnSuccessListener(new

2022-01-24 21:03:44    分类:技术分享    java   heroku   firebase   firebase-authentication   spark-framework

Correct content-type for sending this AJAX Post data

Question 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/4AAQSkZJRgABAQAAAQABAAD

2021-10-22 01:24:41    分类:技术分享    javascript   java   ajax   spark-java   spark-framework

Spark Framework: Listen for server stop

Question 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. Answer1 As @Martin Eden explains an approach is to use Runtime.getRuntime().addShutdownHook(...); but this has nothing to do with spark server (jetty) lifecycle. Actually, you could stop the server without stopping the app and this shutdown hook wouldn't run any hook-cleanup added to the runtime. So this would cleanup your app if you stop it. Another option is to add a Lifecycle (managed) bean bean in Jetty and set the property stop at

2021-10-07 05:23:00    分类:技术分享    java   elasticsearch   jetty   spark-framework