簡體   English   中英

如何處理具有 QAF Webservice 正文的 REST API 請求的 GET 請求

[英]How to handle a GET request for REST API request which is having a body with QAF Webservice

我正在使用對 API 自動化的QAF Web 服務支持 我有一個GET請求存在正文的情況。 如果我使用屬性文件或 xml 文件傳遞請求,則在執行時我收到404 not found 響應。 如果GET請求不存在正文,則它在該場景中可以正常工作,沒有任何問題。 但不是GET請求有一個主體。 調試后發現,如果GET請求有body,最后發現jersey客戶端API將請求從GET變為POST 請讓我知道如何使用 QAF WebService 處理這種情況。

謝謝,

您可以使用 apache HttpClient ,這將允許具有獲取請求的主體。 為了使用 apache HttpClient,您需要提供 RestClientFactory 的實現並使用屬性RestClientFactory進行rest.client.impl

這是來自 qaf 用戶組的示例代碼

package qaf.example.tests;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;

import com.qmetry.qaf.automation.ws.rest.RestClientFactory;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientHandler;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.client.apache.ApacheHttpClient;
import com.sun.jersey.client.apache.ApacheHttpClientHandler;
import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;

/**
 * @author chirag
 *
 */
public class ApacheClientProvider extends RestClientFactory {

    @Override
    protected Client createClient() {
        MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
        connectionManager.getParams().setConnectionTimeout(5000);
        connectionManager.getParams().setSoTimeout(1000);
        connectionManager.getParams().setDefaultMaxConnectionsPerHost(10);
        HttpClient httpClient = new HttpClient(connectionManager);
        ApacheHttpClientHandler clientHandler = new ApacheHttpClientHandler(httpClient);
        ClientHandler root = new ApacheHttpClient(clientHandler );
        ClientConfig config = new DefaultApacheHttpClientConfig();
        Client client = new Client(root, config);
        return client;
    }

}

為了使用它,請使用rest.client.impl屬性注冊您的 class,在上述情況下:

rest.client.impl=qaf.example.tests.ApacheClientProvider

暫無
暫無

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

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