Reputation: 13120
How do I configure Jetty options via Spark framework ?
Im getting the problem below when i submit a large form. The solution for Jetty is documented at Form too Large Exception
But Jetty is hidden from me using Spark Framework, how would I configure to resolve this.
org.eclipse.jetty.http.BadMessageException: 400: Unable to parse form content
at org.eclipse.jetty.server.Request.getParameters(Request.java:373)
at org.eclipse.jetty.server.Request.getParameter(Request.java:1016)
at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:194)
at spark.Request.queryParams(Request.java:283)
at spark.http.matching.RequestWrapper.queryParams(RequestWrapper.java:141)
at com.jthink.songkong.server.callback.ServerEditSongs.startTask(ServerEditSongs.java:45)
at com.jthink.songkong.server.CmdRemote.lambda$null$62(CmdRemote.java:171)
at spark.RouteImpl$1.handle(RouteImpl.java:72)
at spark.http.matching.Routes.execute(Routes.java:61)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:130)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1568)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:564)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:59
1)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Form too large: 273433 > 200000
at org.eclipse.jetty.server.Request.extractFormParameters(Request.java:516)
at org.eclipse.jetty.server.Request.extractContentParameters(Request.java:454)
at org.eclipse.jetty.server.Request.getParameters(Request.java:369)
... 26 more
Upvotes: 3
Views: 4337
Reputation: 9756
A bit of history:
I looked up a little on the git repo of spark and found that this issue was raised on 3 Aug 2015, here issue 314
Perwendel (the guy maintaining Spark) added the Much wanted
label on 11 Oct 2016
Then started working on it on 3 Nov 2016
He merged the Pull Request PR #813 to opens up possibility for any Jetty setting in Spark embedded.
I looked into the modifications added in this PR and I think you might be able to configure something by implementing the JettyServerFactory, if you overwrite the public Server create(...)
method, you can return your custom Server:
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;
}
}
Please have a try and see if you can make this work, I don't have anything setup to try it, but I think this is the correct path to configure your Jetty server.
Upvotes: 5
Reputation: 49515
That is controlled via a org.eclipse.jetty.server.Server
attribute ..
org.eclipse.jetty.server.Request.maxFormContentSize=<int>
for max form size in bytes
org.eclipse.jetty.server.Request.maxFormKeys=<int>
for max form keys (limit here exists to combat hash key collision DoS techniques).
Use a Server.setAttribute(String name, Object value)
call.
Upvotes: 1