Hi
I'm not 100% sure why calling Bus.getDefaultBus() causing the creation
of a new bus.
I believe the default bus is created when CXF bundles get installed, and
as part of that process a default CXF servlet is registered at "/cxf"
(this servlet URL can be changed if needed).
I only guess that an already available default bus is set on the
BusFactory after the application bundle starts activating so if you call
Bus.getDefaultBus() early it causes a new bus creation.
It is up to the application to 'decide' if a shared or per-bundle
servlet URL is needed - I don't know if it is possible to have
per-bundle one if depending on a default CXF servlet - you'd likely need
to go a new Bus per bundle route, customizing a servlet pattern per
every bundle to avoid the clashes.
You may want to have a look at CXF DOSGi code too where
CXFNonSpringServlet is used.
Cheers, Sergey
On 26/08/16 06:54, Randy Leonard wrote:
I am attempting to use CXF within OSGi enRoute (http://enroute.osgi.org/), but
having some issues.
First, my objectives:
No cfx.xml file, but instead to bootstrap all attributes normally found in a
cxf.xml file from OSGi configurations
Understand if I should have one bus for all bundles exposing SOAP services, or
one bus per bundle.
Have each bundle use JaxWsServerFactoryBean to register its services within the
bundle activator during startup, and unregister these services when the bundle
is stopping
I am getting errors when running just a single bundle with no cxf.xml files and
no registered services. Details below.
———————————
I have a single application bundle which does nothing more than call the
following on bundle activation:
public class Activator implements BundleActivator
{
@Override
public void start(BundleContext context) throws Exception
{
try {
System.out.println("activating application - start");
BusFactory.getDefaultBus();
System.out.println("activating application - end");
} catch (Throwable e) {
e.printStackTrace();
}
}
@Override
public void stop(BundleContext context) throws Exception
{
// forthcoming
}
}
The output I get from this is as follows:
activating application - start
Aug 25, 2016 11:43:37 PM org.apache.cxf.bus.osgi.CXFExtensionBundleListener
addExtensions
INFO: Adding the extensions from bundle org.apache.cxf.cxf-rt-bindings-xml (3)
[org.apache.cxf.binding.xml.XMLBindingFactory,
org.apache.cxf.binding.xml.wsdl11.XMLWSDLExtensionLoader]
Aug 25, 2016 11:43:37 PM org.apache.cxf.bus.osgi.CXFExtensionBundleListener
addExtensions
INFO: Adding the extensions from bundle org.apache.cxf.cxf-rt-transports-http
(5) [org.apache.cxf.transport.http.HTTPTransportFactory,
org.apache.cxf.transport.http.HTTPWSDLExtensionLoader,
org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder,
org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder,
org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider]
Aug 25, 2016 11:43:37 PM org.apache.cxf.bus.osgi.CXFExtensionBundleListener
addExtensions
INFO: Adding the extensions from bundle
org.apache.cxf.cxf-rt-transports-http-jetty (6)
[org.apache.cxf.transport.http_jetty.JettyDestinationFactory,
org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory,
org.apache.cxf.transport.http.ContinuationProviderFactory]
Aug 25, 2016 11:43:37 PM
org.apache.cxf.bus.blueprint.NamespaceHandlerRegisterer register
WARNING: Aries Blueprint packages not available. So namespaces will not be
registered
Aug 25, 2016 11:43:37 PM
org.apache.cxf.bus.blueprint.NamespaceHandlerRegisterer register
WARNING: Aries Blueprint packages not available. So namespaces will not be
registered
Aug 25, 2016 11:43:37 PM
org.apache.cxf.bus.blueprint.NamespaceHandlerRegisterer register
WARNING: Aries Blueprint packages not available. So namespaces will not be
registered
activating application - end
2016-08-25 23:43:38.022:INFO::main: Logging initialized @1270ms
2016-08-25 23:43:38.052:INFO:oejs.Server:main: jetty-9.2.12.v20150709
2016-08-25 23:43:38.104:INFO:oejsh.ContextHandler:main: Started
o.e.j.s.ServletContextHandler@19d481b{/,null,AVAILABLE}
2016-08-25 23:43:38.104:INFO:oejs.Server:main: Started @1351ms
2016-08-25 23:43:38.124:INFO:oejs.ServerConnector:main: Started
ServerConnector@4738a206{HTTP/1.1}{0.0.0.0:8080}
[INFO] Started Jetty 9.2.12.v20150709 at port(s) HTTP:8080 on context path /
Aug 25, 2016 11:43:38 PM org.apache.cxf.transport.http.osgi.ServletExporter
updated
WARNING: Error registering CXF OSGi servlet Alias /cxf is already in use.
org.osgi.service.http.NamespaceException: Alias /cxf is already in use.
at
org.apache.felix.http.base.internal.service.SharedHttpServiceImpl.registerServlet(SharedHttpServiceImpl.java:74)
at
org.apache.felix.http.base.internal.service.PerBundleHttpServiceImpl.registerServlet(PerBundleHttpServiceImpl.java:217)
at
org.apache.cxf.transport.http.osgi.ServletExporter.updated(ServletExporter.java:108)
at
org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189)
at
org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152)
at
org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85)
at
org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1444)
at
org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1400)
at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:103)
at java.lang.Thread.run(Thread.java:745)
———————————
Two comments:
Only after the bundle is activated, I get the stack trace given above
indicating a second cxf bus has been created
I do not get errors if I do not call BusFactory.getDefaultBus() from within the
bundle activation method
Questions:
What can I do to prevent the apparent second bus from being created?
Is it best to have one bus per bundle, each with a different servlet alias… or
one bus for multiple bundles, all sharing a common servlet alias
Randy Leonard
[email protected]
[email protected]
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/