Java Code Examples for org.wso2.carbon.registry.core.jdbc.handlers.RequestContext

The following examples show how to use org.wso2.carbon.registry.core.jdbc.handlers.RequestContext. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: carbon-apimgt   Source File: CustomAPIIndexHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This method tests whether the CustomAPIIndexer works correctly under different circumstances without throwing
 * Exception.
 *
 * @throws RegistryException Registry Exception.
 */
@Test
public void testPut() throws RegistryException {
    // Resource without property.
    Resource resource = new ResourceImpl();
    RequestContext requestContext = Mockito.mock(RequestContext.class);
    Mockito.doReturn(Mockito.mock(Registry.class)).when(requestContext).getRegistry();
    ResourcePath resourcePath = Mockito.mock(ResourcePath.class);
    Mockito.doReturn(resource).when(requestContext).getResource();
    Mockito.doReturn(resourcePath).when(requestContext).getResourcePath();
    CustomAPIIndexHandler customAPIIndexHandler = new CustomAPIIndexHandler();
    customAPIIndexHandler.put(requestContext);

    // Resource with property.
    resource.setProperty(APIConstants.CUSTOM_API_INDEXER_PROPERTY, "true");
    Mockito.doReturn(resource).when(requestContext).getResource();
    customAPIIndexHandler.put(requestContext);
}
 
Example 2
@Override
public void put(RequestContext requestContext) throws RegistryException {
    super.put(requestContext);
    Properties properties = EntitlementServiceComponent.getEntitlementConfig().getEngineProperties();
    boolean enableRegistryCacheClear = true ;
    if(properties.getProperty(PDPConstants.PDP_REGISTRY_LEVEL_POLICY_CACHE_CLEAR)!=null){
        enableRegistryCacheClear = Boolean.parseBoolean(properties.getProperty(PDPConstants.PDP_REGISTRY_LEVEL_POLICY_CACHE_CLEAR));
    }
    if(enableRegistryCacheClear) {
        RegistryPolicyStoreManageModule.invalidateCache();
    }


}
 
Example 3
@Override
public void delete(RequestContext requestContext) throws RegistryException {

    super.delete(requestContext);
    Properties properties = EntitlementServiceComponent.getEntitlementConfig().getEngineProperties();
    boolean enableRegistryCacheClear = true ;
    if(properties.getProperty(PDPConstants.PDP_REGISTRY_LEVEL_POLICY_CACHE_CLEAR)!=null){
        enableRegistryCacheClear = Boolean.parseBoolean(properties.getProperty(PDPConstants.PDP_REGISTRY_LEVEL_POLICY_CACHE_CLEAR));
    }
    if(enableRegistryCacheClear) {
        RegistryPolicyStoreManageModule.invalidateCache();
    }

}
 
Example 4
@Override
public boolean handlePut(RequestContext requestContext) throws RegistryException {
    Resource resource = requestContext.getResource();
    if (resource != null) {
        String mType = resource.getMediaType();
        return mType != null && (invert != mType.equals(getMediaType()));
    }
    return false;
}
 
Example 5
Source Project: carbon-identity   Source File: RegistryPolicyHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void put(RequestContext requestContext) throws RegistryException {
    super.put(requestContext);
    Properties properties = EntitlementServiceComponent.getEntitlementConfig().getEngineProperties();
    boolean enableRegistryCacheClear = true ;
    if(properties.getProperty(PDPConstants.PDP_REGISTRY_LEVEL_POLICY_CACHE_CLEAR)!=null){
        enableRegistryCacheClear = Boolean.parseBoolean(properties.getProperty(PDPConstants.PDP_REGISTRY_LEVEL_POLICY_CACHE_CLEAR));
    }
    if(enableRegistryCacheClear) {
        RegistryPolicyStoreManageModule.invalidateCache();
    }


}
 
Example 6
Source Project: carbon-identity   Source File: RegistryPolicyHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void delete(RequestContext requestContext) throws RegistryException {

    super.delete(requestContext);
    Properties properties = EntitlementServiceComponent.getEntitlementConfig().getEngineProperties();
    boolean enableRegistryCacheClear = true ;
    if(properties.getProperty(PDPConstants.PDP_REGISTRY_LEVEL_POLICY_CACHE_CLEAR)!=null){
        enableRegistryCacheClear = Boolean.parseBoolean(properties.getProperty(PDPConstants.PDP_REGISTRY_LEVEL_POLICY_CACHE_CLEAR));
    }
    if(enableRegistryCacheClear) {
        RegistryPolicyStoreManageModule.invalidateCache();
    }

}
 
Example 7
@Override
public boolean handlePut(RequestContext requestContext) throws RegistryException {
    Resource resource = requestContext.getResource();
    if (resource != null) {
        String mType = resource.getMediaType();
        return mType != null && (invert != mType.equals(getMediaType()));
    }
    return false;
}
 
Example 8
/**
 * This method is called for a registry get operation
 *
 * @param requestContext - The request context
 * @return - returns the modified resource
 * @throws RegistryException
 */
public Resource get(RequestContext requestContext) throws RegistryException {
    Resource resource = requestContext.getResource();
    if (resource != null) {
        String resourceContent = RegistryUtils.decodeBytes((byte[]) resource.getContent());
        try {
            OMElement omElement = AXIOMUtil.stringToOM(resourceContent);
            Iterator mainChildIt = omElement.getChildren();
            while (mainChildIt.hasNext()) {
                Object childObj = mainChildIt.next();
                if ((childObj instanceof OMElement) && ((APIConstants.OVERVIEW_ELEMENT)
                        .equals(((OMElement) childObj).getLocalName()))) {
                    Iterator childIt = ((OMElement) childObj)
                            .getChildrenWithLocalName(APIConstants.ENDPOINT_PASSWORD_ELEMENT);
                    //There is only one ep-password, hence no iteration
                    if (childIt.hasNext()) {
                        OMElement child = (OMElement) childIt.next();
                        String actualPassword = child.getText();
                        //Store the password in a hidden property to access in the PUT method.
                        if (!actualPassword.isEmpty()) {
                            resource.setProperty(APIConstants.REGISTRY_HIDDEN_ENDPOINT_PROPERTY, actualPassword);
                            child.setText(APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD);
                        }
                    }
                }
            }
            resource.setContent(RegistryUtils.encodeString(omElement.toString()));
            log.debug("Modified API resource content with default password before get operation");
        } catch (XMLStreamException e) {
            log.error("There was an error in reading XML Stream during API get.");
            throw new RegistryException("There was an error reading the API resource.", e);
        }
    }
    return resource;
}
 
Example 9
Source Project: carbon-apimgt   Source File: GAConfigMediaTypeHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void put(RequestContext requestContext) throws RegistryException {
    ResourceImpl resource = (ResourceImpl) requestContext.getResource();
    if (! resource.isContentModified()) {
        return;
    }

    // Local entry is updated only if the content of ga-config is updated
    Object content = resource.getContent();
    String resourceContent;
    if (content instanceof String) {
        resourceContent = (String) content;
    } else if (content instanceof byte[]) {
        resourceContent = RegistryUtils.decodeBytes((byte[]) content);
    } else {
        log.warn("The resource content is not of expected type");
        return;
    }

    APIManagerConfiguration config = getAPIManagerConfig();
    if (config == null) {
        return;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    Map<String, Environment> environments = config.getApiGatewayEnvironments();

    for (String environmentName : environments.keySet()) {
        Environment environment = environments.get(environmentName);

        try {
            LocalEntryAdminClient localEntryAdminClient = new LocalEntryAdminClient(environment, tenantDomain);
            localEntryAdminClient.deleteEntry(APIConstants.GA_CONF_KEY);
            localEntryAdminClient.addLocalEntry("<localEntry key=\"" + APIConstants.GA_CONF_KEY + "\">"
                    + resourceContent + "</localEntry>");
        } catch (AxisFault e) {
            log.error("Error occurred while adding local entry(GA-config) to gateway " + environmentName, e);
        }
    }
}
 
Example 10
Source Project: carbon-apimgt   Source File: CustomAPIIndexHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void put(RequestContext requestContext) throws RegistryException {
    if (requestContext != null && requestContext.getResource() != null && requestContext.getResource().getProperty
            (APIConstants.CUSTOM_API_INDEXER_PROPERTY) != null) {
        return;
    }
    super.put(requestContext);
}
 
Example 11
/**
 * This method is called for a registry put operation
 *
 * @param requestContext - The request context
 * @throws RegistryException
 */
public void put(RequestContext requestContext) throws RegistryException {
    Resource resource = requestContext.getResource();
    Object content = resource.getContent();
    String resourceContent;
    if (content instanceof String) {
        resourceContent = (String) resource.getContent();
    } else if (content instanceof byte[]) {
        resourceContent = RegistryUtils.decodeBytes((byte[]) resource.getContent());
    } else {
        log.warn("The resource content is not of expected type");
        return;
    }
    try {
        OMElement omElement = AXIOMUtil.stringToOM(resourceContent);
        Iterator mainChildIt = omElement.getChildren();
        while (mainChildIt.hasNext()) {
            Object childObj = mainChildIt.next();
            if ((childObj instanceof OMElement) && ((APIConstants.OVERVIEW_ELEMENT)
                    .equals(((OMElement) childObj).getLocalName()))) {
                Iterator childIt = ((OMElement) childObj)
                        .getChildrenWithLocalName(APIConstants.ENDPOINT_PASSWORD_ELEMENT);
                //There is only one ep-password, hence no iteration
                if (childIt.hasNext()) {
                    OMElement child = (OMElement) childIt.next();
                    String pswd = child.getText();
                    //Password has been edited on put
                    if (!"".equals(pswd) && !((APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD).equals(pswd))) {
                        resource.setProperty(APIConstants.REGISTRY_HIDDEN_ENDPOINT_PROPERTY, pswd);
                        child.setText(pswd);
                    } else if ((APIConstants.DEFAULT_MODIFIED_ENDPOINT_PASSWORD)
                            .equals(pswd)) { //Password not being changed
                        String actualPassword = resource
                                .getProperty(APIConstants.REGISTRY_HIDDEN_ENDPOINT_PROPERTY);
                        child.setText(actualPassword);
                    }
                }
            }
        }
        resource.setContent(RegistryUtils.encodeString(omElement.toString()));
        requestContext.setResource(resource);
        log.debug("Modified API resource content with actual password before put operation");
    } catch (XMLStreamException e) {
        log.error("There was an error in reading XML Stream during API update.");
        throw new RegistryException("There was an error updating the API resource.", e);
    }
}
 
Example 12
public void put(RequestContext requestContext) {
    clearConfigCache();
}
 
Example 13
public void delete(RequestContext requestContext) {
    clearConfigCache();
}
 
Example 14
Source Project: carbon-apimgt   Source File: APIConfigMediaTypeHandler.java    License: Apache License 2.0 4 votes vote down vote up
public void put(RequestContext requestContext) {
    clearConfigCache();
}
 
Example 15
Source Project: carbon-apimgt   Source File: APIConfigMediaTypeHandler.java    License: Apache License 2.0 4 votes vote down vote up
public void delete(RequestContext requestContext) {
    clearConfigCache();
}