Skip to content

Commit d231913

Browse files
committed
adding more details
1 parent 46fda18 commit d231913

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

README.asciidoc

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ Servlet
2121
Persistence
2222
-----------
2323

24-
* Right-click on project, select ``Properties'', search for ``facet'', enable ``JPA'', click on ``Apply'', talk about ``Further configuration available'' and default data source
25-
* Create a new entity `Student`
24+
* Right-click on project, select ``Properties'', search for ``facet'', enable ``JPA'', click on ``Apply''
25+
** Talk about ``Further configuration available'' and default data source (no configuration required)
26+
* Right-click on project, select ``New'', ``JPA Entity'' and give the name as `Student`
2627
* Add a primary key in the wizard. Use `long` datatype and `id` name.
2728
* Generate Getter/Setter by clicking ``Source'', ``Getters and Setters''.
2829
* Add `toString` implementation
@@ -97,6 +98,7 @@ RESTful Web Services
9798
--------------------
9899

99100
* Create a JAX-RS resource `StudentEndpoint`
101+
** `rest.RestApplication` is added and specifies the base URI for REST resoures as `/rest`.
100102
** Use `Student` entity as the basis, select `create`, `findById`, `listAll` methods to be generated.
101103
* Add `@XmlRootElement` in `Student` entity to enable XML <-> Java conversion.
102104
* Add `@NamedQuery(name="findAllStudents", query="select s from Student s")` to `Student` to enable querying all students.
@@ -142,30 +144,22 @@ public class StudentEndpoint {
142144
----
143145
+
144146
* Use ``Advanced REST Client'' in Chrome
145-
** Make a GET request
147+
** Make a GET request to http://localhost:8080/EclipseCon/rest/students
146148
*** Add Accept: application/xml
147149
*** Show empty response
148150
** Make a POST request
149151
*** Payload as `1`
150152
*** ``Content-Type'' header to `text/plain`
151153
** Make a GET request to validate the data is posted
152-
** Change `create` method to add Bean Validation constraint
153-
+
154-
[source,java]
155-
----
156-
public void create(@Min(10) final long id) {
157-
----
158-
+
159-
** Make a POST request with payload as `1` and show an error is being received
160-
* Edit `doGet` of `TestServlet to match the code given below
154+
* Edit `doGet` of `TestServlet` to match the code given below
161155
+
162156
[source,java]
163157
----
164158
ServletOutputStream out = response.getOutputStream();
165159
out.print("Retrieving results ...");
166160
Client client = ClientBuilder.newClient();
167161
Student[] result = client
168-
.target("http://localhost:8080/helloworld/rest/students")
162+
.target("http://localhost:8080/HelloJavaEE7/rest/students")
169163
.request()
170164
.get(Student[].class);
171165
for (Student s : result) {
@@ -175,6 +169,19 @@ for (Student s : result) {
175169
* Access the Servlet in the browser to show the results and explain JAX-RS Client API
176170
177171
172+
Bean Validation
173+
---------------
174+
175+
* Change `create` method to add Bean Validation constraint
176+
+
177+
[source,java]
178+
----
179+
public void create(@Min(10) final long id) {
180+
----
181+
+
182+
* Make a POST request with payload as `1` and show an error is being received
183+
184+
178185
CDI
179186
---
180187

@@ -187,7 +194,20 @@ public interface Greeting {
187194
}
188195
----
189196
+
190-
* Create a new class `SimpleGreeting`, implement the interface
197+
* Create a new class `SimpleGreeting`, implement the interface as:
198+
+
199+
[source, java]
200+
----
201+
public class SimpleGreeting implements Greeting {
202+
203+
@Override
204+
public String sayHello() {
205+
return "Hello World";
206+
}
207+
208+
}
209+
----
210+
+
191211
* Inject the bean in Servlet as `@Inject Greeting greeting;`
192212
* Print the output as `response.getOutputStream().print(greeting.sayHello());`
193213
* Show ``New missing/unsatisfied dependencies'' error and explain default injection

0 commit comments

Comments
 (0)