Lesson 3 (JAX-RS and Servlets) Flashcards

1
Q

What is a servlet?

A

A servlet is some kind of progam running in another program (broker). The broker sends the requests to the server. The broker is responsible to send data back to the client. The servlet program can handle custom steps from a request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a servlet engine? Give an example.

A

For example Tomcat. Tomcat is a Servlet Engine that handles servlet requests for apache. Its like a helper application, its like a servlet container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which servlet-method is called in response to a http GET-command?

A

doGet method is called automatically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which annotation is used in JAVA-RS to specify the relative path of a resource?

A

@Path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
The doGet method of the httpServlet class contains two parameters. The first parameter is of the
class HttpServletRequest. Describe the second parameter.
A

The HttpServletResponse. This is used for preparing the response in the code. It also provides a writer to write the output of the response object as a response to the original request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some JAX-RS annotations and what are they used for?

A

@Path url pattern
@GET as http method
@Procudes as mime type for the response data.
@Consumes content type for the request data
@FormParam / @HeaderParam/ @CookieParam to bind those values to the request or response. Those kind of things.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some JAX-RS implementations in existing solutions?

A

CFX (Apache)
Jersey (from Sun/Oracle)
RESTeasy from Jboss

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What do you need to create a JAX-RS project?

A

A maven project with the jersey as a library included in the POM (kind of manifest) file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some webservers and how do they work?

A

Apache or Nginx, they are very popular and they listen on various ports using the HTTP protocol to serve requests and responses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does a servlet work?

A

1 Client sends a requets to the server
2 Server starts the right servlet
3 Servlets computes a result for the server and does not quit
4 server returns the response to the client
5 Another client sends a request
6 Server calls the same servlet .

A servlet is instantiated like a singleton.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How is a servlet instantiated?

A

The init(config) method is called first and only once. Servlets order can be defined with params, like when you want to start a server as first, or always want to start it BEFORE anything else gets called. The servlet must be thread safe. Finally when its shutdown it calles destroy()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the methods called int the servlets after executing a request?

A

doGet, doPost. doPut, doDelete.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can a servlet retrieve data from the POST?

A

by calling request.getParam if it was a form/url parameter. If there is just a JSON object, the request reader has to be used to read the input stream. Then be parsed to a JSON object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does the url encoding work?

A

Special characters and spaces are replaces, for example a space is %20.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How are request paramters retrieved by different methods? How can you find out which ones are available?

A

getParameterNames() > all that is available by key
getParameter(name) > value for one specific parameter
getParameterValues(name) > used for array values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What kind of datatype is a paramter returned in a servlet?

A

Always as a string. So it has to be formatted to other data types to be using it as an int or other.