RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题

问题[groovy]

Martin Hope
Paramonov Pavel
Asked: 2022-12-20 03:49:41 +0000 UTC

什么可以替换 jenkins.groovy 中的 replaceAll\replace 方法?(脚本不允许使用 staticMethod)

  • 5

尝试在 Jenkins 中建立管道。作为输入,我接受一串标签作为参数。

我试图将接收到的字符串拆分成一个数组,但是当我尝试通过 replaceAll 丢弃多余的部分时,出现错误:

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods replaceAll java.lang.String java.util.regex.Pattern java.lang.String

可执行代码:

task_tags = "${TEST_TAGS_NAME}"
def tags_cutted = task_tags.replaceAll(~/^\[|\]$/, '').split(',').collect{it as String}
groovy
  • 1 个回答
  • 14 Views
Martin Hope
Kostya
Asked: 2022-07-23 21:40:29 +0000 UTC

在以下请求中设置延迟增加?Beanshell jmeter

  • 0

您需要编写一个 beanshell 计时器,或者可能会增加下一个请求的延迟 +1 秒的其他东西。同时,已经有自己的逻辑重复 1 和相同的请求,直到所需的响应到达(通过响应断言 + while + if 控制器完成)。在此处输入图像描述

setup while: ${__javaScript("${txtFound}" == "FALSE" && parseInt(${counter})<=5,)} if: ${JMeterThread.last_sample_ok} sampler bean shell END: vars.put(" txt找到","真")

如果难以理解,我很抱歉

java groovy
  • 1 个回答
  • 23 Views
Martin Hope
Nemod
Asked: 2022-06-28 15:55:33 +0000 UTC

如何发出 POST 请求以使连接至少在 6 小时内不会中断?

  • -1

我正在测试一种应该工作大约 5-6 小时的方法。guid 通过 Post 请求传递给方法。完成后,它将数据写入数据库并返回 OK 200。(非常奇怪的解决方案,但它是什么)。

我正在通过 jmeter + groovy 进行测试,但是有一个请求,运行它并不重要。

我试图设置超时:

    connection.setConnectTimeout(6*60*60*1000);
    connection.setReadTimeout(6*60*60*1000);

但这不起作用,并且连接在 20 分钟(加/减 1 分钟)后因服务器错误导致文件意外结束而中断。其实问题就在标题里。可能是什么问题以及如何不中断第 6 小时的连接?(最好更长)

import groovy.util.*;
import org.apache.jmeter.services.FileServer
import javax.net.ssl.*
import java.net.*

def nullTrustManager = [
    checkClientTrusted: { chain, authType ->  },
    checkServerTrusted: { chain, authType ->  },
    getAcceptedIssuers: { null }
]

def nullHostnameVerifier = [
    verify: { hostname, session -> true }
]


KeyStore ks = KeyStore.getInstance("JKS");
FileInputStream fis = new FileInputStream("Путь к keystore.keys");
def password = "0000000".toCharArray()
ks.load(fis, password);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, password);

ctx = SSLContext.getInstance("TLSv1.2");
ctx.init(kmf.getKeyManagers(), [nullTrustManager as X509TrustManager] as TrustManager[], null);
SSLSocketFactory socketFactory = ctx.getSocketFactory();

def connection
def address = ""

address = "https://someserver.qwe/path/toMethod";

connection = new URL(address).openConnection() as HttpsURLConnection

connection.setConnectTimeout(6*60*60*1000);
connection.setReadTimeout(6*60*60*1000);

connection.setDefaultSSLSocketFactory(ssl_socket_factory);
connection.setDefaultHostnameVerifier(null_host_verifier) as HostnameVerifier)

connection.setDoOutput(true);
connection.setRequestProperty("User-Agent", "jmeter");
connection.setRequestProperty("Content-Type", "application/json; charset=utf8");
connection.setRequestProperty("Accept", "application/json");
SampleResult.setRequestHeaders(connection.getRequestProperties().toString())


def body = """[
    "c6881ad2-a504-49c1-928b-4a1d0a952d14",
    "e9f15af2-a8f3-48c9-97f2-610e1b81b355"
]""";

connection.outputStream.withWriter("utf-8", {
                Writer writer -> writer << body;
})
def response = "";

try{
    if(connection.responseCode < HttpURLConnection.HTTP_BAD_REQUEST){
        SampleResult.setResponseMessage("OK")
        SampleResult.setSuccessful(true)
        response = connection.inputStream.withReader("utf-8", {
            Reader reader -> reader.text
        })
    }else{
        SampleResult.setResponseMessage("Fail")
        SampleResult.setSuccessful(false)
        response = connection.errorStream.withReader("utf-8", {
            Reader reader -> reader.text
        })
    }
}
catch(Exception e){
    log.error "" + e.getMessage() + "\n" + e.getStackTrace();
}

SampleResult.setSamplerData(body)
SampleResult.setResponseCode(connection.responseCode.toString())
SampleResult.setResponseData
java groovy
  • 1 个回答
  • 45 Views
Martin Hope
zin
Asked: 2022-03-30 04:57:28 +0000 UTC

Groovy 脚本在查找换行符时出错

  • 0

我正在使用 GroovyShell 在 java 中执行一个 groovy 脚本。

我的脚本:

if ( !Переменная1.equals(Переменная2) ) {
return "Переменная1 = Переменная2";
};

return "Переменная2 = Переменная3
Переменная1 = Переменная3"

我希望在执行脚本时,将返回第 1 行:

"Переменная1 = Переменная2"

或第 2 行:

return "Переменная2 = Переменная3
Переменная1 = Переменная3"

而是抛出 MultipleCompilationErrorException在此处输入图像描述

请告诉我,我的错误是什么?我对groovy不太了解,也许我在做一些根本错误的事情?

groovy
  • 1 个回答
  • 10 Views
Martin Hope
Кирилл
Asked: 2022-03-24 15:44:34 +0000 UTC

JSR223 Jmeter。用 groovy 编写查询

  • 0

各位论坛的先生们下午好。请帮我解决以下问题

您需要使用 groovy 语言中的 JRS223 来解析 html(可能是 xml)索引(任何站点的主页)并在调试中显示找到的元素列表(在标题元素和所有链接中)。查询有一个常规:<title>(.*?)</title>|<a href="(.*?)"

到目前为止的案例结构如下所示: 在此处输入图像描述

groovy
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5