How to use setCommandHeader method of com.consol.citrus.ftp.message.FtpMessage class

Best Citrus code snippet using com.consol.citrus.ftp.message.FtpMessage.setCommandHeader

Source:FtpMessage.java Github

copy

Full Screen

...60 */61 private FtpMessage(CommandType command) {62 super(command);63 this.command = command;64 setCommandHeader(command);65 setHeader(FtpMessageHeaders.FTP_ARGS, command.getArguments());66 }67 /**68 * Default constructor using command result as payload.69 * @param commandResult70 */71 private FtpMessage(CommandResultType commandResult) {72 super(commandResult);73 this.commandResult = commandResult;74 }75 /**76 * Sets the ftp command.77 * @param command78 * @return79 */80 public static FtpMessage command(FTPCmd command) {81 Command cmd = new Command();82 cmd.setSignal(command.getCommand());83 return new FtpMessage(cmd);84 }85 /**86 * Creates new connect command message.87 * @param sessionId88 * @return89 */90 public static FtpMessage connect(String sessionId) {91 ConnectCommand cmd = new ConnectCommand();92 cmd.setSignal("OPEN");93 cmd.setSessionId(sessionId);94 return new FtpMessage(cmd);95 }96 /**97 * Creates new put command message.98 * @param localPath99 * @return100 */101 public static FtpMessage put(String localPath) {102 return put(localPath, DataType.ASCII);103 }104 /**105 * Creates new put command message.106 * @param localPath107 * @param type108 * @return109 */110 public static FtpMessage put(String localPath, DataType type) {111 return put(localPath, FileUtils.getFileResource(localPath).getFilename(), type);112 }113 /**114 * Creates new put command message.115 * @param localPath116 * @param remotePath117 * @param type118 * @return119 */120 public static FtpMessage put(String localPath, String remotePath, DataType type) {121 PutCommand cmd = new PutCommand();122 cmd.setSignal(FTPCmd.STOR.getCommand());123 PutCommand.File file = new PutCommand.File();124 file.setPath(localPath);125 file.setType(type.name());126 cmd.setFile(file);127 PutCommand.Target target = new PutCommand.Target();128 target.setPath(remotePath);129 cmd.setTarget(target);130 return new FtpMessage(cmd);131 }132 /**133 * Creates new get command message.134 * @param remotePath135 * @return136 */137 public static FtpMessage get(String remotePath) {138 return get(remotePath, DataType.ASCII);139 }140 /**141 * Creates new get command message.142 * @param remotePath143 * @param type144 * @return145 */146 public static FtpMessage get(String remotePath, DataType type) {147 return get(remotePath, FileUtils.getFileResource(remotePath).getFilename(), type);148 }149 /**150 * Creates new get command message.151 * @param remotePath152 * @param localPath153 * @param type154 * @return155 */156 public static FtpMessage get(String remotePath, String localPath, DataType type) {157 GetCommand cmd = new GetCommand();158 cmd.setSignal(FTPCmd.RETR.getCommand());159 GetCommand.File file = new GetCommand.File();160 file.setPath(remotePath);161 file.setType(type.name());162 cmd.setFile(file);163 GetCommand.Target target = new GetCommand.Target();164 target.setPath(localPath);165 cmd.setTarget(target);166 return new FtpMessage(cmd);167 }168 /**169 * Creates new delete command message.170 * @param remotePath171 * @return172 */173 public static FtpMessage delete(String remotePath) {174 DeleteCommand cmd = new DeleteCommand();175 cmd.setSignal(FTPCmd.DELE.getCommand());176 DeleteCommand.Target target = new DeleteCommand.Target();177 target.setPath(remotePath);178 cmd.setTarget(target);179 return new FtpMessage(cmd);180 }181 /**182 * Creates new delete command message.183 * @param remotePath184 * @return185 */186 public static FtpMessage list(String remotePath) {187 ListCommand cmd = new ListCommand();188 cmd.setSignal(FTPCmd.LIST.getCommand());189 ListCommand.Target target = new ListCommand.Target();190 target.setPath(remotePath);191 cmd.setTarget(target);192 return new FtpMessage(cmd);193 }194 public static FtpMessage success() {195 CommandResult commandResult = new CommandResult();196 commandResult.setSuccess(true);197 return result(commandResult);198 }199 public static FtpMessage success(int replyCode) {200 return success(replyCode, "@ignore@");201 }202 public static FtpMessage success(int replyCode, String replyString) {203 return result(replyCode, replyString, true);204 }205 public static FtpMessage error() {206 CommandResult commandResult = new CommandResult();207 commandResult.setSuccess(false);208 return result(commandResult);209 }210 public static FtpMessage error(int replyCode) {211 return success(replyCode, "@ignore@");212 }213 public static FtpMessage error(int replyCode, String replyString) {214 return result(replyCode, replyString, false);215 }216 public static FtpMessage result(int replyCode, String replyString, boolean success) {217 CommandResult commandResult = new CommandResult();218 commandResult.setReplyCode(String.valueOf(replyCode));219 commandResult.setReplyString(replyString);220 commandResult.setSuccess(success);221 return result(commandResult);222 }223 public static FtpMessage deleteResult(int replyCode, String replyString, boolean success) {224 DeleteCommandResult result = new DeleteCommandResult();225 result.setReplyCode(String.valueOf(replyCode));226 result.setReplyString(replyString);227 result.setSuccess(success);228 return result(result);229 }230 public static FtpMessage putResult(int replyCode, String replyString, boolean success) {231 PutCommandResult result = new PutCommandResult();232 result.setReplyCode(String.valueOf(replyCode));233 result.setReplyString(replyString);234 result.setSuccess(success);235 return result(result);236 }237 public static FtpMessage result(CommandResultType commandResult) {238 FtpMessage ftpMessage = new FtpMessage(commandResult);239 ftpMessage.setHeader(FtpMessageHeaders.FTP_REPLY_CODE, commandResult.getReplyCode());240 ftpMessage.setHeader(FtpMessageHeaders.FTP_REPLY_STRING, commandResult.getReplyString());241 return ftpMessage;242 }243 public static FtpMessage result(int replyCode, String replyString, List<String> fileNames) {244 ListCommandResult listCommandResult = new ListCommandResult();245 listCommandResult.setReplyCode(String.valueOf(replyCode));246 listCommandResult.setReplyString(replyString);247 listCommandResult.setSuccess(true);248 ListCommandResult.Files files = new ListCommandResult.Files();249 for (String fileName : fileNames) {250 ListCommandResult.Files.File file = new ListCommandResult.Files.File();251 file.setPath(fileName);252 files.getFiles().add(file);253 }254 listCommandResult.setFiles(files);255 return result(listCommandResult);256 }257 public static FtpMessage result(int replyCode, String replyString, String path, String content) {258 GetCommandResult getCommandResult = new GetCommandResult();259 getCommandResult.setReplyCode(String.valueOf(replyCode));260 getCommandResult.setReplyString(replyString);261 getCommandResult.setSuccess(true);262 GetCommandResult.File file = new GetCommandResult.File();263 file.setPath(path);264 file.setData(content);265 getCommandResult.setFile(file);266 return result(getCommandResult);267 }268 /**269 * Sets the command args.270 * @param arguments271 */272 public FtpMessage arguments(String arguments) {273 if (command != null) {274 command.setArguments(arguments);275 }276 setHeader(FtpMessageHeaders.FTP_ARGS, arguments);277 return this;278 }279 /**280 * Gets the ftp command signal.281 */282 public String getSignal() {283 return Optional.ofNullable(getHeader(FtpMessageHeaders.FTP_COMMAND)).map(Object::toString).orElse(null);284 }285 /**286 * Gets the command args.287 */288 public String getArguments() {289 return Optional.ofNullable(getHeader(FtpMessageHeaders.FTP_ARGS)).map(Object::toString).orElse(null);290 }291 /**292 * Gets the reply code.293 */294 public Integer getReplyCode() {295 Object replyCode = getHeader(FtpMessageHeaders.FTP_REPLY_CODE);296 if (replyCode != null) {297 if (replyCode instanceof Integer) {298 return (Integer) replyCode;299 } else {300 return Integer.valueOf(replyCode.toString());301 }302 } else if (commandResult != null) {303 return Optional.ofNullable(commandResult.getReplyCode()).map(Integer::valueOf).orElse(FTPReply.COMMAND_OK);304 }305 return null;306 }307 /**308 * Check if reply code is set on this message.309 * @return310 */311 public boolean hasReplyCode() {312 return getHeader(FtpMessageHeaders.FTP_REPLY_CODE) != null ||313 Optional.ofNullable(commandResult)314 .map(result -> StringUtils.hasText(result.getReplyCode()))315 .orElse(false);316 }317 /**318 * Check if reply code is set on this message.319 * @return320 */321 public boolean hasException() {322 return Optional.ofNullable(commandResult)323 .map(result -> StringUtils.hasText(result.getException()))324 .orElse(false);325 }326 /**327 * Gets the reply string.328 */329 public String getReplyString() {330 Object replyString = getHeader(FtpMessageHeaders.FTP_REPLY_STRING);331 if (replyString != null) {332 return replyString.toString();333 }334 return null;335 }336 @Override337 public <T> T getPayload(Class<T> type) {338 if (CommandType.class.isAssignableFrom(type)) {339 return (T) getCommand();340 } else if (CommandResultType.class.isAssignableFrom(type)) {341 return (T) getCommandResult();342 } else if (String.class.equals(type)) {343 return (T) getPayload();344 } else {345 return super.getPayload(type);346 }347 }348 @Override349 public Object getPayload() {350 StringResult payloadResult = new StringResult();351 if (command != null) {352 marshaller.marshal(command, payloadResult);353 return payloadResult.toString();354 } else if (commandResult != null) {355 marshaller.marshal(commandResult, payloadResult);356 return payloadResult.toString();357 }358 return super.getPayload();359 }360 /**361 * Gets the command result if any or tries to unmarshal String payload representation to an command result model.362 * @return363 */364 private <T extends CommandResultType> T getCommandResult() {365 if (commandResult == null) {366 if (getPayload() instanceof String) {367 this.commandResult = (T) marshaller.unmarshal(new StringSource(getPayload(String.class)));368 }369 }370 return (T) commandResult;371 }372 /**373 * Gets the command if any or tries to unmarshal String payload representation to an command model.374 * @return375 */376 private <T extends CommandType> T getCommand() {377 if (command == null) {378 if (getPayload() instanceof String) {379 this.command = (T) marshaller.unmarshal(new StringSource(getPayload(String.class)));380 }381 }382 return (T) command;383 }384 /**385 * Gets command header as ftp signal from command object.386 * @param command387 */388 private void setCommandHeader(CommandType command) {389 String header;390 if (command instanceof ConnectCommand) {391 header = FtpMessage.OPEN_COMMAND;392 } else if (command instanceof GetCommand) {393 header = FTPCmd.RETR.getCommand();394 } else if (command instanceof PutCommand) {395 header = FTPCmd.STOR.getCommand();396 } else if (command instanceof ListCommand) {397 header = FTPCmd.LIST.getCommand();398 } else if (command instanceof DeleteCommand) {399 header = FTPCmd.DELE.getCommand();400 } else {401 header = command.getSignal();402 }...

Full Screen

Full Screen

setCommandHeader

Using AI Code Generation

copy

Full Screen

1ftpMessage.setCommandHeader("USER");2ftpMessage.setCommandHeader("PASS");3ftpMessage.setCommandHeader("SYST");4ftpMessage.setCommandHeader("TYPE");5ftpMessage.setCommandHeader("PASV");6ftpMessage.setCommandHeader("STOR");7ftpMessage.setCommandHeader("QUIT");8ftpMessage.setCommandHeader("LIST");9ftpMessage.setCommandHeader("RETR");10ftpMessage.setCommandHeader("DELE");11ftpMessage.setCommandHeader("RMD");12ftpMessage.setCommandHeader("MKD");13ftpMessage.setCommandHeader("PWD");14ftpMessage.setCommandHeader("CWD");15ftpMessage.setCommandHeader("RNFR");16ftpMessage.setCommandHeader("RNTO");

Full Screen

Full Screen

setCommandHeader

Using AI Code Generation

copy

Full Screen

1message.setCommandHeader("STOR " + ftpFile);2message.setCommandHeader("STOR " + ftpFile);3message.setCommandHeader("STOR " + ftpFile);4message.setCommandHeader("STOR " + ftpFile);5message.setCommandHeader("STOR " + ftpFile);6message.setCommandHeader("STOR " + ftpFile);7message.setCommandHeader("STOR " + ftpFile);8message.setCommandHeader("STOR " + ftpFile);9message.setCommandHeader("STOR " + ftpFile);10message.setCommandHeader("STOR " + ftpFile);11message.setCommandHeader("STOR " + ftpFile);12message.setCommandHeader("STOR " + ftpFile);13message.setCommandHeader("STOR " + ftpFile);

Full Screen

Full Screen

setCommandHeader

Using AI Code Generation

copy

Full Screen

1FtpMessage ftpMessage = new FtpMessage();2ftpMessage.setCommandHeader("STOR");3FtpMessage ftpMessage = new FtpMessage();4ftpMessage.setCommandHeader("STOR");5ftpMessage.setCommandArgument("test.txt");6FtpMessage ftpMessage = new FtpMessage();7ftpMessage.setCommandHeader("STOR");8ftpMessage.setCommandArgument("test.txt");9ftpMessage.setCommandBody("Hello World!");10FtpMessage ftpMessage = new FtpMessage();11ftpMessage.setCommandHeader("STOR");12ftpMessage.setCommandArgument("test.txt");13ftpMessage.setCommandBody("Hello World!");14ftpMessage.setCommandBody("Hello Citrus!");15FtpMessage ftpMessage = new FtpMessage();16ftpMessage.setCommandHeader("STOR");17ftpMessage.setCommandArgument("test.txt");18ftpMessage.setCommandBody("Hello World!");19FtpMessage ftpMessage = new FtpMessage();20ftpMessage.setCommandHeader("STOR");21ftpMessage.setCommandArgument("test.txt");22ftpMessage.setCommandBody("Hello World!");23ftpMessage.setCommandBody("Hello Citrus!");24FtpMessage ftpMessage = new FtpMessage();25ftpMessage.setCommandHeader("STOR");26ftpMessage.setCommandArgument("test.txt");27ftpMessage.setCommandBody("Hello World!");

Full Screen

Full Screen

setCommandHeader

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.dsl.runner.TestRunner;2import com.consol.citrus.dsl.runner.TestRunner;3import com.consol.citrus.ftp.message.FtpMessage;4import com.consol.citrus.ftp.server.FtpServer;5import com.consol.citrus.ftp.server.FtpServerBuilder;6import com.consol.citrus.message.MessageType;7import com.consol.citrus.testng.spring.TestNGCitrusSpringSupport;8import org.springframework.beans.factory.annotation.Autowired;9import org.springframework.beans.factory.annotation.Qualifier;10import org.springframework.context.annotation.Bean;11import org.springframework.context.annotation.Configuration;12import org.springframework.context.annotation.Import;13import org.springframework.core.io.ClassPathResource;14import org.springframework.util.SocketUtils;15import org.testng.annotations.Test;16import java.io.IOException;17import static com.consol.citrus.actions.DelegatingTestAction.Builder.delegate;18import static com.consol.citrus.actions.ExecutePLSQLAction.Builder.executePLSQL;19import static com.consol.citrus.actions.ExecuteSQLQueryAction.Builder.query;20import static com.consol.citrus.actions.ExecuteSQLUpdateAction.Builder.update;21import static com.consol.citrus.actions.PurgeJmsQueuesAction.Builder.purgeQueues;22import static com.consol.citrus.actions.ReceiveMessageAction.Builder.receive;23import static com.consol.citrus.actions.SendMessageAction.Builder.send;24import static com.consol.citrus.actions.SleepAction.Builder.sleep;25import static com.consol.citrus.actions.StopServerAction.Builder.server;26import static com.consol.citrus.actions.TraceVariablesAction.Builder.traceVariables;27import static com.consol.citrus.actions.WaitAction.Builder.waitFor;28import static com.consol.citrus.container.FinallySequence.Builder.doFinally;29import static com.consol.citrus.container.Parallel.Builder.parallel;30import static com.consol.citrus.container.Sequence.Builder.sequential;31import static com.consol.citrus.container.Wait.Builder.waitFor;

Full Screen

Full Screen

setCommandHeader

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.samples.ftp;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import org.springframework.http.HttpStatus;5import org.testng.annotations.Test;6import static com.consol.citrus.actions.CreateVariablesAction.Builder.createVariable;7import static com.consol.citrus.actions.EchoAction.Builder.echo;8import static com.consol.citrus.container.Parallel.Builder.parallel;9import static com.consol.citrus.dsl.builder.Builder.Builder;10import static com.consol.citrus.dsl.builder.Builder.Builder.create;11import static com.consol.citrus.dsl.builder.Builder.Builder.createClient;12import static com.consol.citrus.dsl.builder.Builder.Builder.createServer;13import static com.consol.citrus.dsl.builder.Builder.Builder.createTestCase;14import static com.consol.citrus.dsl.builder.Builder.Builder.cre

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful