简体   繁体   English

Java 使用 RestAssured 后调用的安全异常

[英]Java Security Exception using RestAssured post calls

I am getting an exception while using post call using RestAssured.使用 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)

I am using below dependencies in my pom.xml file我在我的 pom.xml 文件中使用以下依赖项

cucumber-java 4.8.0 cucumber-junit 4.8.0 io.rest-assured 4.1.2 jackson-databind 2.10.1 commons-io 2.6 cucumber-java 4.8.0 cucumber-junit 4.8.0 io.rest-assured 4.1.2 jackson-databind 2.10.1 commons-io 2.6

i am using below code to call API我正在使用下面的代码来调用 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();

Please follow请关注

hamcrest tests always fail hamcrest 测试总是失败

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

Consolidating the solution - Change the order of the jars on the java build path - you will find that the JUnit jar is above the hamcrest.jar. Consolidating the solution - Change the order of the jars on the java build path - you will find that the JUnit jar is above the hamcrest.jar. You can move hamcrest above the JUnit jar here and the problem will go away.您可以将 hamcrest 移到 JUnit jar 上方,问题将 go 消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM