2

I am using Camel-CXF to publish a web service from a bundle. I use blueprint for configuration. My understanding is that this CXF configuration will dynamically create a Jetty connector on the specified port and publishes the CXF servlet at the specified path:

<cxf:cxfEndpoint id="myEndpoint" address="http://0.0.0.0:${endpoint.port}/${context}" serviceClass="...">
    <cxf:properties>
        <!-- ... -->
    </cxf:properties>
</cxf:cxfEndpoint>

This works nicely. The service endpoint is available at the specified port and path.

Now I would like to make the original WSDL available, transformed by Tomi Vanek's wsdl-viewer style sheet. I figured out how to make static resources available using Pax Web's DefaultResourceMapping:

<bean id="resourceMapping" class="org.ops4j.pax.web.extender.whiteboard.runtime.DefaultResourceMapping">
    <property name="alias" value="/wsdl" />
    <property name="path" value="/wsdl/v4_0" />
</bean>

However, this makes the WSDL accessible on the default Jetty connector in port 8181. What I cannot figure out is how to bind the resource mapper to any other connector other than the default one. More specifically, to the connector created dynamically for the CXF endpoint.

Ralf
  • 6,735
  • 3
  • 16
  • 32

1 Answers1

2

You have to differentiate between the two connectors. First of all if you use cxf in the way you use it right now, you also have a special Jetty instance running, which opens the connection to be used by cxf. Through your Resource Mapping you are using the Pax-Web provided OSGi HttpService, which itself uses Jetty as underlying Server. That's why both are running on different connectors. To use just one connector, you'll need to make sure that cxf is also using Pax-Web as underlying Server for serving your webservices.

For this make sure your cxf endpoint is having a no connector address:

<cxf:cxfEndpoint id="myEndpoint" address="/${context}" serviceClass="...">

After that you can configure pax-web to use any other port as required.
For using a different port then the std. port the configuration via the org.ops4j.pax.web.cfg file is needed.

org.osgi.service.http.port=9292

changes the default port of the default connector. For different connectors, it's required to add those extra connectors via the jetty.xml in the etc folder of Karaf.

<Call name="addConnector">
    <Arg>
        <New class="org.eclipse.jetty.server.ServerConnector">
            <Arg name="server">
                <Ref refid="Server" />
            </Arg>
            <Arg name="factories">
                <Array type="org.eclipse.jetty.server.ConnectionFactory">
                    <Item>
                        <New class="org.eclipse.jetty.server.HttpConnectionFactory">
                            <Arg name="config">
                                <Ref refid="httpConfig" />
                            </Arg>
                        </New>
                    </Item>
                </Array>
            </Arg>
            <Set name="host">
                <Property name="jetty.host" default="localhost" />
            </Set>
            <Set name="port">
                <Property name="jetty.port" default="8282" />
            </Set>
            <Set name="idleTimeout">
                <Property name="http.timeout" default="30000" />
            </Set>
            <Set name="name">jettyConn1</Set>
        </New>
    </Arg>
</Call>

In your Bundle you'll need to set the following to use the specified connector.

Web-Connectors: jettyConn1
Web-VirtualHosts: localhost

ATTENTION
since you're using Apache Camel, this approach doesn't work for you, as the bundle which does actually take care of this isn't your own bundle but the camel/cxf one. Therefore this won't work for you.

Achim Nierbeck
  • 5,265
  • 2
  • 14
  • 22
  • Could you elaborate on how I can _configure pax-web to use any other port_? I have 3 web services provided in 3 bundles. Each service should be addressable via its own port. They also do not share a common context root. For each I would like to make the original WSDL accessible as a static resource. Thanks! – Ralf Jan 01 '16 at 14:05
  • In that case it won't work. In Pax-Web it's no issue to have multiple connections and virtual Hosts (for example for different bundles), but as you use Camel, it'll use the standard connector of the underlying HttpService. So actually if you want to use multiple connectors you're stuck with the camel way of creating an embedded server for every instance. – Achim Nierbeck Jan 01 '16 at 14:34