天道酬勤,学无止境

spark-framework

Freemarker 模板错误:null 或缺失(Freemarker template error: null or missing)

问题 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 = new

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

Freemarker template error: null or missing

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 = new

2022-02-15 20:17:21    分类:问答    java   rest   templates   freemarker   spark-framework

如果自定义令牌的生成是异步的,我将如何返回 Firebase 自定义令牌?(How would I return a Firebase custom token if the generation of the custom token is asynchronous?)

问题 我正在使用托管在 Heroku 上的 Spark 框架,我在我的服务器中的main : 方法中有这个 post("/token", (request, response) -> "Hello World"); 这很好,但是,我想实际发送一个自定义令牌,而不仅仅是“Hello World”。 所以,从逻辑上讲,我需要这个: FirebaseAuth auth = FirebaseAuth.getInstance(); String uid = UUID.randomUUID().toString(); post("/token", (request, response) -> auth.createCustomToken(uid)); 但是, createCustomToken返回一个Task<String>而不是String 。 所以,我必须这样做: auth.createCustomToken(uid).addOnSuccessListener(new OnSuccessListener<String>() { @Override public void onSuccess(String s) { } }); 但是,在这种形式中: post("/token", (request, response) -> auth.createCustomToken(uid)

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

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

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 OnSuccessListener

2022-01-24 15:15:04    分类:问答    java   heroku   firebase   firebase-authentication   spark-framework

发送此 AJAX Post 数据的正确内容类型(Correct content-type for sending this AJAX Post data)

问题 我在使用 ajax post 发送 base64 图像数据时遇到问题我认为我的 Content-Type 值错误,但尝试了application/json 、 text/json和image/jpeg没有任何成功 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); } 浏览器控制台显示 ["data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD

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

Spark 框架:监听服务器停止(Spark Framework: Listen for server stop)

问题 有没有办法在 Spark 框架关闭时进行侦听,以进行一些清理? 例如,我想关闭我的 ElasticSearch 客户端。 回答1 正如@Martin Eden 解释的那样,一种方法是使用Runtime.getRuntime().addShutdownHook(...); 但这与spark服务器(码头)生命周期无关。 实际上,您可以在不停止应用程序的情况下停止服务器,并且此关闭钩子不会运行添加到runtime任何钩子清理。 所以如果你停止它,这会清理你的应用程序。 另一种选择是在 Jetty 中添加一个 Lifecycle(托管)bean bean,并将属性 stop at shutdown 设置为 true server.setStopAtShutdown(true); . EmbeddedServers.add(EmbeddedServers.Identifiers.JETTY, new MyJettyFactory()); static class MyJettyFactory implements EmbeddedServerFactory { public EmbeddedServer create(Routes routeMatcher, StaticFilesConfiguration staticFilesConfiguration, boolean

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

Spark Framework: Listen for server stop

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.

2021-10-07 04:08:41    分类:问答    java   elasticsearch   jetty   spark-framework

Correct content-type for sending this AJAX Post data

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-09-01 17:05:12    分类:问答    javascript   java   ajax   spark-java   spark-framework