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

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

Source:FtpMessage.java Github

copy

Full Screen

...321 }322 return null;323 }324 @Override325 public <T> T getPayload(Class<T> type) {326 if (CommandType.class.isAssignableFrom(type)) {327 return (T) getCommand();328 } else if (CommandResultType.class.isAssignableFrom(type)) {329 return (T) getCommandResult();330 } else if (String.class.equals(type)) {331 return (T) getPayload();332 } else {333 return super.getPayload(type);334 }335 }336 @Override337 public Object getPayload() {338 StringResult payloadResult = new StringResult();339 if (command != null) {340 marshaller.marshal(command, payloadResult);341 return payloadResult.toString();342 } else if (commandResult != null) {343 marshaller.marshal(commandResult, payloadResult);344 return payloadResult.toString();345 }346 return super.getPayload();347 }348 /**349 * Gets the command result if any or tries to unmarshal String payload representation to an command result model.350 * @return351 */352 private <T extends CommandResultType> T getCommandResult() {353 if (commandResult == null) {354 if (getPayload() instanceof String) {355 this.commandResult = (T) marshaller.unmarshal(new StringSource(getPayload(String.class)));356 }357 }358 return (T) commandResult;359 }360 /**361 * Gets the command if any or tries to unmarshal String payload representation to an command model.362 * @return363 */364 private <T extends CommandType> T getCommand() {365 if (command == null) {366 if (getPayload() instanceof String) {367 this.command = (T) marshaller.unmarshal(new StringSource(getPayload(String.class)));368 }369 }370 return (T) command;371 }372 /**373 * Gets command header as ftp signal from command object.374 * @param command375 */376 private void setCommandHeader(CommandType command) {377 String header;378 if (command instanceof ConnectCommand) {379 header = FtpMessage.OPEN_COMMAND;380 } else if (command instanceof GetCommand) {381 header = FTPCmd.RETR.getCommand();...

Full Screen

Full Screen

Source:SftpServer.java Github

copy

Full Screen

...55 public SftpServer(SftpEndpointConfiguration endpointConfiguration) {56 this.endpointConfiguration = endpointConfiguration;57 }58 public FtpMessage handleMessage(FtpMessage request) {59 if (request.getPayload() instanceof Command) {60 StringResult result = new StringResult();61 endpointConfiguration.getMarshaller().marshal(request.getPayload(Command.class), result);62 request.setPayload(result.toString());63 }64 if (log.isDebugEnabled()) {65 log.debug(String.format("Received request on ftp server: '%s':%n%s",66 request.getSignal(),67 request.getPayload(String.class)));68 }69 return Optional.ofNullable(getEndpointAdapter().handleMessage(request))70 .map(response -> {71 if (response instanceof FtpMessage) {72 return (FtpMessage) response;73 } else {74 return new FtpMessage(response);75 }76 })77 .orElse(FtpMessage.success());78 }79 @Override80 public void startFileEvent(FileOperation op, Path file, long length, Set<PosixFilePermission> perms) {81 startFolderEvent(op, file, perms);82 }83 @Override84 public void startFolderEvent(FileOperation op, Path file, Set<PosixFilePermission> perms) {85 if (op.equals(FileOperation.SEND)) {86 FtpMessage response = handleMessage(FtpMessage.get(file.toString()));87 if (response.hasException()) {88 throw new CitrusRuntimeException(response.getPayload(CommandResult.class).getException());89 }90 } else if (op.equals(FileOperation.RECEIVE)) {91 FtpMessage response = handleMessage(FtpMessage.put(file.toString()));92 if (response.hasException()) {93 throw new CitrusRuntimeException(response.getPayload(CommandResult.class).getException());94 }95 }96 }97 @Override98 public void initialized(ServerSession session, int version) {99 if (log.isDebugEnabled()) {100 log.debug(String.format("Received new SFTP connection: '%s'", Arrays.toString(session.getSessionId())));101 }102 if (!endpointConfiguration.isAutoConnect()) {103 FtpMessage response = handleMessage(FtpMessage.connect(Arrays.toString(session.getSessionId())));104 if (response.hasException()) {105 throw new CitrusRuntimeException(response.getPayload(CommandResult.class).getException());106 }107 }108 }109 @Override110 public void reading(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, byte[] data, int dataOffset, int dataLen) {111 FtpMessage response = handleMessage(FtpMessage.get(localHandle.getFile().toString(), remoteHandle, DataType.ASCII));112 if (response.hasException()) {113 throw new CitrusRuntimeException(response.getPayload(CommandResult.class).getException());114 }115 }116 @Override117 public void writing(ServerSession session, String remoteHandle, FileHandle localHandle, long offset, byte[] data, int dataOffset, int dataLen) {118 FtpMessage response = handleMessage(FtpMessage.put(remoteHandle, localHandle.getFile().toString(), DataType.ASCII));119 if (response.hasException()) {120 throw new CitrusRuntimeException(response.getPayload(CommandResult.class).getException());121 }122 }123 @Override124 public void destroying(ServerSession session) {125 if (!endpointConfiguration.isAutoConnect()) {126 FtpMessage response = handleMessage(FtpMessage.command(FTPCmd.QUIT)127 .arguments(Optional.ofNullable(session.getUsername()).orElse("unknown")));128 if (response.hasException()) {129 throw new CitrusRuntimeException(response.getPayload(CommandResult.class).getException());130 }131 }132 if (log.isDebugEnabled()) {133 log.debug(String.format("Closing FTP connection: '%s'", session.getSessionId()));134 }135 }136 /**137 * Gets the endpointConfiguration.138 *139 * @return140 */141 @Override142 public AbstractPollableEndpointConfiguration getEndpointConfiguration() {143 return endpointConfiguration;...

Full Screen

Full Screen

Source:FtpServerFtpLet.java Github

copy

Full Screen

...53 this.endpointConfiguration = endpointConfiguration;54 this.endpointAdapter = endpointAdapter;55 }56 public FtpMessage handleMessage(FtpMessage request) {57 if (request.getPayload() instanceof Command) {58 StringResult result = new StringResult();59 endpointConfiguration.getMarshaller().marshal(request.getPayload(Command.class), result);60 request.setPayload(result.toString());61 }62 if (log.isDebugEnabled()) {63 log.debug(String.format("Received request on ftp server: '%s':%n%s",64 request.getSignal(),65 request.getPayload(String.class)));66 }67 return Optional.ofNullable(endpointAdapter.handleMessage(request))68 .map(response -> {69 if (response instanceof FtpMessage) {70 return (FtpMessage) response;71 } else {72 return new FtpMessage(response);73 }74 })75 .orElse(FtpMessage.success());76 }77 @Override78 public void init(FtpletContext ftpletContext) {79 if (log.isDebugEnabled()) {80 log.debug(String.format("Total FTP logins: %s", ftpletContext.getFtpStatistics().getTotalLoginNumber()));81 }82 }83 @Override84 public void destroy() {85 log.info("FTP server shutting down ...");86 }87 @Override88 public FtpletResult beforeCommand(FtpSession session, FtpRequest request) {89 String command = request.getCommand().toUpperCase();90 if (log.isDebugEnabled()) {91 log.debug(String.format("Received FTP command: '%s'", command));92 }93 if (endpointConfiguration.isAutoLogin() && (command.equals(FTPCmd.USER.getCommand()) || command.equals(FTPCmd.PASS.getCommand()))) {94 return FtpletResult.DEFAULT;95 }96 if (Stream.of(StringUtils.commaDelimitedListToStringArray(endpointConfiguration.getAutoHandleCommands())).anyMatch(cmd -> cmd.trim().equals(command))) {97 return FtpletResult.DEFAULT;98 }99 FtpMessage response = handleMessage(FtpMessage.command(FTPCmd.valueOf(command)).arguments(request.getArgument()));100 if (response.hasReplyCode()) {101 writeFtpReply(session, response);102 return FtpletResult.SKIP;103 }104 return FtpletResult.DEFAULT;105 }106 @Override107 public FtpletResult afterCommand(FtpSession session, FtpRequest request, FtpReply reply) {108 return FtpletResult.DEFAULT;109 }110 @Override111 public FtpletResult onConnect(FtpSession session) {112 if (log.isDebugEnabled()) {113 log.debug(String.format("Received new FTP connection: '%s'", session.getSessionId()));114 }115 if (!endpointConfiguration.isAutoConnect()) {116 FtpMessage response = handleMessage(FtpMessage.connect(session.getSessionId().toString()));117 if (response.hasReplyCode()) {118 writeFtpReply(session, response);119 return FtpletResult.SKIP;120 }121 }122 return FtpletResult.DEFAULT;123 }124 @Override125 public FtpletResult onDisconnect(FtpSession session) {126 if (!endpointConfiguration.isAutoConnect()) {127 FtpMessage response = handleMessage(FtpMessage.command(FTPCmd.QUIT)128 .arguments(Optional.ofNullable(session.getUser()).map(User::getName).orElse("unknown") + ":" +129 Optional.ofNullable(session.getUser()).map(User::getPassword).orElse("n/a")));130 if (response.hasReplyCode()) {131 writeFtpReply(session, response);132 }133 }134 if (log.isDebugEnabled()) {135 log.debug(String.format("Closing FTP connection: '%s'", session.getSessionId()));136 }137 return FtpletResult.DISCONNECT;138 }139 /**140 * Construct ftp reply from response message and write reply to given session.141 * @param session142 * @param response143 */144 private void writeFtpReply(FtpSession session, FtpMessage response) {145 try {146 CommandResultType commandResult = response.getPayload(CommandResultType.class);147 FtpReply reply = new DefaultFtpReply(Integer.valueOf(commandResult.getReplyCode()), commandResult.getReplyString());148 session.write(reply);149 } catch (FtpException e) {150 throw new CitrusRuntimeException("Failed to write ftp reply", e);151 }152 }153}...

Full Screen

Full Screen

getPayload

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp;2import com.consol.citrus.ftp.client.FtpClient;3import com.consol.citrus.ftp.message.FtpMessage;4import com.consol.citrus.testng.AbstractTestNGCitrusTest;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.core.io.ClassPathResource;7import org.springframework.core.io.Resource;8import org.testng.annotations.Test;9import java.io.IOException;10public class FtpTest extends AbstractTestNGCitrusTest {11 private FtpClient ftpClient;12 public void ftpTest() throws IOException {13 Resource resource = new ClassPathResource("test.txt");14 ftpClient.send(file()15 .remotePath("/test.txt")16 .content(resource));17 ftpClient.receive(file()18 .remotePath("/test.txt")19 .content(resource));20 ftpClient.send(deleteFile()21 .remotePath("/test.txt"));22 ftpClient.receive(deleteFile()23 .remotePath("/test.txt"));24 ftpClient.send(directory()25 .remotePath("/test"));26 ftpClient.receive(directory()27 .remotePath("/test"));28 ftpClient.send(deleteDirectory()29 .remotePath("/test"));30 ftpClient.receive(deleteDirectory()31 .remotePath("/test"));32 ftpClient.send(file()33 .remotePath("/test.txt")34 .content(resource));35 ftpClient.receive(file()36 .remotePath("/test.txt")37 .content(resource));38 ftpClient.send(renameFile()39 .remotePath("/test.txt")40 .newRemotePath("/test2.txt"));41 ftpClient.receive(renameFile()42 .remotePath("/test.txt")43 .newRemotePath("/test2.txt"));44 ftpClient.send(file()45 .remotePath("/test2.txt")46 .content(resource));47 ftpClient.receive(file()48 .remotePath("/test2.txt")49 .content(resource));50 ftpClient.send(deleteFile()51 .remotePath("/test2.txt"));52 ftpClient.receive(deleteFile()53 .remotePath("/test2.txt"));54 ftpClient.send(renameFile()55 .remotePath("/test2.txt")56 .newRemotePath("/test.txt"));57 ftpClient.receive(renameFile()58 .remotePath("/test2.txt")59 .newRemotePath("/test.txt"));60 ftpClient.send(file()61 .remotePath("/test.txt")62 .content(resource));63 ftpClient.receive(file()

Full Screen

Full Screen

getPayload

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.ftp.message.FtpMessage;2import com.consol.citrus.ftp.message.FtpMessageHeaders;3import com.consol.citrus.message.Message;4import com.consol.citrus.message.MessageType;5import com.consol.citrus.message.MessageHeaderType;6import com.consol.citrus.message.MessageHeaders;7import com.consol.citrus.message.MessageTypeResolver;8import org.springframework.integration.MessageHeaders;9import org.springframework.integration.file.remote.session.SessionFactory;10import org.springframework.integration.ftp.session.FtpRemoteFileTemplate;11import org.springframework.util.Assert;12import org.springframework.util.StringUtils;13import java.io.*;14import java.util.HashMap;15import java.util.Map;16public class FtpMessage extends AbstractMessage<FtpMessage> {17 public FtpMessage() {18 super();19 }20 public FtpMessage(Object payload, Map<String, Object> headers) {21 super(payload, headers);22 }23 public FtpMessage(Object payload, MessageHeaders headers) {24 super(payload, headers);25 }26 public FtpMessage(Object payload) {27 super(payload);28 }29 public FtpMessage(Message message) {30 super(message);31 }32 public FtpMessage getPayload() {33 return this;34 }35 public FtpMessage newInstance(Object payload, Map<String, Object> headers) {36 return new FtpMessage(payload, headers);37 }38 public MessageType getType() {39 return MessageTypeResolver.resolveTypeFromHeaders(this);40 }41 public FtpMessage setType(MessageType type) {42 return setHeader(MessageHeaderType.MESSAGE_TYPE, type);43 }44 public String getFileName() {45 return getHeader(FtpMessageHeaders.FILE_NAME);46 }

Full Screen

Full Screen

getPayload

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp.message;2import com.consol.citrus.message.DefaultMessage;3import com.consol.citrus.message.Message;4import org.testng.Assert;5import org.testng.annotations.Test;6public class FtpMessageTest {7public void testGetPayload() {8Message message = new DefaultMessage("test");9FtpMessage ftpMessage = new FtpMessage(message);10ftpMessage.setPayload("test");11Assert.assertEquals(ftpMessage.getPayload(), "test");12}13}

Full Screen

Full Screen

getPayload

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp.samples;2import com.consol.citrus.ftp.message.FtpMessage;3import org.apache.commons.net.ftp.FTPFile;4import org.springframework.core.io.ClassPathResource;5import org.springframework.core.io.Resource;6import org.springframework.integration.Message;7import org.springframework.integration.support.MessageBuilder;8public class test3 {9 public static void main(String[] args) {10 Resource resource = new ClassPathResource("file1.txt");11 Message<?> message = MessageBuilder.withPayload(resource).build();12 FtpMessage ftpMessage = new FtpMessage(message);13 FTPFile file = ftpMessage.getPayload(FTPFile.class);14 System.out.println(file.getName());15 }16}17package com.consol.citrus.ftp.samples;18import com.consol.citrus.ftp.message.FtpMessage;19import org.apache.commons.net.ftp.FTPFile;20import org.springframework.core.io.ClassPathResource;21import org.springframework.core.io.Resource;22import org.springframework.integration.Message;23import org.springframework.integration.support.MessageBuilder;24public class test4 {25 public static void main(String[] args) {26 Resource resource = new ClassPathResource("file1.txt");27 Message<?> message = MessageBuilder.withPayload(resource).build();28 FtpMessage ftpMessage = new FtpMessage(message);29 FTPFile[] files = ftpMessage.getPayload(FTPFile[].class);30 for (FTPFile file : files) {31 System.out.println(file.getName());32 }33 }34}

Full Screen

Full Screen

getPayload

Using AI Code Generation

copy

Full Screen

1FtpMessage ftpMessage = new FtpMessage();2ftpMessage.setPayload("Hello World");3System.out.println(ftpMessage.getPayload());4FtpMessage ftpMessage = new FtpMessage();5ftpMessage.setPayload("Hello World");6System.out.println(ftpMessage.getPayload());7FtpMessage ftpMessage = new FtpMessage();8ftpMessage.setPayload("Hello World");9System.out.println(ftpMessage.getPayload());10FtpMessage ftpMessage = new FtpMessage();11ftpMessage.setPayload("Hello World");12System.out.println(ftpMessage.getPayload());13FtpMessage ftpMessage = new FtpMessage();14ftpMessage.setPayload("Hello World");15System.out.println(ftpMessage.getPayload());16FtpMessage ftpMessage = new FtpMessage();17ftpMessage.setPayload("Hello World");18System.out.println(ftpMessage.getPayload());19FtpMessage ftpMessage = new FtpMessage();20ftpMessage.setPayload("Hello World");21System.out.println(ftpMessage.getPayload());22FtpMessage ftpMessage = new FtpMessage();23ftpMessage.setPayload("Hello World");24System.out.println(ftpMessage.getPayload());25FtpMessage ftpMessage = new FtpMessage();26ftpMessage.setPayload("Hello World");27System.out.println(ftpMessage.getPayload());28FtpMessage ftpMessage = new FtpMessage();29ftpMessage.setPayload("Hello World");30System.out.println(ftpMessage.getPayload());

Full Screen

Full Screen

getPayload

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp;2import org.springframework.context.ApplicationContext;3import org.springframework.context.support.ClassPathXmlApplicationContext;4import org.testng.Assert;5import org.testng.annotations.Test;6import com.consol.citrus.annotations.CitrusTest;7import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;8public class FtpMessageTest extends TestNGCitrusTestDesigner {9 public void ftpMessageTest() {10 ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");11 FtpMessage ftpMessage = (FtpMessage) context.getBean("ftpMessage");12 String payload = ftpMessage.getPayload(String.class);13 Assert.assertEquals(payload, "Hello World!");14 }15}

Full Screen

Full Screen

getPayload

Using AI Code Generation

copy

Full Screen

1FtpMessage ftpMessage = new FtpMessage(message);2String payload = ftpMessage.getPayload(String.class);3System.out.println("The payload of the message is " + payload);4FtpMessage ftpMessage = new FtpMessage(message);5String file = ftpMessage.getFile();6System.out.println("The file of the message is " + file);7FtpMessage ftpMessage = new FtpMessage(message);8String fileName = ftpMessage.getFileName();9System.out.println("The file name of the message is " + fileName);10FtpMessage ftpMessage = new FtpMessage(message);11String remotePath = ftpMessage.getRemotePath();12System.out.println("The remote path of the message is " + remotePath);13FtpMessage ftpMessage = new FtpMessage(message);14String remoteDirectory = ftpMessage.getRemoteDirectory();15System.out.println("The remote directory of the message is " + remoteDirectory);16FtpMessage ftpMessage = new FtpMessage(message);17String localDirectory = ftpMessage.getLocalDirectory();18System.out.println("The local directory of the message is " + localDirectory);19FtpMessage ftpMessage = new FtpMessage(message);20String localFile = ftpMessage.getLocalFile();21System.out.println("The local file of the message is " + localFile);

Full Screen

Full Screen

getPayload

Using AI Code Generation

copy

Full Screen

1public class 3 extends AbstractTestNGCitrusTest {2public void 3() {3send(sendMessageBuilder -> sendMessageBuilder4.endpoint(ftpServer)5.message(new FtpMessage()6.getPayload()7));8receive(receiveMessageBuilder -> receiveMessageBuilder9.endpoint(ftpServer)10.message(new FtpMessage()11.getPayload()12));13}14}15public class 4 extends AbstractTestNGCitrusTest {16public void 4() {17send(sendMessageBuilder -> sendMessageBuilder18.endpoint(ftpServer)19.message(new FtpMessage()20.getPayload()21));22receive(receiveMessageBuilder -> receiveMessageBuilder23.endpoint(ftpServer)24.message(new FtpMessage()25.getPayload()26));27}28}29public class 5 extends AbstractTestNGCitrusTest {30public void 5() {31send(sendMessageBuilder -> sendMessageBuilder32.endpoint(ftpServer)33.message(new FtpMessage()34.getPayload()35));36receive(receiveMessageBuilder -> receiveMessageBuilder37.endpoint(ftpServer)38.message(new FtpMessage()39.getPayload()40));41}42}

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