File: Resources_Metadata.xml

package info (click to toggle)
resteasy 3.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 34,612 kB
  • sloc: java: 265,492; xml: 27,855; javascript: 405; jsp: 166; python: 101; sh: 15; sql: 3; makefile: 2
file content (115 lines) | stat: -rw-r--r-- 2,771 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<chapter id="Resources_Metadata">
<title>Resources metadata configuration</title>

<para>
When processing JAX-RS deployments, RESTEasy relies on <emphasis>ResourceBuilder</emphasis> to create metadata for each JAX-RS resource. Such metadata is defined using the metadata SPI in package <emphasis>org.jboss.resteasy.spi.metadata</emphasis>, in particular the <emphasis>ResourceClass</emphasis> interface:
<programlisting>
package org.jboss.resteasy.spi.metadata;

public interface ResourceClass
{
  String getPath();

  Class&lt;?&gt; getClazz();

  ResourceConstructor getConstructor();

  FieldParameter[] getFields();

  SetterParameter[] getSetters();

  ResourceMethod[] getResourceMethods();

  ResourceLocator[] getResourceLocators();
}
</programlisting>

Among the other classes and interfaces defining metadata SPI, the following interfaces are worth a mention here:

<programlisting>
public interface ResourceConstructor
{
  ResourceClass getResourceClass();

  Constructor getConstructor();

  ConstructorParameter[] getParams();
}

public interface ResourceMethod extends ResourceLocator
{
  Set&lt;String&gt; getHttpMethods();

  MediaType[] getProduces();

  MediaType[] getConsumes();

  boolean isAsynchronous();

  void markAsynchronous();
}

public interface ResourceLocator
{
  ResourceClass getResourceClass();

  Class&lt;?&gt; getReturnType();

  Type getGenericReturnType();

  Method getMethod();

  Method getAnnotatedMethod();

  MethodParameter[] getParams();

  String getFullpath();

  String getPath();

}
</programlisting>
</para>

<para>
Now, the interesting point is that RESTEasy allows tuning the metadata generation by providing implementations of the <emphasis>ResourceClassProcessor</emphasis> interface:
<programlisting>
package org.jboss.resteasy.spi.metadata;

public interface ResourceClassProcessor
{

  /**
   * Allows the implementation of this method to modify the resource metadata represented by
   * the supplied {@link ResourceClass} instance. Implementation will typically create
   * wrappers which modify only certain aspects of the metadata.
   *
   * @param clazz The original metadata
   * @return the (potentially modified) metadata (never null)
   */
  ResourceClass process(ResourceClass clazz);

}
</programlisting>

The processors are meant to be, and are resolved as, regular JAX-RS annotated providers. They allow for wrapping resource metadata classes with custom versions that can be used for various advanced scenarios like
<itemizedlist>
<listitem>
adding additional resource method/locators to the resource
</listitem>
<listitem>
altering the http methods
</listitem>
<listitem>
altering the @Produces / @Consumes media types
</listitem>
<listitem>
...
</listitem>
</itemizedlist>




</para>
</chapter>