You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/11/10 19:15:01 UTC
svn commit: r1033627 - in
/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api:
AbstractCommandDispatcher.java ResponseResultHandler.java
Author: norman
Date: Wed Nov 10 18:15:01 2010
New Revision: 1033627
URL: http://svn.apache.org/viewvc?rev=1033627&view=rev
Log:
Add ResponseResultHandler interface which can be implemented to react on Response's
Added:
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ResponseResultHandler.java
Modified:
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractCommandDispatcher.java
Modified: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractCommandDispatcher.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractCommandDispatcher.java?rev=1033627&r1=1033626&r2=1033627&view=diff
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractCommandDispatcher.java (original)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/AbstractCommandDispatcher.java Wed Nov 10 18:15:01 2010
@@ -41,6 +41,7 @@ public abstract class AbstractCommandDis
*/
private HashMap<String, List<CommandHandler<Session>>> commandHandlerMap = new HashMap<String, List<CommandHandler<Session>>>();
+ private List<ResponseResultHandler<Response, Session>> rHandlers = new ArrayList<ResponseResultHandler<Response, Session>>();
/**
* Add it to map (key as command name, value is an array list of CommandHandlers)
*
@@ -85,29 +86,31 @@ public abstract class AbstractCommandDis
*/
@SuppressWarnings("unchecked")
public void wireExtensions(Class interfaceName, List extension) throws WiringException {
- this.commandHandlerMap = new HashMap<String, List<CommandHandler<Session>>>();
-
- for (Iterator it = extension.iterator(); it.hasNext(); ) {
- CommandHandler handler = (CommandHandler) it.next();
- Collection implCmds = handler.getImplCommands();
-
- for (Iterator i = implCmds.iterator(); i.hasNext(); ) {
- String commandName = ((String) i.next()).trim().toUpperCase(Locale.US);
- addToMap(commandName, (CommandHandler) handler);
- }
+ if (interfaceName.equals(ResponseResultHandler.class)) {
+ rHandlers.addAll(extension);
}
+ if (interfaceName.equals(CommandHandler.class)) {
+ for (Iterator it = extension.iterator(); it.hasNext();) {
+ CommandHandler handler = (CommandHandler) it.next();
+ Collection implCmds = handler.getImplCommands();
+
+ for (Iterator i = implCmds.iterator(); i.hasNext();) {
+ String commandName = ((String) i.next()).trim().toUpperCase(Locale.US);
+ addToMap(commandName, (CommandHandler) handler);
+ }
+ }
- addToMap(getUnknownCommandHandlerIdentifier(), getUnknownCommandHandler());
+ addToMap(getUnknownCommandHandlerIdentifier(), getUnknownCommandHandler());
- if (commandHandlerMap.size() < 2) {
- throw new WiringException("No commandhandlers configured");
- } else {
- List<String> mandatoryCommands = getMandatoryCommands();
- for (int i = 0; i < mandatoryCommands.size(); i++) {
- String cmd = mandatoryCommands.get(i);
- if (!commandHandlerMap.containsKey(mandatoryCommands.get(i))) {
- throw new WiringException(
- "No commandhandlers configured for mandatory command " +cmd) ;
+ if (commandHandlerMap.size() < 2) {
+ throw new WiringException("No commandhandlers configured");
+ } else {
+ List<String> mandatoryCommands = getMandatoryCommands();
+ for (int i = 0; i < mandatoryCommands.size(); i++) {
+ String cmd = mandatoryCommands.get(i);
+ if (!commandHandlerMap.containsKey(mandatoryCommands.get(i))) {
+ throw new WiringException("No commandhandlers configured for mandatory command " + cmd);
+ }
}
}
}
@@ -138,11 +141,17 @@ public abstract class AbstractCommandDis
// fetch the command handlers registered to the command
int count = commandHandlers.size();
for (int i = 0; i < count; i++) {
- Response response = commandHandlers.get(i).onCommand(session, new BaseRequest(curCommandName, curCommandArgument));
+ CommandHandler<Session> cHandler = commandHandlers.get(i);
+ Response response = cHandler.onCommand(session, new BaseRequest(curCommandName, curCommandArgument));
// if the response is received, stop processing of command
// handlers
if (response != null) {
+
+ // now process the result handlers
+ for (int a = 0; a < rHandlers.size(); a++) {
+ response = rHandlers.get(a).onResponse(session, response, (CommandHandler<Session>) cHandler);
+ }
session.writeResponse(response);
break;
@@ -151,7 +160,7 @@ public abstract class AbstractCommandDis
} catch (UnsupportedEncodingException e) {
// Should never happen
- e.printStackTrace();
+ session.getLogger().error("Unable to handle encoding" ,e );
}
@@ -168,6 +177,7 @@ public abstract class AbstractCommandDis
public List<Class<?>> getMarkerInterfaces() {
List res = new LinkedList();
res.add(CommandHandler.class);
+ res.add(ResponseResultHandler.class);
return res;
}
Added: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ResponseResultHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ResponseResultHandler.java?rev=1033627&view=auto
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ResponseResultHandler.java (added)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/ResponseResultHandler.java Wed Nov 10 18:15:01 2010
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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. *
+ ****************************************************************/
+
+package org.apache.james.protocols.api;
+
+public interface ResponseResultHandler<R extends Response, S extends ProtocolSession> {
+
+ /**
+ * Get called when a {@link Response} was returned from the {@link CommandHandler}
+ *
+ * @param session
+ * @param response
+ * @param handler
+ * @return response
+ */
+ public Response onResponse(ProtocolSession session, R response, CommandHandler<S> handler);
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org