| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PortCommandHandler |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright 2008 the original author or authors. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.mockftpserver.stub.command; | |
| 17 | ||
| 18 | import org.mockftpserver.core.command.Command; | |
| 19 | import org.mockftpserver.core.command.CommandHandler; | |
| 20 | import org.mockftpserver.core.command.InvocationRecord; | |
| 21 | import org.mockftpserver.core.command.ReplyCodes; | |
| 22 | import org.mockftpserver.core.session.Session; | |
| 23 | import org.mockftpserver.core.util.HostAndPort; | |
| 24 | import org.mockftpserver.core.util.PortParser; | |
| 25 | ||
| 26 | import java.net.UnknownHostException; | |
| 27 | ||
| 28 | /** | |
| 29 | * CommandHandler for the PORT command. Send back a reply code of 200. | |
| 30 | * <p/> | |
| 31 | * Each invocation record stored by this CommandHandler includes the following data element key/values: | |
| 32 | * <ul> | |
| 33 | * <li>{@link #HOST_KEY} ("host") - the client data host (InetAddress) submitted on the invocation (from parameters 1-4) | |
| 34 | * <li>{@link #PORT_KEY} ("port") - the port number (Integer) submitted on the invocation (from parameter 5-6) | |
| 35 | * </ul> | |
| 36 | * | |
| 37 | * @author Chris Mair | |
| 38 | * @version $Revision: 232 $ - $Date: 2009-06-13 19:18:01 -0400 (Sat, 13 Jun 2009) $ | |
| 39 | */ | |
| 40 | public class PortCommandHandler extends AbstractStubCommandHandler implements CommandHandler { | |
| 41 | ||
| 42 | public static final String HOST_KEY = "host"; | |
| 43 | public static final String PORT_KEY = "port"; | |
| 44 | ||
| 45 | /** | |
| 46 | * Constructor. Initialize the replyCode. | |
| 47 | */ | |
| 48 | 60 | public PortCommandHandler() { |
| 49 | 60 | setReplyCode(ReplyCodes.PORT_OK); |
| 50 | 60 | } |
| 51 | ||
| 52 | /** | |
| 53 | * Handle the command | |
| 54 | * | |
| 55 | * @throws UnknownHostException | |
| 56 | * @see org.mockftpserver.core.command.CommandHandler#handleCommand(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session) | |
| 57 | */ | |
| 58 | public void handleCommand(Command command, Session session, InvocationRecord invocationRecord) throws UnknownHostException { | |
| 59 | 14 | HostAndPort client = PortParser.parseHostAndPort(command.getParameters()); |
| 60 | 13 | LOG.debug("host=" + client.host + " port=" + client.port); |
| 61 | 13 | session.setClientDataHost(client.host); |
| 62 | 13 | session.setClientDataPort(client.port); |
| 63 | 13 | invocationRecord.set(HOST_KEY, client.host); |
| 64 | 13 | invocationRecord.set(PORT_KEY, new Integer(client.port)); |
| 65 | 13 | sendReply(session); |
| 66 | 13 | } |
| 67 | ||
| 68 | } |