use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class SmtpConnection method data.
@PublicAtsApi
public void data(String text) {
try {
//obtain an output stream
OutputStream dataStream = data();
dataStream.write(text.getBytes());
dataStream.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (!finishData()) {
throw new RuntimeException("Error executing data command");
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class SystemOperations method logClassPath.
/**
* Log all JARs in current application's ClassPath
*/
@PublicAtsApi
public void logClassPath() {
ISystemOperations operations = getOperationsImplementationFor(atsAgent);
operations.logClassPath();
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class SystemOperations method getJvmMbeans.
/**
* @param host the address of the host machine
* @param jmxPort the jmx port
*
* @return all MBeans with their attributes and type
* @throws SystemOperationException
*/
@PublicAtsApi
public String getJvmMbeans(String host, String jmxPort) {
JMXConnector jmxCon = null;
try {
// Connect to JMXConnector
JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + jmxPort + "/jmxrmi");
jmxCon = JMXConnectorFactory.newJMXConnector(serviceUrl, null);
jmxCon.connect();
// Access the MBean
MBeanServerConnection con = jmxCon.getMBeanServerConnection();
Set<ObjectName> queryResults = con.queryNames(null, null);
StringBuilder results = new StringBuilder();
for (ObjectName theName : queryResults) {
results.append("\n---");
results.append("\nMBean name: " + theName.getCanonicalName());
MBeanAttributeInfo[] attributes = con.getMBeanInfo(theName).getAttributes();
for (MBeanAttributeInfo attribute : attributes) {
if (attribute.getType() != null) {
if (!"javax.management.openmbean.CompositeData".equals(attribute.getType())) {
if ("java.lang.Long".equals(attribute.getType()) || "java.lang.Integer".equals(attribute.getType()) || "int".equals(attribute.getType()) || "long".equals(attribute.getType()))
results.append("\r " + attribute.getName() + " | " + attribute.getType());
} else {
results.append("\r " + attribute.getName() + " | " + attribute.getType());
CompositeData comdata = (CompositeData) con.getAttribute(theName, attribute.getName());
if (comdata != null) {
for (String key : comdata.getCompositeType().keySet()) {
Object value = comdata.get(key);
if (value instanceof Integer || value instanceof Double || value instanceof Long)
results.append("\r " + key + " | " + value.getClass());
}
}
}
}
}
}
return results.toString();
} catch (Exception e) {
throw new SystemOperationException("MBeans with their attributes cannot be get.", e);
} finally {
if (jmxCon != null)
try {
jmxCon.close();
} catch (IOException e) {
log.error("JMX connection was not closed!");
}
}
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class SystemOperations method isListening.
/**
* Check if some process is listening on some port on some host.
* Note that we cannot give the name of the listening process.
*
* @param host host address
* @param port port number
* @param timeout timeout value in milliseconds
* @return <code>true</code> if the address is listening on this port
* @throws SystemOperationException when the target host is unknown
*/
@PublicAtsApi
public boolean isListening(@Validate(name = "host", type = ValidationType.STRING_NOT_EMPTY) String host, @Validate(name = "port", type = ValidationType.NUMBER_PORT_NUMBER) int port, @Validate(name = "timeout", type = ValidationType.NUMBER_POSITIVE) int timeout) {
// validate input parameters
new Validator().validateMethodParameters(new Object[] { host, port, timeout });
// execute action
ISystemOperations operations = getOperationsImplementationFor(atsAgent);
return operations.isListening(host, port, timeout);
}
use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.
the class XmlText method replace.
/**
* Replace a XML element.
*
* @param xpath XPath , pointing to a XML element
* @param object the new XML element
* @return this instance
* @throws XMLException
*/
@PublicAtsApi
public XmlText replace(String xpath, Object object) throws XMLException {
if (StringUtils.isNullOrEmpty(xpath)) {
throw new XMLException("Null/empty xpath is not allowed.");
}
if (object == null) {
throw new XMLException("Null object is not allowed for replacement." + "If you want to remove existing XML element, use XMLText.remove().");
}
Element newElement = null;
if (object instanceof XmlText) {
newElement = ((XmlText) object).root;
}
if (object instanceof String) {
if (StringUtils.isNullOrEmpty((String) object)) {
throw new XMLException("Null/empty String object is not allowed for replacement." + "If you want to remove existing XML element, use XMLText.remove().");
}
newElement = new XmlText((String) object).root;
}
if (newElement == null) {
throw new XMLException("Given object for replacing an existing one is from invallid class instance. " + "Use String or XMLText instances only.");
}
Element oldElement = findElement(xpath);
if (oldElement != null) {
if (oldElement.isRootElement()) {
throw new XMLException("You cannot replace the root element of the XML document.");
}
Element parent = oldElement.getParent();
if (parent != null) {
parent.elements().set(parent.elements().indexOf(oldElement), newElement);
} else {
throw new XMLException("Parent for element with xpath '" + xpath + "' could not be found.");
}
} else {
throw new XMLException("'" + xpath + "' is not a valid path");
}
return this;
}
Aggregations