简体   繁体   English

播放框架似乎是双重发布我的WS Async Post

[英]Play framework seems to be double posting my WS Async Post

I'm doing a long running post using WSAsync (i've tried using post() and postAsync() with the same results) 我正在使用WSAsync进行长时间运行的帖子(我尝试使用具有相同结果的post()和postAsync())

What seems to be happening is that WS is doing the post with the proper multipart content type, it waits a few ms then does the post again without the content type (why it's doing it twice i've got no idea), the service that it's calling the responds with an HTTP 415 and play then errors out. 似乎正在发生的事情是,WS使用适当的多部分内容类型来执行发布,它会等待几毫秒,然后在没有内容类型的情况下再次执行发布(为什么这样做两次,我也不知道),该服务它使用HTTP 415调用响应,然后播放然后出错。 I'll post the Trace output from play and the method doing the call. 我将发布play的Trace输出以及进行调用的方法。

METHOD 方法

public static void performBatchImport(AssetBatchImport batchImport){
    validation.valid(batchImport);
    if (validation.hasErrors()) {
            putAssetLookupValuesInContext();
            render("@add", batchImport);
    }
    FileParam fp = new FileParam(batchImport.import_file, "file");
    Promise<HttpResponse> fresponse =
WS.url(ApiUtils.getAssetBaseUri() + "batch-
import").setParameter("header_record_present",
batchImport.header_record_present)
                    .setParameter("account_id",
batchImport.account.id).mimeType("multipart/form-
data").files(fp).timeout("1h").postAsync();
    HttpResponse response = null;
    try {
            response = fresponse.get(1, TimeUnit.HOURS);
    }
    catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }
    catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }
    catch (TimeoutException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }

    if(response != null && RestUtils.isOk(response)){
            AssetImportBatch batch =
GsonFactory.getGson().fromJson(response.getString(),
AssetImportBatch.class);
            flash.put("batchId", batch.id);
            flash.keep();
            add(batch.id);
    }else if(RestUtils.isNotSupported(response)){
            //redirect
            flash.success("Your request is currently processing");
            add(null);
    }
    else{
            ApiUtils.processErrorResponse("batchImport", response,
validation);
            putAssetLookupValuesInContext();
            render("@add", batchImport);
    }
}

TRACE 跟踪

17:12:05,776 DEBUG ~
Using cached Channel [id: 0x00f02e1b, /127.0.0.1:50050 => localhost/
127.0.0.1:8080]
 for request
DefaultHttpRequest(chunked: false)
POST /our-product/api/assets/batch-import HTTP/1.1
Host: localhost:8080
Authorization: Bearer d3173239-3e94-4324-be4b-asdfasw452as
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0
Content-Type: multipart/form-data; boundary=JIbZxjblkj0oG0S02OWe47-
Gx_ZlUlNo9Ct
Content-Length: 145758

17:12:18,631 TRACE ~ 0 idle channels closed (times: 1st-loop=0, 2nd-
loop=0).

17:12:36,216 DEBUG ~ Channel Closed: [id: 0x00f02e1b, /
127.0.0.1:50050 :> localhost/127.0.0.1:8080] with attachment
NettyResponseFuture{currentRetry=0,
        isDone=false,
        isCancelled=false,
        asyncHandler=play.libs.ws.WSAsync$WSAsyncRequest$1@d5d62e,
        responseTimeoutInMs=3600000,
        nettyRequest=DefaultHttpRequest(chunked: false)
POST /our-product/api/assets/batch-import HTTP/1.1
Host: localhost:8080
Authorization: Bearer d3173239-3e94-4324-be4b-asdfasw452as
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0
Content-Type: multipart/form-data; boundary=JIbZxjblkj0oG0S02OWe47-
Gx_ZlUlNo9Ct
Content-Length: 145758,
        content=null,
        uri=http://localhost:8080/our-product/api/assets/batch-import,
        keepAlive=true,
        httpResponse=null,
        exEx=null,
        redirectCount=0,

reaperFuture=com.ning.http.client.providers.netty.NettyAsyncHttpProvider
$ReaperFuture@e08014,
        inAuth=false,
        statusReceived=false,
        touch=1322691125777}
17:12:36,216 DEBUG ~ Trying to recover request
DefaultHttpRequest(chunked: false)
POST /our-product/api/assets/batch-import HTTP/1.1
Host: localhost:8080
Authorization: Bearer d3173239-3e94-4324-be4b-asdfasw452as
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0
Content-Type: multipart/form-data; boundary=JIbZxjblkj0oG0S02OWe47-
Gx_ZlUlNo9Ct
Content-Length: 145758

17:12:36,217 DEBUG ~
Non cached request
DefaultHttpRequest(chunked: false)
POST /our-product/api/assets/batch-import HTTP/1.1
Host: localhost:8080
Authorization: Bearer d3173239-3e94-4324-be4b-asdfasw452as
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0
Content-Length: 145758

using Channel
[id: 0x00f8dcfe]

17:12:36,260 DEBUG ~

Request DefaultHttpRequest(chunked: false)
POST /our-product/api/assets/batch-import HTTP/1.1
Host: localhost:8080
Authorization: Bearer d3173239-3e94-4324-be4b-asdfasw452as
Connection: keep-alive
Accept: */*
User-Agent: NING/1.0
Content-Length: 145758

Response DefaultHttpResponse(chunked: false)
HTTP/1.1 415 Unsupported Media Type
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1424
Server: Jetty(7.4.5.v20110725)

Try to use the await-method provided by Play. 尝试使用Play提供的await方法。 This methods suspends the controller until the Promise has a result. 此方法将挂起控制器,直到Promise产生结果为止。

Promise<HttpResponse> promisedResponse = WS.url("http://service.example.com").postAsync();
HttpResponse actualResponse = await(promisedResponse);

Further information and snippets here: Play! 进一步的信息和摘要在这里: 播放! - Asynchronous programming with HTTP -使用HTTP进行异步编程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM