Questions tagged [spark-java]

Spark is a lightweight web application framework inspired by Ruby's Sinatra. DO NOT USE FOR QUESTIONS ABOUT APACHE SPARK.

Spark is a lightweight web application framework inspired by Ruby's Sinatra. Its main focus is rapid development in pure Java with no need for extensive, additional XML configuration.

556 questions
10
votes
3 answers

How do I add headers to a response from spark, when using a transformer

I have this: get ("/test", (req, resp) -> { return repository.getAll(); }, new JsonTransformer()); My transformer looks like: public class JsonTransformer implements ResponseTransformer { ObjectMapper om = new ObjectMapper(); public…
albertjan
  • 7,739
  • 6
  • 44
  • 74
10
votes
1 answer

Getting "Unsupported major.minor version 52.0" exception while using Spark Web Application framework

Getting following exception: Exception in thread "main" java.lang.UnsupportedClassVersionError: spark/Route : Unsupported major.minor version 52.0 trying to use spark web application framework, when I execute file, it throws this exception. Spark…
user3181500
  • 401
  • 1
  • 5
  • 12
9
votes
1 answer

Add `before` filter for static files in SparkJava

I have specified a location for static files in a Spark application: Spark.staticFileLocation("/public") Now I want to add a filter for some files (e.g. for security purposes), but it does not work: Spark.before("/admin.html", myFilter); It does…
Alexey Subach
  • 11,903
  • 7
  • 34
  • 60
9
votes
4 answers

The requested route has not been mapped in Spark

I want to do something to sign up users with spark+java+hibernate+postgres This is my code: post("/registrar", (request, response) -> { EntityManagerFactory emf = Persistence. createEntityManagerFactory("compradorcitoPU"); …
Alex Rodriguez
  • 91
  • 1
  • 1
  • 2
9
votes
1 answer

URL Pattern in spark

I'm trying to make a filter that matches the following URL's: /foo and /foo/* So anything under /foo/ and also the base case /foo I have this filter: Spark.before("/foo/*", (request, response) -> { String ticket =…
Pablo Matias Gomez
  • 6,614
  • 7
  • 38
  • 72
9
votes
1 answer

How download file using java spark?

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…
kain64b
  • 2,258
  • 2
  • 15
  • 27
9
votes
2 answers

How to handle exceptions for multiple Route

I'm getting to grips with the Spark Framework and I'm trying to understand the best way of handling exceptions in a uniform way for multiple Routes. At the moment I have a number of Routes which all handle exceptions along the lines of: ... catch…
Jonathan
  • 20,053
  • 6
  • 63
  • 70
8
votes
1 answer

connect() failed (111: Connection refused) while connecting to upstream. Java (SparkJava) amazon Elastic

Trying to deploy my first app (Back-end). But I meet an error of the type 502 Bad Gateway. 2016/05/03 14:46:14 [error] 2247#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.43.183, server: , request:…
8
votes
3 answers

What's the difference between response.body() and object returned by the callback?

From Spark Java documentation: response.body("Hello"); // sets content to Hello And from Route's JavaDoc: @return The content to be set in the response So what's the difference? Could someone explain to me pls?
FuzzY
  • 660
  • 8
  • 23
8
votes
1 answer

Set specific URL for static files using Spark Framework

I'm using Spark to serve a web page.. For the static files I initialize Spark like stated here: So I have this structure: /src/main/resources/public/ |-- foo/ |-- css/ | …
Pablo Matias Gomez
  • 6,614
  • 7
  • 38
  • 72
7
votes
1 answer

Bundling log4j.properties in a library - bad style or what?

I came across a nice small web request framework for Java: Spark. The API looks nice and promising, but the library bundle itself is pretty strange. Leave alone the fact that it proposes using snapshot artifacts as dependencies. Leave alone the fact…
zamza
  • 337
  • 1
  • 2
  • 12
7
votes
1 answer

How can a native Servlet Filter be used when using Spark web framework?

I'm playing around with Spark (the Java web framework, not Apache Spark). I find it really nice and easy to define routes and filters, however I'm looking to apply a native servlet filter to my routes and can't seem to find a way to do that. More…
elanh
  • 1,401
  • 3
  • 19
  • 31
7
votes
4 answers

Spark web framework unit tests

I am working with the Spark web framework and creating a RESTful API. (http://sparkjava.com since there are multiple things out there named "Spark") My employer's standards mandate that we write a series of unit tests that will be automatically run…
Mr Robot Arms
  • 130
  • 2
  • 11
7
votes
2 answers

Parse POST body to java object using spark

I migrated from spring to spark while ago and now I'm stuck at something basic. When I make a POST request sending data in the body I want to have the JAVA object back in the controller.. In spring I used to do @RequestBody User user And it was…
Pablo Matias Gomez
  • 6,614
  • 7
  • 38
  • 72
7
votes
8 answers

How to add Spark to Maven project in Eclipse?

I would like to start Spark project in Eclipse using Maven. I've installed m2eclipse and I have a working HelloWorld Java application in my Maven project. I would like to use Spark framework and I'm following directions from the official site. I've…
beam022
  • 1,793
  • 4
  • 20
  • 27
1
2
3
37 38