1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/FeedbackService.java,v 1.1 2004/11/20 17:56:39 olegk Exp $
3    * $Revision: 155418 $
4    * $Date: 2005-02-26 08:01:52 -0500 (Sat, 26 Feb 2005) $
5    *
6    * ====================================================================
7    *
8    *  Copyright 2002-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   */
29  package org.apache.commons.httpclient;
30  
31  import java.io.IOException;
32  import java.io.StringWriter;
33  
34  import org.apache.commons.httpclient.server.HttpService;
35  import org.apache.commons.httpclient.server.RequestLine;
36  import org.apache.commons.httpclient.server.SimpleRequest;
37  import org.apache.commons.httpclient.server.SimpleResponse;
38  
39  
40  public class FeedbackService implements HttpService {
41  
42      public FeedbackService() {
43          super();
44      }
45  
46      public boolean process(final SimpleRequest request, final SimpleResponse response)
47          throws IOException
48      {
49          RequestLine requestline = request.getRequestLine();
50          HttpVersion httpversion = requestline.getHttpVersion();
51  
52          StringWriter buffer = new StringWriter(100);
53          buffer.write("Method type: ");
54          buffer.write(requestline.getMethod());
55          buffer.write("\r\n");
56          buffer.write("Requested resource: ");
57          buffer.write(requestline.getUri());
58          buffer.write("\r\n");
59          buffer.write("Protocol version: ");
60          buffer.write(httpversion.toString());
61          buffer.write("\r\n");
62          
63          String requestbody = request.getBodyString();
64          if (requestbody != null && !requestbody.equals("")) {
65              buffer.write("\r\n");
66              buffer.write("Request body: ");
67              buffer.write(requestbody);
68              buffer.write("\r\n");
69          }
70          
71          response.setStatusLine(httpversion, HttpStatus.SC_OK);
72          response.setBodyString(buffer.toString());
73          return true;
74      }
75  }