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/02/21 21:55:20 UTC
svn commit: r629988 - in /httpcomponents/httpcore/branches/limewire_contrib:
module-main/src/main/java/org/apache/http/protocol/
module-nio/src/main/java/org/apache/http/nio/entity/
module-nio/src/main/java/org/apache/http/nio/protocol/
Author: olegk
Date: Thu Feb 21 12:55:18 2008
New Revision: 629988
URL: http://svn.apache.org/viewvc?rev=629988&view=rev
Log:
HTTPCORE-148:
* Updated javadocs
* Factored out URI matching logic into UriPatternMatcher
* Added NHttpRequestHandlerRegistry
Contributed Sam Berlin <sberlin at gmail.com>
Reviewed by Oleg Kalnichevski
Added:
httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/UriPatternMatcher.java (with props)
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerRegistry.java (with props)
Modified:
httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java
httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/HttpRequestHandlerRegistry.java Thu Feb 21 12:55:18 2008
@@ -31,12 +31,10 @@
package org.apache.http.protocol;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
/**
- * Maintains a map of HTTP request handlers keyed by a request URI pattern.
+ * Maintains a map of HTTP request handlers keyed by a request URI pattern.
* {@link HttpRequestHandler} instances can be looked up by request URI
* using the {@link HttpRequestHandlerResolver} interface.<br/>
* Patterns may have three formats:
@@ -52,77 +50,33 @@
*/
public class HttpRequestHandlerRegistry implements HttpRequestHandlerResolver {
- private final Map handlerMap;
-
+ private final UriPatternMatcher matcher;
+
public HttpRequestHandlerRegistry() {
- super();
- this.handlerMap = new HashMap();
+ matcher = new UriPatternMatcher();
}
-
+
public void register(final String pattern, final HttpRequestHandler handler) {
- if (pattern == null) {
- throw new IllegalArgumentException("URI request pattern may not be null");
- }
- if (handler == null) {
- throw new IllegalArgumentException("HTTP request handelr may not be null");
- }
- this.handlerMap.put(pattern, handler);
+ matcher.register(pattern, handler);
}
-
+
public void unregister(final String pattern) {
- if (pattern == null) {
- return;
- }
- this.handlerMap.remove(pattern);
+ matcher.unregister(pattern);
}
-
+
public void setHandlers(final Map map) {
- if (map == null) {
- throw new IllegalArgumentException("Map of handlers may not be null");
- }
- this.handlerMap.clear();
- this.handlerMap.putAll(map);
- }
-
- public HttpRequestHandler lookup(String requestURI) {
- if (requestURI == null) {
- throw new IllegalArgumentException("Request URI may not be null");
- }
- //Strip away the query part part if found
- int index = requestURI.indexOf("?");
- if (index != -1) {
- requestURI = requestURI.substring(0, index);
- }
-
- // direct match?
- Object handler = this.handlerMap.get(requestURI);
- if (handler == null) {
- // pattern match?
- String bestMatch = null;
- for (Iterator it = this.handlerMap.keySet().iterator(); it.hasNext();) {
- String pattern = (String) it.next();
- if (matchUriRequestPattern(pattern, requestURI)) {
- // we have a match. is it any better?
- if (bestMatch == null
- || (bestMatch.length() < pattern.length())
- || (bestMatch.length() == pattern.length() && pattern.endsWith("*"))) {
- handler = this.handlerMap.get(pattern);
- bestMatch = pattern;
- }
- }
- }
- }
- return (HttpRequestHandler) handler;
+ matcher.setHandlers(map);
}
+ public HttpRequestHandler lookup(final String requestURI) {
+ return (HttpRequestHandler) matcher.lookup(requestURI);
+ }
+
+ /**
+ * @deprecated
+ */
protected boolean matchUriRequestPattern(final String pattern, final String requestUri) {
- if (pattern.equals("*")) {
- return true;
- } else {
- return
- (pattern.endsWith("*") && requestUri.startsWith(pattern.substring(0, pattern.length() - 1))) ||
- (pattern.startsWith("*") && requestUri.endsWith(pattern.substring(1, pattern.length())));
- }
+ return matcher.matchUriRequestPattern(pattern, requestUri);
}
-
+
}
Added: httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/UriPatternMatcher.java?rev=629988&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/UriPatternMatcher.java (added)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/UriPatternMatcher.java Thu Feb 21 12:55:18 2008
@@ -0,0 +1,127 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.protocol;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Maintains a map of objects keyed by a request URI pattern.
+ * Instances can be looked up by request URI.<br/>
+ * Patterns may have three formats:
+ * <ul>
+ * <li><code>*</code></li>
+ * <li><code>*<uri></code></li>
+ * <li><code><uri>*</code></li>
+ * </ul>
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ */
+public class UriPatternMatcher {
+
+ private final Map handlerMap;
+
+ public UriPatternMatcher() {
+ super();
+ this.handlerMap = new HashMap();
+ }
+
+ public void register(final String pattern, final Object handler) {
+ if (pattern == null) {
+ throw new IllegalArgumentException("URI request pattern may not be null");
+ }
+ if (handler == null) {
+ throw new IllegalArgumentException("HTTP request handelr may not be null");
+ }
+ this.handlerMap.put(pattern, handler);
+ }
+
+ public void unregister(final String pattern) {
+ if (pattern == null) {
+ return;
+ }
+ this.handlerMap.remove(pattern);
+ }
+
+ public void setHandlers(final Map map) {
+ if (map == null) {
+ throw new IllegalArgumentException("Map of handlers may not be null");
+ }
+ this.handlerMap.clear();
+ this.handlerMap.putAll(map);
+ }
+
+ public Object lookup(String requestURI) {
+ if (requestURI == null) {
+ throw new IllegalArgumentException("Request URI may not be null");
+ }
+ //Strip away the query part part if found
+ int index = requestURI.indexOf("?");
+ if (index != -1) {
+ requestURI = requestURI.substring(0, index);
+ }
+
+ // direct match?
+ Object handler = this.handlerMap.get(requestURI);
+ if (handler == null) {
+ // pattern match?
+ String bestMatch = null;
+ for (Iterator it = this.handlerMap.keySet().iterator(); it.hasNext();) {
+ String pattern = (String) it.next();
+ if (matchUriRequestPattern(pattern, requestURI)) {
+ // we have a match. is it any better?
+ if (bestMatch == null
+ || (bestMatch.length() < pattern.length())
+ || (bestMatch.length() == pattern.length() && pattern.endsWith("*"))) {
+ handler = this.handlerMap.get(pattern);
+ bestMatch = pattern;
+ }
+ }
+ }
+ }
+ return handler;
+ }
+
+ protected boolean matchUriRequestPattern(final String pattern, final String requestUri) {
+ if (pattern.equals("*")) {
+ return true;
+ } else {
+ return
+ (pattern.endsWith("*") && requestUri.startsWith(pattern.substring(0, pattern.length() - 1))) ||
+ (pattern.startsWith("*") && requestUri.endsWith(pattern.substring(1, pattern.length())));
+ }
+ }
+
+}
Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-main/src/main/java/org/apache/http/protocol/UriPatternMatcher.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/BufferingNHttpEntity.java Thu Feb 21 12:55:18 2008
@@ -42,8 +42,14 @@
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.nio.util.SimpleInputBuffer;
-public class BufferingNHttpEntity
- extends HttpEntityWrapper implements ConsumingNHttpEntity {
+/**
+ * A {@link ConsumingNHttpEntity} that consumes content into a buffer. The
+ * content can be retrieved as an InputStream via
+ * {@link HttpEntity#getContent()}, or written to an output stream via
+ * {@link HttpEntity#writeTo(OutputStream)}.
+ */
+public class BufferingNHttpEntity extends HttpEntityWrapper implements
+ ConsumingNHttpEntity {
private final static int BUFFER_SIZE = 2048;
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java Thu Feb 21 12:55:18 2008
@@ -40,6 +40,10 @@
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.IOControl;
+/**
+ * A {@link ConsumingNHttpEntity} that forwards available content to a
+ * {@link ContentListener}.
+ */
public class ConsumingNHttpEntityTemplate
extends HttpEntityWrapper implements ConsumingNHttpEntity {
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NByteArrayEntity.java Thu Feb 21 12:55:18 2008
@@ -44,8 +44,6 @@
/**
* An entity whose content is retrieved from a byte array.
- * This entity is intended for use only as an {@link NHttpEntity}.
- * Blocking methods are not supported.
*
* @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
*
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NFileEntity.java Thu Feb 21 12:55:18 2008
@@ -46,8 +46,6 @@
/**
* An entity whose content is retrieved from from a file.
- * This entity is intended for use only as an {@link NHttpEntity}.
- * Blocking methods are not supported.
*
* @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
*
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/NStringEntity.java Thu Feb 21 12:55:18 2008
@@ -46,8 +46,6 @@
/**
* An entity whose content is retrieved from a string.
- * This entity is intended for use only as an {@link NHttpEntity}.
- * Blocking methods are not supported.
*
* @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
*
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java Thu Feb 21 12:55:18 2008
@@ -1,7 +1,7 @@
/*
- * $HeadURL:$
- * $Revision:$
- * $Date:$
+ * $HeadURL$
+ * $Revision$
+ * $Date$
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
@@ -51,6 +51,9 @@
*/
void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException;
+ /**
+ * Notification that any resources allocated for writing can be released.
+ */
void finish();
}
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java Thu Feb 21 12:55:18 2008
@@ -38,6 +38,9 @@
import org.apache.http.nio.IOControl;
import org.apache.http.nio.util.ByteBufferAllocator;
+/**
+ * A simple {@link ContentListener} that reads and ignores all content.
+ */
public class SkipContentListener implements ContentListener {
private final ByteBuffer buffer;
Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java?rev=629988&r1=629987&r2=629988&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java Thu Feb 21 12:55:18 2008
@@ -52,7 +52,6 @@
import org.apache.http.nio.NHttpServiceHandler;
import org.apache.http.nio.entity.ConsumingNHttpEntity;
import org.apache.http.nio.entity.ConsumingNHttpEntityTemplate;
-import org.apache.http.nio.entity.ContentListener;
import org.apache.http.nio.entity.NByteArrayEntity;
import org.apache.http.nio.entity.ProducingNHttpEntity;
import org.apache.http.nio.entity.SkipContentListener;
@@ -63,38 +62,29 @@
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
-import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.util.EncodingUtils;
/**
* HTTP service handler implementation that works with
* {@link ConsumingNHttpEntity} and {@link ProducingNHttpEntity}. The contents
* of HTTP headers are stored in memory, HTTP entities are streamed directly
- * from the NHttpEntity to the underlying channel (and vice versa).
+ * from the entities to the underlying channel (and vice versa).
* <p>
- * When using this {@link NHttpServiceHandler}, it is important to ensure that
- * entities supplied for writing implement ProducingNHttpEntity. Doing
- * so will allow the entity to be written out asynchronously. If entities
- * supplied for writing do not implement ProducingNHttpEntity, a delegate is
- * added that buffers the entire contents in memory. Additionally, the buffering
- * might take place in the I/O thread, which could cause I/O to block
- * temporarily. For best results, ensure that all entities set on
- * {@link HttpResponse HttpResponses} from
- * {@link HttpRequestHandler HttpRequestHandlers} implement
+ * When using this, it is important to ensure that entities supplied for writing
+ * implement ProducingNHttpEntity. Doing so will allow the entity to be written
+ * out asynchronously. If entities supplied for writing do not implement
+ * ProducingNHttpEntity, a delegate is added that buffers the entire contents in
+ * memory. Additionally, the buffering might take place in the I/O thread, which
+ * could cause I/O to block temporarily. For best results, ensure that all
+ * entities set on {@link HttpResponse HttpResponses} from
+ * {@link NHttpRequestHandler NHttpRequestHandlers} implement
* ProducingNHttpEntity.
* <p>
- * If incoming requests have entities, HttpRequestHandlers <b>must not</b> call
- * {@link HttpEntity#getContent()}. Doing so will throw an
- * {@link UnsupportedOperationException}. Instead, handlers must expect that
- * incoming entities implement ConsumingNHttpEntity and install a
- * {@link ContentListener} on those entities. The ContentListener will be
- * notified when new data is available for reading. After all data has been
- * read, the response will automatically be sent.
- * <p>
- * To support legacy HttpRequestHandlers that do use getContent(), you can wrap
- * the handler within a {@link NBlockingHttpRequestHandler}. Doing so will
- * allow the handler to be processed on a new thread, in a blocking manner.
- * <p>
+ * If incoming requests are entity requests, NHttpRequestHandlers are expected
+ * to return a ConsumingNHttpEntity for reading the content. After the entity is
+ * finished reading the data,
+ * {@link NHttpRequestHandler#handle(HttpRequest, HttpResponse, NHttpResponseTrigger, HttpContext)} is
+ * called to generate a response.
*
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
* @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
@@ -431,27 +421,27 @@
return handler;
}
- static class ServerConnState {
+ protected static class ServerConnState {
private NHttpRequestHandler requestHandler;
private ConsumingNHttpEntity consumingEntity;
private ProducingNHttpEntity producingEntity;
- void finishInput() {
+ public void finishInput() {
if (this.consumingEntity != null) {
this.consumingEntity.finish();
this.consumingEntity = null;
}
}
- void finishOutput() {
+ public void finishOutput() {
if (this.producingEntity != null) {
this.producingEntity.finish();
this.producingEntity = null;
}
}
- void reset() {
+ public void reset() {
finishInput();
finishOutput();
this.requestHandler = null;
Added: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerRegistry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerRegistry.java?rev=629988&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerRegistry.java (added)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerRegistry.java Thu Feb 21 12:55:18 2008
@@ -0,0 +1,44 @@
+package org.apache.http.nio.protocol;
+
+import java.util.Map;
+
+import org.apache.http.protocol.UriPatternMatcher;
+
+/**
+ * Maintains a map of HTTP request handlers keyed by a request URI pattern.
+ * {@link NHttpRequestHandler} instances can be looked up by request URI
+ * using the {@link NHttpRequestHandlerResolver} interface.<br/>
+ * Patterns may have three formats:
+ * <ul>
+ * <li><code>*</code></li>
+ * <li><code>*<uri></code></li>
+ * <li><code><uri>*</code></li>
+ * </ul>
+ *
+ * @version $Revision$
+ */
+public class NHttpRequestHandlerRegistry implements NHttpRequestHandlerResolver {
+
+ private final UriPatternMatcher matcher;
+
+ public NHttpRequestHandlerRegistry() {
+ matcher = new UriPatternMatcher();
+ }
+
+ public void register(final String pattern, final NHttpRequestHandler handler) {
+ matcher.register(pattern, handler);
+ }
+
+ public void unregister(final String pattern) {
+ matcher.unregister(pattern);
+ }
+
+ public void setHandlers(final Map<String, ? extends NHttpRequestHandler> map) {
+ matcher.setHandlers(map);
+ }
+
+ public NHttpRequestHandler lookup(String requestURI) {
+ return (NHttpRequestHandler) matcher.lookup(requestURI);
+ }
+
+}
Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerRegistry.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerRegistry.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerRegistry.java
------------------------------------------------------------------------------
svn:mime-type = text/plain