diff --git a/pom.xml b/pom.xml index 87f6727c..0f9e6aad 100644 --- a/pom.xml +++ b/pom.xml @@ -31,13 +31,7 @@ true - 1.5.7.1 - - 1.6.2 - 1.5.0-alpha.16 - 9.2.6.0 - - DRAFT + 2.0.0-RC.1 scm:git:git@github.com:eclipse-ee4j/jakartaee-tutorial.git @@ -53,101 +47,10 @@ package - - org.apache.maven.plugins - maven-enforcer-plugin - 1.4.1 - - - enforce-versions - - enforce - - - - - [1.8.0,1.9.0) - You need JDK8 or lower - - - - - - - - org.asciidoctor asciidoctor-maven-plugin ${asciidoctor.maven.plugin.version} - - - org.jruby - jruby-complete - ${jruby.version} - - - org.asciidoctor - asciidoctorj - ${asciidoctorj.version} - - - org.asciidoctor - asciidoctorj-pdf - ${asciidoctorj.pdf.version} - - asciidoc-to-html @@ -194,43 +97,7 @@ - - - - - - - - org.glassfish.doc - glassfish-doc-maven-plugin - 1.2 - - - org.apache.maven.plugins - maven-assembly-plugin - 2.4 - - - diff --git a/src/main/asciidoc/batch-processing/batch-processing002.adoc b/src/main/asciidoc/batch-processing/batch-processing002.adoc index c9b02d53..44d6b4eb 100644 --- a/src/main/asciidoc/batch-processing/batch-processing002.adoc +++ b/src/main/asciidoc/batch-processing/batch-processing002.adoc @@ -44,28 +44,14 @@ Java classes to run the jobs in a batch application. The process for creating a batch application in Jakarta EE is the following. -1. Design the batch application. -1. Identify the input sources, the format of the input data, the -desired final result, and the required processing phases. -2. Organize the application as a job with chunk-oriented steps, -task-oriented steps, and decision elements. Determine the dependencies -between them. -3. Determine the order of execution in terms of transitions between -steps. -4. Identify steps that can run in parallel and steps that can run in -more than one thread. -2. Create the batch artifacts as Java classes by implementing the -interfaces specified by the framework for steps, decision elements, and -so on. These Java classes contain the code to read data from input -sources, format items, process items, and store results. Batch artifacts -can access context objects from the batch runtime using dependency -injection. -3. Define jobs, steps, and their execution flow in XML files using the -Job Specification Language. The elements in the XML files reference -batch artifacts implemented as Java classes. The batch artifacts can -access properties declared in the XML files, such as names of files and -databases. -4. Use the Java API provided by the batch runtime to launch the batch +. Design the batch application. +.. Identify the input sources, the format of the input data, the desired final result, and the required processing phases. +.. Organize the application as a job with chunk-oriented steps, task-oriented steps, and decision elements. Determine the dependencies between them. +.. Determine the order of execution in terms of transitions between steps. +.. Identify steps that can run in parallel and steps that can run in more than one thread. +. Create the batch artifacts as Java classes by implementing the interfaces specified by the framework for steps, decision elements, and so on. These Java classes contain the code to read data from input sources, format items, process items, and store results. Batch artifacts can access context objects from the batch runtime using dependency injection. +. Define jobs, steps, and their execution flow in XML files using the Job Specification Language. The elements in the XML files reference batch artifacts implemented as Java classes. The batch artifacts can access properties declared in the XML files, such as names of files and databases. +. Use the Java API provided by the batch runtime to launch the batch application. The following sections describe in detail how to use the components of diff --git a/src/main/asciidoc/bean-validation-advanced/bean-validation-advanced001.adoc b/src/main/asciidoc/bean-validation-advanced/bean-validation-advanced001.adoc index 51ece273..dc1883cd 100644 --- a/src/main/asciidoc/bean-validation-advanced/bean-validation-advanced001.adoc +++ b/src/main/asciidoc/bean-validation-advanced/bean-validation-advanced001.adoc @@ -106,10 +106,10 @@ public String doSomething(String param1, String param2) { ... } In the preceding example, the target is set to the return value of the method. -==== Implementing Temporal Constraints Using ClockProvider - [[implementing-temporal-constraints-using-clockprovider]] +==== Implementing Temporal Constraints Using ClockProvider + In Jakarta Bean Validation 2.0, a Clock instance is available for validator implementations to validate any temporal date or time based constraints. [source,java] ---- @@ -140,9 +140,9 @@ public class CustomConstraintValidator implements ConstraintValidator/domains/domain1/logs/server.log. ---- + -The output from the enterprise beans appears in the server log file. The -Publisher session bean sends two sets of 18 messages numbered 0 through -17. Because of the message selector, the message-driven bean receives -only the messages whose `NewsType` property is `Sports` or `Opinion`. -7. Use the Services tab to undeploy the application after you have -finished running it. +The output from the enterprise beans appears in the server log file. The Publisher session bean sends two sets of 18 messages numbered 0 through 17. Because of the message selector, the message-driven bean receives only the messages whose `NewsType` property is `Sports` or `Opinion`. +. Use the Services tab to undeploy the application after you have finished running it. [[CHDDDHBE]][[to-run-clientsessionmdb-using-maven]] diff --git a/src/main/asciidoc/jsf-configure/jsf-configure013.adoc b/src/main/asciidoc/jsf-configure/jsf-configure013.adoc index df76184c..f26b3876 100644 --- a/src/main/asciidoc/jsf-configure/jsf-configure013.adoc +++ b/src/main/asciidoc/jsf-configure/jsf-configure013.adoc @@ -12,16 +12,13 @@ conform to specific requirements to execute across different containers. At a minimum, a WAR file for a Jakarta Server Faces application may contain the following: -* A web application deployment descriptor, called `web.xml`, to -configure resources required by a web application (required) +* A web application deployment descriptor, called `web.xml`, to configure resources required by a web application (required) * A specific set of JAR files containing essential classes (optional) -* A set of application classes, Jakarta Server Faces pages, and other -required resources, such as image files +* A set of application classes, Jakarta Server Faces pages, and other required resources, such as image files A WAR file may also contain: -* An application configuration resource file, which configures -application resources +* An application configuration resource file, which configures application resources * A set of tag library descriptor files For example, a Java Server Faces web application WAR file using Facelets @@ -58,8 +55,7 @@ configurations, including the following: * The servlet used to process Jakarta Server Faces requests * The servlet mapping for the processing servlet -* The path to the configuration resource file, if it exists and is not -located in a default location +* The path to the configuration resource file, if it exists and is not located in a default location The deployment descriptor can also include other, optional configurations, such as those that @@ -176,20 +172,17 @@ these files. To specify these paths using NetBeans IDE, do the following. -1. Expand the node of your project in the Projects tab. -2. Expand the Web Pages and WEB-INF nodes that are under the project -node. -3. Double-click `web.xml`. -4. After the `web.xml` file appears in the editor, click General at the -top of the editor window. -5. Expand the Context Parameters node. -6. Click Add. -7. In the Add Context Parameter dialog box: -1. Enter `javax.faces.CONFIG_FILES` in the Parameter Name field. -2. Enter the path to your configuration file in the Parameter Value -field. -3. Click OK. -8. Repeat steps 1 through 7 for each configuration file. +. Expand the node of your project in the Projects tab. +. Expand the Web Pages and WEB-INF nodes that are under the project node. +. Double-click `web.xml`. +. After the `web.xml` file appears in the editor, click General at the top of the editor window. +. Expand the Context Parameters node. +. Click Add. +. In the Add Context Parameter dialog box: +.. Enter `javax.faces.CONFIG_FILES` in the Parameter Name field. +.. Enter the path to your configuration file in the Parameter Value field. +.. Click OK. +.. Repeat steps 1 through 7 for each configuration file. [[BNAXN]][[to-specify-where-state-is-saved]] @@ -205,17 +198,16 @@ for information on the advantages and disadvantages of each location. To specify where state is saved using NetBeans IDE, do the following. -1. Expand the node of your project in the Projects tab. -2. Expand the Web Pages and WEB-INF nodes under the project node. -3. Double-click `web.xml`. -4. After the `web.xml` file appears in the editor window, click General -at the top of the editor window. -5. Expand the Context Parameters node. -6. Click Add. -7. In the Add Context Parameter dialog box: -1. Enter `javax.faces.STATE_SAVING_METHOD` in the Parameter Name field. -2. Enter `client` or `server` in the Parameter Value field. -3. Click OK. +. Expand the node of your project in the Projects tab. +. Expand the Web Pages and WEB-INF nodes under the project node. +. Double-click `web.xml`. +. After the `web.xml` file appears in the editor window, click General at the top of the editor window. +. Expand the Context Parameters node. +. Click Add. +. In the Add Context Parameter dialog box: +.. Enter `javax.faces.STATE_SAVING_METHOD` in the Parameter Name field. +.. Enter `client` or `server` in the Parameter Value field. +.. Click OK. If state is saved on the client, the state of the entire view is rendered to a hidden field on the page. The Jakarta Server Faces @@ -261,15 +253,10 @@ When packaging web applications using the included build scripts, you'll notice that the scripts package resources in the following ways. * All web pages are placed at the top level of the WAR file. -* The `faces-config.xml` file and the `web.xml` file are packaged in the -`WEB-INF` directory. +* The `faces-config.xml` file and the `web.xml` file are packaged in the `WEB-INF` directory. * All packages are stored in the `WEB-INF/classes/` directory. -* All application JAR files are packaged in the `WEB-INF/lib/` -directory. -* All resource files are either under the root of the web application -`/resources` directory or in the web application's classpath, the -`META-INF/resources/`resourceIdentifier directory. For more information -on resources, see link:#GIRGM[Web Resources]. +* All application JAR files are packaged in the `WEB-INF/lib/` directory. +* All resource files are either under the root of the web application `/resources` directory or in the web application's classpath, the `META-INF/resources/`resourceIdentifier directory. For more information on resources, see link:#GIRGM[Web Resources]. When packaging your own applications, you can use NetBeans IDE or you can use XML files such as those created for Maven. You can modify the diff --git a/src/main/asciidoc/jsf-custom/jsf-custom004.adoc b/src/main/asciidoc/jsf-custom/jsf-custom004.adoc index 0ab3a346..3fa353f1 100644 --- a/src/main/asciidoc/jsf-custom/jsf-custom004.adoc +++ b/src/main/asciidoc/jsf-custom/jsf-custom004.adoc @@ -5,24 +5,21 @@ You can apply the following steps while developing your own custom component. -1. Create a custom component class that does the following: -1. Overrides the `getFamily` method to return the component family, -which is used to look up renderers that can render the component -2. Includes the rendering code or delegates it to a renderer (explained -in Step link:#CDECBJAE[2]) -3. Enables component attributes to accept expressions -4. Queues an event on the component if the component generates events -5. Saves and restores the component state -2. [[CDECBJAE]] +. Create a custom component class that does the following: +. Overrides the `getFamily` method to return the component family, which is used to look up renderers that can render the component +. Includes the rendering code or delegates it to a renderer (explained in Step link:#CDECBJAE[2]) +. Enables component attributes to accept expressions +. Queues an event on the component if the component generates events +. Saves and restores the component state +. [[CDECBJAE]] Delegate rendering to a renderer if your component does not handle the rendering. To do this: + -Delegate rendering to a renderer if your component does not handle the -rendering. To do this: -1. Create a custom renderer class by extending -`javax.faces.render.Renderer`. -2. Register the renderer to a render kit. -3. Register the component. -4. Create an event handler if your component generates events. -5. Create a tag library descriptor (TLD) that defines the custom tag. +-- +.. Create a custom renderer class by extending `javax.faces.render.Renderer`. +.. Register the renderer to a render kit. +.. Register the component. +.. Create an event handler if your component generates events. +.. Create a tag library descriptor (TLD) that defines the custom tag. +-- See link:#BNAXI[Registering a Custom Component] and link:#BNAXH[Registering a Custom Renderer with a diff --git a/src/main/asciidoc/jsonb/jsonb.adoc b/src/main/asciidoc/jsonb/jsonb.adoc index a637e61a..3ebb8325 100644 --- a/src/main/asciidoc/jsonb/jsonb.adoc +++ b/src/main/asciidoc/jsonb/jsonb.adoc @@ -1,7 +1,7 @@ -=== JSON Binding - [[json-binding]] +=== JSON Binding + This chapter describes the Jakarta JSON Binding. JSON is a data exchange format widely used in web services and other connected applications. For a brief overview of JSON, see link:#introduction-to-json[Introduction to JSON]. diff --git a/src/main/asciidoc/jsonb/jsonb003.adoc b/src/main/asciidoc/jsonb/jsonb003.adoc index 086ec702..54413283 100644 --- a/src/main/asciidoc/jsonb/jsonb003.adoc +++ b/src/main/asciidoc/jsonb/jsonb003.adoc @@ -14,27 +14,15 @@ The following topics are addressed here: * link:#components-of-the-jsonbbasics-example-application[Components of the jsonbbasics Example Application] * link:#running-the-jsonbbasics-example-application[Running the jsonbbasics Example Application] - - [[components-of-the-jsonbbasics-example-application]] ===== Components of the jsonbbasics Example Application The `jsonbbasics` example application contains the following files. * Two JavaServer Faces pages. - -** The `index.xhtml` page contains a form to collect data that is used to -create a `Person` object. - -** The `jsongenerated.xhtml` page contains a text area that displays the data -in JSON format. - -* The `jsonbBean.java` managed bean, which is a session-scoped -managed bean that stores the data from the form and directs the -navigation between the Facelets pages. This file contains code that -uses the JSON Binding API. - - +** The `index.xhtml` page contains a form to collect data that is used to create a `Person` object. +** The `jsongenerated.xhtml` page contains a text area that displays the data in JSON format. +* The `jsonbBean.java` managed bean, which is a session-scoped managed bean that stores the data from the form and directs the navigation between the Facelets pages. This file contains code that uses the JSON Binding API. [[running-the-jsonbbasics-example-application]] ===== Running the jsonbbasics Example Application @@ -42,32 +30,26 @@ uses the JSON Binding API. This section describes how to run the `jsonbbasics` example application from the command line using Maven. - To run the jsonbbasics example application using Maven: - -1. Make sure that GlassFish Server has been started (see -link:#BNADI[Starting and Stopping GlassFish -Server]). -2. In a terminal window, go to: +. Make sure that GlassFish Server has been started (see link:#BNADI[Starting and Stopping GlassFish Server]). +. In a terminal window, go to: + [source,java] ---- tut-install/examples/web/jsonb/jsonbbasics ---- -3. Enter the following command to deploy the application: +. Enter the following command to deploy the application: + [source,java] ---- mvn install ---- -4. Open a web browser window and enter the following address: +. Open a web browser window and enter the following address: + [source,java] ---- http://localhost:8080/jsonbbasics/ ---- -5. Enter data on form and click Serialize to JSON to submit -the form. The following page shows the JSON format of the object data. -6. Click Deserialize JSON. The index page displays and contains the fields populated from -the object data. +. Enter data on form and click Serialize to JSON to submit the form. The following page shows the JSON format of the object data. +. Click Deserialize JSON. The index page displays and contains the fields populated from the object data. diff --git a/src/main/asciidoc/jsonp/jsonp.adoc b/src/main/asciidoc/jsonp/jsonp.adoc index 3daf2490..93e14a2d 100644 --- a/src/main/asciidoc/jsonp/jsonp.adoc +++ b/src/main/asciidoc/jsonp/jsonp.adoc @@ -1,8 +1,7 @@ -=== JSON Processing - - [[json-processing]] +=== JSON Processing + This chapter describes Jakarta JSON Processing. JSON is a data exchange format widely used in web services and other connected applications. Jakarta JSON Processing provides an diff --git a/src/main/asciidoc/partcdi.adoc b/src/main/asciidoc/partcdi.adoc index 2fa87246..fbb45cf7 100644 --- a/src/main/asciidoc/partcdi.adoc +++ b/src/main/asciidoc/partcdi.adoc @@ -8,10 +8,10 @@ Part V explores Jakarta EE Contexts and Dependency Injection (CDI). include::cdi-basic/cdi-basic.adoc[] -include::cdi-basic/cdi-basicexamples.adoc[] +include::cdi-basicexamples/cdi-basicexamples.adoc[] include::cdi-adv/cdi-adv.adoc[] -include::cdi-bootstrap-se/cdi-bootstrap-se8.adoc[] +include::cdi-bootstrap-se8/cdi-bootstrap-se8.adoc[] include::cdi-adv-examples/cdi-adv-examples.adoc[] diff --git a/src/main/asciidoc/persistence-cache/persistence-cache002.adoc b/src/main/asciidoc/persistence-cache/persistence-cache002.adoc index f281d0b0..7e8762e0 100644 --- a/src/main/asciidoc/persistence-cache/persistence-cache002.adoc +++ b/src/main/asciidoc/persistence-cache/persistence-cache002.adoc @@ -224,9 +224,8 @@ if (cache.contains(Person.class, personPK)) { To remove a particular entity or all entities of a given type from the second-level cache: -1. Call one of the `Cache.evict` methods . -1. To remove a particular entity from the cache, call the `evict` -method and pass in the entity class and the primary key of the entity: +. Call one of the `Cache.evict` methods . +.. To remove a particular entity from the cache, call the `evict` method and pass in the entity class and the primary key of the entity: + [source,java] ---- @@ -235,8 +234,7 @@ Cache cache = em.getEntityManagerFactory().getCache(); String personPK = ...; cache.evict(Person.class, personPK); ---- -2. To remove all instances of a particular entity class, including -subclasses, call the `evict` method and specify the entity class: +.. To remove all instances of a particular entity class, including subclasses, call the `evict` method and specify the entity class: + [source,java] ---- diff --git a/src/main/asciidoc/security-advanced/security-advanced002.adoc b/src/main/asciidoc/security-advanced/security-advanced002.adoc index 9c4aee28..c5e5e7db 100644 --- a/src/main/asciidoc/security-advanced/security-advanced002.adoc +++ b/src/main/asciidoc/security-advanced/security-advanced002.adoc @@ -162,36 +162,25 @@ the certificate name to the host name from which it originates. To create a keystore named `client_keystore.jks` that contains a client certificate named `client.cer`, follow these steps. -1. Create a backup copy of the server truststore file. To do this, -1. Change to the directory containing the server's keystore and -truststore files, domain-dir`\config`. -2. Copy `cacerts.jks` to `cacerts.backup.jks`. -3. Copy `keystore.jks` to `keystore.backup.jks`. +. Create a backup copy of the server truststore file. To do this, +.. Change to the directory containing the server's keystore and truststore files, domain-dir`\config`. +.. Copy `cacerts.jks` to `cacerts.backup.jks`. +.. Copy `keystore.jks` to `keystore.backup.jks`. + -Do not put client certificates in the `cacerts.jks` file. Any -certificate you add to the `cacerts` file effectively can be a trusted -root for any and all certificate chains. After you have completed -development, delete the development version of the `cacerts` file and -replace it with the original copy. -2. Generate the client certificate. Enter the following command from -the directory where you want to generate the client certificate: +Do not put client certificates in the `cacerts.jks` file. Any certificate you add to the `cacerts` file effectively can be a trusted root for any and all certificate chains. After you have completed development, delete the development version of the `cacerts` file and replace it with the original copy. +. Generate the client certificate. Enter the following command from the directory where you want to generate the client certificate: + [source,xml] ---- -java-home\bin\keytool -genkey -alias client-alias -keyalg RSA --keypass changeit -storepass changeit -keystore client_keystore.jks +java-home\bin\keytool -genkey -alias client-alias -keyalg RSA -keypass changeit -storepass changeit -keystore client_keystore.jks ---- -3. Export the generated client certificate into the file `client.cer`: +. Export the generated client certificate into the file `client.cer`: + [source,xml] ---- -java-home\bin\keytool -export -alias client-alias -storepass changeit --file client.cer -keystore client_keystore.jks +java-home\bin\keytool -export -alias client-alias -storepass changeit -file client.cer -keystore client_keystore.jks ---- -4. Add the certificate to the truststore file -domain-dir`/config/cacerts.jks`. Run `keytool` from the directory where -you created the keystore and client certificate. Use the following -parameters: +. Add the certificate to the truststore file domain-dir`/config/cacerts.jks`. Run `keytool` from the directory where you created the keystore and client certificate. Use the following parameters: + [source,xml] ---- @@ -217,4 +206,4 @@ Trust this certificate? [no]: yes Certificate was added to keystore [Storing cacerts.jks] ---- -5. Restart GlassFish Server. +. Restart GlassFish Server. diff --git a/src/main/asciidoc/security-api/security-api004.adoc b/src/main/asciidoc/security-api/security-api004.adoc index 90c6ef8f..aab8f753 100644 --- a/src/main/asciidoc/security-api/security-api004.adoc +++ b/src/main/asciidoc/security-api/security-api004.adoc @@ -287,7 +287,7 @@ In this example, use the credentials of user Joe to make a request and to validate the response according to the credentials/roles defined in `DatabaseSetup.java`. -1. Make a request to the deployed application by entering +. Make a request to the deployed application by entering the following request URL in your web browser: + Request URL: @@ -300,7 +300,7 @@ http://localhost:8080/built-in-db-identity-store/servlet Because BASIC authentication is being used here, the container responds back prompting for username and password. -2. Enter the username `Joe`, and the password `secret1` at the prompt. +. Enter the username `Joe`, and the password `secret1` at the prompt. + Once you provide the credentials, the following process occurs: + @@ -331,7 +331,7 @@ web user has role "bar": true web user has role "kaz": false ---- -3. Test the authentication using invalid credentials. Make a request to the +. Test the authentication using invalid credentials. Make a request to the deployed application by entering the following request URL in your web browser: + @@ -345,9 +345,8 @@ http://localhost:8080/built-in-db-identity-store/servlet Again, because BASIC authentication is being used here, the container responds back prompting for username and password. -2. Enter an invalid username and password. +. Enter an invalid username and password. You are promted to enter the credentials again, but you are not authenticated. - + When you click Cancel in the Authentication required window, the following response is returned: diff --git a/src/main/asciidoc/security-webtier/security-webtier004.adoc b/src/main/asciidoc/security-webtier/security-webtier004.adoc index 5dd30dfc..c256b9b2 100644 --- a/src/main/asciidoc/security-webtier/security-webtier004.adoc +++ b/src/main/asciidoc/security-webtier/security-webtier004.adoc @@ -38,26 +38,23 @@ To set up your system for running the security examples, you need to configure a user database that the application can use for authenticating users. Before continuing, follow these steps. -1. Make sure that GlassFish Server has been started (see -link:#BNADI[Starting and Stopping GlassFish -Server]). -2. Add an authorized user to GlassFish Server. For the examples in this +. Make sure that GlassFish Server has been started (see link:#BNADI[Starting and Stopping GlassFish Server]). +. Add an authorized user to GlassFish Server. For the examples in this chapter and in link:#BNBYK[Chapter 52, "Getting Started Securing Enterprise Applications"], add a user to the `file` realm of GlassFish Server, and assign the user to the group `TutorialUser`. -1. From the Administration Console, expand the Configurations node, +.. From the Administration Console, expand the Configurations node, then expand the server-config node. -2. Expand the Security node. -3. Expand the Realms node. -4. Select the File node. -5. On the Edit Realm page, click Manage Users. -6. On the File Users page, click New. -7. In the User ID field, enter a user ID. -8. In the Group List field, enter `TutorialUser`. -9. In the New Password and Confirm New Password fields, enter a -password. -10. Click OK. +.. Expand the Security node. +.. Expand the Realms node. +.. Select the File node. +.. On the Edit Realm page, click Manage Users. +.. On the File Users page, click New. +.. In the User ID field, enter a user ID. +.. In the Group List field, enter `TutorialUser`. +.. In the New Password and Confirm New Password fields, enter a password. +.. Click OK. + Be sure to write down the user name and password for the user you create so that you can use it for testing the example applications. diff --git a/src/main/asciidoc/servlets/servlets002.adoc b/src/main/asciidoc/servlets/servlets002.adoc index e9f3bd2b..d2b5aee6 100644 --- a/src/main/asciidoc/servlets/servlets002.adoc +++ b/src/main/asciidoc/servlets/servlets002.adoc @@ -6,15 +6,11 @@ The lifecycle of a servlet is controlled by the container in which the servlet has been deployed. When a request is mapped to a servlet, the container performs the following steps. -1. If an instance of the servlet does not exist, the web container: -1. Loads the servlet class -2. Creates an instance of the servlet class -3. Initializes the servlet instance by calling the `init` method -(initialization is covered in link:#BNAFU[Creating and -Initializing a Servlet]) -2. The container invokes the `service` method, passing request and -response objects. Service methods are discussed in -link:#BNAFV[Writing Service Methods]. +. If an instance of the servlet does not exist, the web container: +. Loads the servlet class +. Creates an instance of the servlet class +. Initializes the servlet instance by calling the `init` method (initialization is covered in link:#BNAFU[Creating and Initializing a Servlet]) +. The container invokes the `service` method, passing request and response objects. Service methods are discussed in link:#BNAFV[Writing Service Methods]. If it needs to remove the servlet, the container finalizes the servlet by calling the servlet's `destroy` method. For more information, see diff --git a/src/main/asciidoc/servlets/servlets006.adoc b/src/main/asciidoc/servlets/servlets006.adoc index 8d4b10c4..566f16e4 100644 --- a/src/main/asciidoc/servlets/servlets006.adoc +++ b/src/main/asciidoc/servlets/servlets006.adoc @@ -14,10 +14,8 @@ The main tasks that a filter can perform are as follows. * Query the request and act accordingly. * Block the request-and-response pair from passing any further. -* Modify the request headers and data. You do this by providing a -customized version of the request. -* Modify the response headers and data. You do this by providing a -customized version of the response. +* Modify the request headers and data. You do this by providing a customized version of the request. +* Modify the response headers and data. You do this by providing a customized version of the response. * Interact with external resources. Applications of filters include authentication, logging, image @@ -73,20 +71,9 @@ is passed request, response, and filter chain objects. This method can perform the following actions. * Examine the request headers. -* Customize the request object if the filter wishes to modify request -headers or data. -* Customize the response object if the filter wishes to modify response -headers or data. -* Invoke the next entity in the filter chain. If the current filter is -the last filter in the chain that ends with the target web component or -static resource, the next entity is the resource at the end of the -chain; otherwise, it is the next filter that was configured in the WAR. -The filter invokes the next entity by calling the `doFilter` method on -the chain object, passing in the request and response it was called with -or the wrapped versions it may have created. Alternatively, the filter -can choose to block the request by not making the call to invoke the -next entity. In the latter case, the filter is responsible for filling -out the response. +* Customize the request object if the filter wishes to modify request headers or data. +* Customize the response object if the filter wishes to modify response headers or data. +* Invoke the next entity in the filter chain. If the current filter is the last filter in the chain that ends with the target web component or static resource, the next entity is the resource at the end of the chain; otherwise, it is the next filter that was configured in the WAR. The filter invokes the next entity by calling the `doFilter` method on the chain object, passing in the request and response it was called with or the wrapped versions it may have created. Alternatively, the filter can choose to block the request by not making the call to invoke the next entity. In the latter case, the filter is responsible for filling out the response. * Examine response headers after invoking the next filter in the chain. * Throw an exception to indicate an error in processing. @@ -167,39 +154,31 @@ F1's `doFilter` method. ====== To Specify Filter Mappings Using NetBeans IDE -1. Expand the application's project node in the Project tab. -2. Expand the Web Pages and WEB-INF nodes under the project node. -3. Double-click `web.xml`. -4. Click Filters at the top of the editor window. -5. Expand the Servlet Filters node in the editor window. -6. Click Add Filter Element to map the filter to a web resource by name -or by URL pattern. -7. In the Add Servlet Filter dialog box, enter the name of the filter -in the Filter Name field. -8. Click Browse to locate the servlet class to which the filter -applies. +. Expand the application's project node in the Project tab. +. Expand the Web Pages and WEB-INF nodes under the project node. +. Double-click `web.xml`. +. Click Filters at the top of the editor window. +. Expand the Servlet Filters node in the editor window. +. Click Add Filter Element to map the filter to a web resource by name or by URL pattern. +. In the Add Servlet Filter dialog box, enter the name of the filter in the Filter Name field. +. Click Browse to locate the servlet class to which the filter applies. + -You can include wildcard characters so that you can apply the filter to -more than one servlet. -9. Click OK. -10. To constrain how the filter is applied to requests, follow these -steps. -1. Expand the Filter Mappings node. -2. Select the filter from the list of filters. -3. Click Add. -4. In the Add Filter Mapping dialog box, select one of the following -dispatcher types: -* REQUEST: Only when the request comes directly from the client -* ASYNC: Only when the asynchronous request comes from the client -* FORWARD: Only when the request has been forwarded to a component (see -link:#BNAGK[Transferring Control to Another Web -Component]) -* INCLUDE: Only when the request is being processed by a component that -has been included (see link:#BNAGJ[Including Other -Resources in the Response]) -* ERROR: Only when the request is being processed with the error page -mechanism (see link:#BNAFN[Handling Servlet Errors]) +-- +You can include wildcard characters so that you can apply the filter to more than one servlet. +-- +. Click OK. +. To constrain how the filter is applied to requests, follow these steps: + -You can direct the filter to be applied to any combination of the -preceding situations by selecting multiple dispatcher types. If no types -are specified, the default option is REQUEST. +-- +.. Expand the Filter Mappings node. +.. Select the filter from the list of filters. +.. Click Add. +.. In the Add Filter Mapping dialog box, select one of the following dispatcher types: +... REQUEST: Only when the request comes directly from the client +... ASYNC: Only when the asynchronous request comes from the client +... FORWARD: Only when the request has been forwarded to a component (see link:#BNAGK[Transferring Control to Another Web Component]) +... INCLUDE: Only when the request is being processed by a component that has been included (see link:#BNAGJ[Including Other Resources in the Response]) +... ERROR: Only when the request is being processed with the error page mechanism (see link:#BNAFN[Handling Servlet Errors]) + +You can direct the filter to be applied to any combination of the preceding situations by selecting multiple dispatcher types. If no types are specified, the default option is REQUEST. +--