spark-java

SparkJava Variables Scope

倖福魔咒の 提交于 2019-12-01 11:05:16
I'm developing a SparkJava (not Apache Spark) app, and I'd like to share an object between a before filter and a post route. The filter and the route are defined in different classes. I'm not willing to go on with sessions, cause it's a mobile app json api and theoretically speaking, it should be session free. The variable scope should be from the beginning of the request handling until the end. before(Main.API_PROTECTED + "/*", (req, res) -> { String token = req.headers("Authorization"); if (token == null | "".equals(token)) { halt(401, "You're not welcome."); } else { Partner partner = new

SparkJava Variables Scope

风流意气都作罢 提交于 2019-12-01 07:37:56
问题 I'm developing a SparkJava (not Apache Spark) app, and I'd like to share an object between a before filter and a post route. The filter and the route are defined in different classes. I'm not willing to go on with sessions, cause it's a mobile app json api and theoretically speaking, it should be session free. The variable scope should be from the beginning of the request handling until the end. before(Main.API_PROTECTED + "/*", (req, res) -> { String token = req.headers("Authorization"); if

How to return a static html page with Spark Java?

强颜欢笑 提交于 2019-11-30 19:48:13
A hello world with spark: get(new Route("/hello") { @Override public Object handle(Request request, Response response) { response.type("text/html"); return "<h1>Hello Spark MVC Framework!</h1>"; } }); How can I return a static file index.html instead? Notes: I need this index.html to be in the jar in the spirit of simplicity of spark java, I'd like to avoid as much as possible going through templates, that would be overkill for a static page. You can do so by passing the absolute path to your static resources directory in this method: externalStaticFileLocation("/var/www/public"); Or by

Send data in Request body using HttpURLConnection

依然范特西╮ 提交于 2019-11-30 12:41:49
I am using HttpURLConnection to make a POST request to a local service deployed in my local created using JAVA Spark. I want to send some data in request body when I make the POST call using the HttpURLConnection but every time the request body in JAVA Spark is null . Below is the code I am using for this Java Spark POST Service Handler post("/", (req, res) -> { System.out.println("Request Body: " + req.body()); return "Hello!!!!"; }); HTTPClass Making the post call `public class HTTPClassExample{ public static void main(String[] args) { try{ URL url = new URL("http://localhost:4567/");

troubleshooting 解决yarn-cluster模式的JVM栈内存溢出问题

随声附和 提交于 2019-11-30 10:20:28
公司里面你的机器节点一般都是虚拟机啊!所以yarn-client会有网络激增的问题!Yarn-client模式可以跑,但是Yarn-cluster模式不能跑,就是报那么一个JVM永久代溢出的那么一个问题! spark-submit脚本提交spark application到ResourceManager 去ResourceManager申请启动ApplicationMaster 通知一个NodeManager去启动ApplicationMaster(Driver进程) ApplicationMaster去找ResourceManager申请Executor ResourceManager分配container,container代表你能启动的Executor占有的资源,包括内存+CPU返回已经启动container的NodeManager的地址 ApplicationMaster去找NodeManager在container里面申请启动Executor Executor进程会反过来去向Driver注册上去 最后Driver接收到了Executor资源之后就可以去进行我们spark代码的执行了 执行到某个action就触发一个JOB DAGScheduler会划分JOB为一个个Stage TaskScheduler会划分Stage为一个个Task Task发送到Executor执行

Send data in Request body using HttpURLConnection

做~自己de王妃 提交于 2019-11-29 17:10:28
问题 I am using HttpURLConnection to make a POST request to a local service deployed in my local created using JAVA Spark. I want to send some data in request body when I make the POST call using the HttpURLConnection but every time the request body in JAVA Spark is null . Below is the code I am using for this Java Spark POST Service Handler post("/", (req, res) -> { System.out.println("Request Body: " + req.body()); return "Hello!!!!"; }); HTTPClass Making the post call `public class

How to deploy a spark Java web app?

∥☆過路亽.° 提交于 2019-11-28 05:58:01
I used spark web framework to create a webapp, but I don't know how to deploy this webapp. I'm sorry if this is very basic, but I'm new to spark framework and I cannot find any document that guide me how to deploy a spark webapp.: How to deploy a spark webapp standalone How to build a spark webapp (to war file or such a file) and deploy with web server (jetty or Tomcat). dMcNavish You will first need to create a regular Java project that can be built into a .war file (in Eclipse this would be a Dynamic Web Project) The spark documentation at this link describes what needs to be added to your

Where to put static files for Spark Web Framework?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 05:48:48
Where do I put files when trying to serve static files with the Spark web framework? I haven't been able to find anything online - I'm beginning to suspect I don't understand anything about class paths, relative paths etc. for an Eclipse and Java project. This paragraph about static files in Spark refers to /public , but I have no idea where that would be. Using windows, Eclipse Luna and my project is converted to use Maven. I've tried looking at the code on GitHub, but I'm a little out of my depth trying to find it. First you have to tell Spark where to search for the static files like this:

java.lang.ClassCastException using lambda expressions in spark job on remote server

最后都变了- 提交于 2019-11-27 04:37:20
I'm trying to build a web api for my apache spark jobs using sparkjava.com framework. My code is: @Override public void init() { get("/hello", (req, res) -> { String sourcePath = "hdfs://spark:54310/input/*"; SparkConf conf = new SparkConf().setAppName("LineCount"); conf.setJars(new String[] { "/home/sam/resin-4.0.42/webapps/test.war" }); File configFile = new File("config.properties"); String sparkURI = "spark://hamrah:7077"; conf.setMaster(sparkURI); conf.set("spark.driver.allowMultipleContexts", "true"); JavaSparkContext sc = new JavaSparkContext(conf); @SuppressWarnings("resource") JavaRDD

How to deploy a spark Java web app?

≡放荡痞女 提交于 2019-11-27 00:57:20
问题 I used spark web framework to create a webapp, but I don't know how to deploy this webapp. I'm sorry if this is very basic, but I'm new to spark framework and I cannot find any document that guide me how to deploy a spark webapp.: How to deploy a spark webapp standalone How to build a spark webapp (to war file or such a file) and deploy with web server (jetty or Tomcat). 回答1: You will first need to create a regular Java project that can be built into a .war file (in Eclipse this would be a