AppeCommandHandler.java revision 93102446a7b7c3d17888064b4e2e4e5cb534e6d0
1/* 2 * Copyright 2007 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 */ 16package org.mockftpserver.stub.command; 17 18import org.apache.log4j.Logger; 19import org.mockftpserver.core.command.Command; 20import org.mockftpserver.core.command.CommandHandler; 21import org.mockftpserver.core.command.InvocationRecord; 22import org.mockftpserver.core.session.Session; 23 24/** 25 * CommandHandler for the APPE (Append) command. Send back two replies on the control connection: a 26 * reply code of 150 and another of 226. 27 * <p> 28 * Each invocation record stored by this CommandHandler includes the following data element key/values: 29 * <ul> 30 * <li>{@link #PATHNAME_KEY} ("pathname") - the pathname of the directory submitted on the invocation (the first command parameter) 31 * <li>{@link #FILE_CONTENTS_KEY} ("fileContents") - the file contents (<code>byte[]</code>) sent on the data connection 32 * </ul> 33 * 34 * @version $Revision: 95 $ - $Date: 2007-10-30 22:05:41 -0400 (Tue, 30 Oct 2007) $ 35 * 36 * @author Chris Mair 37 */ 38public final class AppeCommandHandler extends AbstractStubDataCommandHandler implements CommandHandler { 39 40 public static final String PATHNAME_KEY = "pathname"; 41 public static final String FILE_CONTENTS_KEY = "filecontents"; 42 43 private static final Logger LOG = Logger.getLogger(AppeCommandHandler.class); 44 45 /** 46 * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#beforeProcessData(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session, org.mockftpserver.core.command.InvocationRecord) 47 */ 48 protected void beforeProcessData(Command command, Session session, InvocationRecord invocationRecord) throws Exception { 49 String filename = command.getRequiredString(0); 50 invocationRecord.set(PATHNAME_KEY, filename); 51 } 52 53 /** 54 * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#processData(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session, org.mockftpserver.core.command.InvocationRecord) 55 */ 56 protected void processData(Command command, Session session, InvocationRecord invocationRecord) { 57 byte[] data = session.readData(); 58 LOG.info("Received " + data.length + " bytes"); 59 LOG.trace("Received data [" + new String(data) + "]"); 60 invocationRecord.set(FILE_CONTENTS_KEY, data); 61 } 62 63} 64