Restlet http handler failed: The “/” Character isn't allowed in a media type parameter name


问题概述: 现在用支付宝即时到账业务,异步通知出现了问题:
apache 的 error message 是:
java.lang.IllegalArgumentException: The Content Type could not be read.
at org.restlet.engine.header.ContentType. <init> (ContentType.java:155)
at org.restlet.engine.adapter.ServerCall.getRequestEntity(ServerCall.java:243)
at org.restlet.engine.adapter.HttpRequest.getEntity(HttpRequest.java:503)
at org.restlet.engine.application.Decoder.beforeHandle(Decoder.java:124)
at org.restlet.routing.Filter.handle(Filter.java:204)
at org.restlet.routing.Filter.doHandle(Filter.java:159)
at org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:155)
at org.restlet.routing.Filter.handle(Filter.java:206)
at org.restlet.routing.Filter.doHandle(Filter.java:159)
at org.restlet.routing.Filter.handle(Filter.java:206)
at org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:211)
...
at org.restlet.routing.Router.handle(Router.java:648)
at org.restlet.routing.Filter.doHandle(Filter.java:159)
at
Caused by: java.io.IOException: The "/" character isn't allowed in a media type parameter name. at org.restlet.engine.header.ContentTypeReader.readValue(ContentTypeReader.java:178) at org.restlet.engine.header.ContentType.(ContentType.java:148) ... 41 more Error while handling an HTTP server call: Error while handling an HTTP server call </init>

我已经试过加annotation:


 @Post("application/json")

或者加request headers:


 ClientResource cr = new ClientResource("...");
        Series<Header> headers = (Series<Header>)      cr.getRequestAttributes().get("org.restlet.http.headers");
     if (headers == null) {              
        headers = new Series(Header.class); 
        headers.add("Access-Control-Allow-Origin", "*");
        headers.add("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
        headers.add("Access-Control-Allow-Headers", "Content-Type");                
        headers.add("Access-Control-Allow-Headers", "authCode");
        headers.add("Access-Control-Allow-Headers", "origin, x-requested-with, content-type");
    } 

    if (headers != null) {              
        headers.add("Content-Type", "application/json");                
        cr.getRequestAttributes().put("org.restlet.http.headers", headers); 
    }

但是都没有解决问题,看起来支付宝发的异步post在进入post code handler 之前就因为restlet的content-type 问题挂掉了
求大神指点

异步通知 支付宝即时到账 content-type java restlet

筷子不可食用 10 years, 3 months ago

Your Answer