如何为Pax Web DefaultResourceMapping指定Jetty连接器

时间:2015-12-31 15:26:27

标签: apache-camel apache-karaf karaf blueprint-osgi pax-web

我正在使用Camel-CXF从捆绑包中发布Web服务。我使用蓝图进行配置。我的理解是这个CXF配置将在指定的端口上动态创建一个Jetty连接器,并在指定的路径上发布CXF servlet:

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

这很好用。服务端点在指定的端口和路径上可用。

现在我想提供原始的WSDL,由Tomi Vanek的wsdl-viewer样式表进行转换。我想出了如何使用Pax Web的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>

但是,这使得WSDL可以在端口8181中的默认Jetty连接器上访问。我无法弄清楚的是如何将资源映射器绑定到除默认连接器之外的任何其他连接器。更具体地说,是为CXF端点动态创建的连接器。

1 个答案:

答案 0 :(得分:2)

您必须区分两个连接器。首先,如果你现在使用cxf的方式,你也有一个特殊的Jetty实例运行,它打开了cxf使用的连接。通过资源映射,您使用的是Pax-Web提供的OSGi HttpService,它本身使用Jetty作为底层服务器。这就是为什么两者都在不同的连接器上运行。要仅使用一个连接器,您需要确保cxf也使用Pax-Web作为基础服务器来提供Web服务。

为此,请确保您的cxf端点没有连接器地址:

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

之后,您可以根据需要配置pax-web以使用任何其他端口 对于使用不同的端口然后std。需要通过 org.ops4j.pax.web.cfg 文件移植配置。

org.osgi.service.http.port=9292

更改默认连接器的默认端口。 对于不同的连接器,需要通过jetf的etc文件夹中的jetty.xml添加这些额外的连接器。

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

在Bundle中,您需要设置以下内容才能使用指定的连接器。

Web-Connectors: jettyConn1
Web-VirtualHosts: localhost

<强>注意
因为你正在使用Apache Camel,这种方法对你不起作用,因为实际上处理这个问题的bundle不是你自己的bundle而是camel / cxf。因此,这对您不起作用。