第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如果沒有 block() 則不會(huì)發(fā)送請(qǐng)求

如果沒有 block() 則不會(huì)發(fā)送請(qǐng)求

繁星coding 2023-10-19 21:16:10
我想使用此 webflux 客戶端代碼發(fā)送帶回復(fù)和不帶回復(fù)的 POST 請(qǐng)求。我嘗試了這個(gè)代碼實(shí)現(xiàn):public class RestClientBuilder {    private String token;    private String username;    private String password;    private URL gatewayUrl;    private SslContextBuilder sslContextBuilder;    public static RestClientBuilder builder() {        return new RestClientBuilder();    }    public RestClientBuilder token(String token) {        this.token = validateAndTrim(token, "Token");        return this;    }    public RestClientBuilder usernamePassword(String username, String password) {        this.username = validateAndTrim(username, "Username");        this.password = validateAndTrim(password, "Password");        return this;    }    private String validateAndTrim(String value, final String parameter) {        if (value == null || value.trim().isEmpty()) {            throw new IllegalArgumentException(parameter + " is empty");        }        return value.trim();    }    public RestClientBuilder gatewayUrl(String gatewayUrl) {        String urlSt = validateAndTrim(gatewayUrl, "Gateway URL");        try {            this.gatewayUrl = new URL(urlSt);        } catch (MalformedURLException e) {            throw new IllegalArgumentException("Malformed URL: " + urlSt, e);        }        return this;    }    public RestClientBuilder truststore(File truststoreFile) {        getSslContextBuilder().trustManager(truststoreFile);        return this;    }    public RestClientBuilder sslCertificate(File keyCertChainFile, File keyFile, String keyPassword) {        getSslContextBuilder().keyManager(keyCertChainFile, keyFile, keyPassword);        return this;    }    public RestClient build() throws SSLException {        SslContext sslContext = sslContextBuilder != null ? sslContextBuilder.build() : null;        return new RestClient(gatewayUrl.toString(), token, username, password, sslContext);    }
查看完整描述

3 回答

?
桃花長(zhǎng)相依

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊

每當(dāng)您使用 Spring-webflux 時(shí),您都必須記住一件事。即你不必打破你的鏈條。因?yàn)橛斜匾?,有人?yīng)該在你的鏈上調(diào)用訂閱。因?yàn)樗m用于 RXJava 規(guī)范。


如果你打破了鏈條,那么你必須打電話,block()這是不推薦的。


您必須按以下方式修改您的代碼。


讓我們假設(shè)您有一個(gè)處理程序正在調(diào)用您的collectEnvironmentData()方法,并且您的方法正在調(diào)用遠(yuǎn)程服務(wù)。


public  Mono<ServerResponse> handelerMethod(ServerRequest request){

  return collectEnvironmentData().flatMap(aVoid -> ServerResponse.ok().build());

}

你的方法應(yīng)該修改為


public Mono<Void> collectEnvironmentData() throws JAXBException {


ReportRequest report = new ReportRequest();

report.setVersion("1.0");


RestClient client = null;

try {

    client = RestClientBuilder.builder()

            .gatewayUrl(URL2)

//                .token(contract.getTerminal_token())

//                  .usernamePassword("user", "password")

//                .truststore(new File("server.pem"))

//                .sslCertificate(new File("client.pem"), new File("clientKey.p8"), 

//"secret").build();

} catch (SSLException e) {

    e.printStackTrace();

}


return client.executeOnly(report);

}

按照上述方式改變你的實(shí)現(xiàn),希望它能奏效。


查看完整回答
反對(duì) 回復(fù) 2023-10-19
?
胡子哥哥

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊

我將如何實(shí)現(xiàn)你的方法是:


public Mono<Void> executeOnly(ReportRequest transaction) {

    Mono<ReportRequest> transactionMono = Mono.just(transaction);

    return client.post().uri(gatewayUrl)

        .accept(MediaType.APPLICATION_XML)

        .contentType(MediaType.APPLICATION_XML)

        .body(transaction, ReportRequest.class)

        .exchange()

        .then();

}

然后我會(huì)按如下方式使用它:


client.executeOnly(report).subscribe()


查看完整回答
反對(duì) 回復(fù) 2023-10-19
?
長(zhǎng)風(fēng)秋雁

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊

將 更改method return type為Mono<Void>進(jìn)行端到端流式傳輸。


public void collectEnvironmentData() throws JAXBException {


    ReportRequest report = new ReportRequest();

    report.setVersion("1.0");


    RestClient client = null;

    try {

        client = RestClientBuilder.builder()

                .gatewayUrl(URL2)

                .build();

    } catch (SSLException e) {

        e.printStackTrace();

    }


    return client.executeOnly(report);


}

或者您也可以訂閱Mono


client.executeOnly(report).subscribe();


查看完整回答
反對(duì) 回復(fù) 2023-10-19
  • 3 回答
  • 0 關(guān)注
  • 276 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)