Suchen

Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

51.2. JBoss Fuse CXF Implementations

download PDF

Overview

This section describes how to use the SwaggerFeature in JBoss Fuse CXF implementations, in which REST services are defined inside JAR files and deployed to a JBoss Fuse container or a fabric8 container.
Your JBoss 6.3 installation contains a Quickstart (installDir/quickstarts/cxf/rest/) that demonstrates how to create a RESTful (JAX-RS) web service using CXF and how to enable Swagger and annotate the JAX-RS endpoints.

Enabling Swagger

Enabling Swagger involves:
  • Modifying the XML file that defines the CXF service by adding the CXF class (io.fabric8.cxf.endpoint.SwaggerFeature) to the <jaxrs:server> definition.
    For example:
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
    xmlns:cxf="http://cxf.apache.org/blueprint/core"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 
    https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
    http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
    http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd">
                          
       <!-- The <jaxrs:server/> element sets up our JAX-RS services. It defines: 
          - the server's address, '/crm', relative to the default CXF servlet URI with the 
            default settings  the server will be running on 'http://localhost:8181/cxf/crm' 
          - a list of service beans. in this example, we refer to another bean defined in this 
    		Blueprint XML file with a <ref/> element    -->
                          
       <jaxrs:server id="customerService" address="/crm">
           <jaxrs:serviceBeans>
               <ref component-id="customerSvc"/>
           </jaxrs:serviceBeans>
           <jaxrs:providers>
               <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
           </jaxrs:providers>
           <jaxrs:features>
    	      <bean class=“io.fabric8.cxf.endpoint.SwaggerFeature” />
    		   <property name=“title” value=“Fabric8:CXF:Quickstarts - Customer Service” />
    	   	<property name=“description” value=“Sample REST-based Customer Service” />
    		   <property name=“version” value=“${project.version}” />
    	      </bean>
           </jaxrs:features>
        </jaxrs:server>
      
    
        <!-- We use the OSGi Blueprint XML syntax to define a bean referred to in the 
        JAX-RS server setup. This bean carries a set of JAX-RS annotations that enable mapping 
        its methods to incoming requests.  -->
        
        <bean id="customerSvc" class="io.fabric8.quickstarts.rest.CustomerService"/>
    
    </blueprint>
  • In the REST resource class:

Building and Deploying the Rest quickstart

See the README file in your JBoss Fuse 6.3 installDir/quickstarts/cxf/rest/ directory for instructions on how to build and deploy the rest quickstart.
Red Hat logoGithubRedditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

© 2024 Red Hat, Inc.