Class WebResourceFactory

  • All Implemented Interfaces:
    java.lang.reflect.InvocationHandler

    public final class WebResourceFactory
    extends java.lang.Object
    implements java.lang.reflect.InvocationHandler
    Factory for client-side representation of a resource. See the package overview for an example on how to use this class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<javax.ws.rs.core.Cookie> cookies  
      private static java.lang.String[] EMPTY  
      private static javax.ws.rs.core.Form EMPTY_FORM  
      private static javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> EMPTY_HEADERS  
      private javax.ws.rs.core.Form form  
      private javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> headers  
      private static java.util.List<java.lang.Class> PARAM_ANNOTATION_CLASSES  
      private javax.ws.rs.client.WebTarget target  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private WebResourceFactory​(javax.ws.rs.client.WebTarget target, javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> headers, java.util.List<javax.ws.rs.core.Cookie> cookies, javax.ws.rs.core.Form form)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static javax.ws.rs.client.WebTarget addPathFromAnnotation​(java.lang.reflect.AnnotatedElement ae, javax.ws.rs.client.WebTarget target)  
      private java.lang.Object[] convert​(java.util.Collection value)  
      private static java.lang.String getHttpMethodName​(java.lang.reflect.AnnotatedElement ae)  
      private boolean hasAnyParamAnnotation​(java.util.Map<java.lang.Class,​java.lang.annotation.Annotation> anns)  
      java.lang.Object invoke​(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)  
      static <C> C newResource​(java.lang.Class<C> resourceInterface, javax.ws.rs.client.WebTarget target)
      Creates a new client-side representation of a resource described by the interface passed in the first argument.
      static <C> C newResource​(java.lang.Class<C> resourceInterface, javax.ws.rs.client.WebTarget target, boolean ignoreResourcePath, javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> headers, java.util.List<javax.ws.rs.core.Cookie> cookies, javax.ws.rs.core.Form form)
      Creates a new client-side representation of a resource described by the interface passed in the first argument.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EMPTY

        private static final java.lang.String[] EMPTY
      • target

        private final javax.ws.rs.client.WebTarget target
      • headers

        private final javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> headers
      • cookies

        private final java.util.List<javax.ws.rs.core.Cookie> cookies
      • form

        private final javax.ws.rs.core.Form form
      • EMPTY_HEADERS

        private static final javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> EMPTY_HEADERS
      • EMPTY_FORM

        private static final javax.ws.rs.core.Form EMPTY_FORM
      • PARAM_ANNOTATION_CLASSES

        private static final java.util.List<java.lang.Class> PARAM_ANNOTATION_CLASSES
    • Constructor Detail

      • WebResourceFactory

        private WebResourceFactory​(javax.ws.rs.client.WebTarget target,
                                   javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> headers,
                                   java.util.List<javax.ws.rs.core.Cookie> cookies,
                                   javax.ws.rs.core.Form form)
    • Method Detail

      • newResource

        public static <C> C newResource​(java.lang.Class<C> resourceInterface,
                                        javax.ws.rs.client.WebTarget target)
        Creates a new client-side representation of a resource described by the interface passed in the first argument.

        Calling this method has the same effect as calling WebResourceFactory.newResource(resourceInterface, rootTarget, false).

        Type Parameters:
        C - Type of the resource to be created.
        Parameters:
        resourceInterface - Interface describing the resource to be created.
        target - WebTarget pointing to the resource or the parent of the resource.
        Returns:
        Instance of a class implementing the resource interface that can be used for making requests to the server.
      • newResource

        public static <C> C newResource​(java.lang.Class<C> resourceInterface,
                                        javax.ws.rs.client.WebTarget target,
                                        boolean ignoreResourcePath,
                                        javax.ws.rs.core.MultivaluedMap<java.lang.String,​java.lang.Object> headers,
                                        java.util.List<javax.ws.rs.core.Cookie> cookies,
                                        javax.ws.rs.core.Form form)
        Creates a new client-side representation of a resource described by the interface passed in the first argument.
        Type Parameters:
        C - Type of the resource to be created.
        Parameters:
        resourceInterface - Interface describing the resource to be created.
        target - WebTarget pointing to the resource or the parent of the resource.
        ignoreResourcePath - If set to true, ignores path annotation on the resource interface (this is used when creating sub-resources)
        headers - Header params collected from parent resources (used when creating a sub-resource)
        cookies - Cookie params collected from parent resources (used when creating a sub-resource)
        form - Form params collected from parent resources (used when creating a sub-resource)
        Returns:
        Instance of a class implementing the resource interface that can be used for making requests to the server.
      • invoke

        public java.lang.Object invoke​(java.lang.Object proxy,
                                       java.lang.reflect.Method method,
                                       java.lang.Object[] args)
                                throws java.lang.Throwable
        Specified by:
        invoke in interface java.lang.reflect.InvocationHandler
        Throws:
        java.lang.Throwable
      • hasAnyParamAnnotation

        private boolean hasAnyParamAnnotation​(java.util.Map<java.lang.Class,​java.lang.annotation.Annotation> anns)
      • convert

        private java.lang.Object[] convert​(java.util.Collection value)
      • addPathFromAnnotation

        private static javax.ws.rs.client.WebTarget addPathFromAnnotation​(java.lang.reflect.AnnotatedElement ae,
                                                                          javax.ws.rs.client.WebTarget target)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getHttpMethodName

        private static java.lang.String getHttpMethodName​(java.lang.reflect.AnnotatedElement ae)