Added: tomee/site/trunk/content/tomee-8.0/pt/examples/cdi-session-scope.html URL: http://svn.apache.org/viewvc/tomee/site/trunk/content/tomee-8.0/pt/examples/cdi-session-scope.html?rev=1866567&view=auto ============================================================================== --- tomee/site/trunk/content/tomee-8.0/pt/examples/cdi-session-scope.html (added) +++ tomee/site/trunk/content/tomee-8.0/pt/examples/cdi-session-scope.html Sat Sep 7 20:31:05 2019 @@ -0,0 +1,362 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Apache TomEE</title> + <meta name="description" + content="Apache TomEE is a lightweight, yet powerful, JavaEE Application server with feature rich tooling." /> + <meta name="keywords" content="tomee,asf,apache,javaee,jee,shade,embedded,test,junit,applicationcomposer,maven,arquillian" /> + <meta name="author" content="Luka Cvetinovic for Codrops" /> + <link rel="icon" href="../../../favicon.ico"> + <link rel="icon" type="image/png" href="../../../favicon.png"> + <meta name="msapplication-TileColor" content="#80287a"> + <meta name="theme-color" content="#80287a"> + <link rel="stylesheet" type="text/css" href="../../../css/normalize.css"> + <link rel="stylesheet" type="text/css" href="../../../css/bootstrap.css"> + <link rel="stylesheet" type="text/css" href="../../../css/owl.css"> + <link rel="stylesheet" type="text/css" href="../../../css/animate.css"> + <link rel="stylesheet" type="text/css" href="../../../fonts/font-awesome-4.1.0/css/font-awesome.min.css"> + <link rel="stylesheet" type="text/css" href="../../../fonts/eleganticons/et-icons.css"> + <link rel="stylesheet" type="text/css" href="../../../css/jqtree.css"> + <link rel="stylesheet" type="text/css" href="../../../css/idea.css"> + <link rel="stylesheet" type="text/css" href="../../../css/cardio.css"> + + <script type="text/javascript"> + + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-2717626-1']); + _gaq.push(['_setDomainName', 'apache.org']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + + </script> +</head> + +<body> + <div class="preloader"> + <img src="../../../img/loader.gif" alt="Preloader image"> + </div> + <nav class="navbar"> + <div class="container"> + <div class="row"> <div class="col-md-12"> + + <!-- Brand and toggle get grouped for better mobile display --> + <div class="navbar-header"> + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + </button> + <a class="navbar-brand" href="/"> + <span> + + + <img src="../../../img/logo-active.png"> + + + </span> + Apache TomEE + </a> + </div> + <!-- Collect the nav links, forms, and other content for toggling --> + <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> + <ul class="nav navbar-nav navbar-right main-nav"> + <li><a href="../../../docs.html">Documentation</a></li> + <li><a href="../../../community/index.html">Community</a></li> + <li><a href="../../../security/security.html">Security</a></li> + <li><a href="../../../download-ng.html">Downloads</a></li> + </ul> + </div> + <!-- /.navbar-collapse --> + </div></div> + </div> + <!-- /.container-fluid --> + </nav> + + + <div id="main-block" class="container main-block"> + <div class="row title"> + <div class="col-md-12"> + <div class='page-header'> + + <h1>CDI @SessionScoped</h1> + </div> + </div> + </div> + <div class="row"> + + <div class="col-md-12"> + <div id="preamble"> +<div class="sectionbody"> +<div class="paragraph"> +<p>Este exemplo mostra o uso da anotação <code>@SessionScoped</code> para objetos injetados. Um objeto que é definido +como <code>@SessionScoped</code> é criado para cada HTTPSession e é compartilhado por todos os beans que o injetam +através do mesmo HTTPSession.</p> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_execute_a_aplicação">Execute a aplicação:</h2> +<div class="sectionbody"> +<div class="literalblock"> +<div class="content"> +<pre>mvn clean install tomee:run</pre> +</div> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_exemplo">Exemplo</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p>Este exemplo tem um endpoint em que um usuário fornece um <code>name</code> no parâmetro da requisição, que é +persistido como um field em um session scoped bean chamado <code>SessionBean</code> e então é recuperado por outro +endpoint.</p> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_requisição">Requisição</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p>GET <a href="http://localhost:8080/cdi-session-scope/set-name?name=Puneeth" class="bare">http://localhost:8080/cdi-session-scope/set-name?name=Puneeth</a></p> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_resposta">Resposta</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p><code>done, go to /name servlet</code></p> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_requisição_2">Requisição</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p>GET <a href="http://localhost:8080/cdi-session-scope/name" class="bare">http://localhost:8080/cdi-session-scope/name</a></p> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_resposta_2">Resposta</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p>name = {Puneeth}</p> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_sessionbean">SessionBean</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p>A anotação <code>@SessionScoped</code> especifica que este bean tem escopo de sessão, então haverá apenas uma +instância dessa classe associada a uma HTTPSession particular.</p> +</div> +<div class="listingblock"> +<div class="content"> +<pre class="highlight"><code class="language-java" data-lang="java">@SessionScoped +public class SessionBean implements Serializable { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +}</code></pre> +</div> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_inputservlet">InputServlet</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p><code>InputServlet</code> é um servlet genérico que é mapeado pela url <code>/set-name</code>. O bean de escopo de sessão +<code>SessionBean</code> foi injetado neste servlet, e o parâmetro de entrada da requisição sera atribuÃdo ao field +<code>name</code> do bean.</p> +</div> +<div class="listingblock"> +<div class="content"> +<pre class="highlight"><code class="language-java" data-lang="java">@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"); + } + + } +}</code></pre> +</div> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_answerbean">AnswerBean</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p>O bean <code>AnswerBean</code> tem escopo de requisição com um <code>SessionBean</code> injetado. Ele contem um método +<code>@PostConstruct</code> em que o valor do campo <code>name</code> do <code>SessionBean</code> é recuperado e atribuÃdo ao campo <code>value</code>.</p> +</div> +<div class="listingblock"> +<div class="content"> +<pre class="highlight"><code class="language-java" data-lang="java">public class AnswerBean { + + @Inject + private SessionBean bean; + + private String value; + + @PostConstruct + public void init() { + value = '{' + bean.getName() + '}'; + } + + public String value() { + return value; + } +}</code></pre> +</div> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_outputservlet">OutputServlet</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p><code>OutputServlet</code> é outro servlet com o <code>AnswerBean</code> injetado. Quando <code>/name</code> é chamado o valor do <code>AnswerBean</code> +é lido e escrito na resposta.</p> +</div> +<div class="listingblock"> +<div class="content"> +<pre class="highlight"><code class="language-java" data-lang="java">@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); + } + } +}</code></pre> +</div> +</div> +</div> +</div> + </div> + + </div> + </div> +<footer> + <div class="container"> + <div class="row"> + <div class="col-sm-6 text-center-mobile"> + <h3 class="white">Be simple. Be certified. Be Tomcat.</h3> + <h5 class="light regular light-white">"A good application in a good server"</h5> + <ul class="social-footer"> + <li><a href="https://www.facebook.com/ApacheTomEE/"><i class="fa fa-facebook"></i></a></li> + <li><a href="https://twitter.com/apachetomee"><i class="fa fa-twitter"></i></a></li> + <li><a href="https://plus.google.com/communities/105208241852045684449"><i class="fa fa-google-plus"></i></a></li> + </ul> + </div> + <div class="col-sm-6 text-center-mobile"> + <div class="row opening-hours"> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../latest/docs/documentation.html" class="white">Documentation</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../latest/docs/admin/configuration/index.html" class="regular light-white">How to configure</a></li> + <li><a href="../../../latest/docs/admin/file-layout.html" class="regular light-white">Dir. Structure</a></li> + <li><a href="../../../latest/docs/developer/testing/index.html" class="regular light-white">Testing</a></li> + <li><a href="../../../latest/docs/admin/cluster/index.html" class="regular light-white">Clustering</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../latest/examples/" class="white">Examples</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../latest/examples/simple-cdi-interceptor.html" class="regular light-white">CDI Interceptor</a></li> + <li><a href="../../../latest/examples/rest-cdi.html" class="regular light-white">REST with CDI</a></li> + <li><a href="../../../latest/examples/ejb-examples.html" class="regular light-white">EJB</a></li> + <li><a href="../../../latest/examples/jsf-managedBean-and-ejb.html" class="regular light-white">JSF</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../community/index.html" class="white">Community</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../community/contributors.html" class="regular light-white">Contributors</a></li> + <li><a href="../../../community/social.html" class="regular light-white">Social</a></li> + <li><a href="../../../community/sources.html" class="regular light-white">Sources</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../security/index.html" class="white">Security</a></h5> + <ul class="list-unstyled"> + <li><a href="http://apache.org/security" target="_blank" class="regular light-white">Apache Security</a></li> + <li><a href="http://apache.org/security/projects.html" target="_blank" class="regular light-white">Security Projects</a></li> + <li><a href="http://cve.mitre.org" target="_blank" class="regular light-white">CVE</a></li> + </ul> + </div> + </div> + </div> + </div> + <div class="row bottom-footer text-center-mobile"> + <div class="col-sm-12 light-white"> + <p>Copyright © 1999-2016 The Apache Software Foundation, Licensed under the Apache License, Version 2.0. Apache TomEE, TomEE, Apache, the Apache feather logo, and the Apache TomEE project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.</p> + </div> + </div> + </div> + </footer> + <!-- Holder for mobile navigation --> + <div class="mobile-nav"> + <ul> + <li><a hef="../../../latest/docs/admin/index.html">Administrators</a> + <li><a hef="../../../latest/docs/developer/index.html">Developers</a> + <li><a hef="../../../latest/docs/advanced/index.html">Advanced</a> + <li><a hef="../../../community/index.html">Community</a> + </ul> + <a href="#" class="close-link"><i class="arrow_up"></i></a> + </div> + <!-- Scripts --> + <script src="../../../js/jquery-1.11.1.min.js"></script> + <script src="../../../js/owl.carousel.min.js"></script> + <script src="../../../js/bootstrap.min.js"></script> + <script src="../../../js/wow.min.js"></script> + <script src="../../../js/typewriter.js"></script> + <script src="../../../js/jquery.onepagenav.js"></script> + <script src="../../../js/tree.jquery.js"></script> + <script src="../../../js/highlight.pack.js"></script> + <script src="../../../js/main.js"></script> + </body> + +</html> +
Added: tomee/site/trunk/content/tomee-8.0/pt/examples/change-jaxws-url.html URL: http://svn.apache.org/viewvc/tomee/site/trunk/content/tomee-8.0/pt/examples/change-jaxws-url.html?rev=1866567&view=auto ============================================================================== --- tomee/site/trunk/content/tomee-8.0/pt/examples/change-jaxws-url.html (added) +++ tomee/site/trunk/content/tomee-8.0/pt/examples/change-jaxws-url.html Sat Sep 7 20:31:05 2019 @@ -0,0 +1,291 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Apache TomEE</title> + <meta name="description" + content="Apache TomEE is a lightweight, yet powerful, JavaEE Application server with feature rich tooling." /> + <meta name="keywords" content="tomee,asf,apache,javaee,jee,shade,embedded,test,junit,applicationcomposer,maven,arquillian" /> + <meta name="author" content="Luka Cvetinovic for Codrops" /> + <link rel="icon" href="../../../favicon.ico"> + <link rel="icon" type="image/png" href="../../../favicon.png"> + <meta name="msapplication-TileColor" content="#80287a"> + <meta name="theme-color" content="#80287a"> + <link rel="stylesheet" type="text/css" href="../../../css/normalize.css"> + <link rel="stylesheet" type="text/css" href="../../../css/bootstrap.css"> + <link rel="stylesheet" type="text/css" href="../../../css/owl.css"> + <link rel="stylesheet" type="text/css" href="../../../css/animate.css"> + <link rel="stylesheet" type="text/css" href="../../../fonts/font-awesome-4.1.0/css/font-awesome.min.css"> + <link rel="stylesheet" type="text/css" href="../../../fonts/eleganticons/et-icons.css"> + <link rel="stylesheet" type="text/css" href="../../../css/jqtree.css"> + <link rel="stylesheet" type="text/css" href="../../../css/idea.css"> + <link rel="stylesheet" type="text/css" href="../../../css/cardio.css"> + + <script type="text/javascript"> + + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-2717626-1']); + _gaq.push(['_setDomainName', 'apache.org']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + + </script> +</head> + +<body> + <div class="preloader"> + <img src="../../../img/loader.gif" alt="Preloader image"> + </div> + <nav class="navbar"> + <div class="container"> + <div class="row"> <div class="col-md-12"> + + <!-- Brand and toggle get grouped for better mobile display --> + <div class="navbar-header"> + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + </button> + <a class="navbar-brand" href="/"> + <span> + + + <img src="../../../img/logo-active.png"> + + + </span> + Apache TomEE + </a> + </div> + <!-- Collect the nav links, forms, and other content for toggling --> + <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> + <ul class="nav navbar-nav navbar-right main-nav"> + <li><a href="../../../docs.html">Documentation</a></li> + <li><a href="../../../community/index.html">Community</a></li> + <li><a href="../../../security/security.html">Security</a></li> + <li><a href="../../../download-ng.html">Downloads</a></li> + </ul> + </div> + <!-- /.navbar-collapse --> + </div></div> + </div> + <!-- /.container-fluid --> + </nav> + + + <div id="main-block" class="container main-block"> + <div class="row title"> + <div class="col-md-12"> + <div class='page-header'> + + <h1>Alterar JAXWS URL</h1> + </div> + </div> + </div> + <div class="row"> + + <div class="col-md-12"> + <div class="paragraph"> +<p>Para alterar a URI de um web service, uma solução é usar o arquivo <code>openejb-jar.xml</code>.</p> +</div> +<div class="paragraph"> +<p>Neste exemplo temos um web service através da classe <code>Rot13</code>:</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre>package org.superbiz.jaxws; + +import javax.ejb.Lock; +import javax.ejb.LockType; +import javax.ejb.Singleton; +import javax.jws.WebService; + +@Lock(LockType.READ) +@Singleton +@WebService +public class Rot13 { + public String rot13(final String in) { + final StringBuilder builder = new StringBuilder(in.length()); + for (int b : in.toCharArray()) { + int cap = b & 32; + b &= ~cap; + if (Character.isUpperCase(b)) { + b = (b - 'A' + 13) % 26 + 'A'; + } else { + b = cap; + } + b |= cap; + builder.append((char) b); + } + return builder.toString(); + } +}</pre> +</div> +</div> +<div class="paragraph"> +<p>Decidimos fazer o deploy na url <code>/tool/rot13</code>.</p> +</div> +<div class="paragraph"> +<p>Para fazer isso, primeiro temos que definir a rota no arquivo <code>openejb-jar.xml</code>:</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre><?xml version="1.0" encoding="UTF-8"?> +<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1"> + <enterprise-beans> + <session> + <ejb-name>Rot13</ejb-name> + <web-service-address>/tool/rot13</web-service-address> + </session> + </enterprise-beans> +</openejb-jar></pre> +</div> +</div> +<div class="paragraph"> +<p>Isto não é o bastante, por que, por padrão o TomEE faz o deploy do web service +com um subcontexto chamado <code>webservices</code>. Para evitar isto simplesmente informe +a propriedade <code>tomee.jaxws.subcontext</code> para <code>/</code> (feito no arquivo <code>arquillian.xml</code> +para nosso teste).</p> +</div> +<div class="paragraph"> +<p>Agora fizemos o deploy do nosso web service <code>Rot13</code> como esperado no contexto +<code>/tool/rot13</code> e vamos verificar isto com o Arquillian e o TomEE embedded:</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre> package org.superbiz.jaxws; + + import org.apache.ziplock.IO; + import org.jboss.arquillian.container.test.api.Deployment; + import org.jboss.arquillian.junit.Arquillian; + import org.jboss.arquillian.test.api.ArquillianResource; + import org.jboss.shrinkwrap.api.ArchivePaths; + import org.jboss.shrinkwrap.api.ShrinkWrap; + import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset; + import org.jboss.shrinkwrap.api.spec.WebArchive; + import org.junit.AfterClass; + import org.junit.BeforeClass; + import org.junit.Test; + import org.junit.runner.RunWith; + + import java.net.URL; + + import static org.junit.Assert.assertThat; + import static org.junit.internal.matchers.StringContains.containsString; + + @RunWith(Arquillian.class) + public class Rot13Test { + @ArquillianResource + private URL url; + + @Deployment(testable = false) + public static WebArchive war() { + return ShrinkWrap.create(WebArchive.class) + .addClass(Rot13.class) + .addAsWebInfResource(new ClassLoaderAsset("META-INF/openejb-jar.xml"), ArchivePaths.create("openejb-jar.xml")); + } + + @Test + public void checkWSDLIsDeployedWhereItIsConfigured() throws Exception { + final String wsdl = IO.slurp(new URL(url.toExternalForm() + "tool/rot13?wsdl")); + assertThat(wsdl, containsString("Rot13")); + } + }</pre> +</div> +</div> + </div> + + </div> + </div> +<footer> + <div class="container"> + <div class="row"> + <div class="col-sm-6 text-center-mobile"> + <h3 class="white">Be simple. Be certified. Be Tomcat.</h3> + <h5 class="light regular light-white">"A good application in a good server"</h5> + <ul class="social-footer"> + <li><a href="https://www.facebook.com/ApacheTomEE/"><i class="fa fa-facebook"></i></a></li> + <li><a href="https://twitter.com/apachetomee"><i class="fa fa-twitter"></i></a></li> + <li><a href="https://plus.google.com/communities/105208241852045684449"><i class="fa fa-google-plus"></i></a></li> + </ul> + </div> + <div class="col-sm-6 text-center-mobile"> + <div class="row opening-hours"> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../latest/docs/documentation.html" class="white">Documentation</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../latest/docs/admin/configuration/index.html" class="regular light-white">How to configure</a></li> + <li><a href="../../../latest/docs/admin/file-layout.html" class="regular light-white">Dir. Structure</a></li> + <li><a href="../../../latest/docs/developer/testing/index.html" class="regular light-white">Testing</a></li> + <li><a href="../../../latest/docs/admin/cluster/index.html" class="regular light-white">Clustering</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../latest/examples/" class="white">Examples</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../latest/examples/simple-cdi-interceptor.html" class="regular light-white">CDI Interceptor</a></li> + <li><a href="../../../latest/examples/rest-cdi.html" class="regular light-white">REST with CDI</a></li> + <li><a href="../../../latest/examples/ejb-examples.html" class="regular light-white">EJB</a></li> + <li><a href="../../../latest/examples/jsf-managedBean-and-ejb.html" class="regular light-white">JSF</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../community/index.html" class="white">Community</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../community/contributors.html" class="regular light-white">Contributors</a></li> + <li><a href="../../../community/social.html" class="regular light-white">Social</a></li> + <li><a href="../../../community/sources.html" class="regular light-white">Sources</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../security/index.html" class="white">Security</a></h5> + <ul class="list-unstyled"> + <li><a href="http://apache.org/security" target="_blank" class="regular light-white">Apache Security</a></li> + <li><a href="http://apache.org/security/projects.html" target="_blank" class="regular light-white">Security Projects</a></li> + <li><a href="http://cve.mitre.org" target="_blank" class="regular light-white">CVE</a></li> + </ul> + </div> + </div> + </div> + </div> + <div class="row bottom-footer text-center-mobile"> + <div class="col-sm-12 light-white"> + <p>Copyright © 1999-2016 The Apache Software Foundation, Licensed under the Apache License, Version 2.0. Apache TomEE, TomEE, Apache, the Apache feather logo, and the Apache TomEE project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.</p> + </div> + </div> + </div> + </footer> + <!-- Holder for mobile navigation --> + <div class="mobile-nav"> + <ul> + <li><a hef="../../../latest/docs/admin/index.html">Administrators</a> + <li><a hef="../../../latest/docs/developer/index.html">Developers</a> + <li><a hef="../../../latest/docs/advanced/index.html">Advanced</a> + <li><a hef="../../../community/index.html">Community</a> + </ul> + <a href="#" class="close-link"><i class="arrow_up"></i></a> + </div> + <!-- Scripts --> + <script src="../../../js/jquery-1.11.1.min.js"></script> + <script src="../../../js/owl.carousel.min.js"></script> + <script src="../../../js/bootstrap.min.js"></script> + <script src="../../../js/wow.min.js"></script> + <script src="../../../js/typewriter.js"></script> + <script src="../../../js/jquery.onepagenav.js"></script> + <script src="../../../js/tree.jquery.js"></script> + <script src="../../../js/highlight.pack.js"></script> + <script src="../../../js/main.js"></script> + </body> + +</html> + Added: tomee/site/trunk/content/tomee-8.0/pt/examples/cloud-tomee-azure.html URL: http://svn.apache.org/viewvc/tomee/site/trunk/content/tomee-8.0/pt/examples/cloud-tomee-azure.html?rev=1866567&view=auto ============================================================================== --- tomee/site/trunk/content/tomee-8.0/pt/examples/cloud-tomee-azure.html (added) +++ tomee/site/trunk/content/tomee-8.0/pt/examples/cloud-tomee-azure.html Sat Sep 7 20:31:05 2019 @@ -0,0 +1,339 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Apache TomEE</title> + <meta name="description" + content="Apache TomEE is a lightweight, yet powerful, JavaEE Application server with feature rich tooling." /> + <meta name="keywords" content="tomee,asf,apache,javaee,jee,shade,embedded,test,junit,applicationcomposer,maven,arquillian" /> + <meta name="author" content="Luka Cvetinovic for Codrops" /> + <link rel="icon" href="../../../favicon.ico"> + <link rel="icon" type="image/png" href="../../../favicon.png"> + <meta name="msapplication-TileColor" content="#80287a"> + <meta name="theme-color" content="#80287a"> + <link rel="stylesheet" type="text/css" href="../../../css/normalize.css"> + <link rel="stylesheet" type="text/css" href="../../../css/bootstrap.css"> + <link rel="stylesheet" type="text/css" href="../../../css/owl.css"> + <link rel="stylesheet" type="text/css" href="../../../css/animate.css"> + <link rel="stylesheet" type="text/css" href="../../../fonts/font-awesome-4.1.0/css/font-awesome.min.css"> + <link rel="stylesheet" type="text/css" href="../../../fonts/eleganticons/et-icons.css"> + <link rel="stylesheet" type="text/css" href="../../../css/jqtree.css"> + <link rel="stylesheet" type="text/css" href="../../../css/idea.css"> + <link rel="stylesheet" type="text/css" href="../../../css/cardio.css"> + + <script type="text/javascript"> + + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-2717626-1']); + _gaq.push(['_setDomainName', 'apache.org']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + + </script> +</head> + +<body> + <div class="preloader"> + <img src="../../../img/loader.gif" alt="Preloader image"> + </div> + <nav class="navbar"> + <div class="container"> + <div class="row"> <div class="col-md-12"> + + <!-- Brand and toggle get grouped for better mobile display --> + <div class="navbar-header"> + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + </button> + <a class="navbar-brand" href="/"> + <span> + + + <img src="../../../img/logo-active.png"> + + + </span> + Apache TomEE + </a> + </div> + <!-- Collect the nav links, forms, and other content for toggling --> + <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> + <ul class="nav navbar-nav navbar-right main-nav"> + <li><a href="../../../docs.html">Documentation</a></li> + <li><a href="../../../community/index.html">Community</a></li> + <li><a href="../../../security/security.html">Security</a></li> + <li><a href="../../../download-ng.html">Downloads</a></li> + </ul> + </div> + <!-- /.navbar-collapse --> + </div></div> + </div> + <!-- /.container-fluid --> + </nav> + + + <div id="main-block" class="container main-block"> + <div class="row title"> + <div class="col-md-12"> + <div class='page-header'> + + <h1>Implantação de TomEE no Azure</h1> + </div> + </div> + </div> + <div class="row"> + + <div class="col-md-12"> + <div id="preamble"> +<div class="sectionbody"> +<div class="paragraph"> +<p>Este exemplo usa um aplicativo de echo básico, implantado com o TomEE incorporado na nuvem do Azure.</p> +</div> +<div class="paragraph"> +<p>Usamos o plugin do maven do TomEE para empacotar o aplicativo com o TomEE Embedded +a fim de gerar um fat jar. Este jar é então escolhido e deployado pelo azure-webapp-maven-plugin.</p> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_configuração_do_azure">Configuração do Azure</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p>Para que o plug-in do Azure funcione, você precisará ter uma conta do Azure e adicionar uma assinatura a ela.</p> +</div> +<div class="paragraph"> +<p>Então, em sua máquina de desenvolvimento, instale a interface da linha de comandos (CLI) do Azure e faça a autenticação com a linha de comando, +antes que você possa implantar seu aplicativo.</p> +</div> +<div class="ulist"> +<ul> +<li> +<p>Crie uma conta Azure, se você não tem uma, faça aqui <a href="https://azure.microsoft.com/en-us" class="bare">https://azure.microsoft.com/en-us</a></p> +</li> +<li> +<p>Use a opção free, se disponÃvel ou <a href="https://portal.azure.com/#blade/Microsoft_Azure_Billing/SubscriptionsBlade">adicione uma assinatura</a>.</p> +</li> +<li> +<p><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">Instale</a> o Azure (CLI) de acordo com o sistema operacional do computador que você está usando para desenvolver.</p> +</li> +<li> +<p>Finalmente, você pode configurar seu computador de desenvolvimento.</p> +</li> +</ul> +</div> +<div class="sect2"> +<h3 id="_fazendo_login_no_azure">Fazendo login no Azure</h3> +<div class="paragraph"> +<p><code>az login</code></p> +</div> +<div class="paragraph"> +<p>O resultado:</p> +</div> +<div class="listingblock"> +<div class="content"> +<pre>[ + { + "cloudName": "AzureCloud", + "id": "aaaaaaaa-aaaa-aaaa-aaaaa-aaaaaaaaaa", + "isDefault": true, + "name": "Pay-As-You-Go", + "state": "Enabled", + "tenantId": "bbbbbbb-bbbbb-bbbb-bbbbb-bbbbbbbbbbb", + "user": { + "name": "<o email da sua conta azure>", + "type": "user" + } + } + ]</pre> +</div> +</div> +<div class="paragraph"> +<p>O TenantId é alguém que pode registrar e gerenciar aplicativos por conta própria. Você precisará disso para mais tarde.</p> +</div> +</div> +<div class="sect2"> +<h3 id="_criando_um_service_principal">Criando um service principal</h3> +<div class="paragraph"> +<p>Um Azure service principal é uma identidade de segurança usada por aplicativos, serviços e ferramentas de automação para acessar recursos especÃficos do Azure:</p> +</div> +<div class="listingblock"> +<div class="content"> +<pre>az ad sp create-for-rbac --name http://<seu-sub-domÃnio> --password <password para este aplicativo> + +{ + "appId": "cccccccc-cccc-cccc-cccc-ccccccccccccccc", + "displayName": "cloud-tomee-azure", + "name": "http://cloud-tomee-azure", + "password": "<password for this app>", + "tenant": "bbbbbbb-bbbbb-bbbb-bbbbb-bbbbbbbbbbb" +}</pre> +</div> +</div> +<div class="paragraph"> +<p>O <seu-sub-domÃnio>, também é chamado de service principal name (nome principal do serviço) na documentação do Azure. +Neste exemplo "http://cloud-tomee-azure" tem que ser exclusivo no Azure. +O appId é a identificação do serviço de aplicativo.</p> +</div> +</div> +<div class="sect2"> +<h3 id="_configurando_o_maven">Configurando o Maven</h3> +<div class="paragraph"> +<p>Você pode continuar usando apenas a CLI do Azure para autenticação, mas também podemos fazê-lo permanentemente com o Maven.</p> +</div> +<div class="paragraph"> +<p>Nesse caso, precisamos editar o arquivo settings.xml do Maven para que o plugin azure-webapp-maven possa autenticar no Azure:</p> +</div> +<div class="paragraph"> +<p>Você pode adicionar um novo servidor em <code>~ / .m2 / settings.xml</code> assim:</p> +</div> +<div class="listingblock"> +<div class="content"> +<pre><server> + <id>azure-auth</id> + <configuration> + <client>cccccccc-cccc-cccc-cccc-ccccccccccccccc</client> + <tenant>bbbbbbb-bbbbb-bbbb-bbbbb-bbbbbbbbbbb</tenant> + <key><password para este aplicativo></key> + <environment>AZURE</environment> + </configuration> +</server></pre> +</div> +</div> +<div class="paragraph"> +<p>à isso aÃ. Agora você pode criar o exemplo e implantá-lo no Azure usando o Maven:</p> +</div> +<div class="paragraph"> +<p><code>mvn clean install -Pazure-single-jar azure-webapp:deploy</code></p> +</div> +<div class="paragraph"> +<p>O azure-webapp é explicitamente chamado porque depende de sua conta do Azure. O build padrão do TomEE não usará uma conta do Azure.</p> +</div> +<div class="paragraph"> +<p>O URL final será semelhante a:</p> +</div> +<div class="paragraph"> +<p><code><a href="https://<your-sub-domain>.azurewebsites.net/cloud-tomee-azure-8.0.0-SNAPSHOT/echo/send-this-back" class="bare">https://<your-sub-domain>.azurewebsites.net/cloud-tomee-azure-8.0.0-SNAPSHOT/echo/send-this-back</a></code></p> +</div> +<div class="sect3"> +<h4 id="_notas">Notas</h4> +<div class="paragraph"> +<p>No momento da criação deste exemplo, há um erro no azure com o JAVA_HOME que impede a implementação. +Verificar: <a href="https://github.com/Azure-App-Service/java/issues/11" class="bare">https://github.com/Azure-App-Service/java/issues/11</a> +A solução é definir a variável de ambiente no console da Web do Azure e reiniciar o aplicativo.</p> +</div> +<div class="paragraph"> +<p>Para implantar o aplicativo de echo localmente, você pode executar:</p> +</div> +<div class="paragraph"> +<p><code>mvn tomee:run</code></p> +</div> +<div class="paragraph"> +<p>Você pode testar o aplicativo chamando <code><a href="http://localhost/cloud-tomee-azure-8.0.0-SNAPSHOT/echo/send-this-back" class="bare">http://localhost/cloud-tomee-azure-8.0.0-SNAPSHOT/echo/send-this-back</a></code></p> +</div> +<div class="paragraph"> +<p>Ele retornará send-this-back.</p> +</div> +<div class="paragraph"> +<p>O aplicativo echo também está disponÃvel com um arquivo war simples que você pode implantar no TomEE manualmente, para fins de teste.</p> +</div> +</div> +</div> +</div> +</div> + </div> + + </div> + </div> +<footer> + <div class="container"> + <div class="row"> + <div class="col-sm-6 text-center-mobile"> + <h3 class="white">Be simple. Be certified. Be Tomcat.</h3> + <h5 class="light regular light-white">"A good application in a good server"</h5> + <ul class="social-footer"> + <li><a href="https://www.facebook.com/ApacheTomEE/"><i class="fa fa-facebook"></i></a></li> + <li><a href="https://twitter.com/apachetomee"><i class="fa fa-twitter"></i></a></li> + <li><a href="https://plus.google.com/communities/105208241852045684449"><i class="fa fa-google-plus"></i></a></li> + </ul> + </div> + <div class="col-sm-6 text-center-mobile"> + <div class="row opening-hours"> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../latest/docs/documentation.html" class="white">Documentation</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../latest/docs/admin/configuration/index.html" class="regular light-white">How to configure</a></li> + <li><a href="../../../latest/docs/admin/file-layout.html" class="regular light-white">Dir. Structure</a></li> + <li><a href="../../../latest/docs/developer/testing/index.html" class="regular light-white">Testing</a></li> + <li><a href="../../../latest/docs/admin/cluster/index.html" class="regular light-white">Clustering</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../latest/examples/" class="white">Examples</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../latest/examples/simple-cdi-interceptor.html" class="regular light-white">CDI Interceptor</a></li> + <li><a href="../../../latest/examples/rest-cdi.html" class="regular light-white">REST with CDI</a></li> + <li><a href="../../../latest/examples/ejb-examples.html" class="regular light-white">EJB</a></li> + <li><a href="../../../latest/examples/jsf-managedBean-and-ejb.html" class="regular light-white">JSF</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../community/index.html" class="white">Community</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../community/contributors.html" class="regular light-white">Contributors</a></li> + <li><a href="../../../community/social.html" class="regular light-white">Social</a></li> + <li><a href="../../../community/sources.html" class="regular light-white">Sources</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../security/index.html" class="white">Security</a></h5> + <ul class="list-unstyled"> + <li><a href="http://apache.org/security" target="_blank" class="regular light-white">Apache Security</a></li> + <li><a href="http://apache.org/security/projects.html" target="_blank" class="regular light-white">Security Projects</a></li> + <li><a href="http://cve.mitre.org" target="_blank" class="regular light-white">CVE</a></li> + </ul> + </div> + </div> + </div> + </div> + <div class="row bottom-footer text-center-mobile"> + <div class="col-sm-12 light-white"> + <p>Copyright © 1999-2016 The Apache Software Foundation, Licensed under the Apache License, Version 2.0. Apache TomEE, TomEE, Apache, the Apache feather logo, and the Apache TomEE project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.</p> + </div> + </div> + </div> + </footer> + <!-- Holder for mobile navigation --> + <div class="mobile-nav"> + <ul> + <li><a hef="../../../latest/docs/admin/index.html">Administrators</a> + <li><a hef="../../../latest/docs/developer/index.html">Developers</a> + <li><a hef="../../../latest/docs/advanced/index.html">Advanced</a> + <li><a hef="../../../community/index.html">Community</a> + </ul> + <a href="#" class="close-link"><i class="arrow_up"></i></a> + </div> + <!-- Scripts --> + <script src="../../../js/jquery-1.11.1.min.js"></script> + <script src="../../../js/owl.carousel.min.js"></script> + <script src="../../../js/bootstrap.min.js"></script> + <script src="../../../js/wow.min.js"></script> + <script src="../../../js/typewriter.js"></script> + <script src="../../../js/jquery.onepagenav.js"></script> + <script src="../../../js/tree.jquery.js"></script> + <script src="../../../js/highlight.pack.js"></script> + <script src="../../../js/main.js"></script> + </body> + +</html> + Added: tomee/site/trunk/content/tomee-8.0/pt/examples/concurrency-utils.html URL: http://svn.apache.org/viewvc/tomee/site/trunk/content/tomee-8.0/pt/examples/concurrency-utils.html?rev=1866567&view=auto ============================================================================== --- tomee/site/trunk/content/tomee-8.0/pt/examples/concurrency-utils.html (added) +++ tomee/site/trunk/content/tomee-8.0/pt/examples/concurrency-utils.html Sat Sep 7 20:31:05 2019 @@ -0,0 +1,593 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Apache TomEE</title> + <meta name="description" + content="Apache TomEE is a lightweight, yet powerful, JavaEE Application server with feature rich tooling." /> + <meta name="keywords" content="tomee,asf,apache,javaee,jee,shade,embedded,test,junit,applicationcomposer,maven,arquillian" /> + <meta name="author" content="Luka Cvetinovic for Codrops" /> + <link rel="icon" href="../../../favicon.ico"> + <link rel="icon" type="image/png" href="../../../favicon.png"> + <meta name="msapplication-TileColor" content="#80287a"> + <meta name="theme-color" content="#80287a"> + <link rel="stylesheet" type="text/css" href="../../../css/normalize.css"> + <link rel="stylesheet" type="text/css" href="../../../css/bootstrap.css"> + <link rel="stylesheet" type="text/css" href="../../../css/owl.css"> + <link rel="stylesheet" type="text/css" href="../../../css/animate.css"> + <link rel="stylesheet" type="text/css" href="../../../fonts/font-awesome-4.1.0/css/font-awesome.min.css"> + <link rel="stylesheet" type="text/css" href="../../../fonts/eleganticons/et-icons.css"> + <link rel="stylesheet" type="text/css" href="../../../css/jqtree.css"> + <link rel="stylesheet" type="text/css" href="../../../css/idea.css"> + <link rel="stylesheet" type="text/css" href="../../../css/cardio.css"> + + <script type="text/javascript"> + + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-2717626-1']); + _gaq.push(['_setDomainName', 'apache.org']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + + </script> +</head> + +<body> + <div class="preloader"> + <img src="../../../img/loader.gif" alt="Preloader image"> + </div> + <nav class="navbar"> + <div class="container"> + <div class="row"> <div class="col-md-12"> + + <!-- Brand and toggle get grouped for better mobile display --> + <div class="navbar-header"> + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + </button> + <a class="navbar-brand" href="/"> + <span> + + + <img src="../../../img/logo-active.png"> + + + </span> + Apache TomEE + </a> + </div> + <!-- Collect the nav links, forms, and other content for toggling --> + <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> + <ul class="nav navbar-nav navbar-right main-nav"> + <li><a href="../../../docs.html">Documentation</a></li> + <li><a href="../../../community/index.html">Community</a></li> + <li><a href="../../../security/security.html">Security</a></li> + <li><a href="../../../download-ng.html">Downloads</a></li> + </ul> + </div> + <!-- /.navbar-collapse --> + </div></div> + </div> + <!-- /.container-fluid --> + </nav> + + + <div id="main-block" class="container main-block"> + <div class="row title"> + <div class="col-md-12"> + <div class='page-header'> + + <h1>Utilitário de Concorrência para o Java EE</h1> + </div> + </div> + </div> + <div class="row"> + + <div class="col-md-12"> + <div id="preamble"> +<div class="sectionbody"> +<div class="paragraph"> +<p>Neste exemplo será usado o <a href="https://docs.oracle.com/javaee/7/tutorial/concurrency-utilities.htm">Utilitário de Concorrência para Java EE</a>, ou JSR 236.</p> +</div> +<div class="paragraph"> +<p>Esse padrão permite que os desenvolvedores de aplicativos usem utilitários de concorrência gerenciados pelo servidor de aplicação. +Dessa forma, o desenvolvedor não tem mais a responsabilidade de gerenciar manualmente pesquisas de thread ou threads. +Além disso, em um objeto de thread não gerenciado, o contêiner não pode garantir que outros serviços da plataforma Java EE funcionem corretamente. Por esses motivos, é recomendável o uso de threads gerenciadas sempre que a necessidade surgir. +Mais informações podem ser encontradas <a href="https://docs.oracle.com/javaee/7/tutorial/concurrency-utilities001.htm">aqui</a>.</p> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="_principais_componentes_do_utilitário_de_concorrência">Principais Componentes do Utilitário de Concorrência</h2> +<div class="sectionbody"> +<div class="paragraph"> +<p>O padrão especifica os componentes principais do utilitário de concorrência. Em suma, esses componentes são objetos gerenciados que oferecem facilidades de concorrência. Esses objetos, uma vez que são gerenciados pelo aplicativo, podem ser injetados usando CDI ou JNDI. Mais informações podem ser encontradas <a href="https://docs.oracle.com/javaee/7/tutorial/concurrency-utilities002.htm">aqui</a>.</p> +</div> +<div class="sect2"> +<h3 id="_managedexecutorservice">ManagedExecutorService</h3> +<div class="paragraph"> +<p>Um <code>ManagedExecutorService</code> é um objeto que permite ao desenvolvedor do aplicativo enviar tarefas de forma assÃncrona. As tarefas são executadas em threads que são gerenciadas pelo contêiner.</p> +</div> +<div class="sect3"> +<h4 id="_exemplo">Exemplo</h4> +<div class="paragraph"> +<p>Aqui está a classe que usa um <code>ManagedExecutorService</code> (código completo pode ser encontrado <a href="https://github.com/apache/tomee/blob/master/examples/concurrency-utils/src/main/java/org/superbiz/executor/ManagedService.java">aqui</a>):</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre>@RequestScoped +public class ManagedService { + + @Resource + private ManagedExecutorService executor; + + public CompletableFuture<Integer> asyncTask(final int value) { + return CompletableFuture + .supplyAsync(longTask(value, 100, null), executor) + .thenApply(i -> i + 1); + } + + public CompletableFuture<Integer> asyncTaskWithException(final int value) { + return CompletableFuture + .supplyAsync(longTask(value, 100, "Planned exception"), executor) + .thenApply(i -> i + 1); + } + + private Supplier<Integer> longTask(final int value, + final int taskDurationMs, + final String errorMessage) { + return () -> { + if (nonNull(errorMessage)) { + throw new RuntimeException(errorMessage); + } + + try { + TimeUnit.MILLISECONDS.sleep(taskDurationMs); + } catch (InterruptedException e) { + throw new RuntimeException("Problem while waiting"); + } + return value + 1; + }; + } + +}</pre> +</div> +</div> +<div class="paragraph"> +<p>O objeto <code>ManagedExecutorService</code>, está sendo gerenciado, é injetado usando a anotação <code>@Resource</code>.</p> +</div> +<div class="paragraph"> +<p>Esse exemplo simula uma computação de longa execução, definida no método <code>longTask</code>.</p> +</div> +<div class="paragraph"> +<p>As capacidades do <code>ManagedExecutorService</code> são exemplificadas nos métodos <code>asyncTask</code> e <code>asyncTaskWithException</code>. +Os dois métodos invocam o método <code>longTask`definido acima; cada execução do `longTask</code> é feita em uma thread gerenciada pela aplicação. +O método <code>asyncTask</code> simula uma execução bem sucedida, enquanto o <code>asyncTaskWithException</code> simula uma execução que vai lançar uma exceção.</p> +</div> +<div class="paragraph"> +<p>Os métodos são usados na seguinte classe de teste (exemplo completo pode ser encontrado <a href="https://github.com/apache/tomee/blob/master/examples/concurrency-utils/src/test/java/org/superbiz/executor/ManagedServiceTest.java">aqui</a>):</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre>@RunWith(Arquillian.class) +public class ManagedServiceTest { + + @Inject + private ManagedService managedService; + + @Deployment() + public static final WebArchive app() { + return ShrinkWrap.create(WebArchive.class, "example.war") + .addClasses(ManagedService.class) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + public void managedInvocationTest() { + final CompletableFuture<Integer> future = managedService.asyncTask(1); + try { + assertEquals(3, future.get(200, TimeUnit.MILLISECONDS).intValue()); + } catch (Exception e) { + fail("Unexpected exception" + e); + } + } + + @Test(expected = TimeoutException.class) + public void managedInvocationTestWithTimeout() throws InterruptedException, ExecutionException, TimeoutException { + final CompletableFuture<Integer> future = managedService.asyncTask(1); + future.get(10, TimeUnit.MILLISECONDS); + } + + @Test + public void managedInvocationTestWithException() { + final CompletableFuture<Integer> future = managedService.asyncTaskWithException(1); + + try { + future.get(200, TimeUnit.MILLISECONDS); + } catch (ExecutionException e) { + assertEquals("Planned exception", e.getCause().getMessage()); + } catch (Exception e) { + fail("Unexpected exception" + e); + } + } +}</pre> +</div> +</div> +</div> +</div> +<div class="sect2"> +<h3 id="_managedscheduledexecutorservice">ManagedScheduledExecutorService</h3> +<div class="paragraph"> +<p>Um <code>ManagedScheduledExecutorService</code> é um objeto que permite que os desenvolvedores executem tarefas assÃncronas em momentos especÃficos. As tarefas são executadas em threads iniciadas pelo contêiner.</p> +</div> +<div class="sect3"> +<h4 id="_exemplo_2">Exemplo</h4> +<div class="paragraph"> +<p>Exemplo completo pode ser encontrado <a href="https://github.com/apache/tomee/blob/master/examples/concurrency-utils/src/main/java/org/superbiz/executor/ManagedScheduledService.java">aqui</a>:</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre>@RequestScoped +public class ManagedScheduledService { + + @Resource + private ManagedScheduledExecutorService executor; + + public Future<Integer> singleFixedDelayTask(final int value, + final String errorMessage) { + return executor.schedule( + longCallableTask(value, 10, errorMessage), 100, TimeUnit.MILLISECONDS); + } + + public ScheduledFuture<?> periodicFixedDelayTask(final int value, + final String errorMessage, + final CountDownLatch countDownLatch) { + return executor.scheduleAtFixedRate( + longRunnableTask(value, 10, errorMessage, countDownLatch), 0, 100, TimeUnit.MILLISECONDS); + } + + private Runnable longRunnableTask(final int value, + final int taskDurationMs, + final String errorMessage, + final CountDownLatch countDownLatch) { + return () -> { + failOrWait(taskDurationMs, errorMessage); + Integer result = value + 1; + countDownLatch.countDown(); + }; + } + + private Callable<Integer> longCallableTask(final int value, + final int taskDurationMs, + final String errorMessage) { + return () -> { + failOrWait(taskDurationMs, errorMessage); + return value + 1; + }; + } + + private void failOrWait(final int taskDurationMs, + final String errorMessage) { + if (nonNull(errorMessage)) { + throw new RuntimeException(errorMessage); + } + try { + TimeUnit.MILLISECONDS.sleep(taskDurationMs); + } catch (InterruptedException e) { + throw new RuntimeException("Problem while waiting"); + } + } + +}</pre> +</div> +</div> +<div class="paragraph"> +<p>Esse exemplo também define um método, <code>longCallableTask</code>, simulando a execução de uma computação de longa duração.</p> +</div> +<div class="paragraph"> +<p>O método <code>singleFixedDelayTask</code> agenda uma tarefa de longa duração (chamando <code>longCallableTask</code>), mas a execução vai iniciar depois de 100 ms. +O método <code>periodicFixedDelayTask</code> agenda tarefas para serem executadas periodicamente, após cada 100 ms, com um delay inicial de 0.</p> +</div> +<div class="paragraph"> +<p>Os metódos são usados nas seguintes classes de teste (código completo pode ser encontrado <a href="https://github.com/apache/tomee/blob/master/examples/concurrency-utils/src/test/java/org/superbiz/executor/ManagedScheduledServiceTest.java">aqui</a>):</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre>@RunWith(Arquillian.class) +public class ManagedScheduledServiceTest { + + @Inject + private ManagedScheduledService scheduledService; + + @Deployment() + public static final WebArchive app() { + return ShrinkWrap.create(WebArchive.class, "example.war") + .addClasses(ManagedScheduledService.class) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + public void singleFixedDelayTask() throws InterruptedException, ExecutionException, TimeoutException { + final Future<Integer> futureA = scheduledService.singleFixedDelayTask(1, null); + final Future<Integer> futureB = scheduledService.singleFixedDelayTask(50, null); + + assertEquals(2, futureA.get(200, TimeUnit.MILLISECONDS).intValue()); + assertEquals(51, futureB.get(200, TimeUnit.MILLISECONDS).intValue()); + + } + + @Test + public void periodicFixedDelayTask() throws InterruptedException { + final CountDownLatch countDownLatch = new CountDownLatch(4); // execute 4 times + final ScheduledFuture<?> scheduledFuture = scheduledService.periodicFixedDelayTask(1, null, countDownLatch); + countDownLatch.await(500, TimeUnit.MILLISECONDS); + if (!scheduledFuture.isCancelled()) { + scheduledFuture.cancel(true); + } + } + + @Test + public void singleFixedDelayTaskWithException() { + final Future<Integer> future = scheduledService.singleFixedDelayTask(1, "Planned exception"); + try { + future.get(200, TimeUnit.MILLISECONDS); + } catch (ExecutionException e) { + assertEquals("Planned exception", e.getCause().getMessage()); + } catch (Exception e) { + fail("Unexpected exception" + e); + } + } + + @Test + public void periodicFixedDelayTaskWithException() { + final CountDownLatch countDownLatch = new CountDownLatch(1); + final ScheduledFuture<?> scheduledFuture = scheduledService.periodicFixedDelayTask(1, "Planned exception", countDownLatch); + + try { + countDownLatch.await(200, TimeUnit.MILLISECONDS); + scheduledFuture.get(200, TimeUnit.MILLISECONDS); + } catch (ExecutionException e) { + assertEquals("Planned exception", e.getCause().getMessage()); + } catch (Exception e) { + fail("Unexpected exception" + e); + } + + if (!scheduledFuture.isCancelled()) { + scheduledFuture.cancel(true); + } + } + +}</pre> +</div> +</div> +</div> +</div> +<div class="sect2"> +<h3 id="_managedthreadfactory">ManagedThreadFactory</h3> +<div class="paragraph"> +<p>Um <code>ManagedThreadFactory</code> é um objeto que permite aos desenvolvedores criar threads gerenciadas por contêiner.</p> +</div> +<div class="sect3"> +<h4 id="_exemplo_3">Exemplo</h4> +<div class="paragraph"> +<p>Exemplo completo pode ser encontrado <a href="https://github.com/apache/tomee/blob/master/examples/concurrency-utils/src/main/java/org/superbiz/executor/ThreadFactoryService.java">aqui</a>:</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre>@RequestScoped +public class ThreadFactoryService { + + @Resource + private ManagedThreadFactory factory; + + public void asyncTask(final LongTask longTask) throws InterruptedException { + final Thread thread = factory.newThread(longTask); + thread.setName("pretty asyncTask"); + thread.start(); + } + + public void asyncHangingTask(final Runnable longTask) { + final Thread thread = factory.newThread(longTask); + thread.setName("pretty asyncHangingTask"); + thread.start(); + + if (thread.isAlive()) { + thread.interrupt(); + } + } + + public static class LongTask implements Runnable { + private final int value; + private final long taskDurationMs; + private final CountDownLatch countDownLatch; + private int result; + private AtomicBoolean isTerminated = new AtomicBoolean(false); + + public LongTask(final int value, + final long taskDurationMs, + final CountDownLatch countDownLatch) { + this.value = value; + this.taskDurationMs = taskDurationMs; + this.countDownLatch = countDownLatch; + } + + public int getResult() { + return result; + } + + public boolean getIsTerminated() { + return isTerminated.get(); + } + + @Override + public void run() { + try { + TimeUnit.MILLISECONDS.sleep(taskDurationMs); + } catch (InterruptedException e) { + isTerminated.set(true); + countDownLatch.countDown(); + throw new RuntimeException("Problem while waiting"); + } + + result = value + 1; + countDownLatch.countDown(); + } + } +}</pre> +</div> +</div> +<div class="paragraph"> +<p>Esse exemplo define uma classe que implementa <code>Runnable</code>, executando uma tarefa de longa duração no método <code>run</code>.</p> +</div> +<div class="paragraph"> +<p>O método <code>asyncTask</code> apenas cria uma thread gerenciada (usando o <code>ManagedThreadFactory</code> injetado) em seguida, a inicia. +O método <code>asyncHangingTask</code> também cria uma thread gerenciada, a inicia, mas também a para.</p> +</div> +<div class="paragraph"> +<p>A seguinte classe testa esses métodos (código completo pode ser encontrado <a href="https://github.com/apache/tomee/blob/master/examples/concurrency-utils/src/test/java/org/superbiz/executor/ThreadFactoryServiceTest.java">aqui</a>):</p> +</div> +<div class="literalblock"> +<div class="content"> +<pre>@RunWith(Arquillian.class) +public class ThreadFactoryServiceTest { + + @Inject + private ThreadFactoryService factoryService; + + @Deployment() + public static final WebArchive app() { + return ShrinkWrap.create(WebArchive.class, "example.war") + .addClasses(ThreadFactoryService.class) + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Test + public void asyncTask() throws InterruptedException { + final CountDownLatch countDownLatch = new CountDownLatch(1); + final LongTask longTask = new LongTask(1, 50, countDownLatch); + factoryService.asyncTask(longTask); + + countDownLatch.await(200, TimeUnit.MILLISECONDS); + + assertEquals(2, longTask.getResult()); + } + + @Test + public void asyncHangingTask() throws InterruptedException { + final CountDownLatch countDownLatch = new CountDownLatch(1); + final LongTask longTask = new LongTask(1, 1000000, countDownLatch); + + factoryService.asyncHangingTask(longTask); + + countDownLatch.await(200, TimeUnit.MILLISECONDS); + + assertTrue(longTask.getIsTerminated()); + } +}</pre> +</div> +</div> +<div class="paragraph"> +<p>O exemplo completo do projeto pode ser encontrado <a href="https://github.com/apache/tomee/tree/master/examples/concurrency-utils">aqui</a>. +à um projeto Maven, e todos os testes podem ser rodados executando o comando <code>mvn clean install</code>.</p> +</div> +</div> +</div> +</div> +</div> + </div> + + </div> + </div> +<footer> + <div class="container"> + <div class="row"> + <div class="col-sm-6 text-center-mobile"> + <h3 class="white">Be simple. Be certified. Be Tomcat.</h3> + <h5 class="light regular light-white">"A good application in a good server"</h5> + <ul class="social-footer"> + <li><a href="https://www.facebook.com/ApacheTomEE/"><i class="fa fa-facebook"></i></a></li> + <li><a href="https://twitter.com/apachetomee"><i class="fa fa-twitter"></i></a></li> + <li><a href="https://plus.google.com/communities/105208241852045684449"><i class="fa fa-google-plus"></i></a></li> + </ul> + </div> + <div class="col-sm-6 text-center-mobile"> + <div class="row opening-hours"> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../latest/docs/documentation.html" class="white">Documentation</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../latest/docs/admin/configuration/index.html" class="regular light-white">How to configure</a></li> + <li><a href="../../../latest/docs/admin/file-layout.html" class="regular light-white">Dir. Structure</a></li> + <li><a href="../../../latest/docs/developer/testing/index.html" class="regular light-white">Testing</a></li> + <li><a href="../../../latest/docs/admin/cluster/index.html" class="regular light-white">Clustering</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../latest/examples/" class="white">Examples</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../latest/examples/simple-cdi-interceptor.html" class="regular light-white">CDI Interceptor</a></li> + <li><a href="../../../latest/examples/rest-cdi.html" class="regular light-white">REST with CDI</a></li> + <li><a href="../../../latest/examples/ejb-examples.html" class="regular light-white">EJB</a></li> + <li><a href="../../../latest/examples/jsf-managedBean-and-ejb.html" class="regular light-white">JSF</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../community/index.html" class="white">Community</a></h5> + <ul class="list-unstyled"> + <li><a href="../../../community/contributors.html" class="regular light-white">Contributors</a></li> + <li><a href="../../../community/social.html" class="regular light-white">Social</a></li> + <li><a href="../../../community/sources.html" class="regular light-white">Sources</a></li> + </ul> + </div> + <div class="col-sm-3 text-center-mobile"> + <h5><a href="../../../security/index.html" class="white">Security</a></h5> + <ul class="list-unstyled"> + <li><a href="http://apache.org/security" target="_blank" class="regular light-white">Apache Security</a></li> + <li><a href="http://apache.org/security/projects.html" target="_blank" class="regular light-white">Security Projects</a></li> + <li><a href="http://cve.mitre.org" target="_blank" class="regular light-white">CVE</a></li> + </ul> + </div> + </div> + </div> + </div> + <div class="row bottom-footer text-center-mobile"> + <div class="col-sm-12 light-white"> + <p>Copyright © 1999-2016 The Apache Software Foundation, Licensed under the Apache License, Version 2.0. Apache TomEE, TomEE, Apache, the Apache feather logo, and the Apache TomEE project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.</p> + </div> + </div> + </div> + </footer> + <!-- Holder for mobile navigation --> + <div class="mobile-nav"> + <ul> + <li><a hef="../../../latest/docs/admin/index.html">Administrators</a> + <li><a hef="../../../latest/docs/developer/index.html">Developers</a> + <li><a hef="../../../latest/docs/advanced/index.html">Advanced</a> + <li><a hef="../../../community/index.html">Community</a> + </ul> + <a href="#" class="close-link"><i class="arrow_up"></i></a> + </div> + <!-- Scripts --> + <script src="../../../js/jquery-1.11.1.min.js"></script> + <script src="../../../js/owl.carousel.min.js"></script> + <script src="../../../js/bootstrap.min.js"></script> + <script src="../../../js/wow.min.js"></script> + <script src="../../../js/typewriter.js"></script> + <script src="../../../js/jquery.onepagenav.js"></script> + <script src="../../../js/tree.jquery.js"></script> + <script src="../../../js/highlight.pack.js"></script> + <script src="../../../js/main.js"></script> + </body> + +</html> +
