perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Documentation lacks information/examples on setting Jetty request size #1021

Open editicalu opened 6 years ago

editicalu commented 6 years ago

I read that it is possible now to tweak the Spark internal Jetty server #314. However, I can't find any example on how to use this to change the request size, as my project gets "Form too large" exceptions all the time.

It would be useful to have at least an example on the official documentation.

jarlah commented 5 years ago

A quick google search tells me how. But thats not guaranteed to be the correct way. Https://blog.codecentric.de/en/2017/07/fine-tuning-embedded-jetty-inside-spark-framework/

jarlah commented 5 years ago

I have added some jetty overrides in one of my OS projects. The use of spark however is temporary. I am trying to make the server framework agnostic.

You can see what i have done here

https://github.com/freeacs/freeacs/blob/master/tr069/src/main/java/com/github/freeacs/App.java

editicalu commented 5 years ago

Thank you, but I already worked around the problem, so it is no issue for me anymore. However, I guess this would be useful for newcomers.

On 8 October 2018 20:26:15 GMT+02:00, "Jarl André Hübenthal" notifications@github.com wrote:

I have added some jetty overrides in one of my OS projects. The use of spark however is temporary. I am trying to make the server framework agnostic.

You can see what i have done here

https://github.com/freeacs/freeacs/blob/master/tr069/src/main/java/com/github/freeacs/App.java

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/perwendel/spark/issues/1021#issuecomment-427933869

-- Sent from my Android device with K-9 Mail. Please excuse my brevity.

toyg commented 5 years ago

I wrote a more comprehensive post: http://blog.pythonaro.com/2019/02/how-to-customise-jetty-embedded-in.html

Because of the current architecture, the topic is not simple enough to fit in the fancy web docs. I think there might be some work to be done to expose this sort of thing in an easy way. To be fair, some of the limitations are due to jetty himself.

ilvez commented 4 years ago

@editicalu I would have been nice to describe the workaround as well.

Anyway currently I'm left to digging into Jetty internals to fix "Form too large" issue. Some official documentation from Spark side would be nice.

ilvez commented 4 years ago

Anyway, got it working with accepted answer from here: https://stackoverflow.com/questions/49054092/how-do-i-configure-jetty-to-allow-larger-forms-when-used-with-spark-framework

Code example:

public class Main {
  public static void main(String ...args) {
    CustomJettyServerFactory customJettyServerFactory = new CustomJettyServerFactory();
    EmbeddedServers.add(
        EmbeddedServers.Identifiers.JETTY, 
        new EmbeddedJettyFactory(customJettyServerFactory));
  }
}

class CustomJettyServerFactory implements JettyServerFactory {
  @Override
  public Server create(int maxThreads, int minThreads, int threadTimeoutMillis) {
    Server server = new Server();
    server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 1000000);
    return server;
  }

  @Override
  public Server create(ThreadPool threadPool) {
    return null;
  }
}
editicalu commented 4 years ago

@ilvez the workaround was to make my requests smaller. :)