spark-java

Testing Java Spark Microservices app that implements SparkApplication interface

拥有回忆 提交于 2020-01-24 15:14:26
问题 I am trying to figure out how to test a web/rest services written in Java Spark and there is not many tutorials on how to do that. It is tricky to find answers due to confusion between Apache Spark and Java Spark . I came across this resource but, I couldn't get it to work the way I had expected. There is also this resource and examples in Java Spark github but they all probably use embedded server. Anyway, Assuming that I have the following service public class RestService implements

Spark rest api server deploy

痞子三分冷 提交于 2020-01-24 09:56:46
问题 With this link, I made rest api server. It works well when I run on eclipse ide. However, I don't know how to deploy on server. I made war file and tried to deploy on tomcat, but somehow cannot access any page that I defined, unlike running on eclipse. Here is some gradle configuration that I made. apply plugin: 'war' war { baseName = 'server' manifest { attributes 'Implementation-Title': 'SparkAPIServer', 'Implementation-Version': '1.0', 'Main-Class': 'com.server.Main' } } I'm sure that

Mutual authentication with Spark Java

ε祈祈猫儿з 提交于 2020-01-06 21:26:48
问题 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. 回答1: It seems that Spark in version 2.6

Mutual authentication with Spark Java

落爺英雄遲暮 提交于 2020-01-06 21:24:50
问题 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. 回答1: It seems that Spark in version 2.6

Eclipse: Auto-load html/JS changes during debug

你说的曾经没有我的故事 提交于 2020-01-06 19:34:19
问题 I am running an app in Java Spark Framework. I run it in Eclipse with Debug-As->Java App . This successfully deploys the changes to the Java files. That is, I save a Java file, and Eclipse compiles it, and the running app reflects the changes to the Java file. Spark uses an embedded Jetty server under the hood, so this is just like running a embedded Jetty app in Eclipse. Anyone aware of a good way to cause the HTML and JS changes to also be auto-deployed? 回答1: In order to auto update the

Correct content-type for sending this AJAX Post data

谁说胖子不能爱 提交于 2020-01-04 09:39:29
问题 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

Why does Html5 audio load all songs from server on file load

泪湿孤枕 提交于 2019-12-31 05:30:10
问题 my local web application (using java spark framework) creates a Html5 report and some of the pages contain audio files that can be played. Originally this done purely via Html such as <audio controls="controls"> <source src="/Music/Melco\TestMusic\TestMusic\WAV\Music\David Ferrard\Across The Troubled Wave\02 - The Slave's Lament.WAV"> </audio> but it only worked if the music was in a subfolder of the Web applications root folder. So to get round this I created a symbolic link to the root

Java Spark Framework: Route to a specific static file

天大地大妈咪最大 提交于 2019-12-25 08:53:12
问题 Is there a simple way of setting up routes to a specific static file using the Java Spark Framework? I'm setting up an Angular (1.5) app to be served from a Java Spark server. I've set up the general way of serving static files: staticFiles.location("/public"); The app will have several angular routes, e.g. /start, /config, /live, etc. Angular will take care of the routing when the index.html and the js-files have been loaded. But I want support for loading the application directly on the

Java Spark Framework: Use Straight HTML Template

别来无恙 提交于 2019-12-24 12:40:30
问题 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

`name` as a variable name in freemarker breaks

假如想象 提交于 2019-12-23 22:30:33
问题 I have the following code in an ftl: <#macro field label name value="" type="text"> ${name} ${name!"print if null"} <div class="field"> <div class="clearfix" id="${name}_field"> <label for="${name}">${label}</label> <div class="input"> <input type="${type}" id="${name}" name="${name}" value="${value}"> <span class="help-inline"></span> <span class="help-block"></span> </div> </div> </div> </#macro> <@field label="label" name="test" /> And this is printing this: foo-test test <div class="field