hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r227059 - /jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java
Date Tue, 02 Aug 2005 18:31:22 GMT
Author: olegk
Date: Tue Aug  2 11:31:17 2005
New Revision: 227059

URL: http://svn.apache.org/viewcvs?rev=227059&view=rev
Log:
Added Tomcat Coyote based implementation of the HttpService interface (partially implemented)

Added:
    jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java
  (with props)

Added: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java?rev=227059&view=auto
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java
(added)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java
Tue Aug  2 11:31:17 2005
@@ -0,0 +1,113 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.coyote;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.coyote.Adapter;
+import org.apache.coyote.Constants;
+import org.apache.coyote.Request;
+import org.apache.coyote.RequestInfo;
+import org.apache.coyote.Response;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpMutableResponse;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpStatus;
+import org.apache.http.MethodNotSupportedException;
+import org.apache.http.ProtocolException;
+import org.apache.http.params.HttpParams;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ */
+public class CoyoteHttpService implements HttpService {
+
+    private static Log LOG = LogFactory.getLog(CoyoteHttpService.class);
+	
+    private final Adapter adapter;
+    private final HttpParams params;
+    
+    public CoyoteHttpService(final Adapter adapter, final HttpParams params) {
+    	super();
+        if (adapter == null) {
+            throw new IllegalArgumentException("Coyote adapter may not be null");
+        }
+        if (params == null) {
+            throw new IllegalArgumentException("Http parameters may not be null");
+        }
+        this.adapter = adapter;
+        this.params = params;
+    }
+
+    public HttpParams getParams() {
+        return this.params;
+    }
+    
+    public void process(final HttpException ex, final HttpMutableResponse response) {
+        LOG.debug("Processing HTTP exception");
+        if (ex instanceof MethodNotSupportedException) {
+            response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
+        } else if (ex instanceof ProtocolException) {
+            response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
+        } else {
+            response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+        }
+        response.setHeader(new Header("Server", "Jakarta HttpCommons"));
+        response.setHeader(new Header("Connection", "Close"));
+    }
+    
+    public void process(final HttpRequest httpreq, final HttpMutableResponse httpres) 
+            throws IOException, HttpException {
+        LOG.debug("Processing HTTP request");
+        Request request = new Request();
+        request.setStartTime(System.currentTimeMillis());
+        
+        RequestInfo reqinfo = request.getRequestProcessor();
+        reqinfo.setStage(Constants.STAGE_PARSE);
+        // convertRequest(httpreq, request);
+
+        Response response = new Response();
+        try {
+            this.adapter.service(request, response);
+        } catch (IOException ex) {
+            throw ex;
+        } catch (Exception ex) {
+            throw new HttpException(ex.getMessage(), ex.getCause()) ;
+        }
+	}
+       
+}

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/java/org/apache/http/coyote/CoyoteHttpService.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message