com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Query Processor Sample

This sample explains how to create a query processor that can be used to run custom queries on WSO2 Governance Registry in few easy steps. We will be reusing the code of the Handler Sample and the WS-API Sample in this example. This sample requires Apache Maven and Apache Ant. See Installation Prerequisites for links on how to install it.

Instructions

1. Navigate to GREG_HOME/ samples/handler/src to find the source code of the Handler Sample.

2. Add a new Java Class named SampleQueryProcessor at

GREG_HOME/samples/handler/src/src/main/java/org/wso2/carbon/registry/samples/task/SampleQueryProcessor.java with the following source:

package org.wso2.carbon.registry.samples.processor;
 
import org.wso2.carbon.registry.core.Collection;
import org.wso2.carbon.registry.core.CollectionImpl;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.core.dataaccess.DataAccessManager;
import org.wso2.carbon.registry.core.dataaccess.QueryProcessor;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import java.util.Map;
 
public class SampleQueryProcessor implements QueryProcessor {
 
    public SampleQueryProcessor(DataAccessManager dataAccessManager) {
        // We need a constructor even if we do no initialization.
    }
 
    public Collection executeQuery(Registry registry, Resource resource, Map map)
            throws RegistryException {
        System.out.println("Executing Sample Query with Query: " + map.get("query"));
        return new CollectionImpl(new String[0]);
    }
}

3. Compile the source code by running the following command inside GREG_HOME/ samples/handler/src:

mvn clean install

The command mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See Installation Prerequisites for links on how to install it.

A successful run of Apache Maven will generate a report similar to the following:

4. Copy the GREG_HOME/ samples/handler/src/target/org.wso2.carbon.registry.samples.handler-5.2.0.jar into GREG_HOME/repository/components/dropins.

5. Edit the registry.xml file which is in GREG_HOME/repository/conf folder and add the following XML snippet.

<queryProcessor>
    <processor>org.wso2.carbon.registry.samples.processor.SampleQueryProcessor</processor>
    <queryType>application/vnd.wso2.sample.query</queryType>
</queryProcessor>

See also Configuration for Query Processors.

7. Start the WSO2 Governance Registry server. See Running the Product for more information.

8. After the server has successfully started, navigate to GREG_HOME/ samples/ws-client to find the source code of the WS-API Sample.

9. Replace the main method of the class in GREG_HOME/samples/ws-client/src/org/wso2/carbon/registry/ws/client/sample/SampleWSRegistryClient.java with the following source:

public static void main(String[] args) throws Exception {
    Registry registry = initialize();
    java.util.HashMap<String, String> map = new java.util.HashMap<String, String>();
    map.put("query", "Hello World Query");
    map.put("mediaType", "application/vnd.wso2.sample.query");
    registry.executeQuery("/", map);
    System.exit(0);
}

10. Compile the source code by running the following command inside GREG_HOME/ samples/ws-client :

ant run

The command ant run will trigger an Apache Ant Build in your command line. This requires you having installed Apache Ant. See Installation Prerequisites for links on how to install it.

A successful run of Apache Ant will generate a report similar to the following:

11. Now observe the command prompt of the WSO2 Governance Registry Server. You should find a line similar to the following printed on your command prompt, which indicates that you query has successfully executed.

Executing Sample Query with Query: Hello World Query

 


com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.