dzieciou / curl-logger Goto Github PK
View Code? Open in Web Editor NEWLogs HTTP requests sent by REST-assured as CURL commands.
License: BSD 3-Clause "New" or "Revised" License
Logs HTTP requests sent by REST-assured as CURL commands.
License: BSD 3-Clause "New" or "Revised" License
Hi, is there any way to exclude the cookies in the generated curl log? I've tried to use .removeHeader("Cookie")
but the cookies still appear in the log, because its use -b
instead of -H
.
Hi,
Is it possible to store the curl logger output to be stored in some variable to display on other places or add curl output in reports for better display?
Depracate 8, 9 and 10.
This will require:
The following buildfailed: https://travis-ci.org/dzieciou/curl-logger/builds/604446696?utm_medium=notification&utm_source=email failed to deploy artifacts to Maven Repository but has not been marked as failed.
Also, issue has been found too late, on release branch. It should be run previously.
I would expect that:
What is about customising?
Enable or disable parameters or headers like:
It will make curl query very short and simple.
Versions and release notes
Have checked the latest master and found public Builder useLogLevel(Level level)
method which I was looking for, but on the maven central, 1.0.5 version does not have the code.
In case request contains Authorization header of Basic type, e.g.,
Authorizaton: Basic bWFjaWVrOnRham5laGFzbG8xMjM=
should translate into
curl -u maciej:tajnehaslo123 ...
Hi,
is it possible to store logs generated by curl after build creation in String format ?
RequestSpecification spec = getRequestSpecification(RestAssured.given());
Response res = spec.config(config).when().post(this.url).then().extract().response();
Logs are generated post execution of above code. Is it possible to store these logs?
Thanks
great work for this rest-assured to curl libary.
I would like to convert some curl string to rest-assured requests. where should I start? thanks
Hey team!
First of all awesome work here! I'm planning to use this as a way of publishing internal documentation in the form of curl
commands.
I was wondering if we could add a configuration option to always print the requestMethod
in the curl command rather than skipping it when not necessary?
Happy to contribute with a PR if this sounds reasonable ๐
This was previously done with Maven release profile
mvn -Prelease package
mvn -Prelease deploy
Now follow: https://gist.github.com/sualeh/ae78dc16123899d7942bc38baba5203c
Hey, the latest version does not exist here as a tag and can't be found on : https://mvnrepository.com/artifact/com.github.dzieciou.testing/curl-logger
Can it be added there?
Thanks!
mvn gauge:execute -DspecsDir="specs/" -DinParallel=true -Dnodes=4
java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
The problem is in REST-assured: rest-assured/rest-assured#911.
We may be less constrained and accept also situations with multiple cookie headers. But we should give at least a warning the HTTP request is invalid.
In http2Curl() there is a block of code for detecting https protocol:
if (host.endsWith(":443")) {
inferredScheme = "https";
} else if (request instanceof RequestWrapper) {
if (getOriginalRequestUri(request).startsWith("https")) {
// This is for original URL, so if during redirects we go out of HTTPs, this might be a wrong guess
inferredScheme = "https";
}
}
This code fails if request is an instance of HttpRequestWrapper (which it will be for versions of http client >= 4.3) because HttpRequestWrapper does not itself derive from RequestWrapper and so the call to getOriginalRequestUri() is never executed.
This results in curl call output always displaying http as the protocol.
Something like this:
/**
* To provide cUrl log configuration for RestAssured
*/
public class RestAssuredConfigFactory {
public static RestAssuredConfig singleLineCurl() {
return config()
.httpClient(httpClientConfig()
.reuseHttpClientInstance()
.httpClientFactory(new SingleCurlLoggingHttpClientFactory()));
}
private static class SingleCurlLoggingHttpClientFactory implements HttpClientConfig.HttpClientFactory {
@Override
public HttpClient createHttpClient() {
AbstractHttpClient client = new DefaultHttpClient();
client.addRequestInterceptor(CurlLoggingInterceptor.defaultBuilder().printSingleliner().build());// singleLine cUrl
return client;
}
}
public static RestAssuredConfig multiLineCurl() {
return config()
.httpClient(httpClientConfig()
.reuseHttpClientInstance()
.httpClientFactory(new MultiCurlLoggingHttpClientFactory()));
}
private static class MultiCurlLoggingHttpClientFactory implements HttpClientConfig.HttpClientFactory {
@Override
public HttpClient createHttpClient() {
AbstractHttpClient client = new DefaultHttpClient();
client.addRequestInterceptor(CurlLoggingInterceptor.defaultBuilder().printMultiliner().build());// multiLine cUrl
return client;
}
}
}
And to use it:
RestAssured.given()
.config(RestAssuredConfigFactory.singleLineCurl())// this will log the cUrl to the log print out
.contentType(ContentType.JSON)
.body(new LandLord("Tao", "Zhang"))
.when()
.post("/landlords")
.then()
.statusCode(201);
A simple POST request is sent with JSON Data. The created curl contains hex code instead of normal text in the request.
For eg. REST ASSURED request was (logs of rest assured)
Request method: POST
Request URI: http://dummy.restapiexample.com/api/v1/create?code=1234&name=test22
Proxy:
Request params:
Query params: code=1234
name=test22
Form params:
Path params:
Headers: Accept=/
Content-Type=application/json
Cookies:
Multiparts:
Body:
{'name':"CKB2",'salary':'123','age':'23'}
And the curl created was --
curl 'http://dummy.restapiexample.com/api/v1/create?code=1234&name=test22' -H 'Accept: /' -H 'Content-Type: application/json' -H 'Host: dummy.restapiexample.com' -H 'Connection: Keep-Alive' -H 'User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_212)' -d $'\x7b\x27\x6e\x61\x6d\x65\x27\x3a\x22\x43\x4b\x42\x32\x22\x2c\x27\x73\x61\x6c\x61\x72\x79\x27\x3a\x27\x31\x32\x33\x27\x2c\x27\x61\x67\x65\x27\x3a\x27\x32\x33\x27\x7d' --compressed -k -v
I suppose, instead of hex data, it should appear in normal text.
Using curl-logger version 2.0.0 with restassured version 4.3.1 and apache http client 4.5.3 (the same thing also happened using the latest version of both)
when I tried to hit api in parallel, it throws this error.
java.lang.IllegalStateException: java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
you can use below code to replicate the error
RestAssured.config = RestAssuredConfig.config().
sslConfig(SSLConfig.sslConfig().relaxedHTTPSValidation()).
httpClient(HttpClientConfig.httpClientConfig().
setParam("http.connection.timeout", 10000).
setParam("http.socket.timeout", 10000).
setParam("http.connection-manager.timeout", 10000)).
encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false));
RestAssured.config = CurlRestAssuredConfigFactory.updateConfig(RestAssured.config); // removing this part will throws no error
List test = new ArrayList<>();
test.add("1");
test.add("2");
test.add("3");
test.add("4");
test.add("5");
test.parallelStream().forEach(i -> given().get("https://run.mocky.io/v3/2c47d181-5d7c-4fb8-81d5-e06265c91203"));
import com.github.dzieciou.testing.curl.CurlCommand;
import com.github.dzieciou.testing.curl.CurlRestAssuredConfigFactory;
import com.github.dzieciou.testing.curl.Options;
import com.github.dzieciou.testing.curl.Platform;
import io.restassured.RestAssured;
import io.restassured.config.HttpClientConfig;
import io.restassured.config.RestAssuredConfig;
import io.restassured.filter.FilterContext;
import io.restassured.filter.OrderedFilter;
import io.restassured.response.Response;
import io.restassured.specification.FilterableRequestSpecification;
import io.restassured.specification.FilterableResponseSpecification;
import org.slf4j.event.Level;
public class CommandFilter implements OrderedFilter {
@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
Options options = Options.builder()
.dontLogStacktrace()
.printMultiliner()
.useLogLevel(Level.INFO)
.targetPlatform(Platform.UNIX).build();
RestAssured.config = CurlRestAssuredConfigFactory.updateConfig(RestAssured.config, options);
return ctx.next(requestSpec, responseSpec);
}
@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
}
}
and test code as following:
RestAssured.given().baseUri("https://google.com").config(RestAssured.config).filters(new CommandFilter()).get("/");
Including migration of some tests to parameterized tests
I have some experiences it fails with newest slf4j and logback...
Is it allowed we use this library in our software?
io.rest-assured
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.1</version>
</dependency>
Ref: https://github.com/dzieciou/curl-logger/actions/runs/4092679132/jobs/7057576657
Warning: Javadoc Warnings
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:61: warning: no @return
Warning: public Builder logStacktrace() {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:67: warning: no @return
Warning: public Builder dontLogStacktrace() {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:73: warning: no @return
Warning: public Builder printMultiliner() {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:79: warning: no @return
Warning: public Builder printSingleliner() {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:85: warning: no @return
Warning: public Builder useShortForm() {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:91: warning: no @return
Warning: public Builder useLongForm() {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:100: warning: no @param for curlUpdater
Warning: public Builder updateCurl(Consumer<CurlCommand> curlUpdater) {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:100: warning: no @return
Warning: public Builder updateCurl(Consumer<CurlCommand> curlUpdater) {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:109: warning: no @param for targetPlatform
Warning: public Builder targetPlatform(Platform targetPlatform) {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:109: warning: no @return
Warning: public Builder targetPlatform(Platform targetPlatform) {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:[115](https://github.com/dzieciou/curl-logger/actions/runs/4092679132/jobs/7057576657#step:5:116): warning: no @return
Warning: public Builder escapeNonAscii() {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:121: warning: no @return
Warning: public Builder dontEscapeNonAscii() {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:127: warning: no @param for level
Warning: public Builder useLogLevel(Level level) {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:127: warning: no @return
Warning: public Builder useLogLevel(Level level) {
Warning: ^
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Options.java:133: warning: no @return
Warning: public Builder alwaysPrintMethod() {
Warning: ^
Ref: https://github.com/dzieciou/curl-logger/actions/runs/4092679132/jobs/7057576657
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/home/runner/.m2/repository/com/thoughtworks/xstream/xstream/1.4.7/xstream-1.4.7.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Maybe I'm missing something here, but it seems the library does not support graphQl requests?
Importing the queries printed into postman gives me some broken formatting.
curl 'https://my.api.com/graphql' \
--header 'Authorization: Bearer ImyBearer_QJj-A' \
--header 'Accept: application/json, application/javascript, text/javascript, text/json' \
--header 'Content-Type: application/json' \
--data-binary $'{"query":" query {\n getUserById(id: \"1riLgJZQHo\x40someEmail.com\", idType: \"authid\") {\n users {\n id\n email\n memberships {\n id\n role\n group {\n id,\n name\n account {\n id\n }\n primaryGroupMemberships {\n user {\n id\n email\n givenName\n familyName\n altIds {\n type\n userId\n value\n }\n }\n role\n }\n }\n }\n }\n }\n }\n"}' \
--compressed \
--insecure \
--verbose
public static RequestSpecification getRequestSpecification() {
/**
* Enables printing request as curl under the terminal as per
* https://github.com/dzieciou/curl-logger
*/
Options options = Options.builder().printMultiliner().updateCurl(curl -> curl.removeHeader("Host").removeHeader("User-Agent").removeHeader("Connection")).build();
RestAssuredConfig config =
CurlRestAssuredConfigFactory.createConfig(options).objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory(new Jackson2ObjectMapperFactory() {
@Override
public ObjectMapper create(Type type, String charset) {
ObjectMapper om = new ObjectMapper().findAndRegisterModules();
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
return om;
}
}));
return given().config(config).contentType(ContentType.JSON).accept(ContentType.JSON).urlEncodingEnabled(false).when().log().everything();
}
<rest-assured.version>4.5.1</rest-assured.version>
<json-schema-validator.version>5.1.1</json-schema-validator.version>
<http.client.version>5.1.2</http.client.version>
<curl.logger.version>2.1.1</curl.logger.version>
Thank you.
Ref: https://github.com/dzieciou/curl-logger/actions/runs/4092679132/jobs/7057576657
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Ref: https://github.com/dzieciou/curl-logger/actions/runs/4092679132/jobs/7057576657
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Http2Curl.java: Some input files use or override a deprecated API.
Warning: /home/runner/work/curl-logger/curl-logger/src/main/java/com/github/dzieciou/testing/curl/Http2Curl.java: Recompile with -Xlint:deprecation for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ curl-logger ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ curl-logger ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /home/runner/work/curl-logger/curl-logger/target/test-classes
Warning: /home/runner/work/curl-logger/curl-logger/src/test/java/com/github/dzieciou/testing/curl/UsingWithRestAssuredTest.java: Some input files use or override a deprecated API.
Warning: /home/runner/work/curl-logger/curl-logger/src/test/java/com/github/dzieciou/testing/curl/UsingWithRestAssuredTest.java: Recompile with -Xlint:deprecation for details.
Warning: /home/runner/work/curl-logger/curl-logger/src/test/java/com/github/dzieciou/testing/curl/UsingWithRestAssuredTest.java: /home/runner/work/curl-logger/curl-logger/src/test/java/com/github/dzieciou/testing/curl/UsingWithRestAssuredTest.java uses unchecked or unsafe operations.
Warning: /home/runner/work/curl-logger/curl-logger/src/test/java/com/github/dzieciou/testing/curl/UsingWithRestAssuredTest.java: Recompile with -Xlint:unchecked for details.
Currently is HTTP requests contains multiple cookies we have
curl -b "cookieA=valueA" -b "cookieB=valueB" ...
This results in sending only first cookie. There can be only one "-b" paramter. The expected format would be
curl -b "cookieA=valueA; cookieB=valueB" ...
In the end we would have three modules
CurlCommand
Http2Curl
specification for HttpRequest
Http2Curl
specific for RestAssuredSpecification
I've picked up this exception on my tests, probably related with payload size.
2020-08-21 10:48:45,033 WARN [curl] (main) Failed to generate CURL command for HTTP request: java.lang.StringIndexOutOfBoundsException: String index out of range: 4
at java.lang.String.substring(String.java:1963)
at com.github.dzieciou.testing.curl.CurlCommand$Serializer.escapeAsHex(CurlCommand.java:304)
at com.github.dzieciou.testing.curl.CurlCommand$Serializer.escape(CurlCommand.java:285)
at com.github.dzieciou.testing.curl.CurlCommand$Serializer.lambda$escapeStringPosix$0(CurlCommand.java:255)
at java.util.stream.IntPipeline$4$1.accept(IntPipeline.java:250)
at java.lang.CharSequence$1CharIterator.forEachRemaining(CharSequence.java:149)
at java.util.Spliterators$IntIteratorSpliterator.forEachRemaining(Spliterators.java:1908)
at java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:693)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at com.github.dzieciou.testing.curl.CurlCommand$Serializer.escapeStringPosix(CurlCommand.java:256)
at com.github.dzieciou.testing.curl.CurlCommand$Serializer.escapeString(CurlCommand.java:357)
at com.github.dzieciou.testing.curl.CurlCommand$Serializer.lambda$serialize$5(CurlCommand.java:327)
at java.util.ArrayList.forEach(ArrayList.java:1259)
at com.github.dzieciou.testing.curl.CurlCommand$Serializer.serialize(CurlCommand.java:327)
at com.github.dzieciou.testing.curl.CurlCommand.asString(CurlCommand.java:121)
at com.github.dzieciou.testing.curl.Http2Curl.generateCurl(Http2Curl.java:161)
at com.github.dzieciou.testing.curl.CurlLoggingInterceptor.process(CurlLoggingInterceptor.java:38)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:133)
at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:167)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)
at io.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:2055)
at io.restassured.internal.http.HTTPBuilder.doRequest(HTTPBuilder.java:495)
at io.restassured.internal.http.HTTPBuilder.request(HTTPBuilder.java:452)
at io.restassured.internal.http.HTTPBuilder$request$2.call(Unknown Source)
at io.restassured.internal.RequestSpecificationImpl.sendHttpRequest(RequestSpecificationImpl.groovy:1451)
at sun.reflect.GeneratedMethodAccessor245.invoke(Unknown Source)
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:107)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1262)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1029)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:816)
at groovy.lang.GroovyObject.invokeMethod(GroovyObject.java:39)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)
at io.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1200)
at sun.reflect.GeneratedMethodAccessor198.invoke(Unknown Source)
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:107)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1262)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1029)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:816)
at groovy.lang.GroovyObject.invokeMethod(GroovyObject.java:39)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:166)
at io.restassured.internal.filter.SendRequestFilter.filter(SendRequestFilter.groovy:30)
at io.restassured.filter.Filter$filter$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at io.restassured.filter.Filter$filter.call(Unknown Source)
at io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)
at io.restassured.filter.time.TimingFilter.filter(TimingFilter.java:56)
at io.restassured.filter.Filter$filter.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at io.restassured.filter.Filter$filter$0.call(Unknown Source)
at io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)
at io.restassured.filter.FilterContext$next.call(Unknown Source)
at io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1655)
at sun.reflect.GeneratedMethodAccessor192.invoke(Unknown Source)
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:107)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1262)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1029)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:816)
at groovy.lang.GroovyObject.invokeMethod(GroovyObject.java:39)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:203)
at io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1661)
at sun.reflect.GeneratedMethodAccessor191.invoke(Unknown Source)
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:107)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1262)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1029)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:816)
at groovy.lang.GroovyObject.invokeMethod(GroovyObject.java:39)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:203)
I have this sample class where I can have a curl printed.
import com.github.dzieciou.testing.curl.CurlRestAssuredConfigFactory;
import com.github.dzieciou.testing.curl.Options;
import io.restassured.config.RestAssuredConfig;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
public class UpdateCatalogTest {
@Test
public void myTest() {
getRequestSpecification().get("https://api.kraken.com/0/public/Ticker?pair=xbtusd");
}
RequestSpecification getRequestSpecification() {
Options options = Options.builder()
.build();
RestAssuredConfig config = CurlRestAssuredConfigFactory.createConfig(options);
RequestSpecification rq = given()
.config(config)
.when();
return rq;
}
}
However, if I append the httpClient config not to reuse instances there's no more printing.
So having this:
RestAssuredConfig config = CurlRestAssuredConfigFactory.createConfig(options).httpClient(HttpClientConfig.httpClientConfig().dontReuseHttpClientInstance());
instead of:
RestAssuredConfig config = CurlRestAssuredConfigFactory.createConfig(options);
These are my pom versions:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<properties>
<rest-assured.version>4.2.0</rest-assured.version>
<junit-jupiter.version>5.5.2</junit-jupiter.version>
<gson.version>2.8.6</gson.version>
<http.client.version>4.5.3</http.client.version>
<curl.logger.version>2.0.0</curl.logger.version>
</properties>
And this is my logback file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>my-rest-assured-curl-log.log</file>
<append>true</append>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
</encoder>
</appender>
<logger name="curl" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>
</configuration>
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.