chrismair | 00dc7bd | 2014-05-11 21:21:28 +0000 | [diff] [blame] | 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 | */
|
| 16 | package org.mockftpserver.stub.command;
|
| 17 |
|
| 18 | import org.mockftpserver.core.command.ReplyCodes;
|
| 19 | import org.mockftpserver.core.session.Session;
|
| 20 |
|
| 21 | /**
|
| 22 | * CommandHandler for the STOU (Store Unique) command. Send back two replies on the control connection: a
|
| 23 | * reply code of 150 and another of 226. The text accompanying the final reply (226) is the
|
| 24 | * unique filename, which is "" by default. You can customize the returned filename by setting
|
| 25 | * the <code>filename</code> property.
|
| 26 | * <p/>
|
| 27 | * Each invocation record stored by this CommandHandler includes the following data element key/values:
|
| 28 | * <ul>
|
| 29 | * <li>{@link #FILE_CONTENTS_KEY} ("fileContents") - the file contents (<code>byte[]</code>) sent on the data connection
|
| 30 | * </ul>
|
| 31 | *
|
| 32 | * @author Chris Mair
|
| 33 | * @version $Revision$ - $Date$
|
| 34 | */
|
| 35 | public class StouCommandHandler extends AbstractStorCommandHandler {
|
| 36 |
|
| 37 | private static final String FINAL_REPLY_TEXT_KEY = "226.WithFilename";
|
| 38 |
|
| 39 | private String filename = "";
|
| 40 |
|
| 41 | /**
|
| 42 | * Override the default implementation to send a custom reply text that includes the STOU response filename
|
| 43 | *
|
| 44 | * @see org.mockftpserver.stub.command.AbstractStubDataCommandHandler#sendFinalReply(org.mockftpserver.core.session.Session)
|
| 45 | */
|
| 46 | protected void sendFinalReply(Session session) {
|
| 47 | final String[] ARGS = {filename};
|
| 48 | sendReply(session, ReplyCodes.TRANSFER_DATA_FINAL_OK, FINAL_REPLY_TEXT_KEY, null, ARGS);
|
| 49 | }
|
| 50 |
|
| 51 | /**
|
| 52 | * Set the filename returned with the final reply of the STOU command
|
| 53 | *
|
| 54 | * @param filename - the filename
|
| 55 | */
|
| 56 | public void setFilename(String filename) {
|
| 57 | this.filename = filename;
|
| 58 | }
|
| 59 |
|
| 60 | }
|