簡體   English   中英

如何使用治理API將服務注冊到WSO2治理注冊表?

[英]How to register a Service to WSO2 Governance Registry using governance API?

我想使用Governance Registry API注冊服務,編寫如下代碼:

    ServiceManager serviceManager = new ServiceManager(registry);
    Service newService = serviceManager.newService(new QName("http://services.talend.org/ReservationService", "ReservationServiceProvider"));
    newService.addAttribute("endpoint", "http://localhost:8040/services/ReservationServiceProvider");
    newService.addAttribute("metadataVersion",String.valueOf(1));

    String scope = "http://com.talend/Reservation";
    URI[] scopes = new URI[] { URI.create(scope) };
    newService.setAttributes("scopes", Util.toStringArray(scopes));

    String address1 = "http://localhost:8040/services/ReservationServiceProvider";
    String address2 = "https://localhost:9001/services/ReservationServiceProvider";
    URI[] xAddresses = new URI[] { URI.create(address1), URI.create(address2) };
    newService.setAttributes("xAddresses", Util.toStringArray(xAddresses));

    serviceManager.addService(newService);
    //newService.activate();

它可以工作,並且可以在Web-UI中找到該服務。

然后,我想使用org.wso2.carbon.discovery.client.DiscoveryClient類來探測此服務,如下所示:

public String[] lookupEndpoints(String scope) throws DiscoveryException{
    URI[] scopes = new URI[] { URI.create(scope) };
    TargetService[] services = client.probe(null, scopes);
    if (services != null && services.length > 0) {
        URI[] endpoints = services[0].getXAddresses();

        if (endpoints != null && endpoints.length > 0) {
            String[] returnEps = new String[endpoints.length];
            for (int i =0; i< endpoints.length; i ++){
                returnEps[i] = endpoints[i].toString();
            }
            return returnEps;
        }
    }
    throw new DiscoveryException("Unable to locate a service for the scope: " + scope);
}

但有例外:

[java] Exception in thread "main" org.wso2.carbon.discovery.DiscoveryException: Error while executing the WS-Discovery probe
[java]     at org.wso2.carbon.discovery.client.DiscoveryClient.probe(DiscoveryClient.java:134)
[java]     at org.wso2.carbon.discovery.client.DiscoveryClient.probe(DiscoveryClient.java:100)
[java]     at com.talend.esb.test.wso2.greg.WSDiscoveryClient.lookupEndpoints(WSDiscoveryClient.java:54)
[java]     at com.talend.esb.test.wso2.greg.WSDiscoveryClient.main(WSDiscoveryClient.java:97)
[java] Caused by: org.apache.axis2.AxisFault: Error while searching for services
[java]     at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
[java]     at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
[java]     at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
[java]     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
[java]     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
[java]     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)
[java]     at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)
[java]     at org.wso2.carbon.discovery.client.DiscoveryClient.probe(DiscoveryClient.java:128)
[java]     ... 3 more

我錯過了什么? 提前致謝!

這些服務不是實際的服務端點(例如托管在應用程序服務器中)。 在Governance Registry中,我們存儲了實際服務的合同詳細信息(wsdl,策略,架構,端點...等)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM