簡體   English   中英

播放框架似乎是雙重發布我的WS Async Post

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

我正在使用WSAsync進行長時間運行的帖子(我嘗試使用具有相同結果的post()和postAsync())

似乎正在發生的事情是,WS使用適當的多部分內容類型來執行發布,它會等待幾毫秒,然后在沒有內容類型的情況下再次執行發布(為什么這樣做兩次,我也不知道),該服務它使用HTTP 415調用響應,然后播放然后出錯。 我將發布play的Trace輸出以及進行調用的方法。

方法

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);
    }
}

跟蹤

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)

嘗試使用Play提供的await方法。 此方法將掛起控制器,直到Promise產生結果為止。

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

進一步的信息和摘要在這里: 播放! -使用HTTP進行異步編程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM