You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2019/04/22 11:49:16 UTC

[httpcomponents-core] branch master updated: Better messages in file server examples.

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 64de929  Better messages in file server examples.
     new de19a60  Merge pull request #121 from garydgregory/better_file_server_example_messages
64de929 is described below

commit 64de929b0027e80dfcf7247ba0518f46c21a1c0f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Apr 20 11:20:31 2019 -0400

    Better messages in file server examples.
---
 .../apache/hc/core5/http/examples/AsyncFileServerExample.java | 11 ++++++-----
 .../hc/core5/http/examples/ClassicFileServerExample.java      | 11 ++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/AsyncFileServerExample.java b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
index 87775d7..024dbc5 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
@@ -110,19 +110,20 @@ public class AsyncFileServerExample {
                         final File file = new File(docRoot, path);
                         if (!file.exists()) {
 
-                            println("File " + file.getPath() + " not found");
+                            final String msg = "File " + file.getPath() + " not found";
+                            println(msg);
                             responseTrigger.submitResponse(new BasicResponseProducer(
                                     HttpStatus.SC_NOT_FOUND,
-                                    "<html><body><h1>File " + file.getPath() +
-                                            " not found</h1></body></html>",
+                                    "<html><body><h1>" + msg + "</h1></body></html>",
                                     ContentType.TEXT_HTML), context);
 
                         } else if (!file.canRead() || file.isDirectory()) {
 
-                            println("Cannot read file " + file.getPath());
+                            final String msg = "Cannot read file " + file.getPath();
+                            println(msg);
                             responseTrigger.submitResponse(new BasicResponseProducer(
                                     HttpStatus.SC_FORBIDDEN,
-                                    "<html><body><h1>Access denied</h1></body></html>",
+                                    "<html><body><h1>" + msg + "</h1></body></html>",
                                     ContentType.TEXT_HTML), context);
 
                         } else {
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicFileServerExample.java b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
index 90f1770..d0f3ed5 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
@@ -167,21 +167,22 @@ public class ClassicFileServerExample {
             if (!file.exists()) {
 
                 response.setCode(HttpStatus.SC_NOT_FOUND);
+                final String msg = "File " + file.getPath() + " not found";
                 final StringEntity outgoingEntity = new StringEntity(
-                        "<html><body><h1>File " + file.getPath() +
-                        " not found</h1></body></html>",
+                        "<html><body><h1>" + msg + "</h1></body></html>",
                         ContentType.create("text/html", "UTF-8"));
                 response.setEntity(outgoingEntity);
-                System.out.println("File " + file.getPath() + " not found");
+                System.out.println(msg);
 
             } else if (!file.canRead() || file.isDirectory()) {
 
                 response.setCode(HttpStatus.SC_FORBIDDEN);
+                final String msg = "Cannot read file " + file.getPath();
                 final StringEntity outgoingEntity = new StringEntity(
-                        "<html><body><h1>Access denied</h1></body></html>",
+                        "<html><body><h1>" + msg + "</h1></body></html>",
                         ContentType.create("text/html", "UTF-8"));
                 response.setEntity(outgoingEntity);
-                System.out.println("Cannot read file " + file.getPath());
+                System.out.println(msg);
 
             } else {
                 final HttpCoreContext coreContext = HttpCoreContext.adapt(context);