0

I am trying to send a request with one header(authorization) but when i check the logs i am seeing same header is added twice to the request which is causing my tests to fail.

Below is the post method which i am using

public static Response doPost(String basePath, Object payload, String header) {
    return reqSpec.given().header("X-HSBC-E2E-Trust-Token", header).config(RestAssuredConfig.config())
            .body(payload.toString()).log().all()
                .post(basePath).then().extract().response();
    }

Log:

    Request URI:    https:Url
    Proxy:                  <none>
    Request params: <none>
    Query params:   <none>
    Form params:    <none>
    Path params:    <none>
    Headers:E2E-Trust-Token=0JDX09VRIMl9TRVJWRVJfREVWIn0.eyJzaXQiOiJhZDp1c3I6ZW1wbG95ZWVJZCIsInN1YiI6IkdCLVNWQy1GV0tUQVBJRlAiLCJhbHQiOlt7InNpdCI6ImVtYWlsIiwic3ViIjoiR0ItU1ZDLUZXS1RBUElGUEBOb3RSZWNlaXZpbmdNYWlmhzYmMuY29tIn0seyJzaXQiOiJuYW1lIiwic3ViIjoiR0ItU1ZDLUZXS1RBUElGUCJ9LHsic2l0IjoibG9naW5JZCIsInN1YiI6IkdCLVNWQy1GV0tUQVBJRlAifV0sImdycCI6WyJDTj1JbmZvZGlyLUFQSUF1dG9GV0stUHJvZFN    W5kYXJkLE9VPUlUSURBUEksT1U9QXBwbGljYXRpb25zLE9VPUdyb3VwcyxEQz1JbmZvRGlyLERDPVByb2QsREM9SFNCQyIsIkNOPUluZm9kaXItQVBJQXV0b0ZXSy1Qcm9kQWRtaW4sT1U9SVRJREFQSSxPVT1BcHBsaWNhdGlvbnM1U9R3JvdXBzLERDPUluZm9EaXIsREM9UHJvZCxEQz1IU0JDIl0sInNjb3BlIjoiSVRJREFQSSIsImp0aSI6IjBlMGQ0YzM5LThlMjQtNDI5MC1iZGExLTE0MzllOTRlMzcxYyIsImlzcyI6ImdibDIwMTA5MDk2LmhjLmNsb3VkLnVmhzYmMiLCJpYXQiOjE2NTc1MzE2NTEsImV4cCI6MTY1NzUzMjI1MSwiYXVkIjoiR0ItU1ZDLUFQSUZXREVWQEhCRVUiLCJ1c2VyX25hbWUiOiJHQi1TVkMtRldLVEFQSUZQIn0.HgxR7j7fbl5JRQxTFX0Z7OJLk_11Vc4fUFPEZ9E      
Accept=*/*
E2E-Trust-Token=0JDX09BVVRIMl9TRVJWRVJfREVWIn0.eyJzaXQiOiJhZDp1c3I6ZW1wbG95ZWVJZCIsInN1YiI6IkdCLVNWQy1GV0tUQVBJRlAiLCJhbHQiOlt7InNpdCI6ImVtYWlsIiwic3ViIjoiR0ItU1ZDLUZXS1RBUElGUEBOb3RSZWNlaXZmdNYWlsLmhzYmMuY29tIn0seyJzaXQiOiJuYW1lIiwic3ViIjoiR0ItU1ZDLUZXS1RBUElGUCJ9LHsic2l0IjoibG9naW5JZCIsInN1YiI6IkdCLVNWQy1GV0tUQVBJRlAifV0sImdycCI6WyJDTj1JbmZvZGlyLUFQSUF1dG9GV0sHJvZFN0YW5kYXJkLE9VPUlUSURBUEksT1U9QXBwbGljYXRpb25zLE9VPUdyb3VwcyxEQz1JbmZvRGlyLERDPVByb2QsREM9SFNCQyIsIkNOPUluZm9kaXItQVBJQXV0b0ZXSy1Qcm9kQWRtaW4sT1U9SVRJREFQSSxPVT1BcHBsaWN
3VkLnVrLmhzYmMiLCJpYXQiOjE2NTc1MzE2NTEsImV4cCI6MTY1NzUzMjI1MSwiYXVkIjoiR0ItU1ZDLUFQSUZXREVWQEhCRVUiLCJ1c2VyX25hbWUiOiJHQi1TVkMtRldLVEFQSUZQIn0.HgxR7j7fbl5JRQxTFX0Z7OJLk_11Vc4FPEZ9Ec2xVXmUxeE6M3f8wBe4HOrQDJw_gWm_Kvf_hepsvAu0S0ACRQ3P_4i5yf2z0FXtBoUd3v9AvZcB299PZGJhNZ4HxUEP5SdzjQWOuZgdHAFg6GJdgsYBLTuCXQqy-kdqgPczgx7bgKTBfqrWH2I4qH1ZSE2OlksvGPj0Ia1Ts
Content-Type=application/json; charset=UTF-8
    Cookies:                <none>
    Multiparts:             <none>
    Body:
    {
        "name": "TestRole11072733",
        "requiresApproval": true,
        "signatures": [
            1091
        ]
    }
    10:27:36.574 [main] DEBUG org.apache.http.impl.conn.BasicClientConnectionManager - Get connection for route {s}->https:URL
    10:27:36.574 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnectionOperator - Connecting to Endpoint
    10:27:37.001 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: ignoreCookies
    10:27:37.001 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
    10:27:37.001 [main] DEBUG org.apache.http.client.protocol.RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
    10:27:37.001 [main] DEBUG org.apache.http.impl.client.DefaultHttpClient - Attempt 1 to execute request
    10:27:37.001 [main] DEBUG org.apache.http.impl.conn.DefaultClientConnection - Sending request: POST Endpoint
tester
  • 1
  • 1
  • Could you provide the request log? How many request did you send? I guess not only one. – lucas-nguyen-17 Jul 05 '22 at 03:55
  • When i run individual tests then tests are passing but when i run them all together they fail. Logs are displaying the same header twice and sometimes more than 3 times for same request. – tester Jul 11 '22 at 09:31
  • Yeah. I know the problem. It's been asked multiple times on Stackoverflow. The reason is you're re-using the `reqSpec` object. The solution is creating a new object `requestSpecification` for each request. – lucas-nguyen-17 Jul 12 '22 at 00:56
  • @lucas-nguyen-17 i am using requestSpecification, static RequestSpecification reqSpec; – tester Jul 21 '22 at 17:00
  • see my suggestion in the above comment. – lucas-nguyen-17 Jul 22 '22 at 02:33
  • I am not 100% sure how i do that, new to Rest assured As of now i am using below > `public static Response doPost(String basePath, Object payload, String header) { return reqSpec.given().header("Auth token", token).body(payload.toString()).log().all() .post(basePath).then().extract().response(); }`
    Below is the reqresponse
    `public static void setRequestResponseSpecification(RequestSpecification req, ResponseSpecification res) { reqSpec = req; respSpec = res; } public static void setRequestSpecification(RequestSpecification req) { reqSpec = req; }`
    – tester Jul 22 '22 at 13:39
  • It's just java, create new object each time. Similar problem https://stackoverflow.com/a/69569031/7574461 – lucas-nguyen-17 Jul 25 '22 at 02:00

0 Answers0