How to use getNetworkConnection method of com.consol.citrus.jmx.client.JmxClient class

Best Citrus code snippet using com.consol.citrus.jmx.client.JmxClient.getNetworkConnection

Source:JmxClient.java Github

copy

Full Screen

...79 MBeanServerConnection serverConnection;80 if (getEndpointConfiguration().getServerUrl().equals("platform")) {81 serverConnection = ManagementFactory.getPlatformMBeanServer();82 } else {83 serverConnection = getNetworkConnection();84 }85 if (log.isDebugEnabled()) {86 log.debug("Sending message to JMX MBeanServer server: '" + getEndpointConfiguration().getServerUrl() + "'");87 log.debug("Message to send:\n" + message.getPayload(String.class));88 }89 context.onOutboundMessage(message);90 ManagedBeanInvocation invocation = getEndpointConfiguration().getMessageConverter().convertOutbound(message, getEndpointConfiguration(), context);91 try {92 if (StringUtils.hasText(invocation.getMbean())) {93 objectName = new ObjectName(invocation.getMbean().toString());94 } else if (StringUtils.hasText(invocation.getObjectKey())) {95 objectName = new ObjectName(invocation.getObjectDomain(), invocation.getObjectKey(), invocation.getObjectValue());96 } else {97 objectName = new ObjectName(invocation.getObjectDomain(), "name", invocation.getObjectName());98 }99 } catch (MalformedObjectNameException e) {100 throw new CitrusRuntimeException("Failed to create object name", e);101 }102 try {103 if (invocation.getOperation() != null) {104 Object result = serverConnection.invoke(objectName, invocation.getOperation().getName(), invocation.getOperation().getParamValues(context.getApplicationContext()), invocation.getOperation().getParamTypes());105 if (result != null) {106 correlationManager.store(correlationKey, JmxMessage.result(result));107 } else {108 correlationManager.store(correlationKey, JmxMessage.result());109 }110 } else if (invocation.getAttribute() != null) {111 ManagedBeanInvocation.Attribute attribute = invocation.getAttribute();112 if (StringUtils.hasText(attribute.getValue())) {113 serverConnection.setAttribute(objectName, new Attribute(attribute.getName(), invocation.getAttributeValue(context.getApplicationContext())));114 } else {115 Object attributeValue = serverConnection.getAttribute(objectName, attribute.getName());116 if (StringUtils.hasText(attribute.getInnerPath())) {117 if (attributeValue instanceof CompositeData) {118 if (!((CompositeData) attributeValue).containsKey(attribute.getInnerPath())) {119 throw new CitrusRuntimeException("Failed to find inner path attribute value: " + attribute.getInnerPath());120 }121 attributeValue = ((CompositeData) attributeValue).get(attribute.getInnerPath());122 } else {123 throw new CitrusRuntimeException("Failed to get inner path on attribute value: " + attributeValue);124 }125 }126 if (attributeValue != null) {127 correlationManager.store(correlationKey, JmxMessage.result(attributeValue));128 } else {129 correlationManager.store(correlationKey, JmxMessage.result());130 }131 }132 } else {133 addNotificationListener(objectName, correlationKey, serverConnection);134 }135 } catch (JMException e) {136 throw new CitrusRuntimeException("Failed to execute MBean operation", e);137 } catch (IOException e) {138 throw new CitrusRuntimeException("Failed to execute MBean operation", e);139 }140 }141 /**142 * Establish network connection to remote mBean server.143 * @return144 */145 private MBeanServerConnection getNetworkConnection() {146 try {147 JMXServiceURL url = new JMXServiceURL(getEndpointConfiguration().getServerUrl());148 String[] creds = {getEndpointConfiguration().getUsername(), getEndpointConfiguration().getPassword()};149 JMXConnector networkConnector = JMXConnectorFactory.connect(url, Collections.singletonMap(JMXConnector.CREDENTIALS, creds));150 connectionId = networkConnector.getConnectionId();151 networkConnector.addConnectionNotificationListener(this, null, null);152 return networkConnector.getMBeanServerConnection();153 } catch (IOException e) {154 throw new CitrusRuntimeException("Failed to connect to network MBean server", e);155 }156 }157 @Override158 public Message receive(TestContext context) {159 return receive(correlationManager.getCorrelationKey(160 getEndpointConfiguration().getCorrelator().getCorrelationKeyName(getName()), context), context);161 }162 @Override163 public Message receive(String selector, TestContext context) {164 return receive(selector, context, getEndpointConfiguration().getTimeout());165 }166 @Override167 public Message receive(TestContext context, long timeout) {168 return receive(correlationManager.getCorrelationKey(169 getEndpointConfiguration().getCorrelator().getCorrelationKeyName(getName()), context), context, timeout);170 }171 @Override172 public Message receive(String selector, TestContext context, long timeout) {173 Message message = correlationManager.find(selector, timeout);174 if (message == null) {175 throw new ActionTimeoutException("Action timeout while receiving synchronous reply message from MBean server");176 }177 return message;178 }179 @Override180 public void handleNotification(Notification notification, Object handback) {181 JMXConnectionNotification connectionNotification = (JMXConnectionNotification) notification;182 if (connectionNotification.getConnectionId().equals(getConnectionId()) && connectionLost(connectionNotification)) {183 log.warn("JmxClient lost JMX connection for : {}", getEndpointConfiguration().getServerUrl());184 if (getEndpointConfiguration().isAutoReconnect()) {185 scheduleReconnect();186 }187 }188 }189 /**190 * Finds connection lost type notifications.191 * @param connectionNotification192 * @return193 */194 private boolean connectionLost(JMXConnectionNotification connectionNotification) {195 return connectionNotification.getType().equals(JMXConnectionNotification.NOTIFS_LOST)196 || connectionNotification.getType().equals(JMXConnectionNotification.CLOSED)197 || connectionNotification.getType().equals(JMXConnectionNotification.FAILED);198 }199 /**200 * Schedules an attempt to re-initialize a lost connection after the reconnect delay201 */202 public void scheduleReconnect() {203 Runnable startRunnable = new Runnable() {204 @Override205 public void run() {206 try {207 MBeanServerConnection serverConnection = getNetworkConnection();208 if (notificationListener != null) {209 serverConnection.addNotificationListener(objectName, notificationListener, getEndpointConfiguration().getNotificationFilter(), getEndpointConfiguration().getNotificationHandback());210 }211 } catch (Exception e) {212 log.warn("Failed to reconnect to JMX MBean server. {}", e.getMessage());213 scheduleReconnect();214 }215 }216 };217 log.info("Reconnecting to MBean server {} in {} milliseconds.", getEndpointConfiguration().getServerUrl(), getEndpointConfiguration().getDelayOnReconnect());218 scheduledExecutor.schedule(startRunnable, getEndpointConfiguration().getDelayOnReconnect(), TimeUnit.MILLISECONDS);219 }220 /**221 * Add notification listener for response messages....

Full Screen

Full Screen

getNetworkConnection

Using AI Code Generation

copy

Full Screen

1public void testGetNetworkConnection() {2 run(new TestCase()3 .applyBehavior(new JmxClientBehavior()4 .client(new JmxClient())5 .objectName("java.lang:type=Runtime")6 .attribute("Uptime")7 .operation("gc")8 .operationArgs(new Object[] { })9 .operationSignature(new String[] { })10 .operationResultType(Long.class)11 .operationResult(0L)12 );13}

Full Screen

Full Screen

getNetworkConnection

Using AI Code Generation

copy

Full Screen

1public void testJMXClient() {2 JmxClient jmxClient = new JmxClient();3 jmxClient.setEndpointConfiguration(jmxEndpointConfiguration());4 jmxClient.setBeanName("java.lang:type=OperatingSystem");5 jmxClient.setMethodName("getSystemLoadAverage");6 jmxClient.setMethodParams(new Object[] { });7 jmxClient.setMethodSignature(new String[] { });8 jmxClient.setMethodReturnType(Double.class);9 jmxClient.setOperationTimeout(3000L);10 jmxClient.setJmxClientFactory(jmxClientFactory());11 jmxClient.afterPropertiesSet();12 jmxClient.init();13 jmxClient.send(new JmxMessage());14 jmxClient.receive(new JmxMessage());15 jmxClient.destroy();16}17public void testJMXClient() {18 variable("sys

Full Screen

Full Screen

getNetworkConnection

Using AI Code Generation

copy

Full Screen

1public void testGetNetworkConnection() {2 description("Test to get the network connection of the remote JMX server");3 variable("JMX_SERVER_USER", "admin");4 variable("JMX_SERVER_PASSWORD", "admin");5 jmx()6 .client(jmxClient()7 .url("${JMX_SERVER_URL}")8 .credentials("${JMX_SERVER_USER}", "${JMX_SERVER_PASSWORD}"))9 .send()10 .getNetworkConnection()11 .attribute("java.lang:type=Runtime", "VmVendor");12 jmx()13 .client(jmxClient()14 .url("${JMX_SERVER_URL}")15 .credentials("${JMX_SERVER_USER}", "${JMX_SERVER_PASSWORD}"))16 .receive()17 .assertJmxResponse()18 .attribute("java.lang:type=Runtime", "VmVendor")19 .value("Oracle Corporation");20}21public void testGetMBeanCount() {22 description("Test to get the number of MBeans registered in the remote JMX server");23 variable("JMX_SERVER_USER", "admin");24 variable("JMX_SERVER_PASSWORD", "admin");25 jmx()26 .client(jmxClient()27 .url("${JMX_SERVER_URL}")28 .credentials("${JMX_SERVER_USER}", "${JMX_SERVER_PASSWORD}"))29 .send()30 .getMBeanCount();31 jmx()

Full Screen

Full Screen

getNetworkConnection

Using AI Code Generation

copy

Full Screen

1public void testGetNetworkConnection() {2 run(new TestCase()3 .actions(4 jmx()5 .client(jmxClient)6 .send()7 .operation("getNetworkConnection")8 .noArgs(),9 echo("${jmx:getNetworkConnection}"),10 createVariable("networkConnection", "${jmx:getNetworkConnection}"),11 echo("${networkConnection}"),12 createVariable("jmxConnection", "${jmx:connection}"),13 echo("${jmxConnection}"),14 assertJmx()15 .client(jmxClient)16 .receive()17 .operation("getNetworkConnection")18 .noArgs()19 .result("${networkConnection}")20 );21}22public void testGetNetworkConnection() {23 run(new TestCase()24 .actions(25 jmx()26 .client(jmxClient)27 .send()28 .operation("getNetworkConnection")29 .noArgs(),30 echo("${jmx:getNetworkConnection}"),31 createVariable("networkConnection", "${jmx:getNetworkConnection}"),32 echo("${networkConnection}"),33 createVariable("jmxConnection", "${jmx:connection}"),34 echo("${jmxConnection}"),35 assertJmx()36 .client(jmxClient)37 .receive()38 .operation("getNetworkConnection")39 .noArgs()40 .result("${networkConnection}")41 );42}43public void testGetNetworkConnection() {44 run(new TestCase()45 .actions(46 jmx()47 .client(jmxClient)48 .send()49 .operation("getNetworkConnection")50 .noArgs(),51 echo("${jmx:getNetworkConnection}"),52 createVariable("networkConnection", "${jmx:getNetworkConnection}"),53 echo("${networkConnection}"),54 createVariable("jmxConnection", "${jmx:connection}"),55 echo("${jmxConnection

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