spark-java

How to wait until Spark service is stopped?

﹥>﹥吖頭↗ 提交于 2019-12-23 19:28:13
问题 For my Spark API I'm building integration tests. Sometimes I want to stop and start the Spark instance. When I do that I sometimes run into the problem that I'm creating a new Spark instance, while the old one is still shutting down on a separate thread. It would be helpful to know when the Spark instance actually shut down. First I start my Spark instance like this: Spark.init(); Spark.awaitInitialization(); Then I stop it like this: Spark.stop(); Now after I call stop() , the Spark Service

Spark Java: Unable to process parts as no multi-part configuration has been provided

馋奶兔 提交于 2019-12-23 18:08:56
问题 I want to upload a file from an html form using spark. Following is my java function to handle the post route: Spark.post("/upload", "multipart/form-data", (request, response) -> { String location = "temporary"; // the directory location where files will be stored long maxFileSize = 100000000; // the maximum size allowed for uploaded files long maxRequestSize = 100000000; // the maximum size allowed for multipart/form-data requests int fileSizeThreshold = 1024; // the size threshold after

How download file using java spark?

一个人想着一个人 提交于 2019-12-23 07:26:20
问题 I want to write simple rest api for file download. I cant find docs about it as I understood I need to set mimetype='application/zip' for response, but not clear how to return stream. http://sparkjava.com/ update: resolved here example code: public static void main(String[] args) { //setPort(8080); get("/hello", (request, responce) -> getFile(request,responce)); } private static Object getFile(Request request, Response responce) { File file = new File("MYFILE"); responce.raw().setContentType(

Apache Shiro with Embedded-Jetty or Spark-Java - Is it possible?

主宰稳场 提交于 2019-12-23 02:44:09
问题 Does anyone have an example project on how I could integrate Shiro with Spark-Java/Jetty(embedded) please? I can see from http://sparkjava.com/documentation#filters that it must be the way. But not sure what would be the smartest way to do this according to https://shiro.apache.org/web.html If you may have any examples, appreciate much! 来源: https://stackoverflow.com/questions/54835994/apache-shiro-with-embedded-jetty-or-spark-java-is-it-possible

What's the difference between `:path-param` and `{path-param}` in Java Spark?

落花浮王杯 提交于 2019-12-12 15:28:34
问题 I'm working on a REST server built with Java Spark, and I was wondering about the difference between the following two syntaxes for defining path parameters, using :path-parameter vs {path-parameter} : path("/containers/:container-id", () -> { ...} ) path("/shipments/{shipment-id}", () -> { ... } ) At one point, when querying the path parameters on the path /{handler-id} (which is nested inside /v1 and /handlers ), I had to change the syntax from the : form to the {} form to get Spark to not

Cross origin communication between NGINX and spark Java

情到浓时终转凉″ 提交于 2019-12-12 12:26:23
问题 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

Refresh static files served by SparkJava

前提是你 提交于 2019-12-12 11:05:43
问题 I'm doing a project using Spark Java. On the server side, some images are created and I want them to be available in the client. Since I have a static content directory, after creating the image on the server side, I place it in that directory. However, this file is not available unless I reboot the server. I guess there must be a way to refresh the static directory file for Spark Java on runtime so that requests of on-runtime created images can be fulfilled. Right? Thanks! 回答1: The

How read data sent by Client with Spark?

a 夏天 提交于 2019-12-12 09:42:43
问题 I have to read some data sent by Client using Spark (a framework for Java). This is the code of client's post request. I am using jQuery. $.post("/insertElement", {item:item.value, value: value.value, dimension: dimension.value }); The code of server: post(new Route("/insertElement") { @Override public Object handle(Request request, Response response) { String item = (String) request.attribute("item"); String value = (String) request.attribute("value"); String dimension = (String) request

How to serialize List object in Gson

半腔热情 提交于 2019-12-12 03:35:21
问题 I have data returned from DB using the below method (method from spark-java framework) below: get("/data_on_page_load", "application/json", (Request request, Response response) -> { List<Post> list = Post.findAll(); // NEED TO SERIALIZE THE RESPONSE System.out.println("list is " + list); return (list); }, new JsonTransformer()); Data returned from DB: [Model: com.soul.seeker.models.Post, table: 'post', attributes: {created_at=2017-03-26 04:06:35.0, details=aaa, id=36, title=Eventsa, url

Can't load static file while in route “/post/:postId” in spark-java framework

走远了吗. 提交于 2019-12-12 03:29:43
问题 In my spark-java project, I put css file and js file into folder static in src/main/resources . I use Spark.staticFileLocation("/static") to set the static file path. When I use get("/posts", (req, res) ->{...}) , css and js file can load correctly. The path is http://0.0.0.0:4567/css/style.css , it works well. But when I want to get the single post by postId get("/post/:postId", (req, res) ->{...}) , it can't load the css and js file correctly. The path become http://0.0.0.0:4567/post/css