@FFDCIgnore(value = { NoSuchMethodException.class, NumberFormatException.class, Exception.class })
    // Liberty Change for CXF End
    @SuppressWarnings("unchecked")
    public static <T> T handleParameter(String value,
                                        boolean decoded,
                                        Class<T> pClass,
                                        Type genericType,
                                        Annotation[] paramAnns,
                                        ParameterType pType,
                                        Message message) {
        if (value == null) {
            return null;
        }

        //fix new Date("") throw exception defect
        if (value.isEmpty() && genericType == Date.class) {
            return null;
        }

        if (pType == ParameterType.PATH) {
            if (PathSegment.class.isAssignableFrom(pClass)) {
                return pClass.cast(new PathSegmentImpl(value, decoded));
            } else if (!MessageUtils.isTrue(
                            message.getContextualProperty(IGNORE_MATRIX_PARAMETERS))) {
                value = new PathSegmentImpl(value, false).getPath();
            }
        }

        value = decodeValue(value, decoded, pType);

        Object result = null;
        try {
            result = createFromParameterHandler(value, pClass, genericType, paramAnns, message);
        } catch (IllegalArgumentException nfe) {
            throw createParamConversionException(pType, nfe);
        }
        if (result != null) {
            T theResult = null;
            if (pClass.isPrimitive()) {
                theResult = (T) result;
            } else {
                theResult = pClass.cast(result);
            }
            return theResult;
        }
        if (Number.class.isAssignableFrom(pClass) && "".equals(value)) {
            //pass empty string to boxed number type will result in 404
            return null;
        }
        if (Boolean.class == pClass) {
            // allow == checks for Boolean object
            pClass = (Class<T>) Boolean.TYPE;
        }
        if (pClass.isPrimitive()) {
            try {
                @SuppressWarnings("unchecked")
                T ret = (T) PrimitiveUtils.read(value, pClass);
                // cannot us pClass.cast as the pClass is something like
                // Boolean.TYPE (representing the boolean primitive) and
                // the object is a Boolean object
                return ret;
            } catch (NumberFormatException nfe) {
                throw createParamConversionException(pType, nfe);
            }
        }

        boolean adapterHasToBeUsed = false;
        Class<?> cls = pClass;
        Class<?> valueType = JAXBUtils.getValueTypeFromAdapter(pClass, pClass, paramAnns);
        if (valueType != cls) {
            cls = valueType;
            adapterHasToBeUsed = true;
        }
        if (pClass == String.class && !adapterHasToBeUsed) {
            return pClass.cast(value);
        }
        // check constructors accepting a single String value
        try {
            Constructor<?> c = cls.getConstructor(new Class<?>[] { String.class });
            result = c.newInstance(new Object[] { value });
        } catch (NoSuchMethodException ex) {
            // try valueOf
        } catch (WebApplicationException ex) {
            throw ex;
        } catch (Exception ex) {
            Throwable t = getOrThrowActualException(ex);
            Tr.warning(tc, new org.apache.cxf.common.i18n.Message("CLASS_CONSTRUCTOR_FAILURE",
                            BUNDLE,
                            pClass.getName()).toString());
            Response r = JAXRSUtils.toResponse(HttpUtils.getParameterFailureStatus(pType));
            throw ExceptionUtils.toHttpException(t, r);
        }
        if (result == null) {
            // check for valueOf(String) static methods
            String[] methodNames = cls.isEnum()
                            ? new String[] { "fromString", "fromValue", "valueOf" }
                            : new String[] { "valueOf", "fromString" };
            result = evaluateFactoryMethods(value, pType, result, cls, methodNames);
        }

        if (adapterHasToBeUsed) {
            // as the last resort, try XmlJavaTypeAdapters
            Object valueToReplace = result != null ? result : value;
            try {
                result = JAXBUtils.convertWithAdapter(valueToReplace, pClass, paramAnns);
            } catch (Throwable ex) {
                result = null;
            }
        }

        if (result == null) {
            reportServerError("WRONG_PARAMETER_TYPE", pClass.getName());
        }

        return pClass.cast(result);
    }
@ FFDCIgnore ( value = { NoSuchMethodException . class , NumberFormatException . class , Exception . class } ) @ SuppressWarnings ( "unchecked" ) public static < T > T handleParameter ( String value , boolean decoded , Class < T > pClass , Type genericType , Annotation [ ] paramAnns , ParameterType pType , Message message ) { if ( value == null ) { return null ; } if ( value . isEmpty ( ) && genericType == Date . class ) { return null ; } if ( pType == ParameterType . PATH ) { if ( PathSegment . class . isAssignableFrom ( pClass ) ) { return pClass . cast ( new PathSegmentImpl ( value , decoded ) ) ; } else if ( ! MessageUtils . isTrue ( message . getContextualProperty ( IGNORE_MATRIX_PARAMETERS ) ) ) { value = new PathSegmentImpl ( value , false ) . getPath ( ) ; } } value = decodeValue ( value , decoded , pType ) ; Object result = null ; try { result = createFromParameterHandler ( value , pClass , genericType , paramAnns , message ) ; } catch ( IllegalArgumentException nfe ) { throw createParamConversionException ( pType , nfe ) ; } if ( result != null ) { T theResult = null ; if ( pClass . isPrimitive ( ) ) { theResult = ( T ) result ; } else { theResult = pClass . cast ( result ) ; } return theResult ; } if ( Number . class . isAssignableFrom ( pClass ) && "" . equals ( value ) ) { return null ; } if ( Boolean . class == pClass ) { pClass = ( Class < T > ) Boolean . TYPE ; } if ( pClass . isPrimitive ( ) ) { try { @ SuppressWarnings ( "unchecked" ) T ret = ( T ) PrimitiveUtils . read ( value , pClass ) ; return ret ; } catch ( NumberFormatException nfe ) { throw createParamConversionException ( pType , nfe ) ; } } boolean adapterHasToBeUsed = false ; Class < ? > cls = pClass ; Class < ? > valueType = JAXBUtils . getValueTypeFromAdapter ( pClass , pClass , paramAnns ) ; if ( valueType != cls ) { cls = valueType ; adapterHasToBeUsed = true ; } if ( pClass == String . class && ! adapterHasToBeUsed ) { return pClass . cast ( value ) ; } try { Constructor < ? > c = cls . getConstructor ( new Class < ? > [ ] { String . class } ) ; result = c . newInstance ( new Object [ ] { value } ) ; } catch ( NoSuchMethodException ex ) { } catch ( WebApplicationException ex ) { throw ex ; } catch ( Exception ex ) { Throwable t = getOrThrowActualException ( ex ) ; Tr . warning ( tc , new org . apache . cxf . common . i18n . Message ( "CLASS_CONSTRUCTOR_FAILURE" , BUNDLE , pClass . getName ( ) ) . toString ( ) ) ; Response r = JAXRSUtils . toResponse ( HttpUtils . getParameterFailureStatus ( pType ) ) ; throw ExceptionUtils . toHttpException ( t , r ) ; } if ( result == null ) { String [ ] methodNames = cls . isEnum ( ) ? new String [ ] { "fromString" , "fromValue" , "valueOf" } : new String [ ] { "valueOf" , "fromString" } ; result = evaluateFactoryMethods ( value , pType , result , cls , methodNames ) ; } if ( adapterHasToBeUsed ) { Object valueToReplace = result != null ? result : value ; try { result = JAXBUtils . convertWithAdapter ( valueToReplace , pClass , paramAnns ) ; } catch ( Throwable ex ) { result = null ; } } if ( result == null ) { reportServerError ( "WRONG_PARAMETER_TYPE" , pClass . getName ( ) ) ; } return pClass . cast ( result ) ; }
Liberty Change for CXF Begin