cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "iris ding (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-6369) org.apache.cxf.jaxrs.impl.ConfigurationImpl does not comply with SPEC
Date Tue, 28 Apr 2015 02:03:06 GMT

    [ https://issues.apache.org/jira/browse/CXF-6369?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14516182#comment-14516182
] 

iris ding commented on CXF-6369:
--------------------------------

Thanks Sergey for this clarification. Let's take a detailed look at the method:

 public void register(Object provider, Map<Class<?>, Integer> contracts) {
          if (provider.getClass() == Class.class) {
            provider = createProvider((Class<?>) provider);
        }
        Map<Class<?>, Integer> metadata = providers.get(provider);
        if (metadata == null) {
            metadata = new HashMap<Class<?>, Integer>();
            providers.put(provider, metadata);
        }
        for (Class<?> contract : contracts.keySet()) {
            if (contract.isAssignableFrom(provider.getClass())) {
                metadata.put(contract, contracts.get(contract));
            }
        }
    }

You can see when register new providers, we will new a provider instance and put it into the
LinkedHashMap, In such case,
config.register(GzipInterceptor.class);
config.register(GzipInterceptor.class);
We will have two providers registered as we wil new two provider instances.

How about we use below fix:
 public void register(Object provider, Map<Class<?>, Integer> contracts) {
//proposed change start
        for (Object o : providers.keySet())
        {
            if (o.getClass() == provider.getClass())
            {
               //just return and issue an waringing is possible.
                return;
            }

        }
//proposed change end
        if (provider.getClass() == Class.class) {
            provider = createProvider((Class<?>) provider);
        }
        Map<Class<?>, Integer> metadata = providers.get(provider);
        if (metadata == null) {
            metadata = new HashMap<Class<?>, Integer>();
            providers.put(provider, metadata);
        }
        for (Class<?> contract : contracts.keySet()) {
            if (contract.isAssignableFrom(provider.getClass())) {
                metadata.put(contract, contracts.get(contract));
            }
        }
    }

> org.apache.cxf.jaxrs.impl.ConfigurationImpl does not comply with SPEC
> ---------------------------------------------------------------------
>
>                 Key: CXF-6369
>                 URL: https://issues.apache.org/jira/browse/CXF-6369
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.0.3, 3.0.4, 2.7.15
>            Reporter: iris ding
>            Assignee: Sergey Beryozkin
>             Fix For: 3.1.0, 3.0.5
>
>
> According to http://docs.oracle.com/javaee/7/api/javax/ws/rs/core/Configurable.html
> As a general rule, for each JAX-RS component class there can be at most one registration
— class-based or instance-based — configured at any given moment. Implementations MUST
reject any attempts to configure a new registration for a provider class that has been already
registered in the given configurable context earlier. Implementations SHOULD also raise a
warning to inform the user about the rejected component registration.
> For example:
>  config.register(GzipInterceptor.class, WriterInterceptor.class);
>  config.register(GzipInterceptor.class);       // Rejected by runtime.
>  config.register(new GzipInterceptor());       // Rejected by runtime.
>  config.register(GzipInterceptor.class, 6500); // Rejected by runtime.
> So we need to check whether the same class's instances have already been put into config
before hand.
> Also to check whether the class/instance has been registered via  public boolean isRegistered(Class<?>
cls) , we need to check whether the two class is the same other than just isAssignableFrom.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message