首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用治理API将服务注册到WSO2治理注册表?

如何使用治理API将服务注册到WSO2治理注册表?
EN

Stack Overflow用户
提问于 2012-06-08 18:10:04
回答 1查看 940关注 0票数 0

我想使用治理注册表API注册一个服务,编写的代码如下:

代码语言:javascript
运行
复制
    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类来探测这个服务,如下所示:

代码语言:javascript
运行
复制
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);
}

但得到了异常:

代码语言:javascript
运行
复制
[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

我错过了什么吗?提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2012-10-03 17:17:01

这些服务不是实际的服务端点(比如托管在应用程序服务器中)。在治理注册表中,我们存储了实际服务的契约细节(wsdl、策略、模式、endpoints...etc)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10946884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档