40
40
41
41
-->
42
42
43
- Managed Beans Example
44
- =====================
45
-
46
- This example demonstrates managed bean support in Jersey. JAX-RS root
47
- resource classes are annotated with @ManagedBean , which means EE-related
48
- resources may be injected into instances of those classes.
49
-
50
- Content
51
- -------
52
-
53
- The example application includes two root resource classes that are
54
- treated as Java EE managed beans. One root resource class is managed in
55
- the default JAX-RS life-cycle (one instance per request) and the other
56
- is managed in the singleton life-cycle (one instance per web
57
- application).
58
-
59
- Two Java EE artifacts are injected into the singleton root resource. The
60
- first is a resource constant defined in the web.xml. The second is an
61
- entity manager factory to allow integration with JPA layer.
62
-
63
- Running the Example
64
- -------------------
65
-
66
- This sample utilizes Java EE features in GlassFish application server.
67
-
68
- The easiest way to get the application running is to build it and deploy
69
- as follows:
70
-
71
- mvn clean package
72
- $AS_HOME/asadmin deploy target/managed-beans-webapp.war
73
-
74
- From a web browser, visit:
75
-
76
- - < http://localhost:8080/managed-beans-webapp >
77
-
78
43
Managed Client Example
79
44
======================
80
45
@@ -94,7 +59,8 @@ URI path | Resource class | HTTP methods
94
59
** _ /internal/b_ ** | InternalResource | GET
95
60
96
61
In the example, the requests to a * public resource* deployed on
97
- ` /public/ ` path are forwarded to an * internal resource* (deployed on ` /internal/ ` path) using injected
62
+ ` /public/ ` path are forwarded to an * internal resource* (deployed on
63
+ ` /internal/ ` path) using injected
98
64
[ javax.ws.rs.client.WebTarget] ( https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/client/WebTarget.html )
99
65
instances produced using 2 separate managed clients each of the managed
100
66
clients using it's own custom configuration.
@@ -115,17 +81,17 @@ Running the Example
115
81
116
82
Run the example as follows:
117
83
118
- > mvn clean compile exec:java
84
+ > mvn clean package exec:java
119
85
120
86
This deploys current example on the local host. You can then access WADL
121
87
description of the deployed application at
122
- < http://localhost:8080/managedclient /application.wadl > .
88
+ < http://localhost:8080/managed-client-webapp /application.wadl > .
123
89
124
90
You can access public resource of this application using curl:
125
91
126
- > curl -v -H "Accept: text/plain" http://localhost:8080/managedclient /public/a
92
+ > curl -v -H "Accept: text/plain" http://localhost:8080/managed-client-webapp /public/a
127
93
128
- > curl -v -H "Accept: text/plain" http://localhost:8080/managedclient /public/b
94
+ > curl -v -H "Accept: text/plain" http://localhost:8080/managed-client-webapp /public/b
129
95
130
96
In this example you should see the returned response message body
131
97
contains "a" or "b" respectively upon successful invocation.
@@ -134,16 +100,16 @@ You may also verify that access to internal resource is not possible
134
100
without including a proper header in the request. First try to access
135
101
the internal resource without any custom header:
136
102
137
- > curl -v -H "Accept: text/plain" http://localhost:8080/managedclient /internal/a
103
+ > curl -v -H "Accept: text/plain" http://localhost:8080/managed-client-webapp /internal/a
138
104
139
- > curl -v -H "Accept: text/plain" http://localhost:8080/managedclient /internal/b
105
+ > curl -v -H "Accept: text/plain" http://localhost:8080/managed-client-webapp /internal/b
140
106
141
107
In both cases a ` HTTP 403 Forbidden. ` response is returned. Now lets try
142
108
to access the resource once again, but this time we'll include also the
143
109
expected custom headers:
144
110
145
- > curl -v -H "Accept: text/plain" -H "custom-header:a" http://localhost:8080/managedclient /internal/a
111
+ > curl -v -H "Accept: text/plain" -H "custom-header:a" http://localhost:8080/managed-client-webapp /internal/a
146
112
147
- > curl -v -H "Accept: text/plain" -H "custom-header:b" http://localhost:8080/managedclient /internal/b
113
+ > curl -v -H "Accept: text/plain" -H "custom-header:b" http://localhost:8080/managed-client-webapp /internal/b
148
114
149
- Finally, you should see the invocation succeeded and the returned response message body contains "a" or "b" respectively.
115
+ Finally, you should see the invocation succeeded and the returned response message body contains "a" or "b" respectively.
0 commit comments