[
https://issues.apache.org/jira/browse/CXF-6230?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14300741#comment-14300741
]
Sergey Beryozkin commented on CXF-6230:
---------------------------------------
In CXF 2.7.12 you can have a "check.parameter.handlers.first" contextual
property set to true to ensure ParamConverters are checked first. In CXF 2.7.x
it is dome to minimize any side-effects, while in CXF 3.0.x ParamConverters are
indeed checked first
Can you try this property (set in jaxrs:properties) ?
> Using ParamConverterProvider to validate @PathParam value.
> ----------------------------------------------------------
>
> Key: CXF-6230
> URL: https://issues.apache.org/jira/browse/CXF-6230
> Project: CXF
> Issue Type: Bug
> Affects Versions: 2.7.12
> Reporter: Metin KILIC
>
> I am using cxf version 2.7.12 and I have an end-point in my application takes
> two PathParam parameters. one of the parameter takes Long and the other one
> takes java.util.UUID. I am running into an issue where validating the UUID. I
> created a ParameterHandler by implementing ParamConverterProvider
> public class AppParameterHandler implements ParamConverterProvider {
> @Override
> public <T> ParamConverter<T> getConverter(final Class<T> rawType, final
> Type genericType, final Annotation[] annotations) {
> if (rawType.getName().equals(Long.class.getName())) {
> return new ParamConverter<T>() {
> @Override
> public T fromString(String value) {
> try {
> //
> } catch (NumberFormatException e) {
> //
> }
> }
> @Override
> public String toString(T value) {
> if (value == null) {
> return null;
> }
> return value.toString();
> }
> };
> }
> else if (rawType.getName().equals(UUID.class.getName())) {
> return new ParamConverter<T>() {
> @Override
> public T fromString(String value) {
> try {
> //
> } catch (Exception e) {
> //
> }
> }
> @Override
> public String toString(T value) {
> if (value == null) {
> return null;
> }
> return value.toString();
> }
> };
> }
> return null;
> }
> }
> This code is working fine for Long type (if the param parameter is passed
> like 123123a123123 , I can handle it and send back the custom message in the
> response), but It throws an exception for UUID validation.
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> charset=ISO-8859-1"/>
> <title>Error 500 javax.ws.rs.core.Response.hasEntity()Z</title>
> </head>
> <body>
> <h2>HTTP ERROR 500</h2>
> <p>Problem accessing /v1/foo/LONG/bar/INVALID_UUID. Reason:
> <pre> javax.ws.rs.core.Response.hasEntity()Z</pre>
> </p>
> <h3>Caused by:</h3>
> <pre>java.lang.NoSuchMethodError:
> javax.ws.rs.core.Response.hasEntity()Z
> at
> org.apache.cxf.jaxrs.utils.ExceptionUtils.convertFaultToResponse(ExceptionUtils.java:67)
> at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.convertFaultToResponse(JAXRSUtils.java:1524)
> at
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.convertExceptionToResponseIfPossible(JAXRSInInterceptor.java:261)
> So I debugged the cxf code and found out that it is not even creating the
> parameter handler that I registered. It hits
> https://github.com/apache/cxf/blob/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java#L394
> line and threw NoSuchMethodException and then It calls
> https://github.com/apache/cxf/blob/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java#L490
> to see if it can evaluate valueOf, fromString for UUID since it is not valid
> UUID evaluateFactoryMethod throws WebApplicationException :
> https://github.com/apache/cxf/blob/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java#L507
> To my opinion, it should not throw that exception and let my
> AppParameterHandler handle the case in here
> https://github.com/apache/cxf/blob/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java#L423.
> I can provide working/not working example as well if it is needed.
> So I would like these:
> 1- ParamConverterProvider should be used to validate ? if not, what should I
> use?
> 2- Why cxf does not call ParameterHandler even I registered it for the class
> type before throwing exception?
> Thanks,
> Metin
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)