Closed QMG-kazala closed 7 years ago
Same problem here.
I am sending a picture as a byte-array-string inside my request-params to the SparkServer and therefore the Post becomes too big. (3.5MB picture produces POST-request of approx. 7MB (2MB is the "hardcoded-jetty-maximum-post-size"))
I was quite happy with spark until discovering that it is not possible to configure embedded jetty server :cry:
+1 i was researching a lightweight way of creating a tiny web gui backed up by java (need to use rmi) and stumbled across sparkjava which really looked quite nice. But not able to solve jetty problems is a bit of a problem. But i might look at sparkjava again on future projects for sure and see how it evolves, it is very hard to create a project that does everything right the first time.
same problem,expect owner solve the problem
@perwendel are there any plans to expose parts of the embedded Jetty server? For me, I would like to be able to inject my own SocketConnectorFactory as I would like to enable http/2. This seems achievable is pass in via the ignite call from SparkInstance before any routes have been set up.
+1 for this.
Well I used a workaround... It's as ugly at it seems...
Copy the EmbeddedJettyServer, JettyFactory and JettyServer classes in your project.
In the copied JettyFactory change the new
to you copied EmbeddedJettyServer.
Now, here my main initialization (in kotlin, sorry):
val niceMap = HashMap<Any, EmbeddedServerFactory>()
niceMap.put(EmbeddedServers.defaultIdentifier(), CustomJettyFactory())
val evilsMap = object: HashMap<Any, EmbeddedServerFactory>(niceMap){
override fun put(key: Any, value: EmbeddedServerFactory): EmbeddedServerFactory? = value
}
val factoriesField = EmbeddedServers::class.java.getDeclaredField("factories")
factoriesField.isAccessible = true
factoriesField.set(null, evilsMap)
Roughly translated in java :
Map<Object, EmbeddedServerFactory> niceMap = new HashMap<>();
niceMap.put(EmbeddedServers.defaultIdentifier(), new CustomJettyFactory());
Map<Object, EmbeddedServerFactory> evilsMap = new HashMap<Object, EmbeddedServerFactory>(niceMap){
public EmbeddedServerFactory put(Object key, EmbeddedServerFactory value) {return value;}
};
Field factoriesField = EmbeddedServers.class.getDeclaredField("factories")
factoriesField.setAccessible(true)
factoriesField.set(null, evilsMap)
I am up-voting this issue as it seems to be really one of the very few missing bits for broader application of Spark.
Upvoted. We definitely need a nice, clean way of changing some of the basic Jetty settings. I'll look into this as well during the week.
Upvoted. I want to change the jetty session management to mongodb
If I look in the code it should be possible to run spark as a servlet in a different container... implying that you yourself can configure it to suit. That said, posting a picture in a form or posting very large forms can open the door to other problems. Security is one of the reasons to keep the size of a POST in check and making it < 2M...
I think the size of uploads allowed should ultimately be determined by the developer of the application and not a restriction imposed by the framework.
You're lucky you're not using PHP where the default was 128K. I think a reasonable default is useful especially since developers and especially the less experienced ones are probably going to forget to configure that. Or misconfigure it. Can I remind you about that time Exchange was configured as an open relay as a default?
Having a default totally makes sense, but you should still be able to configure the settings yourself if you need to.
Well in this case I think that you then must run spark in a different container as I indicated.
Is it possible to fix this problem?
FrameworkXYZ is a Java framework for developing ops-friendly, high-performance, RESTful web services.
What if I don't need to develop a "RESTfull webservice"? What if I need to develop a normal web app?
I do understand the problem. FrameworkXYZ is not for everybody. I don't like this solution either, but it worked for us. You have to make your own decision. Other solutions?
You could get the jetty source from git and change maxFormContentSize,maxFormKey in the Rquest.java. Except... you would have to do it each time you wanted to use a new version of Spark. Bleh!
You could look for other similar solutions..... You could contact Jetty authors, discuss the problem with them, introduce changes in your branch, create a pull request.... and wait for them to accept it. You could... pay them to do it for you ;) What can I say. There is no perfect solution.
How can I reproduce this? I can upload images much larger than this by setting the form to multipart.
eg. create a form with an input text and paste in very long text.
I would really like to be able to set a context path to allow different services on the same port. Jetty exposes this but it doesn't seem possible to get to that setting in the Spark embedded Jetty. This seems like an oversight. Had considered a configuration value to put in the front of every route but this feels 'wrong' when with Jetty you can easily set a context path. Can this be addressed?
A new project, a new look at spark. I'm surprised to see that this issue hasn't been solved. Isn't it possible to implement something similar like spring-boot does: http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/context/embedded/jetty/JettyServerCustomizer.html This gives you full control of the jetty Server object.
We will look at this when there is time. We are currently two persons working with Spark on our sparetime besides our dayjobs and our private lifes with all the time that goes into that. This seems to be a wanted functionality, hence we will prioritize this higher. However, one can't expect that everything everyone wants will be fixed in one day, or week or even in the next release. We are doing what we can. And for the record, this is not a forum for promoting other frameworks, it's for filing and discussing issues/feature requests etc for Spark.
@perwendel ignore the ungrateful assholes, that's just the internet being the internet.
Exposing Jetty as much as possible would likely take some pressure off you, since things like SSL would stop being your problem, leaving you free to concentrate on the declaration/routing thing that spark does so well.
Thanks for all the great work!
I will start looking at this now. If there are any proposals on how to do this the best way I'm all ears!
You've already got this proposal: https://github.com/perwendel/spark/issues/314#issuecomment-252940974 ;)
@perwendel thanks for your great work on this project. I love Spark for being small and clean. Having just started a new project with Spark, the prospect of convenient Jetty configuration is very welcome.
Merged PR #813 opens up possibility for any Jetty setting in Spark embedded.
Awesome!!!! BIG THX to everyone involved! :) Cheers
So its fixed in 2.6 but how do I use it ? Some explanation on how we can now configure to avoid "Form too large" exception' would be much appreciated.
Any example how the Jetty server is full configurable now?
Any example how the Jetty server is full configurable now?
using 2.2 with 9.0.2 ?
Any example how the Jetty server is full configurable now?
using 2.2 with 9.0.2 ?
I am on Sprarkjava 2.7.2.
I actually found out how to set a max queued request limit that I wanted. I don't see however how to completely configure a Jetty server and have access to all attributes.
EmbeddedServers.add(EmbeddedServers.Identifiers.JETTY, new EmbeddedJettyFactory().withThreadPool(
new QueuedThreadPool(200, 8, 60000, new BlockingArrayQueue<>(8, 8, 100))
));
Any example how the Jetty server is full configurable now?
using 2.2 with 9.0.2 ?
I am on Sprarkjava 2.7.2.
I actually found out how to set a max queued request limit that I wanted. I don't see however how to completely configure a Jetty server and have access to all attributes.
EmbeddedServers.add(EmbeddedServers.Identifiers.JETTY, new EmbeddedJettyFactory().withThreadPool( new QueuedThreadPool(200, 8, 60000, new BlockingArrayQueue<>(8, 8, 100)) ));
This section had threads, ssl etc. http://sparkjava.com/documentation#embedded-web-server
For further you need XML config. https://www.eclipse.org/jetty/documentation/9.4.x/quick-start-configure.html#quickstart-config-how
I've tried to put together an howto as simple as I could manage, explaining step by step: http://blog.pythonaro.com/2019/02/how-to-customise-jetty-embedded-in.html
I'm using SparkJava 2.2 which is using Jetty 9.0.2.
I'm getting "Form too large" exception which is thrown by Jetty. I know how to solve this problem if I was using Jetty directly:
http://www.eclipse.org/jetty/documentation/current/setting-form-size.html
I've already checked that setting env.properties has no effect. Debugger doesn't even stop at any breakpoint set within org.eclipse.jetty.server.handlerContextHandler... Plus when it stops at org.eclipse.jetty.server.Request breakpoints, _context property is null.
Is there any way to create context for Jetty requests? Is there any way to alter maxFormContentSize?