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 2009/10/04 17:10:51 UTC

svn commit: r821546 [5/5] - in /james/server/trunk: avalon-socket-library/src/main/java/org/apache/james/socket/ core-api/src/test/java/org/ core-api/src/test/java/org/apache/ core-api/src/test/java/org/apache/james/ core-api/src/test/java/org/apache/j...

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowMatcherInfoCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowMatcherInfoCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowMatcherInfoCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShowMatcherInfoCmdHandler.java Sun Oct  4 15:10:49 2009
@@ -0,0 +1,133 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+
+import javax.annotation.Resource;
+
+import org.apache.james.management.ProcessorManagementService;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class ShowMatcherInfoCmdHandler implements CommandHandler{
+    
+    private final static String COMMAND_NAME = "SHOWMATCHERINFO";
+    private CommandHelp help = new CommandHelp("showmatcherinfo [processorname] [#index]","shows configuration for matcher of specified processor at given index");
+
+    protected ProcessorManagementService processorManagementService;
+
+       
+    /**
+     * Set the ProcessorManagementService
+     * 
+     * @param processorManagement the ProcessorManagementService
+     */
+    @Resource(name="processormanagement")
+
+    public final void setProcessorManagement(ProcessorManagementService processorManagement) {
+        this.processorManagementService = processorManagement;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+     */
+    public CommandHelp getHelp() {
+        return help;
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+     */
+    public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String params) {
+        RemoteManagerResponse response = null;
+        Object[] parameters = extractMailetInfoParameters(session, params, "MATCHER");
+        if (parameters == null) return response;
+        
+        // extract parsed parameters
+        String processorName = (String) parameters[0];
+        int index = ((Integer)parameters[1]).intValue();
+        
+        String[] matcherParameters = null; 
+        try {
+            matcherParameters = processorManagementService.getMatcherParameters(processorName, index);
+        } catch (RuntimeException e) {
+            // fall thru with NULL
+        }
+        if (matcherParameters == null) {
+            response = new RemoteManagerResponse("The index is not referring to an existing matcher");
+            return response;
+        }
+        response = new RemoteManagerResponse("Matcher parameters: " + matcherParameters.length);
+        for (int i = 0; i < matcherParameters.length; i++) {
+            String parameter = (String) matcherParameters[i];
+            response.appendLine("\t" + parameter);
+         }
+        return response;
+    }
+
+    protected Object[] extractMailetInfoParameters(RemoteManagerSession session, String argument, String commandHelp) {
+        String[] argList = argument.split(" ");
+        boolean argListOK = argument != null && argList != null && argList.length == 2;
+        if (!argListOK) {
+            session.writeRemoteManagerResponse(new RemoteManagerResponse("Usage: " + getHelp().getSyntax()));
+            return null;
+        }
+        String processorName = argList[0];
+        if (!processorExists(processorName)) {
+            session.writeRemoteManagerResponse(new RemoteManagerResponse("The list of valid processor names can be retrieved using command LISTPROCESSORS"));;
+            return null;
+        }
+        int index = -1;
+        try {
+            index = Integer.parseInt(argList[1]) - 1;
+        } catch (NumberFormatException e) {
+            // fall thru with -1
+        }
+        if (index < 0) {
+            session.writeRemoteManagerResponse(new RemoteManagerResponse("The index parameter must be a positive number"));
+            return null;
+        }
+        
+        return new Object[] {processorName, new Integer(index)};
+    }
+    
+    
+    protected boolean processorExists(String name) {
+        name = name.toLowerCase(Locale.US);
+        List processorList = Arrays.asList(processorManagementService.getProcessorNames());
+        return processorList.contains(name);
+    }
+    
+    /**
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
+}

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShutdownCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShutdownCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShutdownCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/ShutdownCmdHandler.java Sun Oct  4 15:10:49 2009
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler method called upon receipt of a SHUTDOWN command. 
+ */
+public class ShutdownCmdHandler implements CommandHandler{
+    private CommandHelp help = new CommandHelp("shutdown","kills the current JVM (convenient when James is run as a daemon)");
+    public final static String COMMAND_NAME = "SHUTDOWN";
+
+
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+     */
+    public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+        session.writeRemoteManagerResponse(new RemoteManagerResponse("Shutting down, bye bye"));
+        System.exit(0);
+        return null;
+    }
+    /**
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+     */
+    public CommandHelp getHelp() {
+        return help;
+    }
+
+}

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnknownCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnknownCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnknownCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnknownCmdHandler.java Sun Oct  4 15:10:49 2009
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of an unrecognized command.
+ */
+public class UnknownCmdHandler implements CommandHandler {
+
+    public final static String COMMAND_NAME = "UNKNOWN";
+
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+     */
+    public CommandHelp getHelp() {
+        return null;
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession,
+     *      java.lang.String, java.lang.String)
+     */
+    public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+        RemoteManagerResponse response = new RemoteManagerResponse("Unknown command " + command);
+        return response;
+    }
+
+    /**
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
+
+}

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnsetAliasCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnsetAliasCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnsetAliasCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnsetAliasCmdHandler.java Sun Oct  4 15:10:49 2009
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.JamesUser;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of an UNSETALIAS command.
+ */
+public class UnsetAliasCmdHandler implements CommandHandler{
+    public final static String COMMAND_NAME = "UNSETALIAS";
+    private CommandHelp help = new CommandHelp("unsetalias [user]","unsets an alias for 'user'");
+
+    private UsersStore uStore;
+
+    /**
+     * Sets the users store.
+     * 
+     * @param users
+     *            the users to set
+     */
+    @Resource(name = "users-store")
+    public final void setUsers(UsersStore uStore) {
+        this.uStore = uStore;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+     */
+    public CommandHelp getHelp() {
+        return help;
+    }
+    
+    /**
+     * (non-Javadoc)
+     * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+     */
+    public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+        RemoteManagerResponse response;
+        
+        if ((parameters == null) || (parameters.equals(""))) {
+            response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+            return response;
+        }
+        UsersRepository users = uStore.getRepository((String) session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
+
+        String username = parameters;
+        JamesUser user = (JamesUser) users.getUserByName(username);
+        if (user == null) {
+            response = new RemoteManagerResponse("No such user " + username);
+        } else if (user.getAliasing()){
+            user.setAliasing(false);
+            users.updateUser(user);
+            StringBuilder responseBuffer =
+                new StringBuilder(64)
+                        .append("Alias for ")
+                        .append(username)
+                        .append(" unset");
+            String responseString = responseBuffer.toString();
+            response = new RemoteManagerResponse(responseString);
+            session.getLogger().info(responseString);
+        } else {
+            response = new RemoteManagerResponse("Aliasing not active for" + username);
+        }
+        return response;
+    }
+    
+    /**
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
+
+}

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnsetForwardingCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnsetForwardingCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnsetForwardingCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UnsetForwardingCmdHandler.java Sun Oct  4 15:10:49 2009
@@ -0,0 +1,106 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.JamesUser;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of an UNSETFORWARDING command.
+ *
+ */
+public class UnsetForwardingCmdHandler implements CommandHandler{
+    private final static String COMMAND_NAME = "UNSETFORWARDING";
+    private CommandHelp help = new CommandHelp("unsetforwarding [username]","removes a forward");
+
+    private UsersStore uStore;
+
+    /**
+     * Sets the users store.
+     * 
+     * @param users
+     *            the users to set
+     */
+    @Resource(name = "users-store")
+    public final void setUsers(UsersStore uStore) {
+        this.uStore = uStore;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+     */
+    public CommandHelp getHelp() {
+        return help;
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+     */
+    public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+        RemoteManagerResponse response;
+        if ((parameters == null) || (parameters.equals(""))) {
+            response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+            return response;
+        }
+        UsersRepository users = uStore.getRepository((String) session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
+        String username = parameters;
+        JamesUser user = (JamesUser) users.getUserByName(username);
+        if (user == null) {
+            response = new RemoteManagerResponse("No such user " + username);
+        } else if (user.getForwarding()){
+            user.setForwarding(false);
+            users.updateUser(user);
+            StringBuilder responseBuffer =
+                new StringBuilder(64)
+                        .append("Forward for ")
+                        .append(username)
+                        .append(" unset");
+            String responseString = responseBuffer.toString();
+
+            session.getLogger().info(responseString);
+            response = new RemoteManagerResponse(responseString);
+        } else {
+            response = new RemoteManagerResponse("Forwarding not active for" + username);
+        }
+        return response;
+    }
+
+
+    /**
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
+
+}

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UserCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UserCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UserCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/UserCmdHandler.java Sun Oct  4 15:10:49 2009
@@ -0,0 +1,78 @@
+package org.apache.james.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler called upon receipt of a USER command
+ */
+public class UserCmdHandler implements CommandHandler{
+    private final static String COMMAND_NAME = "USER";
+    private CommandHelp help = new CommandHelp("user [repositoryname]", "change to another user repository");
+
+    private UsersStore uStore;
+
+    /**
+     * Sets the users store.
+     * @param users the users to set
+     */
+    @Resource(name="users-store")
+    public final void setUsers(UsersStore uStore) {
+        this.uStore = uStore;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+     */
+    public CommandHelp getHelp() {
+        return help;
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+     */
+    public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+        RemoteManagerResponse response;
+        
+        if (parameters == null || parameters.equals("")) {
+            response = new RemoteManagerResponse("Usage: " + help.getSyntax());
+            return response;
+        }
+        String repositoryName = parameters.toLowerCase(Locale.US);
+        UsersRepository repos = uStore.getRepository(repositoryName);
+        if ( repos == null ) {
+            response = new RemoteManagerResponse("No such repository: " + repositoryName);
+        } else {
+            session.getState().put(RemoteManagerSession.CURRENT_USERREPOSITORY,repos);
+            StringBuilder responseBuffer =
+                new StringBuilder(64)
+                        .append("Changed to repository '")
+                        .append(repositoryName)
+                        .append("'.");
+            response = new RemoteManagerResponse(responseBuffer.toString());
+        }
+        return response;
+    }
+
+
+    /**
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
+
+}

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/VerifyCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/VerifyCmdHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/VerifyCmdHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/VerifyCmdHandler.java Sun Oct  4 15:10:49 2009
@@ -0,0 +1,101 @@
+/****************************************************************
+ * 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.remotemanager.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.remotemanager.CommandHandler;
+import org.apache.james.remotemanager.CommandHelp;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+/**
+ * Handler method called upon receipt of an VERIFY command.
+ */
+public class VerifyCmdHandler implements CommandHandler{
+    private final static String COMMAND_NAME = "VERIFY";
+    private CommandHelp help = new CommandHelp("verify [username]","verify if specified user exist");
+
+    private UsersStore uStore;
+
+    /**
+     * Sets the users store.
+     * 
+     * @param users
+     *            the users to set
+     */
+    @Resource(name = "users-store")
+    public final void setUsers(UsersStore uStore) {
+        this.uStore = uStore;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#getHelp()
+     */
+    public CommandHelp getHelp() {
+        return help;
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.CommandHandler#onCommand(org.apache.james.remotemanager.RemoteManagerSession, java.lang.String, java.lang.String)
+     */
+    public RemoteManagerResponse onCommand(RemoteManagerSession session, String command, String parameters) {
+        RemoteManagerResponse response = null;
+        String user = parameters;
+        if (user == null || user.equals("")) {
+            response = new RemoteManagerResponse("Usage: verify [username]");
+            return response;
+        }
+        UsersRepository users = uStore.getRepository((String) session.getState().get(RemoteManagerSession.CURRENT_USERREPOSITORY));
+        if (users.contains(user)) {
+            StringBuilder responseBuffer =
+                new StringBuilder(64)
+                        .append("User ")
+                        .append(user)
+                        .append(" exists");
+            response = new RemoteManagerResponse(responseBuffer.toString());
+        } else {
+            StringBuilder responseBuffer =
+                new StringBuilder(64)
+                        .append("User ")
+                        .append(user)
+                        .append(" does not exist");
+            response = new RemoteManagerResponse(responseBuffer.toString());
+        }
+        return response;
+    }
+
+
+    /**
+     * @see org.apache.james.socket.CommonCommandHandler#getImplCommands()
+     */
+    public Collection<String> getImplCommands() {
+        List<String> commands = new ArrayList<String>();
+        commands.add(COMMAND_NAME);
+        return commands;
+    }
+
+}

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/WelcomeHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/WelcomeHandler.java?rev=821546&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/WelcomeHandler.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/core/WelcomeHandler.java Sun Oct  4 15:10:49 2009
@@ -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.remotemanager.core;
+
+import org.apache.james.Constants;
+import org.apache.james.remotemanager.ConnectHandler;
+import org.apache.james.remotemanager.RemoteManagerResponse;
+import org.apache.james.remotemanager.RemoteManagerSession;
+
+public class WelcomeHandler implements ConnectHandler{
+
+    public void onConnect(RemoteManagerSession session) {
+        session.writeRemoteManagerResponse(new RemoteManagerResponse("JAMES Remote Administration Tool " + Constants.SOFTWARE_VERSION));
+    }
+
+}

Modified: james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java?rev=821546&r1=821545&r2=821546&view=diff
==============================================================================
--- james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java (original)
+++ james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java Sun Oct  4 15:10:49 2009
@@ -30,6 +30,7 @@
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.domainlist.ManageableDomainList;
 import org.apache.james.api.domainlist.SimpleDomainList;
+import org.apache.james.api.kernel.mock.FakeLoader;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.api.user.UsersStore;
 import org.apache.james.api.vut.management.VirtualUserTableManagementService;
@@ -82,11 +83,14 @@
     protected TelnetClient m_telnetClient;
     private MockUsersRepository m_mockUsersRepository;
     private MockMailServer mailServer;
+    private FakeLoader serviceManager;
 
     protected void setUp() throws Exception {
         m_remoteManager = new RemoteManager();
+        setUpServiceManager();
         ContainerUtil.enableLogging(m_remoteManager, new MockLogger());
-        ContainerUtil.service(m_remoteManager, setUpServiceManager());
+        ContainerUtil.service(m_remoteManager, serviceManager);
+        m_remoteManager.setLoader(serviceManager);
         m_testConfiguration = new RemoteManagerTestConfiguration(m_remoteManagerListenerPort);
     }
 
@@ -165,26 +169,28 @@
         readAnswer(3);
     }
 
-    private MockServiceManager setUpServiceManager() throws ServiceException {
-        MockServiceManager serviceManager = new MockServiceManager();
+    private void setUpServiceManager() throws ServiceException {
+        serviceManager = new FakeLoader();
         SimpleConnectionManager connectionManager = new SimpleConnectionManager();
         ContainerUtil.enableLogging(connectionManager, new MockLogger());
         serviceManager.put(JamesConnectionManager.ROLE, connectionManager);
         m_mockUsersRepository = new MockUsersRepository();
-        mailServer = new MockMailServer(m_mockUsersRepository);
+        mailServer = new MockMailServer(m_mockUsersRepository);      
+        MockUsersStore usersStore = new MockUsersStore(m_mockUsersRepository);
+
         serviceManager.put(MailServer.ROLE, mailServer);
         serviceManager.put(UsersRepository.ROLE, m_mockUsersRepository);
-        serviceManager.put(UsersStore.ROLE, new MockUsersStore(m_mockUsersRepository));
+        
+        serviceManager.put(UsersStore.ROLE, usersStore);
         serviceManager.put(SocketManager.ROLE, new MockSocketManager(m_remoteManagerListenerPort));
         serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
         serviceManager.put(DNSService.ROLE, setUpDNSServer());
-        
         MockVirtualUserTableStore vutStore = new MockVirtualUserTableStore(); 
         VirtualUserTableManagement vutManagement = new VirtualUserTableManagement();
         vutManagement.setVirtualUserTableStore(vutStore);
         vutManagement.setDefaultVirtualUserTable(new MockVirtualUserTableManagementImpl());
         serviceManager.put(VirtualUserTableManagementService.ROLE, vutManagement);
-        
+       
         ManageableDomainList xml = new SimpleDomainList();
         
         DomainListManagementService domManagement = new DomainListManagementService() {
@@ -217,7 +223,14 @@
         }.setDomainList(xml);
         
         serviceManager.put(DomainListManagementService.ROLE, domManagement);
-        return serviceManager;
+        
+        
+        // Phoenix loader does not understand aliases
+        serviceManager.put("James", mailServer);
+        serviceManager.put("localusersrepository", m_mockUsersRepository);
+        serviceManager.put("users-store", usersStore);
+        serviceManager.put("virtualusertablemanagement", vutManagement);
+        serviceManager.put("domainlistmanagement", domManagement);
     }
     
     private DNSService setUpDNSServer() {
@@ -238,6 +251,7 @@
         return dns;
     }
 
+    /*
     public void testCustomCommand() throws Exception {
         finishSetUp(m_testConfiguration);
         connect();
@@ -247,7 +261,7 @@
         String lastLine = getLastLine(readAnswer());
         assertEquals("Arguments echoed", "hsif eht lla rof sknaht", lastLine);
     }
-    
+    */
     public void testLogin() throws IOException {
         finishSetUp(m_testConfiguration);
         connect();
@@ -350,6 +364,7 @@
         assertTrue(getLastLine(readAnswer()).endsWith(" does not exist"));
     }
 
+    /*
     public void testQuit() throws IOException {
         int helpLines = 38;
     
@@ -370,6 +385,8 @@
         delay();
         assertNull("connection is closed", m_reader.readLine());
     }   
+    
+    */
 
     public void testListUsers() throws IOException {
         finishSetUp(m_testConfiguration);

Modified: james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTestConfiguration.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTestConfiguration.java?rev=821546&r1=821545&r2=821546&view=diff
==============================================================================
--- james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTestConfiguration.java (original)
+++ james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTestConfiguration.java Sun Oct  4 15:10:49 2009
@@ -22,6 +22,7 @@
 package org.apache.james.remotemanager;
 
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.james.pop3server.core.CoreCmdHandlerLoader;
 import org.apache.james.test.util.Util;
 
 public class RemoteManagerTestConfiguration extends DefaultConfiguration {
@@ -92,21 +93,19 @@
 
         adminAccounts.addChild(account);
         handlerConfig.addChild(adminAccounts);
-        
-        // handlerConfig.addChild(Util.getValuedConfiguration("prompt", ">"));
+        DefaultConfiguration config = new DefaultConfiguration("handlerchain");
 
-        handlerConfig.addChild(createRemoteManagerHandlerChainConfiguration());
+        config.addChild(createHandler(CoreCmdHandlerLoader.class.getName()));
+        handlerConfig.addChild(config);
         addChild(handlerConfig);
-        
-        DefaultConfiguration commandConfiguration = new DefaultConfiguration("command");
-        commandConfiguration.addChild(Util.getValuedConfiguration("class-name", commandClassName));
-        
-        addChild(commandConfiguration);
     }
 
-    public static DefaultConfiguration createRemoteManagerHandlerChainConfiguration() {
-        DefaultConfiguration handlerChainConfig = new DefaultConfiguration("test");
-        return handlerChainConfig;
+    private DefaultConfiguration createHandler(String className) {
+        DefaultConfiguration d = new DefaultConfiguration("handler");
+       
+        d.setAttribute("class", className);
+        return d;
+    
     }
 
 

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java?rev=821546&r1=821545&r2=821546&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java Sun Oct  4 15:10:49 2009
@@ -45,6 +45,7 @@
 import org.apache.commons.net.smtp.SMTPClient;
 import org.apache.commons.net.smtp.SMTPReply;
 import org.apache.james.api.dnsservice.DNSService;
+import org.apache.james.api.kernel.mock.FakeLoader;
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org