Class JAXRSUtils


  • public final class JAXRSUtils
    extends Object
    • Method Detail

      • isStreamingLikeOutType

        public static boolean isStreamingLikeOutType​(Class<?> cls,
                                                     Type type)
        Consider additional types as stream-like and returns if the class and corresponding type refer to one of those.
        Parameters:
        cls - class to check
        type - type to check
        Returns:
        "true" is the class and corresponding type could be considered streaming-like, "false" otherwise.
      • isStreamingOutType

        public static boolean isStreamingOutType​(Class<?> type)
      • getPathSegments

        public static List<javax.ws.rs.core.PathSegment> getPathSegments​(String thePath,
                                                                         boolean decode)
      • getPathSegments

        public static List<javax.ws.rs.core.PathSegment> getPathSegments​(String thePath,
                                                                         boolean decode,
                                                                         boolean ignoreLastSlash)
        Parses path segments taking into account the URI templates and template regexes. Per RFC-3986, "A path consists of a sequence of path segments separated by a slash ("/") character.", however it is possible to include slash ("/") inside template regex, for example "/my/path/{a:b/c}", see please URITemplate. In this case, the whole template definition is extracted as a path segment, without breaking it.
        Parameters:
        thePath - path
        decode - should the path segments be decoded or not
        ignoreLastSlash - should the last slash be ignored or not
        Returns:
      • getProviderConsumeTypes

        public static List<javax.ws.rs.core.MediaType> getProviderConsumeTypes​(javax.ws.rs.ext.MessageBodyReader<?> provider)
      • getProviderProduceTypes

        public static List<javax.ws.rs.core.MediaType> getProviderProduceTypes​(javax.ws.rs.ext.MessageBodyWriter<?> provider)
      • getMediaTypes

        public static List<javax.ws.rs.core.MediaType> getMediaTypes​(String[] values)
      • injectParameters

        public static void injectParameters​(OperationResourceInfo ori,
                                            Object requestObject,
                                            org.apache.cxf.message.Message message)
      • findTargetMethod

        public static OperationResourceInfo findTargetMethod​(Map<ClassResourceInfo,​javax.ws.rs.core.MultivaluedMap<String,​String>> matchedResources,
                                                             org.apache.cxf.message.Message message,
                                                             String httpMethod,
                                                             javax.ws.rs.core.MultivaluedMap<String,​String> matchedValues,
                                                             String requestContentType,
                                                             List<javax.ws.rs.core.MediaType> acceptContentTypes,
                                                             boolean throwException,
                                                             boolean recordMatchedUri)
      • getExceptionLogLevel

        public static Level getExceptionLogLevel​(org.apache.cxf.message.Message message,
                                                 Class<? extends javax.ws.rs.WebApplicationException> exClass)
      • getRootResources

        public static List<ClassResourceInfo> getRootResources​(org.apache.cxf.message.Message message)
      • noResourceMethodForOptions

        public static boolean noResourceMethodForOptions​(javax.ws.rs.core.Response exResponse,
                                                         String httpMethod)
      • createResponse

        public static javax.ws.rs.core.Response createResponse​(List<ClassResourceInfo> cris,
                                                               org.apache.cxf.message.Message msg,
                                                               String responseMessage,
                                                               int status,
                                                               boolean addAllow)
      • headMethodPossible

        public static boolean headMethodPossible​(String expectedMethod,
                                                 String httpMethod)
      • getConsumeTypes

        public static List<javax.ws.rs.core.MediaType> getConsumeTypes​(javax.ws.rs.Consumes cm)
      • getConsumeTypes

        public static List<javax.ws.rs.core.MediaType> getConsumeTypes​(javax.ws.rs.Consumes cm,
                                                                       List<javax.ws.rs.core.MediaType> defaultTypes)
      • getProduceTypes

        public static List<javax.ws.rs.core.MediaType> getProduceTypes​(javax.ws.rs.Produces pm)
      • getProduceTypes

        public static List<javax.ws.rs.core.MediaType> getProduceTypes​(javax.ws.rs.Produces pm,
                                                                       List<javax.ws.rs.core.MediaType> defaultTypes)
      • compareSortedConsumesMediaTypes

        public static int compareSortedConsumesMediaTypes​(List<javax.ws.rs.core.MediaType> mts1,
                                                          List<javax.ws.rs.core.MediaType> mts2,
                                                          javax.ws.rs.core.MediaType ct)
      • compareSortedAcceptMediaTypes

        public static int compareSortedAcceptMediaTypes​(List<javax.ws.rs.core.MediaType> mts1,
                                                        List<javax.ws.rs.core.MediaType> mts2,
                                                        List<javax.ws.rs.core.MediaType> acceptTypes)
      • compareSortedMediaTypes

        public static int compareSortedMediaTypes​(List<javax.ws.rs.core.MediaType> mts1,
                                                  List<javax.ws.rs.core.MediaType> mts2,
                                                  String qs)
      • compareMethodParameters

        public static int compareMethodParameters​(Class<?>[] paraList1,
                                                  Class<?>[] paraList2)
      • compareMediaTypes

        public static int compareMediaTypes​(javax.ws.rs.core.MediaType mt1,
                                            javax.ws.rs.core.MediaType mt2)
      • compareMediaTypes

        public static int compareMediaTypes​(javax.ws.rs.core.MediaType mt1,
                                            javax.ws.rs.core.MediaType mt2,
                                            String qs)
      • compareMediaTypesQualityFactors

        public static int compareMediaTypesQualityFactors​(javax.ws.rs.core.MediaType mt1,
                                                          javax.ws.rs.core.MediaType mt2)
      • compareMediaTypesQualityFactors

        public static int compareMediaTypesQualityFactors​(javax.ws.rs.core.MediaType mt1,
                                                          javax.ws.rs.core.MediaType mt2,
                                                          String qs)
      • getMediaTypeQualityFactor

        public static float getMediaTypeQualityFactor​(String q)
      • getMatrixParams

        public static javax.ws.rs.core.MultivaluedMap<String,​String> getMatrixParams​(String path,
                                                                                           boolean decode)
      • getContextMessage

        public static org.apache.cxf.message.Message getContextMessage​(org.apache.cxf.message.Message m)
      • createContextValue

        public static <T> T createContextValue​(org.apache.cxf.message.Message m,
                                               Type genericType,
                                               Class<T> clazz)
      • createContextResolver

        public static javax.ws.rs.ext.ContextResolver<?> createContextResolver​(Type genericType,
                                                                               org.apache.cxf.message.Message m)
      • createResourceValue

        public static Object createResourceValue​(org.apache.cxf.message.Message m,
                                                 Type genericType,
                                                 Class<?> clazz)
      • getStructuredParams

        public static javax.ws.rs.core.MultivaluedMap<String,​String> getStructuredParams​(String query,
                                                                                               String sep,
                                                                                               boolean decode,
                                                                                               boolean decodePlus)
        Retrieve map of query parameters from the passed in message
        Returns:
        a Map of query parameters.
      • getStructuredParams

        public static void getStructuredParams​(javax.ws.rs.core.MultivaluedMap<String,​String> queries,
                                               String query,
                                               String sep,
                                               boolean decode,
                                               boolean decodePlus)
      • getStructuredParams

        public static void getStructuredParams​(javax.ws.rs.core.MultivaluedMap<String,​String> queries,
                                               String query,
                                               String sep,
                                               boolean decode,
                                               boolean decodePlus,
                                               boolean valueIsCollection)
      • readFromMessageBodyReader

        public static Object readFromMessageBodyReader​(List<javax.ws.rs.ext.ReaderInterceptor> readers,
                                                       Class<?> targetTypeClass,
                                                       Type parameterType,
                                                       Annotation[] parameterAnnotations,
                                                       InputStream is,
                                                       javax.ws.rs.core.MediaType mediaType,
                                                       org.apache.cxf.message.Message m)
                                                throws IOException,
                                                       javax.ws.rs.WebApplicationException
        Throws:
        IOException
        javax.ws.rs.WebApplicationException
      • writeMessageBody

        public static void writeMessageBody​(List<javax.ws.rs.ext.WriterInterceptor> writers,
                                            Object entity,
                                            Class<?> type,
                                            Type genericType,
                                            Annotation[] annotations,
                                            javax.ws.rs.core.MediaType mediaType,
                                            javax.ws.rs.core.MultivaluedMap<String,​Object> httpHeaders,
                                            org.apache.cxf.message.Message message)
                                     throws javax.ws.rs.WebApplicationException,
                                            IOException
        Throws:
        javax.ws.rs.WebApplicationException
        IOException
      • matchConsumeTypes

        public static boolean matchConsumeTypes​(javax.ws.rs.core.MediaType requestContentType,
                                                OperationResourceInfo ori)
      • matchProduceTypes

        public static boolean matchProduceTypes​(javax.ws.rs.core.MediaType acceptContentType,
                                                OperationResourceInfo ori)
      • matchMimeTypes

        public static boolean matchMimeTypes​(javax.ws.rs.core.MediaType requestContentType,
                                             javax.ws.rs.core.MediaType acceptContentType,
                                             OperationResourceInfo ori)
      • parseMediaTypes

        public static List<javax.ws.rs.core.MediaType> parseMediaTypes​(String types)
      • doMimeTypesIntersect

        public static boolean doMimeTypesIntersect​(List<javax.ws.rs.core.MediaType> mimeTypesA,
                                                   javax.ws.rs.core.MediaType mimeTypeB)
      • doMimeTypesIntersect

        public static boolean doMimeTypesIntersect​(List<javax.ws.rs.core.MediaType> requiredMediaTypes,
                                                   List<javax.ws.rs.core.MediaType> userMediaTypes)
      • intersectMimeTypes

        public static List<javax.ws.rs.core.MediaType> intersectMimeTypes​(List<javax.ws.rs.core.MediaType> requiredMediaTypes,
                                                                          List<javax.ws.rs.core.MediaType> userMediaTypes,
                                                                          boolean addRequiredParamsIfPossible)
        intersect two mime types
        Parameters:
        requiredMediaTypes -
        userMediaTypes -
        addRequiredParamsIfPossible -
        Returns:
        return a list of intersected mime types
      • intersectMimeTypes

        public static List<javax.ws.rs.core.MediaType> intersectMimeTypes​(List<javax.ws.rs.core.MediaType> requiredMediaTypes,
                                                                          List<javax.ws.rs.core.MediaType> userMediaTypes,
                                                                          boolean addRequiredParamsIfPossible,
                                                                          boolean addDistanceParameter)
      • intersectMimeTypes

        public static List<javax.ws.rs.core.MediaType> intersectMimeTypes​(List<javax.ws.rs.core.MediaType> mimeTypesA,
                                                                          javax.ws.rs.core.MediaType mimeTypeB)
      • intersectMimeTypes

        public static List<javax.ws.rs.core.MediaType> intersectMimeTypes​(String mimeTypesA,
                                                                          String mimeTypesB)
      • sortMediaTypes

        public static List<javax.ws.rs.core.MediaType> sortMediaTypes​(String mediaTypes,
                                                                      String qs)
      • sortMediaTypes

        public static List<javax.ws.rs.core.MediaType> sortMediaTypes​(List<javax.ws.rs.core.MediaType> types,
                                                                      String qs)
      • convertFaultToResponse

        public static <T extends Throwable> javax.ws.rs.core.Response convertFaultToResponse​(T ex,
                                                                                             org.apache.cxf.message.Message currentMessage)
      • setMessageContentType

        public static void setMessageContentType​(org.apache.cxf.message.Message message,
                                                 javax.ws.rs.core.Response response)
      • getClassQName

        public static QName getClassQName​(Class<?> type)
      • convertStringToQName

        public static QName convertStringToQName​(String name)
      • mediaTypeToString

        public static String mediaTypeToString​(javax.ws.rs.core.MediaType mt,
                                               String... ignoreParams)
      • toMediaType

        public static javax.ws.rs.core.MediaType toMediaType​(String value)
      • toResponse

        public static javax.ws.rs.core.Response toResponse​(int status)
      • toResponse

        public static javax.ws.rs.core.Response toResponse​(javax.ws.rs.core.Response.Status status)
      • toResponseBuilder

        public static javax.ws.rs.core.Response.ResponseBuilder toResponseBuilder​(int status)
      • toResponseBuilder

        public static javax.ws.rs.core.Response.ResponseBuilder toResponseBuilder​(javax.ws.rs.core.Response.Status status)
      • fromResponse

        public static javax.ws.rs.core.Response.ResponseBuilder fromResponse​(javax.ws.rs.core.Response response)
      • fromResponse

        public static javax.ws.rs.core.Response.ResponseBuilder fromResponse​(javax.ws.rs.core.Response response,
                                                                             boolean copyEntity)
      • copyResponseIfNeeded

        public static javax.ws.rs.core.Response copyResponseIfNeeded​(javax.ws.rs.core.Response response)
      • getCurrentMessage

        public static org.apache.cxf.message.Message getCurrentMessage()
      • getRootResource

        public static ClassResourceInfo getRootResource​(org.apache.cxf.message.Message m)
      • pushOntoStack

        public static void pushOntoStack​(OperationResourceInfo ori,
                                         javax.ws.rs.core.MultivaluedMap<String,​String> params,
                                         org.apache.cxf.message.Message msg)
      • logMessageHandlerProblem

        public static String logMessageHandlerProblem​(String name,
                                                      Class<?> cls,
                                                      javax.ws.rs.core.MediaType ct)
      • getUriTemplate

        public static String getUriTemplate​(org.apache.cxf.message.Message message,
                                            ClassResourceInfo cri,
                                            OperationResourceInfo ori,
                                            OperationResourceInfo subOri)
        Get path URI template, combining base path, class & method & subresource templates
        Parameters:
        message - message instance
        cri - class resource info
        ori - operation resource info
        subOri - operation subresource info
        Returns:
        the URI template for the method in question
      • getUriTemplate

        public static String getUriTemplate​(org.apache.cxf.message.Message message,
                                            ClassResourceInfo cri,
                                            OperationResourceInfo ori)
        Get path URI template, combining base path, class & method templates
        Parameters:
        message - message instance
        cri - class resource info
        ori - operation resource info
        Returns:
        the URI template for the method in question