How to use getEndpointConfiguration method of com.consol.citrus.ssh.server.SshServer class

Best Citrus code snippet using com.consol.citrus.ssh.server.SshServer.getEndpointConfiguration

Source:SshClient.java Github

copy

Full Screen

...56 super(endpointConfiguration);57 this.correlationManager = new PollingCorrelationManager<>(endpointConfiguration, "Reply message did not arrive yet");58 }59 @Override60 public SshEndpointConfiguration getEndpointConfiguration() {61 return (SshEndpointConfiguration) super.getEndpointConfiguration();62 }63 /**64 * Send a message as SSH request. The message format is created from65 * {@link com.consol.citrus.ssh.server.SshServer}.66 *67 * @param message the message object to send.68 * @param context69 */70 public void send(Message message, TestContext context) {71 String correlationKeyName = getEndpointConfiguration().getCorrelator().getCorrelationKeyName(getName());72 String correlationKey = getEndpointConfiguration().getCorrelator().getCorrelationKey(message);73 correlationManager.saveCorrelationKey(correlationKeyName, correlationKey, context);74 SshRequest request = (SshRequest) getEndpointConfiguration().getMessageConverter().convertOutbound(message, getEndpointConfiguration(), context);75 if (getEndpointConfiguration().isStrictHostChecking()) {76 setKnownHosts();77 }78 String rUser = getRemoteUser(message);79 connect(rUser);80 ChannelExec channelExec = null;81 ByteArrayOutputStream outStream = new ByteArrayOutputStream();82 ByteArrayOutputStream errStream = new ByteArrayOutputStream();83 int rc;84 try {85 channelExec = openChannelExec();86 channelExec.setErrStream(errStream);87 channelExec.setOutputStream(outStream);88 channelExec.setCommand(request.getCommand());89 doConnect(channelExec);90 if (request.getStdin() != null) {91 sendStandardInput(channelExec, request.getStdin());92 }93 waitCommandToFinish(channelExec);94 rc = channelExec.getExitStatus();95 } finally {96 if (channelExec != null && channelExec.isConnected()) {97 channelExec.disconnect();98 }99 disconnect();100 }101 SshResponse sshResp = new SshResponse(outStream.toString(),errStream.toString(),rc);102 Message response = getEndpointConfiguration().getMessageConverter().convertInbound(sshResp, getEndpointConfiguration(), context)103 .setHeader("user", rUser);104 correlationManager.store(correlationKey, response);105 }106 @Override107 public Message receive(TestContext context) {108 return receive(correlationManager.getCorrelationKey(109 getEndpointConfiguration().getCorrelator().getCorrelationKeyName(getName()), context), context);110 }111 @Override112 public Message receive(String selector, TestContext context) {113 return receive(selector, context, getEndpointConfiguration().getTimeout());114 }115 @Override116 public Message receive(TestContext context, long timeout) {117 return receive(correlationManager.getCorrelationKey(118 getEndpointConfiguration().getCorrelator().getCorrelationKeyName(getName()), context), context, timeout);119 }120 @Override121 public Message receive(String selector, TestContext context, long timeout) {122 Message message = correlationManager.find(selector, timeout);123 if (message == null) {124 throw new ActionTimeoutException("Action timeout while receiving synchronous reply message from ssh server");125 }126 return message;127 }128 @Override129 public Producer createProducer() {130 return this;131 }132 @Override133 public SelectiveConsumer createConsumer() {134 return this;135 }136 private void connect(String rUser) {137 if (session == null || !session.isConnected()) {138 try {139 if (StringUtils.hasText(getEndpointConfiguration().getPrivateKeyPath())) {140 jsch.addIdentity(getPrivateKeyPath(), getEndpointConfiguration().getPrivateKeyPassword());141 }142 } catch (JSchException e) {143 throw new CitrusRuntimeException("Cannot add private key " + getEndpointConfiguration().getPrivateKeyPath() + ": " + e,e);144 } catch (IOException e) {145 throw new CitrusRuntimeException("Cannot open private key file " + getEndpointConfiguration().getPrivateKeyPath() + ": " + e,e);146 }147 try {148 session = jsch.getSession(rUser, getEndpointConfiguration().getHost(), getEndpointConfiguration().getPort());149 if (StringUtils.hasText(getEndpointConfiguration().getPassword())) {150 session.setUserInfo(new UserInfoWithPlainPassword(getEndpointConfiguration().getPassword()));151 session.setPassword(getEndpointConfiguration().getPassword());152 }153 session.setConfig(KnownHostsServerKeyVerifier.STRICT_CHECKING_OPTION, getEndpointConfiguration().isStrictHostChecking() ? "yes" : "no");154 session.connect();155 } catch (JSchException e) {156 throw new CitrusRuntimeException("Cannot connect via SSH: " + e,e);157 }158 }159 }160 private void disconnect() {161 if (session.isConnected()) {162 session.disconnect();163 }164 }165 private ChannelExec openChannelExec() throws CitrusRuntimeException {166 ChannelExec channelExec;167 try {168 channelExec = (ChannelExec) session.openChannel("exec");169 } catch (JSchException e) {170 throw new CitrusRuntimeException("Cannot open EXEC SSH channel: " + e,e);171 }172 return channelExec;173 }174 private void waitCommandToFinish(ChannelExec pCh) {175 final long until = System.currentTimeMillis() + getEndpointConfiguration().getCommandTimeout();176 try {177 while (!pCh.isClosed() && System.currentTimeMillis() < until) {178 Thread.sleep(250);179 }180 } catch (InterruptedException e) {181 throw new RuntimeException("Interrupted", e);182 }183 if (!pCh.isClosed()) {184 throw new CitrusRuntimeException("Timeout: Channel not finished within " + getEndpointConfiguration().getCommandTimeout() + " ms");185 }186 }187 private void sendStandardInput(ChannelExec pCh, String pInput) {188 OutputStream os = null;189 try {190 os = pCh.getOutputStream();191 os.write(pInput.getBytes());192 } catch (IOException e) {193 throw new CitrusRuntimeException("Cannot write to standard input of SSH channel: " + e,e);194 } finally {195 if (os != null) {196 try {197 os.close();198 } catch (IOException e) {199 // best try200 }201 }202 }203 }204 private void doConnect(ChannelExec pCh) {205 try {206 if (getEndpointConfiguration().getConnectionTimeout() != 0) {207 pCh.connect(getEndpointConfiguration().getConnectionTimeout());208 } else {209 pCh.connect();210 }211 } catch (JSchException e) {212 throw new CitrusRuntimeException("Cannot connect EXEC SSH channel: " + e,e);213 }214 }215 private String getRemoteUser(Message message) {216 String rUser = (String) message.getHeader("user");217 if (rUser == null) {218 // Use default uses219 rUser = getEndpointConfiguration().getUser();220 }221 if (rUser == null) {222 throw new CitrusRuntimeException("No user given for connecting to SSH server");223 }224 return rUser;225 }226 private void setKnownHosts() {227 if (getEndpointConfiguration().getKnownHosts() == null) {228 throw new CitrusRuntimeException("Strict host checking is enabled but no knownHosts given");229 }230 try {231 InputStream khIs = FileUtils.getFileResource(getEndpointConfiguration().getKnownHosts()).getInputStream();232 if (khIs == null) {233 throw new CitrusRuntimeException("Cannot find knownHosts at " + getEndpointConfiguration().getKnownHosts());234 }235 jsch.setKnownHosts(khIs);236 } catch (JSchException e) {237 throw new CitrusRuntimeException("Cannot add known hosts from " + getEndpointConfiguration().getKnownHosts() + ": " + e,e);238 } catch (IOException e) {239 throw new CitrusRuntimeException("Cannot find known hosts file " + getEndpointConfiguration().getKnownHosts() + ": " + e,e);240 }241 }242 private String getPrivateKeyPath() throws IOException {243 if (!StringUtils.hasText(getEndpointConfiguration().getPrivateKeyPath())) {244 return null;245 } else if (getEndpointConfiguration().getPrivateKeyPath().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {246 File priv = File.createTempFile("citrus-ssh","priv");247 InputStream is = getClass().getClassLoader().getResourceAsStream(getEndpointConfiguration().getPrivateKeyPath().substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()));248 if (is == null) {249 throw new CitrusRuntimeException("No private key found at " + getEndpointConfiguration().getPrivateKeyPath());250 }251 FileCopyUtils.copy(is, new FileOutputStream(priv));252 return priv.getAbsolutePath();253 } else {254 return getEndpointConfiguration().getPrivateKeyPath();255 }256 }257 // UserInfo which simply returns a plain password258 private static class UserInfoWithPlainPassword implements UserInfo {259 private String password;260 public UserInfoWithPlainPassword(String pPassword) {261 password = pPassword;262 }263 public String getPassphrase() {264 return null;265 }266 public String getPassword() {267 return password;268 }...

Full Screen

Full Screen

Source:SshServer.java Github

copy

Full Screen

...182 throw new CitrusRuntimeException("Failed to stop SSH server - " + e.getMessage(), e);183 }184 }185 @Override186 public AbstractPollableEndpointConfiguration getEndpointConfiguration() {187 return endpointConfiguration;188 }189 /**190 * Gets the server port.191 * @return192 */193 public int getPort() {194 return port;195 }196 /**197 * Sets the port.198 * @param port the port to set199 */200 public void setPort(int port) {...

Full Screen

Full Screen

Source:SshServerBuilder.java Github

copy

Full Screen

...96 * @param pollingInterval97 * @return98 */99 public SshServerBuilder pollingInterval(int pollingInterval) {100 endpoint.getEndpointConfiguration().setPollingInterval(pollingInterval);101 return this;102 }103 /**104 * Sets the endpoint adapter.105 * @param endpointAdapter106 * @return107 */108 public SshServerBuilder endpointAdapter(EndpointAdapter endpointAdapter) {109 endpoint.setEndpointAdapter(endpointAdapter);110 return this;111 }112 /**113 * Sets the debug logging enabled flag.114 * @param enabled115 * @return116 */117 public SshServerBuilder debugLogging(boolean enabled) {118 endpoint.setDebugLogging(enabled);119 return this;120 }121 /**122 * Sets the default timeout.123 * @param timeout124 * @return125 */126 public SshServerBuilder timeout(long timeout) {127 endpoint.getEndpointConfiguration().setTimeout(timeout);128 return this;129 }130 /**131 * Sets the autoStart property.132 * @param autoStart133 * @return134 */135 public SshServerBuilder autoStart(boolean autoStart) {136 endpoint.setAutoStart(autoStart);137 return this;138 }139}...

Full Screen

Full Screen

getEndpointConfiguration

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import com.consol.citrus.dsl.endpoint.CitrusEndpoints;3import com.consol.citrus.dsl.junit.JUnit4CitrusTest;4import com.consol.citrus.ssh.SshServer;5import com.consol.citrus.ssh.SshServerBuilder;6import com.consol.citrus.ssh.message.SshMessage;7import com.consol.citrus.ssh.model.SshEndpointConfiguration;8import org.apache.sshd.common.NamedFactory;9import org.apache.sshd.common.keyprovider.KeyPairProvider;10import org.apache.sshd.server.Command;11import org.apache.sshd.server.SshServer;12import org.apache.sshd.server.auth.UserAuth;13import org.apache.sshd.server.auth.password.PasswordAuthenticator;14import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;15import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;16import org.apache.sshd.server.session.ServerSession;17import org.testng.annotations.Test;18import java.io.IOException;19import java.security.PublicKey;20import java.util.ArrayList;21import java.util.List;22public class SshServerTest extends JUnit4CitrusTest {23 public void testSshServer() {24 SshServer sshServer = CitrusEndpoints.ssh()25 .port(2222)26 .timeout(10000L)27 .autoStart(true)28 .build();29 sshServer.create();30 sshServer.start();31 sshServer.stop();32 sshServer.destroy();33 SshEndpointConfiguration sshEndpointConfiguration = sshServer.getEndpointConfiguration();34 sshEndpointConfiguration.setPort(2222);35 sshEndpointConfiguration.setKeyPairProvider(new KeyPairProvider() {36 public List<String> loadKeys() {37 return null;38 }39 public Iterable<KeyPair> loadKeyPairs() {40 return null;41 }42 });43 sshEndpointConfiguration.setPasswordAuthenticator(new PasswordAuthenticator() {44 public boolean authenticate(String s, String s1, ServerSession serverSession) {45 return false;46 }47 });48 sshEndpointConfiguration.setPublickeyAuthenticator(new PublickeyAuthenticator() {49 public boolean authenticate(String s, PublicKey publicKey, ServerSession serverSession) {50 return false;51 }52 });53 sshEndpointConfiguration.setHostKeyProvider(new SimpleGeneratorHostKeyProvider

Full Screen

Full Screen

getEndpointConfiguration

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus;2import com.consol.citrus.ssh.server.SshServer;3import org.springframework.context.annotation.Bean;4import org.springframework.context.annotation.Configuration;5import org.springframework.context.annotation.Import;6@Import({SshServer.class})7public class 3 {8public SshServer sshServer() {9SshServer sshServer = new SshServer();10sshServer.setPort(2222);11sshServer.setEndpointConfiguration(sshServerEndpointConfiguration());12return sshServer;13}14public SshServerEndpointConfiguration sshServerEndpointConfiguration() {15SshServerEndpointConfiguration sshServerEndpointConfiguration = new SshServerEndpointConfiguration();16sshServerEndpointConfiguration.setKeyPath("classpath:com/consol/citrus/ssh/server/keys/ssh_host_rsa_key");17return sshServerEndpointConfiguration;18}19}20package com.consol.citrus;21import com.consol.citrus.ssh.client.SshClient;22import org.springframework.context.annotation.Bean;23import org.springframework.context.annotation.Configuration;24import org.springframework.context.annotation.Import;25@Import({SshClient.class})26public class 4 {27public SshClient sshClient() {28SshClient sshClient = new SshClient();29sshClient.setEndpointConfiguration(sshClientEndpointConfiguration());30return sshClient;31}32public SshClientEndpointConfiguration sshClientEndpointConfiguration() {33SshClientEndpointConfiguration sshClientEndpointConfiguration = new SshClientEndpointConfiguration();34sshClientEndpointConfiguration.setKeyPath("classpath:com/consol/citrus/ssh/client/keys/ssh_host_rsa_key");35return sshClientEndpointConfiguration;36}37}38package com.consol.citrus;39import com.consol.citrus.jms.server.JmsServer;40import org.springframework.context.annotation.Bean;41import org.springframework.context.annotation.Configuration;42import org.springframework.context.annotation.Import;43@Import({JmsServer.class})44public class 5 {45public JmsServer jmsServer() {46JmsServer jmsServer = new JmsServer();47jmsServer.setEndpointConfiguration(jmsServerEndpointConfiguration());48return jmsServer;49}

Full Screen

Full Screen

getEndpointConfiguration

Using AI Code Generation

copy

Full Screen

1import com.consol.citrus.ssh.server.SshServer;2import com.consol.citrus.ssh.server.SshServerConfiguration;3public class 3 {4public static void main(String[] args) {5SshServer sshServer = new SshServer();6SshServerConfiguration configuration = sshServer.getEndpointConfiguration();7}8}9import com.consol.citrus.ssh.server.SshServer;10import com.consol.citrus.ssh.server.SshServerConfiguration;11public class 4 {12public static void main(String[] args) {13SshServer sshServer = new SshServer();14SshServerConfiguration configuration = sshServer.getEndpointConfiguration();15}16}17import com.consol.citrus.ssh.server.SshServer;18import com.consol.citrus.ssh.server.SshServerConfiguration;19public class 5 {20public static void main(String[] args) {21SshServer sshServer = new SshServer();22SshServerConfiguration configuration = sshServer.getEndpointConfiguration();23}24}25import com.consol.citrus.ssh.server.SshServer;26import com.consol.citrus.ssh.server.SshServerConfiguration;27public class 6 {28public static void main(String[] args) {29SshServer sshServer = new SshServer();30SshServerConfiguration configuration = sshServer.getEndpointConfiguration();31}32}33import com.consol.citrus.ssh.server.SshServer;34import com.consol.citrus.ssh.server.SshServerConfiguration;35public class 7 {36public static void main(String[] args) {37SshServer sshServer = new SshServer();38SshServerConfiguration configuration = sshServer.getEndpointConfiguration();39}40}41import com.consol.citrus.s

Full Screen

Full Screen

getEndpointConfiguration

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import com.consol.citrus.ssh.server.SshServer;3import com.consol.citrus.ssh.server.SshServerBuilder;4import com.consol.citrus.ssh.server.SshServerConfiguration;5public class SshServerTest {6 public void test() {7 SshServerConfiguration config = new SshServerConfiguration();8 SshServerBuilder builder = new SshServerBuilder();9 SshServer server = builder.server(config).build();10 server.getEndpointConfiguration();11 }12}13package com.consol.citrus.ssh.client;14import com.consol.citrus.ssh.client.SshClient;15import com.consol.citrus.ssh.client.SshClientBuilder;16import com.consol.citrus.ssh.client.SshClientConfiguration;17public class SshClientTest {18 public void test() {19 SshClientConfiguration config = new SshClientConfiguration();20 SshClientBuilder builder = new SshClientBuilder();21 SshClient client = builder.client(config).build();22 client.getEndpointConfiguration();23 }24}25package com.consol.citrus.ssh.message;26import java.util.Map;27import com.consol.citrus.ssh.message.SshMessage;28import com.consol.citrus.ssh.message.SshMessageHeaders;29public class SshMessageTest {30 public void test() {31 SshMessage message = new SshMessage("test");32 message.getHeaders();33 message.getPayload();34 message.getPayload(String.class);35 message.getPayload(Map.class);36 message.getPayload(String.class, SshMessageHeaders.SSH_MESSAGE);37 }38}39package com.consol.citrus.ssh.message;40import com.consol.citrus.ssh.message.SshMessageHeaders;41public class SshMessageHeadersTest {42 public void test() {43 SshMessageHeaders.SSH_MESSAGE;44 SshMessageHeaders.SSH_MESSAGE_ID;

Full Screen

Full Screen

getEndpointConfiguration

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner;3import org.springframework.beans.factory.annotation.Autowired;4import org.springframework.context.ApplicationContext;5import org.springframework.core.io.Resource;6import org.testng.annotations.Test;7public class SshServerJavaIT extends TestNGCitrusTestDesigner {8 private ApplicationContext applicationContext;9 public void sshServerJavaIT() {10 variable("sshServer", "sshServer");11 ssh()12 .server("${sshServer}")13 .autoStart(true)14 .autoStop(true)15 .keyPairResource("classpath:com/consol/citrus/ssh/server/citrus-secure.key")16 .port(2222)17 .user("citrus")18 .password("citrus")19 .publicKeyResource("classpath:com/consol/citrus/ssh/server/citrus-secure.pub")20 .privateKeyResource("classpath:com/consol/citrus/ssh/server/citrus-secure.key")21 .knownHostsResource("classpath:com/consol/citrus/ssh/server/citrus-secure.known_hosts")22 .knownHostsResource("classpath:com/consol/citrus/ssh/server/citrus-secure.known_hosts");23 echo("Endpoint configuration: ${sshServer}");24 Resource knownHostsResource = applicationContext.getBean("sshServer", SshServer.class).getEndpointConfiguration().getKnownHostsResource();25 echo("Known hosts resource: ${knownHostsResource}");26 Resource publicKeyResource = applicationContext.getBean("sshServer", SshServer.class).getEndpointConfiguration().getPublicKeyResource();27 echo("Public key resource: ${publicKeyResource}");28 Resource privateKeyResource = applicationContext.getBean("sshServer", SshServer.class).getEndpointConfiguration().getPrivateKeyResource();29 echo("Private key resource: ${privateKeyResource}");30 }31}32package com.consol.citrus.ssh.server;33import com.consol.citrus.endpoint.AbstractEndpointBuilder;34import com.consol.citrus.endpoint.Endpoint;35import com.consol.citrus.endpoint.EndpointConfiguration;36import com.consol.citrus.endpoint.EndpointConfigurationAware;37import com.consol.citrus.endpoint.EndpointAdapter;38import com.consol.citrus.endpoint.EndpointAdapterAware;39import com.consol.citrus.endpoint.EndpointBuilder

Full Screen

Full Screen

getEndpointConfiguration

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ssh.server;2import com.consol.citrus.ssh.config.annotation.SshServerConfig;3import com.consol.citrus.ssh.message.SshEndpointConfiguration;4import org.springframework.context.annotation.Bean;5import org.springframework.context.annotation.Configuration;6public class SshServerConfig {7 public SshServerConfig getEndpointConfiguration() {8 SshEndpointConfiguration endpointConfiguration = new SshEndpointConfiguration();9 endpointConfiguration.setPort(2222);10 return endpointConfiguration;11 }12 public SshServer sshServer() {13 return new SshServer(getEndpointConfiguration());14 }15}16package com.consol.citrus.ssh.client;17import com.consol.citrus.ssh.config.annotation.SshClientConfig;18import com.consol.citrus.ssh.message.SshEndpointConfiguration;19import org.springframework.context.annotation.Bean;20import org.springframework.context.annotation.Configuration;21public class SshClientConfig {22 public SshClientConfig getEndpointConfiguration() {23 SshEndpointConfiguration endpointConfiguration = new SshEndpointConfiguration();24 endpointConfiguration.setPort(2222);25 return endpointConfiguration;26 }27 public SshClient sshClient() {28 return new SshClient(getEndpointConfiguration());29 }30}31package com.consol.citrus.ssh.actions;32import com.consol.citrus.ssh.message.SshEndpointConfiguration;33import org.springframework.context.annotation.Bean;34import org.springframework.context.annotation.Configuration;35public class SshActionConfig {36 public SshActionConfig getEndpointConfiguration() {37 SshEndpointConfiguration endpointConfiguration = new SshEndpointConfiguration();38 endpointConfiguration.setPort(2222);39 return endpointConfiguration;40 }41 public SshAction sshAction() {42 return new SshAction(getEndpointConfiguration());43 }44}

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