Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not unique JAXRS method candidates WARN caused by CrossOriginResourceSharingFilter #862

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import javax.ws.rs.ext.Provider;

import org.apache.cxf.common.util.ReflectionUtil;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
Expand Down Expand Up @@ -290,8 +291,21 @@ private OperationResourceInfo findPreflightMethod(
String httpMethod,
MultivaluedMap<String, String> values,
Message m) {
final String contentType = MediaType.WILDCARD;
final MediaType acceptType = MediaType.WILDCARD_TYPE;
Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?, ?>)m.get(Message.PROTOCOL_HEADERS));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to use HttpHeadersImpl:

final HttpHeaders headers = new HttpHeadersImpl(m);
MediaType contentType = headers.getMediaType();
if (contentType == null) {
    contentType = MediaType.WILDCARD_TYPE;
}
        
final List<MediaType> acceptTypes = headers.getAcceptableMediaTypes();

(which would need to introduce JAXRSUtils::findTargetMethod that accepts content type as MediaType)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is based on the main JAXRS routing code. It is really a good idea to differ that logic?
I think it is best to extract some common code for extraction of content-type and accept headers to JAXRSUtils. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 , also works, we already have JAXRSUtils::setMessageContentType, introducing get counterpart would make sense

String contentType;
List<String> ctHeaderValues = protocolHeaders.get(Message.CONTENT_TYPE);
if (ctHeaderValues != null && !ctHeaderValues.isEmpty()) {
contentType = ctHeaderValues.get(0);
} else {
contentType = MediaType.WILDCARD;
}
String acceptType;
List<String> acceptHeaderValues = protocolHeaders.get(Message.ACCEPT_CONTENT_TYPE);
if (acceptHeaderValues != null && !acceptHeaderValues.isEmpty()) {
acceptType = acceptHeaderValues.get(0);
} else {
acceptType = MediaType.WILDCARD;
}
OperationResourceInfo ori = JAXRSUtils.findTargetMethod(matchedResources,
m, httpMethod, values,
contentType,
Expand Down