You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Noel Ang (Jira)" <ji...@apache.org> on 2019/12/10 08:00:04 UTC

[jira] [Created] (CXF-8181) CXFNonSpringJaxrsServlet Feature registration fails via javax.ws.rs.Application

Noel Ang created CXF-8181:
-----------------------------

             Summary: CXFNonSpringJaxrsServlet Feature registration fails via javax.ws.rs.Application
                 Key: CXF-8181
                 URL: https://issues.apache.org/jira/browse/CXF-8181
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 3.3.4, 3.2.11
            Reporter: Noel Ang


*CXFNonSpringJaxrsServlet* always overwrites Features surfaced by a javax.ws.rs.core.Application implementation with Features specified in the servlet configuration, _even if the latter set is empty_.

The server factory bean [created|https://github.com/apache/cxf/blob/b75830ffd90cab9cfcdc7550fdd17490dbe9c8c5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java#L514-L519] to encapsulate the instantiated Application class has its Features list initialized twice.
 * The [first time|https://github.com/apache/cxf/blob/b75830ffd90cab9cfcdc7550fdd17490dbe9c8c5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java#L947] uses the classes [that the Application yields|https://github.com/apache/cxf/blob/b75830ffd90cab9cfcdc7550fdd17490dbe9c8c5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java#L903-L904].
 * The [second time|https://github.com/apache/cxf/blob/b75830ffd90cab9cfcdc7550fdd17490dbe9c8c5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java#L529-L530] uses the classes that the [Servlet configuration describes|https://github.com/apache/cxf/blob/b75830ffd90cab9cfcdc7550fdd17490dbe9c8c5/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java#L323-L326].

The features enumerated by the servlet config [replaces|https://github.com/apache/cxf/blob/b75830ffd90cab9cfcdc7550fdd17490dbe9c8c5/core/src/main/java/org/apache/cxf/endpoint/AbstractEndpointFactory.java#L176-L178] the first list. 
  

I discovered the problem while trying to get OpenAPI 3.0 / Swagger-UI support to work, so FWIW, an example:
 * Application implementation that registers OpenApiFeature.

 
{code:java}
package org.foo.service;

import org.apache.cxf.feature.Feature;
import org.apache.cxf.jaxrs.openapi.OpenApiFeature;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import static java.util.Objects.requireNonNull;

@ApplicationPath("FooService")
public class FooServiceApplication extends Application
{
    @Override
    public Set<Class<?>> getClasses ()
    {
        Set<Class<?>> classes = new HashSet<>();
        classes.add(Resource1.class);
        classes.add(Resource2.class); 
        return classes;
    }

    @Override
    public Set<Object> getSingletons ()
    {
        Set<Object> singletons = new HashSet<>();
        singletons.add(openapiFeature());
        return singletons;
    }

    private Feature openapiFeature () {
        /*
         * Enables automatic Swagger document generation for the web service.
         */
        OpenApiFeature feature = new OpenApiFeature();
        feature.setTitle("FooService");
        feature.setReadAllResources(false);
        feature.setPrettyPrint(true);
        feature.setSupportSwaggerUi(true);
        return feature;
    }
}
{code}
 * Corresponding servlet config - Swagger-UI support does not enable unless the commented-out section below is enabled.

 
{code:java}
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0">
    
    <display-name>FooService</display-name>
    
    <servlet>
        <servlet-name>FooService</servlet-name>
        <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
        
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>org.foo.service.FooServiceApplication</param-value>
        </init-param>
<!--
        <init-param>
            <param-name>jaxrs.features</param-name>
            <param-value>org.apache.cxf.jaxrs.openapi.OpenApiFeature</param-value>
        </init-param>
-->

        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>SLA835Gateway</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    
    <session-config>
        <session-timeout>1</session-timeout>
    </session-config>
</web-app>

{code}
 

 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)