Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info
iconfalse

Web Service is one of many well-defined extension points supported by the WSO2 Governance Registry. Read more on Supported Extension Points for a complete list of extension points supported by WSO2 Governance Registry.

...

Code Block
languagehtml/xml
<dependency>
    <groupId>org.wso2.carbon</groupId>
    <artifactId>org.wso2.carbon.governance.api</artifactId>
    <version>4.02.1<0</version>
</dependency>

3. Add the following plugin to your POM file:

...

Info

The Fragment-Host Bundle Manifest Header declares this sample bundle to be a Fragment of the Registry Kernel. This would mean that the sample handler bundle will become an extension to the Registry Kernel. However, bundles containing services.xml files would not be deployed until the Apache Axis2 runtime has been initialized. Due to OSGi bundle start-up order, it is required that the Registry Kernel starts up before the Apache Axis2 runtime.

Since the Fragment now also being an extension to the Registry Kernel, the combination of this bundle and the Registry Kernel (plus any other fragments) should start up before the Apache Axis2 runtime. But, due to the bundle not getting deployed until the Apache Axis2 runtime has been initialized, it will create a deadlock situation. Due to this reason, we have to get rid of the Fragment-Host header.

5. Add the following content to Create a file named services.xml in GREG_HOME/samples/handler/src/resources/META-INFINF and add the following content:

Code Block
languagehtml/xml
<serviceGroup>
    <service name="EndpointLookupService" scope="transportsession">
        <transports>
            <transport>http</transport>
        </transports>
        <parameter name="ServiceClass" locked="false">
            org.wso2.carbon.registry.samples.services.EndpointLookupService
        </parameter>
    </service>
</serviceGroup>

...

Code Block
languagejava
package org.wso2.carbon.registry.samples.services;
 
import org.wso2.carbon.governance.api.exception.GovernanceException;
import org.wso2.carbon.governance.api.services.ServiceFilter;
import org.wso2.carbon.governance.api.services.ServiceManager;
import org.wso2.carbon.governance.api.services.dataobjects.Service;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
 
import java.util.LinkedList;
import java.util.List;
 
public class EndpointLookupService {
 
    private Registry governanceRegistry;
 
    public EndpointLookupService() {
        try {
            governanceRegistry = EndpointLookupServiceComponent.getRegistryService()
                    .getGovernanceSystemRegistry();
        } catch (RegistryException e) {
            e.printStackTrace();
        }
    }
 
    public String[] getEndpoints(final String serviceName, final String serviceNamespace,
                                 final String version, final String environment)
            throws GovernanceException, RegistryException {
        ServiceManager manager = new ServiceManager(governanceRegistry);
        Service[] services = manager.findServices(new ServiceFilter() {
            public boolean matches(Service service) throws GovernanceException {
                return serviceName.equals(service.getQName().getLocalPart()) &&
                        (serviceNamespace == null || serviceNamespace.length() == 0 ||
                                serviceNamespace.equals(service.getQName().getNamespaceURI())) &&
                        (version == null || version.length() == 0 ||
                                version.equals(service.getAttribute("overview_version")));
            }
        });
        if (services != null && services.length > 0) {
            List<String> endpoints = new LinkedList<String>();
            for (Service service : services) {
                String[] entries = service.getAttributes("endpoints_entry");
                if (entries != null && entries.length > 0) {
                    for (String entry : entries) {
                        int idx = entry.indexOf(":");
                        if (entry.substring(0, idx).equals(environment)) {
                            endpoints.add(entry.substring(idx + 1));
                        }
                    }
                }
            }
            return endpoints.toArray(new String[endpoints.size()]);
        }
        return new String[0];
    }
}

...

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

10. Start the server and observe the command prompt. See  See Running the Product on Windows or Installing on Linux.Image Removed for more information.

Running the Sample

1. After the sample has been successfully deployed and the server has started, open a browser Window and type the following URL:

...

4. Fill in the following payload as the request:. At least one endpoint must exist for the Dev environment in order to receive a response.

Code Block
languagehtml/xml
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://services.samples.registry.carbon.wso2.org">
   <soap:Header/>
   <soap:Body>
      <ser:getEndpoints>
         <ser:serviceName>SimpleStockQuoteService</ser:serviceName>
         <ser:environment>Dev</ser:environment>
      </ser:getEndpoints>
   </soap:Body>
</soap:Envelope>

...