use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.
the class ConfigurationParser method createConnection.
/**
* Create a DB connection from an attributes map
*
* @param nodeMap the map of attributes
* @return the db connection
* @throws AgentException on error
*/
private DbConnection createConnection(NamedNodeMap nodeMap) throws AgentException {
//the default host is localhost, if the attribute host is set
//it will override the default setting
String host = "127.0.0.1";
if (nodeMap.getNamedItem("host") != null) {
host = nodeMap.getNamedItem("host").getNodeValue();
}
String user = nodeMap.getNamedItem("user").getNodeValue();
String password = nodeMap.getNamedItem("password").getNodeValue();
String type = nodeMap.getNamedItem("type").getNodeValue();
Map<String, Object> customProperties = new HashMap<String, Object>();
if (nodeMap.getNamedItem("port") != null) {
String portValue = nodeMap.getNamedItem("port").getNodeValue();
try {
Integer port = Integer.parseInt(portValue);
customProperties.put(DbKeys.PORT_KEY, port);
} catch (NumberFormatException nfe) {
throw new AgentException("Cannot convert DB port number to integer: '" + portValue + "'");
}
}
//get the database type
String dbType = type.toUpperCase();
if (dbType == null) {
throw new AgentException("Database type " + type + " not supported");
}
// custom SID / Service Name (Oracle only)
if (dbType.equals(DbConnOracle.DATABASE_TYPE)) {
// So if your database name is some db and your instance number is 3, then your SID is somedb3.
if (nodeMap.getNamedItem("sid") != null) {
customProperties.put(OracleKeys.SID_KEY, nodeMap.getNamedItem("sid").getNodeValue());
}
// or secondary connections, or to not use certain SIDs at all.
if (nodeMap.getNamedItem("serviceName") != null) {
customProperties.put(OracleKeys.SERVICE_NAME_KEY, nodeMap.getNamedItem("serviceName").getNodeValue());
}
}
String database;
if (nodeMap.getNamedItem("name") != null) {
database = nodeMap.getNamedItem("name").getNodeValue();
} else if (dbType.equals(DbConnOracle.DATABASE_TYPE) && (nodeMap.getNamedItem("sid") != null || nodeMap.getNamedItem("serviceName") != null)) {
database = "";
} else {
throw new AgentException("No DB Name" + (dbType.equals(DbConnOracle.DATABASE_TYPE) ? "/SID/Service Name" : "") + " is specified.");
}
return DatabaseProviderFactory.createDbConnection(dbType, host, database, user, password, customProperties);
}
use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.
the class ComponentEnvironment method backupOnlyIfNotAlreadyDone.
public void backupOnlyIfNotAlreadyDone() throws AgentException {
try {
File backupDir = new File(backupFolder);
String[] fileList = backupDir.list();
if (backupDir.isDirectory() && fileList != null && fileList.length > 0) {
log.info("Backup directory '" + backupDir.getAbsolutePath() + "' already exists and the backup will be skipped.");
} else if (backupDir.exists() && !backupDir.isDirectory()) {
throw new AgentException("Could not create backup directory '" + backupDir.getAbsolutePath() + "'. File with this name already exists.");
} else {
log.info("Creating backup for component " + componentName);
for (EnvironmentUnit environmentUnit : environmentUnits) {
environmentUnit.backup();
}
}
} catch (EnvironmentCleanupException ece) {
throw new AgentException("Could not backup environment for component '" + componentName + "'" + recurseCauses(ece), ece);
}
}
use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.
the class ComponentEnvironment method restore.
public void restore(String folderPath) throws AgentException {
// All additional actions are implicitly added to the Additional Actions Queue Instance
try {
for (EnvironmentUnit environmentUnit : environmentUnits) {
environmentUnit.setTempBackupDir(folderPath);
environmentUnit.restore();
}
} catch (EnvironmentCleanupException ece) {
throw new AgentException("Could not restore environment for component '" + this.componentName + "'" + recurseCauses(ece), ece);
}
// Now execute the additional actions and clean the queue
try {
AdditionalActionsQueue.getInstance().flushAllActions();
} catch (EnvironmentCleanupException ece) {
throw new AgentException("Could not restore environment for component '" + this.componentName + "'" + recurseCauses(ece), ece);
}
}
use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.
the class Test_ConfigurationParser method testDB_NoDbNameServiceNameAndSID_forOracle.
@Test
public void testDB_NoDbNameServiceNameAndSID_forOracle() throws Exception {
InputStream _descriptorFileStream = Test_ConfigurationParser.class.getClassLoader().getResourceAsStream("test_descriptors/test_agent_descriptor_no_db_name_sid_sname.xml");
ConfigurationParser configParser = new ConfigurationParser();
try {
configParser.parse(_descriptorFileStream, jarFileAbsolutePath);
fail();
} catch (AgentException ae) {
assertEquals("No DB Name/SID/Service Name is specified.", ae.getMessage());
}
}
use of com.axway.ats.agent.core.exceptions.AgentException in project ats-framework by Axway.
the class AgentServicePool method createServicePort.
private AgentService createServicePort(String host) throws AgentException {
try {
String protocol = AgentConfigurator.getConnectionProtocol(host);
if (protocol == null) {
protocol = "http";
} else {
SslUtils.trustAllHttpsCertificates();
SslUtils.trustAllHostnames();
}
URL url = this.getClass().getResource("/META-INF/wsdl/" + AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME + ".wsdl");
Service agentService = Service.create(url, new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME));
AgentService agentServicePort = agentService.getPort(new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_PORT_NAME), AgentService.class);
Map<String, Object> ctxt = ((BindingProvider) agentServicePort).getRequestContext();
// setting ENDPOINT ADDRESS, which defines the web service URL for SOAP communication
// NOTE: if we specify WSDL URL (...<endpoint_address>?wsdl), the JBoss server returns the WSDL on a SOAP call,
// but we are expecting a SOAP message response and an exception is thrown.
// The Jetty server (in ATS agents) is working in both cases.
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, protocol + "://" + host + AgentWsDefinitions.AGENT_SERVICE_ENDPOINT_ADDRESS);
// setting timeouts
// timeout in milliseconds
ctxt.put(BindingProviderProperties.CONNECT_TIMEOUT, 10000);
// check if new unique id must be generated each time
if (!useNewUuId) {
// create temp file containing caller working directory and the unique id
String userWorkingDirectory = AtsSystemProperties.SYSTEM_USER_HOME_DIR;
String uuiFileLocation = AtsSystemProperties.SYSTEM_USER_TEMP_DIR + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + "\\ats_uid.txt";
File uuiFile = new File(uuiFileLocation);
// otherwise add it to the file
if (uuiFile.exists()) {
String uuiFileContent = IoUtils.streamToString(IoUtils.readFile(uuiFileLocation));
if (uuiFileContent.contains(userWorkingDirectory)) {
for (String line : uuiFileContent.split("\n")) {
if (line.contains(userWorkingDirectory)) {
uniqueId = line.substring(userWorkingDirectory.length()).trim();
}
}
} else {
generateNewUUID();
new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
}
} else {
generateNewUUID();
try {
uuiFile.createNewFile();
} catch (IOException e) {
log.warn("Unable to create file '" + uuiFile.getAbsolutePath() + "'");
}
if (uuiFile.exists()) {
new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
}
}
} else {
generateNewUUID();
}
// add header with unique session ID
Map<String, List<String>> requestHeaders = new HashMap<>();
requestHeaders.put(ApplicationContext.ATS_UID_SESSION_TOKEN, Arrays.asList(uniqueId));
ctxt.put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
return agentServicePort;
} catch (Exception e) {
throw new AgentException("Cannot connect to Agent application on host '" + host + "' check your configuration", e);
}
}
Aggregations