1

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) Does the Registry can store Java Object?

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");

I cannot get the properties i set using UI.

Thanks.

Community
  • 1
  • 1
Alex
  • 1,515
  • 2
  • 22
  • 44

1 Answers1

1

Here's the answers for your questions.

  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].

  2. 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/dynamic-class-loading-reloading.html

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

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

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
Eranda
  • 1,439
  • 1
  • 17
  • 30
  • i was interested by your previous code. It is really useful. Another question is, how can i cast a resource into a sequence mediator? Should have i to get the ContentStream and to parse it into a OMElement and finally to create a sequence mediator by the means of SequenceMediatorFactory? How can i update it? In my previous experiences i used the synapse api i.e. SequenceMediator and SequenceMediatorSerializer. Have i to use the carbon api? if yes is there any example? what's the api? – Alex Jan 21 '15 at 20:53
  • 1
    You can access via get-property XPath function. For example if you have a resource A.xml in registry location /_system/governance/A.xml, then you can access it using get-property('gov:/A.xml'). Check the following code where I loaded the value as a property where the type is OM. – Eranda Jan 22 '15 at 16:51