Search in sources :

Example 1 with LocalEntryAdminException

use of org.wso2.carbon.localentry.LocalEntryAdminException in project carbon-apimgt by wso2.

the class GoogleAnalyticsConfigDeployer method deployAsLocalEntry.

private void deployAsLocalEntry(CloseableHttpResponse closeableHttpResponse, LocalEntryServiceProxy localEntryServiceProxy) throws IOException, ArtifactSynchronizerException {
    if (closeableHttpResponse.getStatusLine().getStatusCode() == 200) {
        try (InputStream content = closeableHttpResponse.getEntity().getContent()) {
            MessageContext.setCurrentMessageContext(GatewayUtils.createAxis2MessageContext());
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
            String resourceContent = IOUtils.toString(content);
            if (localEntryServiceProxy.localEntryExists(APIConstants.GA_CONF_KEY)) {
                localEntryServiceProxy.deleteEntry(APIConstants.GA_CONF_KEY);
            }
            DataHolder.getInstance().addGoogleAnalyticsConfig(tenantDomain, resourceContent);
            localEntryServiceProxy.addLocalEntry("<localEntry key=\"" + APIConstants.GA_CONF_KEY + "\">" + resourceContent + "</localEntry>");
        } catch (LocalEntryAdminException e) {
            log.error("Error while deploying LocalEntry ga-config", e);
        } finally {
            MessageContext.destroyCurrentMessageContext();
            PrivilegedCarbonContext.endTenantFlow();
        }
    } else {
        throw new ArtifactSynchronizerException("Error while deploying localEntry status code : " + closeableHttpResponse.getStatusLine().getStatusCode());
    }
}
Also used : ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException) InputStream(java.io.InputStream) LocalEntryAdminException(org.wso2.carbon.localentry.LocalEntryAdminException)

Aggregations

InputStream (java.io.InputStream)1 ArtifactSynchronizerException (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException)1 LocalEntryAdminException (org.wso2.carbon.localentry.LocalEntryAdminException)1