This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

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 Installing Apache Maven for Governance Registry on Windows or Installing Apache Maven for Governance Registry on Linux and Installing Apache Ant for Governance Registry on Windows or Installing Apache Ant for Governance Registry on Linux.

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.Registry;
import org.wso2.carbon.registry.core.Resource;
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

Note

The command mvn clean install will trigger an Apache Maven Build in your command line. This requires you having installed Apache Maven. See Installing Apache Maven for Governance Registry on Windows or Installing Apache Maven for Governance Registry on Linux.

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-4.5.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 Starting Governance Registry Management Console on Windows or Starting Governance Registry Management Console on Linux.

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/WSRegistryServiceClient.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

Note

The command ant run will trigger an Apache Ant Build in your command line. This requires you having installed Apache Ant. See Installing Apache Ant for Governance Registry on Windows or Installing Apache Ant for Governance Registry on Linux.

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

 

 

 

 

  • No labels