이 콘텐츠는 선택한 언어로 제공되지 않습니다.

1.3. Understanding the Example


Overview

The example builds a simple HelloWorld service and packages it for deployment into Red Hat JBoss Fuse. The service is written using standard JAX-WS APIs. It implements a single operation sayHi(). Once deployed, the service is exposed as a SOAP/HTTP endpoint. The most interesting parts of the example are the Spring configuration used to configure the endpoint and the Maven POM used to build the bundle.
The Spring configuration provides the details needed to expose the service using SOAP/HTTP. It can also contain details used to configure advanced Apache CXF functionality.
The Maven POM, in addition to compiling the code, uses the bundle generation plug-in to package the resulting classes into an OSGi bundle. It contains all of the details needed by the Red Hat JBoss Fuse container to activate the bundle and deploy the packaged service.

Using the Maven tools

The Red Hat JBoss Fuse Maven tooling automates a number of the steps in packaging functionality for deployment into JBoss Fuse. In order to use the Maven OSGi tooling, you add the elements shown in Example 1.2, “POM Elements for Using Red Hat JBoss Fuse OSGi Tooling” to your POM file.

Example 1.2. POM Elements for Using Red Hat JBoss Fuse OSGi Tooling

...
<pluginRepositories>
  <pluginRepository>
     <id>fusesource.m2</id>
      <name>Open Source Community Release Repository</name>
       <url>http://repo.fusesource.com/maven2</url>
        <snapshots>
           <enabled>false</enabled>
         </snapshots>
           <releases>
              <enabled>true</enabled>
           </releases>
  </pluginRepository>
</pluginRepositories>
 ...
<build>
   <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
         ...
       </plugin>
    </plugins>
</build>
  ...
Copy to Clipboard Toggle word wrap
These elements point Maven to the correct repositories to download the Red Hat JBoss Fuse Maven tooling and load the plug-in that implements the OSGi tooling.

The Spring configuration

The Red Hat JBoss Fuse container needs some details about a service before it can instantiate and endpoint for it. Apache CXF uses Spring based configuration to define endpoints for services. The configuration shown in Example 1.3, “OSGi Example Spring Configuration” is stored in the example's \src\main\resources\META-INF\spring\beans.xml file.

Example 1.3. OSGi Example Spring Configuration

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" /> 1
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
    <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />

	<jaxws:endpoint id="helloWorld" 2
	                implementor="org.apache.servicemix.examples.cxf.HelloWorldImpl"
	                address="/HelloWorld"/>

</beans>
Copy to Clipboard Toggle word wrap
The configuration shown in Example 1.3, “OSGi Example Spring Configuration” does the following:
1
Imports the required configuration to load the required parts of the Apache CXF runtime.
2
Configures the endpoint that exposes the service using the jaxws:endpoint element and its attributes.
  • id is an identifier used by the configuration mechanism.
  • implementor specifies the class that implements the service. It must be on the classpath.
  • address specifies the address at which the service will be exposed. This address is relative to the containers HTTP address with cxf appended to it.

The POM

Example 1.4. OSGi POM

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.apache.servicemix.examples</groupId>
        <artifactId>examples</artifactId>
        <version>6.0.0.redhat-024</version>
    </parent>

    <groupId>org.apache.servicemix.examples</groupId>
    <artifactId>cxf-osgi</artifactId>
    <packaging>bundle</packaging>
    <version>6.0.0.redhat-024</version>
    <name>Apache ServiceMix Example :: CXF OSGi</name>

<!-- Add ServiceMix repositories for snaphots and releases -->
 ...

    <dependencies>
        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
            <version>${geronimo.wsmetadata.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                        <Import-Package>
                            javax.jws,
                            javax.wsdl,
                            META-INF.cxf,
                            META-INF.cxf.osgi,
                            org.apache.cxf.bus,
                            org.apache.cxf.bus.spring,
                            org.apache.cxf.bus.resource,
                            org.apache.cxf.configuration.spring,
                            org.apache.cxf.resource,
                            org.apache.servicemix.cxf.transport.http_osgi,
                            org.springframework.beans.factory.config
                        </Import-Package>
                        <Private-Package>org.apache.servicemix.examples.cxf</Private-Package>
                        <Require-Bundle>org.apache.cxf.cxf-bundle</Require-Bundle>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat