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

Andriy Redko commented on CXF-8097:
-----------------------------------

Hey [~carsten.d] ,

Thanks a lot for the sample project. I've noticed that you are using custom 
resource comparator (by overriding the CXF's default one):
{noformat}
        ...
        factory.setResourceComparator(new QueryResourceInfoComperator());
        factory.setServiceName(new QName("CXF-8097"));
        return factory.create();
 {noformat}
This comparator's implementation is the reason why you see warning. When 
default CXF resource comparator is used , the warning is gone:
{noformat}
2020-01-02 16:24:53,814 INFO  [qtp603658030-20] [] 
[ServletRequestLogHandler.handle:23] Request: HEAD /api/test/path/x/y/z/test, 
Content-Type: null, Body: 0 bytes
2020-01-02 16:24:53,828 INFO  [qtp603658030-20] [] 
[TestRestServiceImpl.testAsHeadRequest:46] HEAD request
2020-01-02 16:24:53,828 INFO  [qtp603658030-20] [] 
[ServletRequestLogHandler.handle:33] Response -- Status: 200, Content-Type: 
application/octet-stream
2020-01-02 16:24:55,808 INFO  [qtp603658030-19] [] 
[ServletRequestLogHandler.handle:23] Request: GET /api/test/path/x/y/z/test, 
Content-Type: null, Body: 0 bytes
2020-01-02 16:24:55,810 INFO  [qtp603658030-19] [] 
[TestRestServiceImpl.test:34] GET request
2020-01-02 16:24:55,810 INFO  [qtp603658030-19] [] 
[ServletRequestLogHandler.handle:33] Response -- Status: 200, Content-Type: null
 {noformat}
The issue is that the custom comparator (*QueryResourceInfoComperator*) is 
inherited from *OperationResourceInfoComparator* but does not properly 
initialize it (passing *null*s to parent's constructor).
{noformat}
    public QueryResourceInfoComperator()
    {
        super(null, null);
    } {noformat}
This is purely CXF documentation fault (since this where the original example 
of custom resource comparator comes from), the 
*OperationResourceInfoComparator* is not reusable and is very 
context-dependent. Probably, the simplest solution in this case is to remove 
*OperationResourceInfoComparator* from inheritance chain and use delegation 
instead (otherwise the important details (like HTTP method) are not passed 
through, leading to warnings and surprises), for example:
{noformat}
    @Override
    public int compare(OperationResourceInfo oper1, OperationResourceInfo 
oper2, Message message)
    {
         // HTTP method
        final String httpMethod = HttpUtils.getProtocolHeader(message, 
Message.HTTP_REQUEST_METHOD, HttpMethod.POST, true);
        final OperationResourceInfoComparator delegate = new 
OperationResourceInfoComparator(null, httpMethod);
        
        // Check if CXF can make a decision
        final int cxfResult = delegate .compare(oper1, oper2);
        ...
    }  {noformat}
The proper fix would take some time but the workaround with delegation should 
do the job meantime. 
I am wondering, would it work for the time being? 
Thank you.

Best Regards,
    Andriy Redko

> Equal candidates for handling the current request (HEAD / GET)
> --------------------------------------------------------------
>
>                 Key: CXF-8097
>                 URL: https://issues.apache.org/jira/browse/CXF-8097
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.3.2, 3.3.3, 3.3.4
>            Reporter: Carsten D
>            Priority: Major
>         Attachments: Screenshot 2019-12-17 at 08.44.29.png, cxf-8097-mcve.zip
>
>
> I have just migrated a very outdated Spring backend to Spring 5 and with it 
> upgraded CXF to first 3.3.2 and just now 3.3.3. I have a REST service class 
> defining two different methods with the same path defined via 
> {{javax.ws.rs.Path}} annotation, differentiated by {{javax.ws.rs.HEAD}} and 
> {{javax.ws.rs.GET}} annotations. Both methods are annotated with 
> {{@Produces(MediaType.APPLICATION_OCTET_STREAM)}}.
> When this method is called I get (redacted):
> {{WARN  [JAXRSUtils.compare:129] Both ServiceRestImpl#getFile and 
> ServiceRestImpl#getFileAsHeadRequest are equal candidates for handling the 
> current request which can lead to unpredictable results}}
> The differentiation works: HEAD requests are handled by the {{@HEAD}} 
> annotated method and GET requests by the {{@GET}} annotated one (this has 
> always worked). Therefore the warning is false but will severely clutter 
> production log output, possibly affect performance.
> Relevant dependencies:
> * Spring framework 5.1.8
> * "org.apache.cxf", "cxf-rt-rs-service-description", "3.3.3"
> * "javax.servlet", "javax.servlet-api", "4.0.1"
> * "javax.ws.rs", "javax.ws.rs-api", "2.0.1"
> I'd appreciate support. May be linked to:
> * CXF-7670
> * CXF-6684



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

Reply via email to