来自 WSO2 ESB 中介者的 WSO2 治理 API [英] WSO2 Governance API from WSO2 ESB Mediator

查看:24
本文介绍了来自 WSO2 ESB 中介者的 WSO2 治理 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面向 wso2 ESB 4.8.1 和 WSO2 GREG 4.6.0.我已将 GREG 连接为 esb 的远程注册表,现在我需要开发一个类调解器,通过它我可以将共享资源存储在远程注册表中.

im facing up to wso2 ESB 4.8.1 and WSO2 GREG 4.6.0. I have connected GREG as esb's remote Registry and now i need to develop a class mediator by which i can store shared recources inside the remote registry.

1) Registry 是否可以存储 Java 对象?

1) Does the Registry can store Java Object?

2) 我应该使用 org.apache.synapse.registry.Registry 来浏览注册表吗?还是在 mediator 项目中导入治理 api 更好?

2) should i use org.apache.synapse.registry.Registry for browing the registry? or is it better to import the governance api inside the mediator project?

例如,我需要添加和获取资源并将其设置为我的自定义属性.然后我想读它们.使用此代码:

For example i need to add and get a resource and to set it my custom properties. Then i want to read them. Using this code:

    org.apache.axis2.context.MessageContext axis2MsgContext;
    axis2MsgContext =  ((Axis2MessageContext) synapseMsgContext).getAxis2MessageContext();
    Registry regInstance = synapseMsgContext.getConfiguration()
            .getRegistry();


    Object obj = regInstance.getResource(new Entry ("conf:/provaDUE"), null);


    Properties prop  = regInstance.getResourceProperties("conf:/provaDUE");

我无法获取我使用 UI 设置的属性.

I cannot get the properties i set using UI.

谢谢.

推荐答案

这里是您问题的答案.

  1. 目前 Registry 不支持保存 java 对象,但您可以编写一个注册表处理程序 [1],将 java 实例数据保存在注册表资源中,并在检索对象时从注册表资源中的数据创建 java 对象.您可以使用 java 反射 [2].

  1. Currently Registry does not support saving java objects but you can write a registry handler [1] which save the java instance data in a registry resource and when retrieve the object create a java object out of that data in registry resource. You may use java Reflection [2].

您应该使用注册表 API 或治理 API,而不是用于突触资源的 org.apache.synapse.registry.Registry.这就是为什么您没有获得您在 UI 中设置的属性的原因.

You should use registry API or governance API, not org.apache.synapse.registry.Registry which uses for synapse resources. That is why you didn't get the properties which you set in the UI.

这是访问配置注册表中资源属性的示例代码.

Here is an sample code to access resource properties which are in config registry.

Registry registry = CarbonContext.getThreadLocalCarbonContext(). getRegistry(RegistryType.USER_CONFIGURATION);

Resource resource = registry.get("/provaDUE");

Properties properties = resource.getProperties();

[1].https://docs.wso2.com/display/Governance460/Handler+Sample

[2].http://tutorials.jenkov.com/java-reflection/动态类加载重新加载.html

[3].https://docs.wso2.com/display/Governance460/Registry+API

[4].https://docs.wso2.com/display/Governance460/Governance+API

这篇关于来自 WSO2 ESB 中介者的 WSO2 治理 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆