简体   繁体   English

如何处理具有 QAF Webservice 正文的 REST API 请求的 GET 请求

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

I am using QAF Webservice support for API automation.我正在使用对 API 自动化的QAF Web 服务支持 I have a case where a GET request has a body present.我有一个GET请求存在正文的情况。 If I pass the request as either using properties file or xml file, on executing I am getting 404 not found response.如果我使用属性文件或 xml 文件传递请求,则在执行时我收到404 not found 响应。 If the GET request does not have a body present, it works fine in that scenario without any issues.如果GET请求不存在正文,则它在该场景中可以正常工作,没有任何问题。 But not with GET request having a body.但不是GET请求有一个主体。 Upon debugging, found that jersey client API at the end changes the request from GET to POST if a GET request has a body.调试后发现,如果GET请求有body,最后发现jersey客户端API将请求从GET变为POST Please let me know on how to handle this scenario using QAF WebService.请让我知道如何使用 QAF WebService 处理这种情况。

Thanks,谢谢,

You can use apache HttpClient that will allow to have body with get request.您可以使用 apache HttpClient ,这将允许具有获取请求的主体。 In order to use apache HttpClient, you need to provide implementation of RestClientFactory and register using property rest.client.impl .为了使用 apache HttpClient,您需要提供 RestClientFactory 的实现并使用属性RestClientFactory进行rest.client.impl

Here is the sample code from the qaf users group.这是来自 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;
    }

}

In order to use it, register your class using rest.client.impl property, in above case:为了使用它,请使用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