天道酬勤,学无止境

spark-java

Java Spark Framework: Use Straight HTML Template

问题 使用直接 HTML 页面作为 Spark 模板的最简单方法是什么(IE,我不想通过TemplateEngine实现)。 我可以很好地使用模板引擎,如下所示: Spark.get("/test", (req, res) -> new ModelAndView(map, "template.html"), new MustacheTemplateEngine()); 我尝试只使用没有引擎的 ModelAndView: Spark.get("/", (req, res) -> new ModelAndView(new HashMap(), "index.html")); 但这只是模型和视图的 toString() : spark.ModelAndView@3bdadfd8 。 我正在考虑编写自己的引擎并实现 render() 来执行 IO 以提供 html 文件,但是有更好的方法吗? 回答1 Spark.get("/", (req, res) -> renderContent("index.html")); ... private String renderContent(String htmlFile) { new String(Files.readAllBytes(Paths.get(getClass().getResource(htmlFile).toURI()))

2022-05-12 09:33:22    分类:技术分享    java   spark-java

Java Spark Framework: Use Straight HTML Template

What is the easiest way to use a straight HTML page as a Spark template (IE, I don't want to go through a TemplateEngine implementation). I can use a template engine fine, like so: Spark.get("/test", (req, res) -> new ModelAndView(map, "template.html"), new MustacheTemplateEngine()); And I tried just using the ModelAndView without an Engine: Spark.get("/", (req, res) -> new ModelAndView(new HashMap(), "index.html")); But that get's me just the toString() of the model and view: spark.ModelAndView@3bdadfd8. I am thinking of writing my own engine and implementing render() to do the IO to serve

2022-04-28 05:35:15    分类:问答    java   spark-java

在 spark-java 中使用 https(Use https in spark-java)

问题 如何在 spark-java 框架中使用自定义 SSLContext 和自定义 SSLServerSocketFactory? 我在 SparkServerImpl 中搜索过,但不知道如何注入 sslfactory,有什么建议吗? 回答1

2022-03-16 19:36:54    分类:技术分享    spark-java

Use https in spark-java

How can i use custom SSLContext and custom SSLServerSocketFactory in spark-java framework? I've searched in SparkServerImpl but have no idea how to inject sslfactory, any suggestions?

2022-03-12 00:27:30    分类:问答    spark-java

Mutual authentication with Spark Java

I am trying to achieve a mutually authenticated REST API server using spark-java and from the documentation I see: secure(keystoreFilePath, keystorePassword, truststoreFilePath, truststorePassword); ... which looks like exactly what I need. However I am only able to do one way authentication of the server, the client certificate never seems to be verified against the truststore. I'm using version 2.1, any advise or pointers would be greatly appreciated.

2022-02-15 06:03:17    分类:问答    java   spark-java

How can I return `index.html` from webapp folder instead of resources folder in spark-java?

I want to return index.html from my spark-java server. This page is located under: src/main/webapp/portal/v1/index.html I added this route: get("/portal/v1/*", (req, res) -> { Map < String, Object > model = new HashMap <> (); return new VelocityTemplateEngine().render( new ModelAndView(model, "/portal/v1/index.html") ); }); When I open the URL in the browser: http://localhost:8080/portal/v1/ I get this error: 500 Internal Server Error In the logs, I see this stack trace: 29-Mar-2021 11:58:22.038 SEVERE [http-nio-8080-exec-9] org.apache.velocity.runtime.log.JdkLogChute.log ResourceManager

2022-02-12 05:55:45    分类:问答    java   resources   spark-java

NGINX 和 Spark Java 之间的跨域通信(Cross origin communication between NGINX and spark Java)

问题 我正在为我的 Web 应用程序使用 NGINX 和 sparkjava。 我确定我已正确启用所有 CORS 标头。 尽管如此,我仍然收到“XMLHttpRequest cannot load http://localhost:3003/platformAPI/login. Invalid HTTP status code 404”错误。下面提到的是我分别来自 extjs 和 spark java 的客户端和服务器方法。 我检查了浏览器的网络选项卡以获取发送的响应和请求标头。 它们也在下面提到。 非常感谢任何让我知道我的方法有什么问题的帮助:) 来自 Nginx 的客户端方法: function(button, event, options){ var form = Ext.getCmp("LoginformId").getForm(); if (form.isValid()) { var userJson = JSON.stringify(form.getFieldValues()); form.submit({ url: 'http://localhost:3003/platformAPI/login', //headers : {'Content-Type':undefined,}, //dataType: 'jsonp', success: function(form

2022-01-21 17:14:11    分类:技术分享    extjs   nginx   spark-java

Cross origin communication between NGINX and spark Java

I am using NGINX and sparkjava for my web application. I am sure I have enabled all CORS headers properly. Still, I am getting "XMLHttpRequest cannot load http://localhost:3003/platformAPI/login. Invalid HTTP status code 404" error.Below mentioned are my client and server methods from extjs and spark java respectively. I have inspected the network tab of my browser to get the response and request headers sent as well. They are also mentioned below. Any help to let me know as to what's wrong with my approach is highly appreciated :) Client method from Nginx: function(button, event, options){

2022-01-18 06:41:01    分类:问答    extjs   nginx   spark-java