You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by en...@apache.org on 2020/10/01 23:32:11 UTC

[sling-org-apache-sling-testing-clients] branch master updated: SLING-9784 Include the response content in the SlingHttpResponse#checkContentRegexp exception message

This is an automated email from the ASF dual-hosted git repository.

enorman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new 1ea519a  SLING-9784 Include the response content in the SlingHttpResponse#checkContentRegexp exception message
1ea519a is described below

commit 1ea519a0fa42503d8bec96641ede3ed34815cf2c
Author: Eric Norman <en...@apache.org>
AuthorDate: Thu Oct 1 16:32:01 2020 -0700

    SLING-9784 Include the response content in the
    SlingHttpResponse#checkContentRegexp exception message
---
 .../sling/testing/clients/SlingHttpResponse.java   | 38 +++++++++++++---------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/clients/SlingHttpResponse.java b/src/main/java/org/apache/sling/testing/clients/SlingHttpResponse.java
index a8baca3..9f19f9e 100644
--- a/src/main/java/org/apache/sling/testing/clients/SlingHttpResponse.java
+++ b/src/main/java/org/apache/sling/testing/clients/SlingHttpResponse.java
@@ -16,15 +16,22 @@
  */
 package org.apache.sling.testing.clients;
 
-import org.apache.http.*;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.params.HttpParams;
-import org.apache.http.util.EntityUtils;
-
 import java.io.IOException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Scanner;
+import java.util.StringTokenizer;
 import java.util.regex.Pattern;
 
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpEntity;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.util.EntityUtils;
+
 public class SlingHttpResponse implements CloseableHttpResponse {
 
     public static final String STATUS = "Status";
@@ -108,18 +115,19 @@ public class SlingHttpResponse implements CloseableHttpResponse {
     public void checkContentRegexp(String... regexp) throws ClientException {
         for(String expr : regexp) {
             final Pattern p = Pattern.compile(".*" + expr + ".*");
-            final Scanner scanner = new Scanner(this.getContent());
             boolean matched = false;
-            while (scanner.hasNextLine()) {
-                String line = scanner.nextLine();
-                if (p.matcher(line).matches()) {
-                    matched = true;
-                    break;
+            try (final Scanner scanner = new Scanner(this.getContent())) {
+                while (scanner.hasNextLine()) {
+                    String line = scanner.nextLine();
+                    if (p.matcher(line).matches()) {
+                        matched = true;
+                        break;
+                    }
                 }
             }
 
             if (!matched) {
-                throw new ClientException("Pattern " + p + " didn't match any line in content");
+                throw new ClientException("Pattern " + p + " didn't match any line in content. Content is: \n\n" + getContent());
             }
         }
     }
@@ -381,13 +389,13 @@ public class SlingHttpResponse implements CloseableHttpResponse {
 
     @SuppressWarnings("deprecation")
     @Override
-    public HttpParams getParams() {
+    public org.apache.http.params.HttpParams getParams() {
         return httpResponse.getParams();
     }
 
     @SuppressWarnings("deprecation")
     @Override
-    public void setParams(HttpParams params) {
+    public void setParams(org.apache.http.params.HttpParams params) {
         httpResponse.setParams(params);
     }