【问题标题】:Java Security Exception using RestAssured post calls使用 RestAssured 后调用的 Java 安全异常
【发布时间】:2020-06-30 13:17:58
【问题描述】:

我在使用 RestAssured 使用 post call 时遇到异常。

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:891)
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:661)
at java.lang.ClassLoader.defineClass(ClassLoader.java:754)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at io.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:134)
at io.restassured.internal.ValidatableResponseOptionsImpl.statusCode(ValidatableResponseOptionsImpl.java:89)
at io.restassured.internal.ValidatableResponseImpl.super$2$statusCode(ValidatableResponseImpl.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
at io.restassured.internal.ValidatableResponseImpl.statusCode(ValidatableResponseImpl.groovy:142)
at io.restassured.internal.ValidatableResponseImpl.statusCode(ValidatableResponseImpl.groovy)

我在 pom.xml 文件中使用以下依赖项

黄瓜-java 4.8.0 黄瓜junit 4.8.0 io.rest-assured 4.1.2 杰克逊数据绑定 2.10.1 commons-io 2.6

我正在使用下面的代码来调用 API

    FileInputStream fileInputStream = new FileInputStream( new File("jsonFileInput\\pricingAPI.json"));
    RestAssured.baseURI ="my base url here";
    
    given().header("Content-Type","application/json")
    .and()
    .body(IOUtils.toString(fileInputStream,"UTF-8"))
    .when()
    .post("v/pr")
    .then()
    .statusCode(200)
    .and()
    .log().all();

【问题讨论】:

    标签: java maven rest-assured hamcrest securityexception


    【解决方案1】:

    请关注

    hamcrest tests always fail

    https://code.google.com/archive/p/hamcrest/issues/128

    合并解决方案 - 更改 java 构建路径上 jar 的顺序 - 你会发现 JUnit jar 在 hamcrest.jar 之上。您可以在此处将 hamcrest 移到 JUnit jar 上方,问题就会消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-01
      • 2014-02-05
      • 2019-12-10
      • 2017-03-01
      • 1970-01-01
      相关资源
      最近更新 更多