eclipse-vertx / vert.x

Vert.x is a tool-kit for building reactive applications on the JVM
http://vertx.io
Other
14.25k stars 2.07k forks source link

ErrorDataDecoderException: Bad string #2616

Open stsefanenko opened 6 years ago

stsefanenko commented 6 years ago

Looks like more netty bug, but I report here for investigation. I have a simple configuration like:

        Vertx vertx = Vertx.vertx();
        Router router = Router.router(vertx).exceptionHandler(ex -> log.error("error", ex));
        router.route().handler(BodyHandler.create());  // capture POST body parameters
        router.route().handler(CorsHandler.create("*").allowedMethod(HttpMethod.GET));  // allow cross-domain requests from anywhere
        router.route().handler(CookieHandler.create());  // capture cookies
        router.route("/alive").handler(this::handleAlive);
        HttpServer trackerServer = vertx.createHttpServer(opts);
        trackerServer.requestHandler(router::accept)
                .listen(Integer.parseInt(props.getProperty("server.tracker.port")), props.getProperty("server.tracker.host"));

For special requests the code fails before my handler. Request like:

POST <URL> HTTP/1.1
Content-Type: application/x-www-form-urlencoded

BODY:
test=org.springframework.core.SerializableTypeWrapper$TypeProviderxrjava.lang.reflect.Proxy�'� �C�Lht%Ljava/lang/reflect/InvocationHandler;xpsr2sun.reflect.annotation.AnnotationInvocationHandlerU���~�LmemberValuestLjava/util/Map;LtypetLjava/lang/Class;xpsrjava.util.HashMap���`�F

Error:

io.netty.handler.codec.http.multipart.HttpPostRequestDecoder$ErrorDataDecoderException: Bad string: 'org.springframework.core.SerializableTypeWrapper$TypeProviderxrjava.lang.reflect.Proxy�'� �C�Lht%Ljava/lang/reflect/InvocationHandler;xpsr2sun.reflect.annotation.AnnotationInvocationHandlerU���~�LmemberValuestLjava/util/Map;LtypetLjava/lang/Class;xpsrjava.util.HashMap���`�F'
    at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.decodeAttribute(HttpPostStandardRequestDecoder.java:646)
    at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.setFinalBuffer(HttpPostStandardRequestDecoder.java:631)
    at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.parseBodyAttributes(HttpPostStandardRequestDecoder.java:595)
    at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.parseBody(HttpPostStandardRequestDecoder.java:360)
    at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.offer(HttpPostStandardRequestDecoder.java:289)
    at io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.offer(HttpPostStandardRequestDecoder.java:46)
    at io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.offer(HttpPostRequestDecoder.java:227)
    at io.vertx.core.http.impl.HttpServerRequestImpl.handleEnd(HttpServerRequestImpl.java:395)
    at io.vertx.core.http.impl.ServerConnection.handleLastHttpContent(ServerConnection.java:475)

Vertx version: 3.5.0

vietj commented 6 years ago

your HTTP request body seems to not be in the right encoding, the body as you show looks like to have invalid characters and is not x-www-form-urlencoded

stsefanenko commented 6 years ago

Yes, string is not urlencoded. True to say, may be it's ok to have such exception, but for me will be better to have some warning may be. And response code is 500 for such case which looks strange. May be will better to return 400 Bad Request?

vietj commented 6 years ago

can you check which part of vertx or netty takes this decision to send a 500 error ?

there is already some specific handling of errors : https://github.com/eclipse/vert.x/blob/master/src/main/java/io/vertx/core/http/impl/Http1xServerConnection.java#L497

in this case indeed we are sending a 400 errors

On 6 Sep 2018, at 15:39, stsefanenko notifications@github.com wrote:

Yes, string is not urlencoded. True to say, may be it's ok to have such exception, but for me will be better to have some warning may be. And response code is 500 for such case which looks strange. May be will better to return 400 Bad Request?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eclipse/vert.x/issues/2616#issuecomment-419096901, or mute the thread https://github.com/notifications/unsubscribe-auth/AANxiopkDnmxvz0kqUe5SMT8_yTFmrjNks5uYSWcgaJpZM4WcwlV.

stsefanenko commented 6 years ago

From vertx-web https://github.com/vert-x3/vertx-web/blob/8da283b9e783b0eb5d08d97fa89055019333ef84/vertx-web/src/main/java/io/vertx/ext/web/impl/RoutingContextImplBase.java#L149