You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2008/10/07 21:13:28 UTC

svn commit: r702589 - in /httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples: ElementalHttpGet.java ElementalHttpPost.java ElementalHttpServer.java

Author: olegk
Date: Tue Oct  7 12:13:28 2008
New Revision: 702589

URL: http://svn.apache.org/viewvc?rev=702589&view=rev
Log:
Minor improvements in the blocking HTTP examples

Modified:
    httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java
    httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java
    httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java

Modified: httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java?rev=702589&r1=702588&r2=702589&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java (original)
+++ httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java Tue Oct  7 12:13:28 2008
@@ -113,6 +113,7 @@
                 request.setParams(params);
                 httpexecutor.preProcess(request, httpproc, context);
                 HttpResponse response = httpexecutor.execute(request, conn, context);
+                response.setParams(params);
                 httpexecutor.postProcess(response, httpproc, context);
                 
                 System.out.println("<< Response: " + response.getStatusLine());

Modified: httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java?rev=702589&r1=702588&r2=702589&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java (original)
+++ httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java Tue Oct  7 12:13:28 2008
@@ -127,6 +127,7 @@
                 request.setParams(params);
                 httpexecutor.preProcess(request, httpproc, context);
                 HttpResponse response = httpexecutor.execute(request, conn, context);
+                response.setParams(params);
                 httpexecutor.postProcess(response, httpproc, context);
                 
                 System.out.println("<< Response: " + response.getStatusLine());

Modified: httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java?rev=702589&r1=702588&r2=702589&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java (original)
+++ httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java Tue Oct  7 12:13:28 2008
@@ -172,7 +172,7 @@
 
         private final ServerSocket serversocket;
         private final HttpParams params; 
-        private final String docRoot;
+        private final HttpService httpService;
         
         public RequestListenerThread(int port, final String docroot) throws IOException {
             this.serversocket = new ServerSocket(port);
@@ -183,7 +183,25 @@
                 .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
                 .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
                 .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
-            this.docRoot = docroot;
+
+            // Set up the HTTP protocol processor
+            BasicHttpProcessor httpproc = new BasicHttpProcessor();
+            httpproc.addInterceptor(new ResponseDate());
+            httpproc.addInterceptor(new ResponseServer());
+            httpproc.addInterceptor(new ResponseContent());
+            httpproc.addInterceptor(new ResponseConnControl());
+            
+            // Set up request handlers
+            HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
+            reqistry.register("*", new HttpFileHandler(docroot));
+            
+            // Set up the HTTP service
+            this.httpService = new HttpService(
+                    httpproc, 
+                    new DefaultConnectionReuseStrategy(), 
+                    new DefaultHttpResponseFactory());
+            this.httpService.setParams(this.params);
+            this.httpService.setHandlerResolver(reqistry);
         }
         
         public void run() {
@@ -196,27 +214,8 @@
                     System.out.println("Incoming connection from " + socket.getInetAddress());
                     conn.bind(socket, this.params);
 
-                    // Set up the HTTP protocol processor
-                    BasicHttpProcessor httpproc = new BasicHttpProcessor();
-                    httpproc.addInterceptor(new ResponseDate());
-                    httpproc.addInterceptor(new ResponseServer());
-                    httpproc.addInterceptor(new ResponseContent());
-                    httpproc.addInterceptor(new ResponseConnControl());
-                    
-                    // Set up request handlers
-                    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
-                    reqistry.register("*", new HttpFileHandler(this.docRoot));
-                    
-                    // Set up the HTTP service
-                    HttpService httpService = new HttpService(
-                            httpproc, 
-                            new DefaultConnectionReuseStrategy(), 
-                            new DefaultHttpResponseFactory());
-                    httpService.setParams(this.params);
-                    httpService.setHandlerResolver(reqistry);
-                    
                     // Start worker thread
-                    Thread t = new WorkerThread(httpService, conn);
+                    Thread t = new WorkerThread(this.httpService, conn);
                     t.setDaemon(true);
                     t.start();
                 } catch (InterruptedIOException ex) {