Coverage Report - org.mockftpserver.stub.command.EprtCommandHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
EprtCommandHandler
100%
12/12
N/A
1
 
 1  
 /*
 2  
  * Copyright 2009 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.PortParser;
 24  
 import org.mockftpserver.core.util.HostAndPort;
 25  
 
 26  
 import java.net.UnknownHostException;
 27  
 
 28  
 /**
 29  
  * CommandHandler for the EPRT 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  
  * See RFC2428 for more information.
 37  
  *
 38  
  * @author Chris Mair
 39  
  * @version $Revision: 262 $ - $Date: 2012-07-15 08:33:02 -0400 (Sun, 15 Jul 2012) $
 40  
  */
 41  
 public class EprtCommandHandler extends AbstractStubCommandHandler implements CommandHandler {
 42  
 
 43  
     public static final String HOST_KEY = "host";
 44  
     public static final String PORT_KEY = "port";
 45  
 
 46  
     /**
 47  
      * Constructor. Initialize the replyCode.
 48  
      */
 49  61
     public EprtCommandHandler() {
 50  61
         setReplyCode(ReplyCodes.EPRT_OK);
 51  61
     }
 52  
 
 53  
     /**
 54  
      * Handle the command
 55  
      *
 56  
      * @throws java.net.UnknownHostException
 57  
      * @see org.mockftpserver.core.command.CommandHandler#handleCommand(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session)
 58  
      */
 59  
     public void handleCommand(Command command, Session session, InvocationRecord invocationRecord) throws UnknownHostException {
 60  3
         String parameter = command.getRequiredParameter(0);
 61  
 
 62  2
         HostAndPort client = PortParser.parseExtendedAddressHostAndPort(parameter);
 63  2
         LOG.debug("host=" + client.host + " port=" + client.port);
 64  2
         session.setClientDataHost(client.host);
 65  2
         session.setClientDataPort(client.port);
 66  2
         invocationRecord.set(HOST_KEY, client.host);
 67  2
         invocationRecord.set(PORT_KEY, new Integer(client.port));
 68  2
         sendReply(session);
 69  2
     }
 70  
 
 71  
 }