Service link in OSGi / plan not working properly

Currently, I have two OSGi packages ( bundle1 and bundle2 ), both of which provide services through a project in EBA. In bundle2 blueprint.xml I want to refer to a service from bundle1 and embed it in BuildService (code below), because BuildService will be used to call TicketService. However, this results in a timeout exception (also below). It seems that BuildService is never registered with OSGi. How do I do something like this work?

blueprint.xml for bundle1 :

 <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:bptx="http://aries.apache.org/xmlns/transactions/v1.0.0"> <bean id="TicketServiceBean" class="com.example.b2.impl.TicketServiceImpl"> <bptx:transaction value="Required" method="*" /> </bean> <service ranking="0" id="TicketService" interface="com.example.b2.service.TicketService" ref="TicketServiceBean"> <service-properties> <entry key="service.exported.interfaces" value="*" /> </service-properties> </service> </blueprint> 

blueprint.xml for bundle2

 <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="BuildServiceImplBean" class="com.example.b1.impl.BuildServiceImpl" activation="eager" > <property name="ticketService" ref="TicketServiceRef" /> </bean> <service id="BuildService" ref="BuildServiceImplBean" interface="com.example.b1.service.BuildService" activation="eager"> <service-properties> <entry key="service.exported.interfaces" value="*" /> </service-properties> </service> <reference id="TicketServiceRef" interface="com.example.b2.service.TicketService" availability="mandatory" activation="eager" /> </blueprint> 

BuildService implementation:

 public class BuildServiceImpl implements BuildService { private TicketService ticketService; @Override public TicketBuildResponse ticketBuild(TicketBuildRequest ticketBuildRequest) throws BuildServiceException { //do stuff here } public TicketService getTicketService() { return ticketService; } public void setTicketService(TicketService ticketService) { this.ticketService = ticketService; } } 

When starting the application server (Websphere), I get the following exception:

  BlueprintCont E org.apache.aries.blueprint.container.BlueprintContainerImpl$1 run Unable to start blueprint container for bundle com.example.b1.module due to unresolved dependencies [(objectClass=com.example.b2.service.TicketService)] java.util.concurrent.TimeoutException at org.apache.aries.blueprint.container.BlueprintContainerImpl$1.run(BlueprintContainerImpl.java:273) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:453) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:315) at java.util.concurrent.FutureTask.run(FutureTask.java:150) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:736) 
+4
source share
1 answer

Here is the solution: OSGi runtime processes remote services differently from local services due to different default call semantics (local pass by reference or remote pass by value). To prevent the application from accidentally invoking an exported service intended only for forwarding calls, it is hidden from local requests.

This solution is to export the same bean twice, once for remote calls, and the second for local. In other words, you would add another <service /> element with the same configuration, but without the service.exported.interfaces property.

 <service ranking="0" id="TicketServiceExport" interface="com.example.b2.service.TicketService" ref="TicketServiceBean"> <service-properties> <entry key="service.exported.interfaces" value="*" /> </service-properties> </service> <service ranking="0" id="TicketService" interface="com.example.b2.service.TicketService" ref="TicketServiceBean"/> 

Websphere also has an osgi console, and it can be found under [local websphere installation]/profiles/[profileName]/bin/osgiApplicationConsole.bat . After highlighting, help() gives you a list of commands. To see the imported services from SCA, first connect to your application (for example, connect(2) , where the application number is listed in the list() command). You can then do services("(service.imported=true)") to see the service proxies that have been added by the SCA. The services() command displays all the services in the application.

+5
source

Source: https://habr.com/ru/post/1344160/


All Articles