Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroovyCastException when using http client 4.4/4.5 APIs #704

Closed
sslavic opened this issue Jun 8, 2016 · 5 comments
Closed

GroovyCastException when using http client 4.4/4.5 APIs #704

sslavic opened this issue Jun 8, 2016 · 5 comments

Comments

@sslavic
Copy link

sslavic commented Jun 8, 2016

Using rest-assured 3.0.0, and configuring it to use http client with custom settings, using apache http client 4.4+ APIs like:

       RestAssured.config = RestAssured.config()
                .encoderConfig(EncoderConfig.encoderConfig().defaultContentCharset("UTF-8").defaultQueryParameterCharset("UTF-8"))
                .sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation("SSL").and().relaxedHTTPSValidation("TLS"))
                .httpClient(HttpClientConfig.httpClientConfig()
                        .httpClientFactory(() ->
                                HttpClientBuilder.create()
                                        .setDefaultRequestConfig(customRequestConfig)
                                        .setSSLHostnameVerifier(new NoopHostnameVerifier())
                                        .setConnectionManager(new PoolingHttpClientConnectionManager())
                                        .build()));

results in no compile time errors, but at runtime class cast exception gets thrown:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'org.apache.http.impl.client.InternalHttpClient@6622a690' with class 'org.apache.http.impl.client.InternalHttpClient' to class 'org.apache.http.impl.client.AbstractHttpClient'
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
    at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
    at io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1630)
    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:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1212)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)
    at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
    at io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1637)
    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:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1212)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812)
    at io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)
    at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
    at io.restassured.internal.RequestSpecificationImpl.delete(RequestSpecificationImpl.groovy:178)
    at io.restassured.internal.RequestSpecificationImpl.delete(RequestSpecificationImpl.groovy)
...

Am I doing something wrong?

If it's compatibility bug, not sure if it would be enough, but I guess replacing AbstractHttpClient references with CloseableHttpClient or HttpClient would be a start.

@sslavic
Copy link
Author

sslavic commented Jun 8, 2016

rest-assured depends on http-client 4.5.2 (see here) and I cannot use APIs available since 4.3 like HttpClientBuilder.

Seems like compatibility bug to me.

@sslavic
Copy link
Author

sslavic commented Jun 8, 2016

Found https://github.com/rest-assured/rest-assured/blob/master/rest-assured/src/main/java/io/restassured/config/HttpClientConfig.java#L283

Important: Version 1.9.0 of REST Assured ONLY supports instances of {@link org.apache.http.impl.client.AbstractHttpClient}

Then it's by design, even two major rest-assured versions later.
It's so ugly configuring AbstractHttpClient using all deprecated configuration parameters, whole code striked through. Please consider removing this limitation.

@johanhaleby
Copy link
Collaborator

Yes this is indeed known and the reason for not supporting this is because I have a limited amount of time working with this project (mostly) on my spare time and (afaict) this will require a HUGE refactoring of REST Assured. You're very welcome to help out, this is an open source project after all. See #497 for more info.

@sslavic
Copy link
Author

sslavic commented Jun 8, 2016

Sorry for creating a duplicate. Thanks for fast response. Already cloned repo, but I see it's non trivial task.

@johanhaleby
Copy link
Collaborator

No problem. I really wish to solve this but unfortunately it'll require some (hard to come by) time :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants