use of org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException in project carbon-business-process by wso2.
the class URLGeneratorUtil method getPermanentLink.
/**
* Generate the permanent link for the given attachment uri based on current system configurations like host, port
* eg - if {@code uniqueID} is abc123, then the resultant permanent link would {@code https://127.0.0.1:9443/context/abc123}
* So this url can be used to download the attachment
*
* @param uniqueID uri for the attachment
* @return downloadable url of the attachment
* @throws AttachmentMgtException
*/
public static URL getPermanentLink(URI uniqueID) throws AttachmentMgtException {
String scheme = CarbonConstants.HTTPS_TRANSPORT;
String host;
try {
host = NetworkUtils.getLocalHostname();
} catch (SocketException e) {
log.error(e.getMessage(), e);
throw new AttachmentMgtException(e.getLocalizedMessage(), e);
}
int port = 9443;
try {
ConfigurationContext serverConfigContext = AttachmentServerHolder.getInstance().getConfigurationContextService().getServerConfigContext();
port = CarbonUtils.getTransportProxyPort(serverConfigContext, scheme);
if (port == -1) {
port = CarbonUtils.getTransportPort(serverConfigContext, scheme);
}
} catch (Exception ex) {
log.warn("Using default port settings");
}
String webContext = ServerConfiguration.getInstance().getFirstProperty("WebContextRoot");
if (webContext == null || webContext.equals("/")) {
webContext = "";
}
String tenantDomain = String.valueOf(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
try {
tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
} catch (Throwable e) {
tenantDomain = null;
}
String url = null;
try {
String link = scheme + "://" + host + ":" + port + webContext + ((tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) ? "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + tenantDomain : "") + AttachmentMgtConfigurationConstants.ATTACHMENT_DOWNLOAD_SERVELET_URL_PATTERN + "/" + uniqueID.toString();
return new URL(link);
} catch (MalformedURLException e) {
log.error(e.getMessage(), e);
throw new AttachmentMgtException(e.getLocalizedMessage(), e);
}
}
use of org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException in project carbon-business-process by wso2.
the class JDBCManager method getDBConfig.
private static JDBCConfiguration getDBConfig(String configPath) throws AttachmentMgtException {
String config = null;
try {
config = FileUtil.readFileToString(configPath);
OMElement omElement = AXIOMUtil.stringToOM(config);
String dbURL = omElement.getFirstChildWithName(new QName("url")).getText();
String driverName = omElement.getFirstChildWithName(new QName("driverName")).getText();
String userName = omElement.getFirstChildWithName(new QName("userName")).getText();
String password = omElement.getFirstChildWithName(new QName("password")).getText();
String validationQuery = omElement.getFirstChildWithName(new QName("validationQuery")).getText();
JDBCConfiguration dbConfiguration = new JDBCConfiguration(dbURL, driverName, userName, password, validationQuery);
return dbConfiguration;
} catch (IOException e) {
throw new AttachmentMgtException(e.getLocalizedMessage(), e);
} catch (XMLStreamException e) {
throw new AttachmentMgtException(e.getLocalizedMessage(), e);
}
}
use of org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException in project carbon-business-process by wso2.
the class JDBCManager method initFromFileConfig.
public void initFromFileConfig(String dbConfigurationPath) throws AttachmentMgtException {
String jdbcURL;
String driver;
String username;
String password;
String validationQuery;
if (dataSource == null) {
synchronized (JDBCManager.class) {
if (dataSource == null) {
JDBCConfiguration configuration = getDBConfig(dbConfigurationPath);
jdbcURL = configuration.getJdbcURL();
driver = configuration.getDriver();
username = configuration.getUsername();
password = configuration.getPassword();
validationQuery = configuration.getValidationQuery();
if (jdbcURL == null || driver == null || username == null || password == null) {
throw new AttachmentMgtException("DB configurations are not properly defined");
}
dataSource = new BasicDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(jdbcURL);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setValidationQuery(validationQuery);
}
}
}
}
use of org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException in project carbon-business-process by wso2.
the class JDBCManager method shutdown.
@Override
public void shutdown() throws AttachmentMgtException {
try {
dataSource.close();
dataSource = null;
} catch (SQLException e) {
throw new AttachmentMgtException(e.getLocalizedMessage(), e);
}
}
use of org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException in project carbon-business-process by wso2.
the class AttachmentManagerService method add.
/**
* {@inheritDoc}
*/
@Override
public String add(final TAttachment attachment) throws AttachmentMgtException {
if (log.isDebugEnabled() && attachment != null) {
log.debug("Saving the attachment with id " + attachment.getId());
}
try {
Attachment att = TransformerUtil.convertAttachment(attachment);
// 1. get Att-Mgt DAO Conn factory
// 2. get Att-Mgt DAO Connection
// 3. addAttachment
// getDaoConnectionFactory().getDAOConnection().addAttachment(att);
AttachmentDAO daoImpl = getDaoConnectionFactory().getDAOConnection().getAttachmentMgtDAOFactory().addAttachment(att);
return daoImpl.getID().toString();
} catch (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException ex) {
String errMsg = "org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService.add " + "operation failed. Reason:" + ex.getLocalizedMessage();
log.error(errMsg, ex);
throw new AttachmentMgtException(errMsg, ex);
}
}
Aggregations