标签: rest-client

ruby rest-client:永远不会超时?

我正在尝试使用ruby rest-client将大量图像上传到我正在编写的网站.我的代码看起来像:

RestClient.post url, :timeout => 90000000, :open_timeout => 90000000, :file_param => file_obj
Run Code Online (Sandbox Code Playgroud)

但是,我收到此错误:

RestClient::RequestTimeout: Request Timeout
    from /Library/Ruby/Gems/1.8/gems/rest-client-1.6.1/lib/restclient/request.rb:174:in `transmit'
    from /Library/Ruby/
Run Code Online (Sandbox Code Playgroud)

但是当我查看服务器日志时

Completed in 61493ms (View: 2, DB: 1) | 201 Created 
Run Code Online (Sandbox Code Playgroud)

所以似乎没有任何理由为什么这是超时.任何人都知道如果有超时参数我没有正确设置?

谢谢

ruby-on-rails rest-client

18
推荐指数
3
解决办法
2万
查看次数

用于测试RESTful Web服务的工具

我正在尝试评估正确的工具来测试RESTful Web服务,并最终为我们的项目自动化.想知道,当我比较互联网上的各种工具时,我需要寻找这种测试的规格是什么.

当然,其中一个要求是开源工具.

我查看了一些工具,例如SOAPUI,RestClient,TestMaker,RestAssured.想知道他们的利弊.此外,任何有关如何实现它的想法或指示都会有很大帮助.

rest web-services soapui rest-client rest-assured

18
推荐指数
3
解决办法
4万
查看次数

Ruby错误:无法加载此类文件 - rest-client

我正在使用Ruby on Rails 4.

我在尝试着

require 'rest-client'
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,以便我可以解析我从表单中获取的登录信息并将其发送到API.

我可以验证gem是否已安装,并且也在应用程序根目录下的Gemfile中.

但是,当我尝试在我的控制器中需要该文件时,仍然会抛出"无法加载此类文件 - rest-client".

我用谷歌搜索了错误,我看到的大多数答案要么是没有安装gem,要么不是Gemfile,要么是两者的组合.这里的情况也不是.

我的控制器是否由于某种原因无法访问rest-client gem?我必须使用rest-client,因为它在API中是必需的.

这是我用来安装gem的行:

gem install rest-client
Run Code Online (Sandbox Code Playgroud)

这是gem的主页:https://github.com/archiloque/rest-client
这只是将你重定向到https://github.com/rest-client/rest-client

我还应该注意,当我没有在Rails项目中使用代码而只是在终端中运行命令时,它工作正常.

ruby ruby-on-rails rest-client

17
推荐指数
3
解决办法
3万
查看次数

CodeIgniter将POST数据从RestClient传递到RestServer API

我花了一整天的时间试图找出这个问题.在这里发布这个问题是我最后的希望.我希望有人能帮助我继续完成我的第一份工作.

因此,当直接将数据从我的视图传递到RestServer时,POST工作正常.但是,RESTServer API无法找到从RestClient发送的POST数据.

以下是片段:

RestClient API:

        $ver = 'v1';
        $config = array('server'          => base_url()."v1",
                        'api_key'         => 'xxxxxx',
                        'api_name'        => 'X-API-KEY',
                        'http_user'       => 'admin',
                        'http_pass'       => 'xxxxx',
                        'http_auth'       => 'basic',
                );

        $this->rest->initialize($config);
        $this->rest->format('application/json');
        $param = array(
                'id' => $this->input->post('id'), // works fine here
                'name' => $this->input->post('name')
                );
        $user = $this->rest->post('employer/postNewProject', $param, 'json');


        //if (isset($user->errors)) show_404('admin');
        $this->rest->debug();
Run Code Online (Sandbox Code Playgroud)

RestServer API

class Employer extends REST_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->lang->load("application");
        $this->load->library("users/auth"); 
        Datamapper::add_model_path( array( APPPATH."modules" ) );
    }

    public function postNewProject_post()
    {  
        // …
Run Code Online (Sandbox Code Playgroud)

php codeigniter rest-client codeigniter-2 codeigniter-restserver

17
推荐指数
2
解决办法
1万
查看次数

Jackson根据json输入映射Object或Object列表

我有这个POJO:

public class JsonObj {

    private String id;
    private List<Location> location;


    public String getId() {
        return id;
    }

    public List<Location> getLocation() {
        return location;
    }

    @JsonSetter("location")
    public void setLocation(){
        List<Location> list = new ArrayList<Location>();
        if(location instanceof Location){
            list.add((Location) location);
            location = list;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

json输入中的"location"对象可以是Location的简单实例,也可以是Location的Array.当它只是一个实例时,我收到此错误:

Could not read JSON: Can not deserialize instance of java.util.ArrayList out of   START_OBJECT token
Run Code Online (Sandbox Code Playgroud)

我试图实现自定义setter但它不起作用.我怎么能根据json输入映射位置或列表?

java android json rest-client jackson

15
推荐指数
2
解决办法
8812
查看次数

如何向不同的Web服务发送多个异步请求?

我需要向多个不同的Web服务发送多个请求并接收结果.问题是,如果我逐个发送请求,只要我需要单独发送和处理所有请求.

我想知道如何立即发送所有请求并收到结果.

如下面的代码所示,我有三个主要方法,每个方法都有自己的子方法.每个子方法向其关联的Web服务发送请求并接收结果;因此,例如,为了接收Web服务9的结果,我必须等到1到8的所有Web服务都完成,这需要很长时间才能发送所有请求一个接一个,并收到他们的结果.

如下所示,没有任何方法或子方法彼此相关,所以我可以将它们全部调用并以任何顺序接收它们的结果,唯一重要的是接收每个子方法的结果并填充它们相关列表.

private List<StudentsResults> studentsResults = new ArrayList();
private List<DoctorsResults> doctorsResults = new ArrayList();
private List<PatientsResults> patientsResults = new ArrayList();

main (){
    retrieveAllLists();
}

retrieveAllLists(){

     retrieveStudents();
     retrieveDoctors();
     retrievePatients();
}

retrieveStudents(){

    this.studentsResults = retrieveStdWS1();   //send request to Web Service 1 to receive its  list of students
    this.studentsResults = retrieveStdWS2();  //send request to Web Service 2 to receive its  list of students
    this.studentsResults = retrieveStdWS3(); //send request to Web Service 3 to receive its  list of students

}

retrieveDoctors(){

   this.doctorsResults …
Run Code Online (Sandbox Code Playgroud)

java web-services soap-client java-ee rest-client

14
推荐指数
2
解决办法
2万
查看次数

如何让Ruby的RestClient gem在帖子上尊重content_type?

例如,在RestClient控制台中:

RestClient.post 'http://localhost:5001', {:a => 'b'}, :content_type => 'application/json'
Run Code Online (Sandbox Code Playgroud)

这不会将application/json作为内容类型发送.相反,我看到:

Content-Type: application/x-www-form-urlencoded
Run Code Online (Sandbox Code Playgroud)

我能够跟踪对restclient/payload.rb的更改:

  class UrlEncoded < Base
  ...

  def headers
    super.merge({'Content-Type' => 'application/x-www-form-urlencoded'})
  end
end
Run Code Online (Sandbox Code Playgroud)

用super替换super.merge导致内容类型得到尊重,但显然这不是一个真正的解决方案.有谁知道解决这个问题的正确方法?谢谢.

ruby rest-client

13
推荐指数
3
解决办法
2万
查看次数

我可以覆盖RESTClient默认的"HttpResponseException"响应> 399返回代码吗?

我正在使用Groovy RESTClient类为Java WebServices写一些(spock)验收测试我一直在创作.

我遇到的一个挫折就是测试答案......

200 状态很简单:

when:  def result = callServiceWithValidParams()
then:  result.status == 200
Run Code Online (Sandbox Code Playgroud)

但是400+我被迫要么包装,要么默认try-catch测试HttpResponseException那个RESTClient抛出.

when:
    callWithInvalidParams()
then:
    def e = thrown(Exception)
    e.message == 'Bad Request'
Run Code Online (Sandbox Code Playgroud)

这有点好,如果有点令人沮丧......但我想做得更好.

理想情况下,我希望我的测试更像这样(如果你不使用groovy/spock,可能会让人感到困惑)

@Unroll
def "should return #statusCode '#status' Response"()
{
    when:
    def result = restClient.get(path: PATH, query: [param: parameter])

    then:
    result.status == statusCode

    where:
    status         | statusCode | parameter                
    'OK'           | 200        | validParam
    'Bad Request'  | 400        | invalidParam
}
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,"错误请求"案例失败. …

testing groovy rest-client spock

13
推荐指数
2
解决办法
2914
查看次数

Spring RestTemplate与Jersey Rest Client和RestEasy客户端

对于来自客户端应用程序的异步rest API调用,建议使用以下哪一种实现?

  1. Sprint resttemplate
  2. 泽西休息客户
  3. 休息轻松的客户

api rest asynchronous rest-client

13
推荐指数
1
解决办法
8136
查看次数

如何正确共享JAX-RS 2.0客户端

为我的问题提供一点背景......

我有一个Java EE Web应用程序(作为UI /客户端),它使用JAX-RS 2.0客户端API(Resteasy实现)通过REST接口访问数据/业务逻辑服务.

目前,我使用RequestScoped CDI托管bean为每个请求注入一个新的JAXRS客户端实例,其思想是客户端应用程序可以为每个请求调用多个后端资源,并且我为整个请求重用相同的JAXRS客户端(尽管我在某处读到这可能不是是正确的,因为我可能会更改每个调用的URI)

JAXRS Client的文档似乎表明客户端是一个可能很昂贵的操作,应用程序应该限制它创建的连接数量.它似乎也与自己相矛盾,并建议在完成对特定WebTarget的所有请求后关闭客户端.

客户端应用程序可能会支持数千个并发用户,因此创建和销毁数千个"昂贵客户端"似乎不是正确的方法,所以我认为共享客户端池更合适但似乎没有任何关于如何这应该实现.

所有示例似乎都显示为请求创建了一个新客户端,a)在关闭之后关闭它,或者b)没有关闭它,但没有真正解释第二个请求发生了什么.

您能否提供一些答案,说明您认为如何解决这个问题,或者提供有关此方法的最佳实践的信息.

谢谢.

rest java-ee rest-client

13
推荐指数
1
解决办法
3249
查看次数