Search in sources :

Example 21 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.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);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) SocketException(java.net.SocketException) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MalformedURLException(java.net.MalformedURLException) MalformedURLException(java.net.MalformedURLException) AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) SocketException(java.net.SocketException) URL(java.net.URL)

Example 22 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.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);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) XMLStreamException(javax.xml.stream.XMLStreamException) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) IOException(java.io.IOException)

Example 23 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.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);
            }
        }
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 24 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.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);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) SQLException(java.sql.SQLException)

Example 25 with AttachmentMgtException

use of org.wso2.carbon.attachment.mgt.skeleton.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);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException) AttachmentDAO(org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) Attachment(org.wso2.carbon.attachment.mgt.api.attachment.Attachment)

Aggregations

AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)11 AttachmentMgtException (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)9 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)8 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)7 DataHandler (javax.activation.DataHandler)4 Query (javax.persistence.Query)4 Attachment (org.wso2.carbon.attachment.mgt.api.attachment.Attachment)4 AttachmentManagerService (org.wso2.carbon.attachment.mgt.core.service.AttachmentManagerService)4 TAttachment (org.wso2.carbon.attachment.mgt.stub.types.TAttachment)4 Calendar (java.util.Calendar)3 EndpointReference (org.apache.axis2.addressing.EndpointReference)3 Options (org.apache.axis2.client.Options)3 AttachmentMgtServiceStub (org.wso2.carbon.attachment.mgt.stub.AttachmentMgtServiceStub)3 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 URI (org.apache.axis2.databinding.types.URI)2 AttachmentDAOImpl (org.wso2.carbon.attachment.mgt.core.dao.impl.jpa.openjpa.entity.AttachmentDAOImpl)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1