Hi I using java and testng for my test suite and allure report for reporting , issue is I am not able to figure out how to implement condition where

  1. Blacklist specific header value
  2. Logged response only if test case failed.

I am using Listners at class level

package testListnersT;

import com.aventstack.extentreports.markuputils.ExtentColor;
import com.aventstack.extentreports.markuputils.MarkupHelper;
import configurationAPI.BaseConfiguration;
import io.qameta.allure.Attachment;
import io.restassured.RestAssured;
import io.restassured.filter.log.LogDetail;
import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class ListenersT extends BaseConfiguration implements ITestListener {

    private final ByteArrayOutputStream request = new ByteArrayOutputStream();

    private final ByteArrayOutputStream reponse = new ByteArrayOutputStream();

    private final PrintStream requestVar = new PrintStream(request, true);

    private final PrintStream responseVar = new PrintStream(reponse, true);

    public void onFinish(ITestContext arg0) {
        // TODO Auto-generated method stub


    public void onStart(ITestContext arg0) {
        RestAssured.filters(new ResponseLoggingFilter(LogDetail.BODY, responseVar),
                new RequestLoggingFilter(LogDetail.BODY, requestVar));

    public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
        // TODO Auto-generated method stub


    public void onTestFailure(ITestResult result) {
        childTest.fail(MarkupHelper.createLabel("FAIL", ExtentColor.RED));

    public void onTestSkipped(ITestResult arg0) {
        // TODO Auto-generated method stub

    public void onTestStart(ITestResult arg0) {
        // TODO Auto-generated method stub


    public void onTestSuccess(ITestResult arg0) {

    public byte[] attach(final ByteArrayOutputStream log) {
        final byte[] array = log.toByteArray();
        return array;

    @Attachment(value = "request")
    public byte[] logRequest(final ByteArrayOutputStream stream) {
        return attach(stream);

    @Attachment(value = "response")
    public byte[] logResponse(final ByteArrayOutputStream stream) {
        return attach(stream);


Below is sample test code

    @Description("Test Desc")
    @Test(priority = 1, groups = {"testOne"})
    public void verifyTEST(Method method) {
        domainURL = env.apiBaseURL();
        body = JsonBuilderFactory.buildObject()
                .add("id", 12345)

        response = given()
                .header("Content-Type", "application/json")
                .header("key", Key())