14bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair/* 24bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * Copyright 2007 the original author or authors. 34bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * 44bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * Licensed under the Apache License, Version 2.0 (the "License"); 54bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * you may not use this file except in compliance with the License. 64bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * You may obtain a copy of the License at 74bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * 84bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * http://www.apache.org/licenses/LICENSE-2.0 94bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * 104bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * Unless required by applicable law or agreed to in writing, software 114bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * distributed under the License is distributed on an "AS IS" BASIS, 124bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * See the License for the specific language governing permissions and 144bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * limitations under the License. 154bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair */ 164bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismairpackage org.mockftpserver.stub.command; 174bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair 184bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismairimport org.apache.log4j.Logger; 194bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismairimport org.mockftpserver.core.command.Command; 204bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismairimport org.mockftpserver.core.command.CommandHandler; 214bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismairimport org.mockftpserver.core.command.InvocationRecord; 224bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismairimport org.mockftpserver.core.session.Session; 234bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair 244bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair/** 254bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * CommandHandler for the APPE (Append) command. Send back two replies on the control connection: a 264bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * reply code of 150 and another of 226. 274bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * <p> 284bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * Each invocation record stored by this CommandHandler includes the following data element key/values: 294bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * <ul> 304bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * <li>{@link #PATHNAME_KEY} ("pathname") - the pathname of the directory submitted on the invocation (the first command parameter) 314bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * <li>{@link #FILE_CONTENTS_KEY} ("fileContents") - the file contents (<code>byte[]</code>) sent on the data connection 324bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * </ul> 334bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * 344bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * @version $Revision$ - $Date$ 354bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * 364bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * @author Chris Mair 374bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair */ 384bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismairpublic final class AppeCommandHandler extends AbstractStubDataCommandHandler implements CommandHandler { 394bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair 404bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair public static final String PATHNAME_KEY = "pathname"; 414bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair public static final String FILE_CONTENTS_KEY = "filecontents"; 424bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair 434bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair private static final Logger LOG = Logger.getLogger(AppeCommandHandler.class); 444bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair 454bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair /** 464bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#beforeProcessData(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session, org.mockftpserver.core.command.InvocationRecord) 474bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair */ 484bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair protected void beforeProcessData(Command command, Session session, InvocationRecord invocationRecord) throws Exception { 494bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair String filename = command.getRequiredString(0); 504bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair invocationRecord.set(PATHNAME_KEY, filename); 514bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair } 524bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair 534bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair /** 544bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#processData(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session, org.mockftpserver.core.command.InvocationRecord) 554bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair */ 564bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair protected void processData(Command command, Session session, InvocationRecord invocationRecord) { 574bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair byte[] data = session.readData(); 584bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair LOG.info("Received " + data.length + " bytes"); 594bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair LOG.trace("Received data [" + new String(data) + "]"); 604bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair invocationRecord.set(FILE_CONTENTS_KEY, data); 614bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair } 624bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair 634bc314fb002f3e5369cd724b91e83e0c71aeeccbchrismair} 64