Configuring proxy in karate-config.js get parse error

落爺英雄遲暮 提交于 2019-12-11 12:43:15

问题


I have proxy settings for our testing, e.g.,

function() {                                                                                                                                                                                                                                            

    var config = { // base config JSON                                                                                                                                                                                                                  
        sslConfig: true,                                                                                                                                                                                                                                
        apiUrl: 'https://my-api.com',                                                                                                                                                                                                                   
        api2Url: 'https://my-api2.com',                                                                                                                                                                                                                 
        proxy:                                                                                                                                                                                                                                          
        {                                                                                                                                                                                                                                               
            uri: 'http://my-proxy.com:3128',
            nonProxyHosts:                                                                                                                                                                                                                              
            [                                                                                                                                                                                                                                           
                'my-api2.com',                                                                                                                                                                                                                          
            ]                                                                                                                                                                                                             
        }                                                                                                                                                                                                                                               
    };                                                                                                                                                                                                                                                  

    karate.configure('connectTimeout', 10001);                                                                                                                                                                                                          
    karate.configure('readTimeout', 10000);                                                                                                                                                                                                             
    karate.configure('proxy', config.proxy);                                                                                                                                                                                                            
    return config;                                                                                                                                                                                                                                      
}

And it works fine in 0.9.2, after upgrade to 0.9.3, I get parsing error message below and process hanging there

    13:47:45.639 | [ForkJoinPool-1-worker-1] | ERROR 

    failed function body: function() {

          var config = { // base config JSON
              sslConfig: true,
              apiUrl: 'https://my-api.com',
              api2Url: 'https://my-api2.com',
              proxy:
              {
                  uri: 'http://my-proxy.com:3128',
                  nonProxyHosts:
                  [
                      'my-api2.com',
                  ]
              }
          };

          karate.configure('connectTimeout', 10001);
          karate.configure('readTimeout', 10000);
          karate.configure('proxy', config.proxy);
          return config;
      }

    13:47:45.646 | [ForkJoinPool-1-worker-1] | ERROR 

    evaluation of 'karate-config.js' failed: javascript function call failed: net.minidev.json.JSONArray cannot be cast to jdk.nashorn.api.scripting.ScriptObjectMirror

And I try to remove the key nonProxyHosts, it works again. Can anyone suggest the solution for this issue?


回答1:


Yes, this is a bug that was introduced in 0.9.3 - we opened a ticket here and it is fixed (in the develop branch) https://github.com/intuit/karate/issues/802

If you can build this from source and confirm that it works for you, we can expedite releasing a patch version.



来源:https://stackoverflow.com/questions/56555491/configuring-proxy-in-karate-config-js-get-parse-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!