more readmes
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a632f9d7 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a632f9d7 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a632f9d7 Branch: refs/heads/master Commit: a632f9d7f7643d54e76b13a331438fa627970150 Parents: 7125321 Author: Jean-Louis Monteiro <jeano...@gmail.com> Authored: Thu Dec 27 09:02:03 2018 +0100 Committer: Jean-Louis Monteiro <jeano...@gmail.com> Committed: Thu Dec 27 09:02:03 2018 +0100 ---------------------------------------------------------------------- examples/cdi-session-scope/README.md | 244 +++++++++++++-------------- examples/mp-metrics-metered/README.md | 260 ++++++++++++++--------------- 2 files changed, 252 insertions(+), 252 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/a632f9d7/examples/cdi-session-scope/README.md ---------------------------------------------------------------------- diff --git a/examples/cdi-session-scope/README.md b/examples/cdi-session-scope/README.md index 0b14fbe..3ca2080 100644 --- a/examples/cdi-session-scope/README.md +++ b/examples/cdi-session-scope/README.md @@ -1,122 +1,122 @@ -index-group=Unrevised -type=page -status=unpublished -title=CDI @SessionScoped -~~~~~~ - -This example show the use of `@SessionScoped` annotation for injected objects. An object -which is defined as `@SessionScoped` is created once for every HTTPSession and is shared by all the -beans that inject it throughout the same HTTPSession. - -##### Run the application: - - mvn clean install tomee:run - -# Example - -This example has an end point wherein a user provides a request parameter 'name' which is persisted as a feild in a session scoped bean SessionBean and -then retrieved through another endpoint. - -#Request - -GET http://localhost:8080/cdi-session-scope-8.0.0-SNAPSHOT/set-name?name=Puneeth - -#Response - -done, go to /name servlet - -#Request - -GET http://localhost:8080/cdi-session-scope-8.0.0-SNAPSHOT/name - -#Response - -name = {Puneeth} - -##SessionBean - -The annotation @SessionScoped specifies that a bean is session scoped ie there will be only one instance of the class associated with a particular -HTTPSession. - -@SessionScoped -public class SessionBean implements Serializable { - - private String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} - -##InputServlet - -InputServlet is a generic servlet which is mapped to the url pattern '/set-name'. -The session scoped bean 'SessionBean' has been injected into this servlet, and the incoming request parameter is set to the feild name of the bean. - -@WebServlet(name = "input-servlet", urlPatterns = {"/set-name"}) -public class InputServlet extends HttpServlet { - - @Inject - private SessionBean bean; - - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - final String name = req.getParameter("name"); - if (name == null || name.isEmpty()) { - resp.getWriter().write("please add a parameter name=xxx"); - } else { - bean.setName(name); - resp.getWriter().write("done, go to /name servlet"); - } - - } -} - -##AnswerBean - -AnswerBean is a request scoped bean with an injected 'SessionBean'. It has an postconstruct method wherein the value from the sessionBean is retrieved and set to a feild. - -public class AnswerBean { - - @Inject - private SessionBean bean; - - private String value; - - @PostConstruct - public void init() { - value = '{' + bean.getName() + '}'; - } - - public String value() { - return value; - } -} - -##OutputServlet - -OutputServlet is another servlet with 'AnswerBean' as an injected feild. When '/name' is called the value from 'Answerbean' is read and written to the response. - -@WebServlet(name = "output-servlet", urlPatterns = {"/name"}) -public class OutputServlet extends HttpServlet { - - @Inject - private AnswerBean bean; - - @Override - protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - final String name = bean.value(); - if (name == null || name.isEmpty()) { - resp.getWriter().write("please go to servlet /set-name please"); - } else { - resp.getWriter().write("name = " + name); - } - } -} - - - +index-group=Unrevised +type=page +status=unpublished +title=CDI @SessionScoped +~~~~~~ + +This example show the use of `@SessionScoped` annotation for injected objects. An object +which is defined as `@SessionScoped` is created once for every HTTPSession and is shared by all the +beans that inject it throughout the same HTTPSession. + +##### Run the application: + + mvn clean install tomee:run + +# Example + +This example has an end point wherein a user provides a request parameter 'name' which is persisted as a feild in a session scoped bean SessionBean and +then retrieved through another endpoint. + +#Request + +GET http://localhost:8080/cdi-session-scope-8.0.0-SNAPSHOT/set-name?name=Puneeth + +#Response + +done, go to /name servlet + +#Request + +GET http://localhost:8080/cdi-session-scope-8.0.0-SNAPSHOT/name + +#Response + +name = {Puneeth} + +##SessionBean + +The annotation @SessionScoped specifies that a bean is session scoped ie there will be only one instance of the class associated with a particular +HTTPSession. + +@SessionScoped +public class SessionBean implements Serializable { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + +##InputServlet + +InputServlet is a generic servlet which is mapped to the url pattern '/set-name'. +The session scoped bean 'SessionBean' has been injected into this servlet, and the incoming request parameter is set to the feild name of the bean. + +@WebServlet(name = "input-servlet", urlPatterns = {"/set-name"}) +public class InputServlet extends HttpServlet { + + @Inject + private SessionBean bean; + + @Override + protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + final String name = req.getParameter("name"); + if (name == null || name.isEmpty()) { + resp.getWriter().write("please add a parameter name=xxx"); + } else { + bean.setName(name); + resp.getWriter().write("done, go to /name servlet"); + } + + } +} + +##AnswerBean + +AnswerBean is a request scoped bean with an injected 'SessionBean'. It has an postconstruct method wherein the value from the sessionBean is retrieved and set to a feild. + +public class AnswerBean { + + @Inject + private SessionBean bean; + + private String value; + + @PostConstruct + public void init() { + value = '{' + bean.getName() + '}'; + } + + public String value() { + return value; + } +} + +##OutputServlet + +OutputServlet is another servlet with 'AnswerBean' as an injected feild. When '/name' is called the value from 'Answerbean' is read and written to the response. + +@WebServlet(name = "output-servlet", urlPatterns = {"/name"}) +public class OutputServlet extends HttpServlet { + + @Inject + private AnswerBean bean; + + @Override + protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + final String name = bean.value(); + if (name == null || name.isEmpty()) { + resp.getWriter().write("please go to servlet /set-name please"); + } else { + resp.getWriter().write("name = " + name); + } + } +} + + + http://git-wip-us.apache.org/repos/asf/tomee/blob/a632f9d7/examples/mp-metrics-metered/README.md ---------------------------------------------------------------------- diff --git a/examples/mp-metrics-metered/README.md b/examples/mp-metrics-metered/README.md index 8008fbe..fed2d52 100644 --- a/examples/mp-metrics-metered/README.md +++ b/examples/mp-metrics-metered/README.md @@ -1,130 +1,130 @@ -index-group=Unrevised -type=page -status=published -~~~~~~ -# Microprofile Metrics -This is an example on how to use microprofile metrics in TomEE. - -##### Run the application: - - mvn clean install tomee:run - -Within the application, there is an enpoint that will give you a weather weather status for the day and week. - -##### For the day status call: - - GET http://localhost:8080/mp-metrics-metered/weather/day/status - -##### Response: - - Hi, today is a sunny day! - -#### Metered Feature -MicroProfile metrics has a feature that can be used to find the rate of requests to a service. - -To use this feature you need to annotate the JAX-RS resource method with @Metered. - - @Path("/weather") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApplicationScoped - public class WeatherService { - - @Path("/day/status") - @Metered(name = "dailyStatus", unit = MetricUnits.MINUTES, description = "Metrics to daily weather status method", absolute = true) - @GET - @Produces(MediaType.TEXT_PLAIN) - public String dayStatus() { - return "Hi, today is a sunny day!"; - } - ... - } - -There are some configurations, as part of @Metered, that you need to know: - -**String name** -Optional. Sets the name of the metric. If not explicitly given the name of the annotated object is used. - -**boolean absolute** -If true, uses the given name as the absolute name of the metric. If false, prepends the package name and class name before the given name. Default value is false. - -**String displayName** -Optional. A human-readable display name for metadata. - -**String description** -Optional. A description of the metric. - -**String[] tags** -Optional. Array of Strings in the <key>=<value> format to supply special tags to a metric. - -**boolean reusable** -Denotes if a metric with a certain name can be registered in more than one place. Does not apply to gauges. - -**String unit** -Unit of the metric. Default for @Metered is nanoseconds. - -#### Metric data - -Check the Metered metric doing a _GET_ request: - -##### Prometheus format: - - GET http://localhost:8080/mp-metrics-metered/metrics/application/dailyStatus - -##### Response: - - # TYPE application:daily_status_seconds_count meter - application:daily_status_seconds_count 1.2E-7 - # TYPE application:daily_status_rate_per_second meter - application:daily_status_rate_per_second 0.0 - # TYPE application:daily_status_one_min_rate_per_second meter - application:daily_status_one_min_rate_per_second 1.3376002644204984E-19 - # TYPE application:daily_status_five_min_rate_per_second meter - application:daily_status_five_min_rate_per_second 3.5942838529305413E-20 - # TYPE application:daily_status_fifteen_min_rate_per_second meter - application:daily_status_fifteen_min_rate_per_second 3.4665766454142955E-21 - - -##### JSON Format: - -For json format add the header _Accept=application/json_ to the request. - - { - "dailyStatus": { - "count": 2, - "fifteenMinRate": 5.77762774235716e-14, - "fiveMinRate": 5.990473088217569e-13, - "meanRate": 0, - "oneMinRate": 2.229333774034164e-12, - "unit": "minutes" - } - } - -#### Metric metadata -A metric will have a metadata so you can know more information about it, like displayName, description, tags etc. - -Check the metric metadata doing a _OPTIONS_ request: - -##### Request - - OPTIONS http://localhost:8080/mp-metrics-metered/metrics/application/dailyStatus - -##### Response: - - { - "dailyStatus": { - "description": "Metrics to daily weather status method", - "displayName": "", - "name": "dailyStatus", - "reusable": false, - "tags": "", - "type": "meter", - "typeRaw": "METERED", - "unit": "minutes" - } - } - - -##### Test the application: - - mvn test +index-group=Unrevised +type=page +status=published +~~~~~~ +# Microprofile Metrics +This is an example on how to use microprofile metrics in TomEE. + +##### Run the application: + + mvn clean install tomee:run + +Within the application, there is an enpoint that will give you a weather weather status for the day and week. + +##### For the day status call: + + GET http://localhost:8080/mp-metrics-metered/weather/day/status + +##### Response: + + Hi, today is a sunny day! + +#### Metered Feature +MicroProfile metrics has a feature that can be used to find the rate of requests to a service. + +To use this feature you need to annotate the JAX-RS resource method with @Metered. + + @Path("/weather") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApplicationScoped + public class WeatherService { + + @Path("/day/status") + @Metered(name = "dailyStatus", unit = MetricUnits.MINUTES, description = "Metrics to daily weather status method", absolute = true) + @GET + @Produces(MediaType.TEXT_PLAIN) + public String dayStatus() { + return "Hi, today is a sunny day!"; + } + ... + } + +There are some configurations, as part of @Metered, that you need to know: + +**String name** +Optional. Sets the name of the metric. If not explicitly given the name of the annotated object is used. + +**boolean absolute** +If true, uses the given name as the absolute name of the metric. If false, prepends the package name and class name before the given name. Default value is false. + +**String displayName** +Optional. A human-readable display name for metadata. + +**String description** +Optional. A description of the metric. + +**String[] tags** +Optional. Array of Strings in the <key>=<value> format to supply special tags to a metric. + +**boolean reusable** +Denotes if a metric with a certain name can be registered in more than one place. Does not apply to gauges. + +**String unit** +Unit of the metric. Default for @Metered is nanoseconds. + +#### Metric data + +Check the Metered metric doing a _GET_ request: + +##### Prometheus format: + + GET http://localhost:8080/mp-metrics-metered/metrics/application/dailyStatus + +##### Response: + + # TYPE application:daily_status_seconds_count meter + application:daily_status_seconds_count 1.2E-7 + # TYPE application:daily_status_rate_per_second meter + application:daily_status_rate_per_second 0.0 + # TYPE application:daily_status_one_min_rate_per_second meter + application:daily_status_one_min_rate_per_second 1.3376002644204984E-19 + # TYPE application:daily_status_five_min_rate_per_second meter + application:daily_status_five_min_rate_per_second 3.5942838529305413E-20 + # TYPE application:daily_status_fifteen_min_rate_per_second meter + application:daily_status_fifteen_min_rate_per_second 3.4665766454142955E-21 + + +##### JSON Format: + +For json format add the header _Accept=application/json_ to the request. + + { + "dailyStatus": { + "count": 2, + "fifteenMinRate": 5.77762774235716e-14, + "fiveMinRate": 5.990473088217569e-13, + "meanRate": 0, + "oneMinRate": 2.229333774034164e-12, + "unit": "minutes" + } + } + +#### Metric metadata +A metric will have a metadata so you can know more information about it, like displayName, description, tags etc. + +Check the metric metadata doing a _OPTIONS_ request: + +##### Request + + OPTIONS http://localhost:8080/mp-metrics-metered/metrics/application/dailyStatus + +##### Response: + + { + "dailyStatus": { + "description": "Metrics to daily weather status method", + "displayName": "", + "name": "dailyStatus", + "reusable": false, + "tags": "", + "type": "meter", + "typeRaw": "METERED", + "unit": "minutes" + } + } + + +##### Test the application: + + mvn test