https://linen.dev logo
#help
Title
# help
j

Jackie chen

08/11/2023, 1:37 AM
Hello Everyone Looks like this is a bug in wiremock when it can’t merge query parameters (e.g. http://<host>?NAME=R%83%69%83%78%83%43%83%59) that are not UTF-8 encoding, e.g. if there is a query parameter that is Windows-31J encoding, it throws the following exception: Could you please help? Http 400
Copy code
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>Error 400 Bad query encoding</title>
</head>

<body>
	<h2>HTTP ERROR 400 Bad query encoding</h2>
	<table>
		<tr>
			<th>URI:</th>
		</tr>
		<tr>
			<th>STATUS:</th>
			<td>400</td>
		</tr>
		<tr>
			<th>MESSAGE:</th>
			<td>Bad query encoding</td>
		</tr>
		<tr>
			<th>SERVLET:</th>
			<td>com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet-345e2f53</td>
		</tr>
		<tr>
			<th>CAUSED BY:</th>
			<td>org.eclipse.jetty.http.BadMessageException: 400: Bad query encoding</td>
		</tr>
		<tr>
			<th>CAUSED BY:</th>
			<td>org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! byte 83 in state 0</td>
		</tr>
	</table>
	<h3>Caused by:</h3>
	<pre>org.eclipse.jetty.http.BadMessageException: 400: Bad query encoding
	at org.eclipse.jetty.server.Request.mergeQueryParameters(Request.java:2450)
	at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:201)
	at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:79)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.forwardToFilesContext(WireMockHandlerDispatchingServlet.java:320)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.access$300(WireMockHandlerDispatchingServlet.java:46)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet$ServletHttpResponder.respondTo(WireMockHandlerDispatchingServlet.java:212)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet$ServletHttpResponder.respondSync(WireMockHandlerDispatchingServlet.java:173)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet$ServletHttpResponder.respond(WireMockHandlerDispatchingServlet.java:167)
	at com.github.tomakehurst.wiremock.http.AbstractRequestHandler.handle(AbstractRequestHandler.java:97)
	at com.github.tomakehurst.wiremock.servlet.WireMockHandlerDispatchingServlet.service(WireMockHandlerDispatchingServlet.java:142)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1617)
	at org.eclipse.jetty.servlets.CrossOriginFilter.handle(CrossOriginFilter.java:310)
	at org.eclipse.jetty.servlets.CrossOriginFilter.doFilter(CrossOriginFilter.java:264)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1604)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:545)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:767)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:500)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! byte 83 in state 0
	at org.eclipse.jetty.util.Utf8Appendable.appendByte(Utf8Appendable.java:254)
	at org.eclipse.jetty.util.Utf8Appendable.append(Utf8Appendable.java:155)
	at org.eclipse.jetty.util.UrlEncoded.decodeUtf8To(UrlEncoded.java:355)
	at org.eclipse.jetty.util.UrlEncoded.decodeTo(UrlEncoded.java:228)
	at org.eclipse.jetty.util.UrlEncoded.decodeTo(UrlEncoded.java:211)
	at org.eclipse.jetty.server.Request.mergeQueryParameters(Request.java:2446)
	... 37 more
This is not happening in Record and playback mode (proxy request to the destination). It fails before hitting stub.
t

Tom

08/12/2023, 2:53 PM
Hi @Jackie chen thanks for flagging this. It looks like this is probably a bug, so please could you raise an issue in GitHub with the repro steps?
j

Jackie chen

08/12/2023, 10:25 PM
@Tom I have raised the issue in the GitHub wit the repro steps https://github.com/wiremock/wiremock/issues/2313. Could you please also fix this bug in wiremock-jre 2.33.2? as i have been using java 8. Thank you.
t

Tom

08/14/2023, 10:32 AM
Thanks for raising this @Jackie chen. Unfortunately we’re not doing any more releases of 2.x now as we can’t update a number of key dependencies due to their being Java 11+, and consequently we get a flurry of security scanner/CVE errors sent our way if we attempt it. There is now a Testcontainers (Docker) edition of WireMock 3.x which will work with Java 8, so it might be worth trying this out once we’ve shipped the fix.
j

Jackie chen

08/14/2023, 10:45 AM
Hi @Tom i am using wiremock-jre8 2.33.2 in my maven springboot project, which is compatible with Java 8. is there a way to include WireMock 3.x in my maven project that is still compatible with Java 8?
t

Tom

08/14/2023, 11:12 AM
Not by directly adding it to your dependencies, but you can do it by running the WireMock 3.x server via Testcontainers (which at the moment does still support Java 😎.
j

Jackie chen

08/14/2023, 12:02 PM
@Tom i got it. is there a workaround on this issue? i tried using StubRequestFilter to change the non-utf8 encoding parameter but the exception is still thrown, i would like it to match stub data somehow.