Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Jetty settings through SparkJava #314

Closed
QMG-kazala opened this issue Aug 3, 2015 · 36 comments

Comments

@QMG-kazala
Copy link

@QMG-kazala QMG-kazala commented Aug 3, 2015

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?

@keltik85

This comment has been minimized.

Copy link

@keltik85 keltik85 commented Sep 24, 2015

Same problem here.

@keltik85

This comment has been minimized.

Copy link

@keltik85 keltik85 commented Sep 25, 2015

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"))

@tipsy tipsy changed the title How to change Jetty settings through SparkJava? / Form too Large Exception / org.eclipse.jetty.server.Request.maxFormContentSize Changing Jetty settings through SparkJava Nov 22, 2015
@koraytaylan

This comment has been minimized.

Copy link

@koraytaylan koraytaylan commented Jan 5, 2016

I was quite happy with spark until discovering that it is not possible to configure embedded jetty server 😢

@tinustate

This comment has been minimized.

Copy link

@tinustate tinustate commented Jan 23, 2016

+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.

@Melody12ab

This comment has been minimized.

Copy link

@Melody12ab Melody12ab commented Feb 29, 2016

same problem,expect owner solve the problem

@tom-smalls

This comment has been minimized.

Copy link

@tom-smalls tom-smalls commented Mar 14, 2016

@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.

@Maunte

This comment has been minimized.

Copy link

@Maunte Maunte commented May 5, 2016

+1 for this.

@ylemoigne

This comment has been minimized.

Copy link

@ylemoigne ylemoigne commented May 8, 2016

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)
@1inuxoid

This comment has been minimized.

Copy link

@1inuxoid 1inuxoid commented May 12, 2016

I am up-voting this issue as it seems to be really one of the very few missing bits for broader application of Spark.

@kshep92

This comment has been minimized.

Copy link

@kshep92 kshep92 commented May 15, 2016

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.

@winterdl

This comment has been minimized.

Copy link

@winterdl winterdl commented May 17, 2016

Upvoted. I want to change the jetty session management to mongodb

@ruurd

This comment has been minimized.

Copy link
Contributor

@ruurd ruurd commented May 17, 2016

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...

@kshep92

This comment has been minimized.

Copy link

@kshep92 kshep92 commented May 17, 2016

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.

@ruurd

This comment has been minimized.

Copy link
Contributor

@ruurd ruurd commented May 17, 2016

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?

@danechitoaie

This comment has been minimized.

Copy link

@danechitoaie danechitoaie commented May 17, 2016

Having a default totally makes sense, but you should still be able to configure the settings yourself if you need to.

@ruurd

This comment has been minimized.

Copy link
Contributor

@ruurd ruurd commented May 17, 2016

Well in this case I think that you then must run spark in a different container as I indicated.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jun 20, 2016

Is it possible to fix this problem?

@danechitoaie

This comment has been minimized.

Copy link

@danechitoaie danechitoaie commented Jun 20, 2016

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?

@QMG-kazala

This comment has been minimized.

Copy link
Author

@QMG-kazala QMG-kazala commented Jun 20, 2016

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.

@tipsy

This comment has been minimized.

Copy link
Collaborator

@tipsy tipsy commented Jun 20, 2016

How can I reproduce this? I can upload images much larger than this by setting the form to multipart.

@QMG-kazala

This comment has been minimized.

Copy link
Author

@QMG-kazala QMG-kazala commented Jun 20, 2016

eg. create a form with an input text and paste in very long text.

@swellard

This comment has been minimized.

Copy link

@swellard swellard commented Jun 21, 2016

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?

jeckep added a commit to jeckep/chat-room that referenced this issue Sep 4, 2016
perwendel/spark#366
perwendel/spark#314
not implemented yet

so we cannot replace jetty HashedSessionManager
@tinustate

This comment has been minimized.

Copy link

@tinustate tinustate commented Oct 11, 2016

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.

@perwendel

This comment has been minimized.

Copy link
Owner

@perwendel perwendel commented Oct 11, 2016

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.

@toyg

This comment has been minimized.

Copy link

@toyg toyg commented Oct 20, 2016

@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!

@perwendel

This comment has been minimized.

Copy link
Owner

@perwendel perwendel commented Nov 3, 2016

I will start looking at this now. If there are any proposals on how to do this the best way I'm all ears!

@maxxyme

This comment has been minimized.

Copy link

@maxxyme maxxyme commented Nov 3, 2016

You've already got this proposal: #314 (comment) ;)

@streamflex

This comment has been minimized.

Copy link

@streamflex streamflex commented Nov 7, 2016

@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.

@perwendel

This comment has been minimized.

Copy link
Owner

@perwendel perwendel commented Apr 8, 2017

Merged PR #813 opens up possibility for any Jetty setting in Spark embedded.

@perwendel perwendel closed this Apr 8, 2017
@QMG-kazala

This comment has been minimized.

Copy link
Author

@QMG-kazala QMG-kazala commented Apr 10, 2017

Awesome!!!!
BIG THX to everyone involved! :)
Cheers

@ijabz

This comment has been minimized.

Copy link

@ijabz ijabz commented Mar 7, 2018

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.

@kliakos

This comment has been minimized.

Copy link
Contributor

@kliakos kliakos commented Feb 6, 2019

Any example how the Jetty server is full configurable now?

@tweenietomatoes

This comment has been minimized.

Copy link
Contributor

@tweenietomatoes tweenietomatoes commented Feb 6, 2019

Any example how the Jetty server is full configurable now?

using 2.2 with 9.0.2 ?

@kliakos

This comment has been minimized.

Copy link
Contributor

@kliakos kliakos commented Feb 6, 2019

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))
));
@tweenietomatoes

This comment has been minimized.

Copy link
Contributor

@tweenietomatoes tweenietomatoes commented Feb 6, 2019

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

@toyg

This comment has been minimized.

Copy link

@toyg toyg commented Feb 11, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.