如何在httpserver(Spring remoting)的contexts属性中添加OSGI服务引用?(How to add OSGI service references in contexts

系统教程 行业动态 更新时间:2024-06-14 16:57:39
如何在httpserver(Spring remoting)的contexts属性中添加OSGI服务引用?(How to add OSGI service references in contexts property of httpserver (Spring remoting)?)

我使用Spring remoting和OSGI。

<bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean"> <property name="contexts"> <util:map> <entry key="/remoting/Service1" value-ref="serviceBean1"/> </util:map> </property> <property name="port" value="8080" /> </bean>

我声明了一个动态列表如下:

<osgi:list id="serviceList" interface="com.xyz.IRemoteService" member-type="service-object">

现在可以动态注册这些服务。 在某个时间点,serviceList将保存实现com.xyz.IRemoteService的所有服务引用。 如何将此服务列表设置为contexts属性?

更新1:

com.xyz.IRemoteService有两个方法,一个返回密钥,即url,另一个返回SimpleHttpInvokerServiceExporter对象。所以我将配置更改为as

<bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean"> <property name="contexts"> <util:map> <entry key="/remoting/ArchiveEDSImpl" value-ref="archiveEDS" /> <entry key="#{serviceList[0].url}" value="#{serviceList[0].httpHandler}" /> <entry key="#{serviceList[1].url}" value="#{serviceList[1].httpHandler}" /> </util:map> </property> <property name="port" value="8081" /> </bean> <osgi:list id="serviceList" interface="com.xyz.IRemoteServiceProvider" member-type="service-object"> </osgi:list>

这很好,但只有在bean httpserver初始化时serviceReferenceList中至少有2个元素才有效。 如何根据列表中的大小动态配置?

I use Spring remoting and OSGI.

<bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean"> <property name="contexts"> <util:map> <entry key="/remoting/Service1" value-ref="serviceBean1"/> </util:map> </property> <property name="port" value="8080" /> </bean>

I declare an dynamic list as below :

<osgi:list id="serviceList" interface="com.xyz.IRemoteService" member-type="service-object">

Now these services can be registered dynamically. At one point of time serviceList will hold all the service references implementing com.xyz.IRemoteService. How can I set this service list to the contexts property?

Update 1 :

The com.xyz.IRemoteService has two methods one which returns the key i.e. the url and the other returns the SimpleHttpInvokerServiceExporter object.So I changed teh configurations to as

<bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean"> <property name="contexts"> <util:map> <entry key="/remoting/ArchiveEDSImpl" value-ref="archiveEDS" /> <entry key="#{serviceList[0].url}" value="#{serviceList[0].httpHandler}" /> <entry key="#{serviceList[1].url}" value="#{serviceList[1].httpHandler}" /> </util:map> </property> <property name="port" value="8081" /> </bean> <osgi:list id="serviceList" interface="com.xyz.IRemoteServiceProvider" member-type="service-object"> </osgi:list>

This is great but works only if there are at least 2 elements in the serviceReferenceList when bean httpserver is initialized. How do I configure this dynamically based on the size in the list ??

最满意答案

您可以,而不是使用util:map,定义在IRemoteServiceProvider中连接并输出Map的工厂或bean。

class MyMapFactory { List<IRemoteServiceProvider> providers; public Map buildMap() { //build Map of urls to http handlers here. // if the map wraps the list directory it can possibly even be dynamic! Depending on // whether SimpleHttpServerFactoryBean clones the map or uses it directly. } } <bean class="MyMapFactory" id="myMapFactory"/> <bean id="httpServer" class="org.springframework.remoting.support.SimpleHttpServerFactoryBean"> <property name="contexts"> <bean factory-bean="myMapFactory" factory-method="buildMap" class="java.util.Map"/> </property> <property name="port" value="8081" /> </bean> <osgi:list id="serviceList" interface="com.xyz.IRemoteServiceProvider" member-type="service- object"> </osgi:list>

Thanks for the reply Sheena. It turns out that SimpleHttpServerFactoryBean holds a copy of the Map and not the reference. So contexts property will be the set when the bean is being initialized.I could not find any other way to update it.

As a workaround I had to refresh the bundle in which the SimpleHttpServerFactoryBean bean is initialized.

Please let me know if there is a better solution.

更多推荐

serviceList,IRemoteService,电脑培训,计算机培训,IT培训"/> <meta name="de

本文发布于:2023-04-13 12:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/08b068f4a8f838cee9a1ffe0ef0dc550.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   如何在   Spring   remoting   property

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!