breakponchito commented on a change in pull request #580: TOMEE-2698: Translate
to spanish simple-rest
URL: https://github.com/apache/tomee/pull/580#discussion_r331294319
##########
File path: examples/simple-rest/README_es.adoc
##########
@@ -0,0 +1,140 @@
+:index-group: REST
+:jbake-type: page
+:jbake-status: status=published
+
+= REST Simple
+
+Definir un servicio Rest es muy fácil, simplemente necesitamos agregar la
anotación ``@Path`` en la clase y después definir los métodos HTTP que vamos a
usar (``@GET``, ``@POST``, …).
+
+= El Código
+
+== El servicio REST: ``@Path``, ``@GET``, ``@POST``
+
+Aquí tenemos un REST simple, anotamos la clase con ``@Path("/greeting")`` para
indicar la ruta correspondiente a la clase ``GreetingService``. Definimos
``message()`` como ``@GET`` y ``lowerCase()`` como ``@POST`` para la ruta
``/greeting``. Pronto tenemos un servicio, muy simple ¿verdad?
+
+....
+package org.superbiz.rest;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+@Path("/greeting")
+public class GreetingService {
+ @GET
+ public String message() {
+ return "Hi REST!";
+ }
+
+ @POST
+ public String lowerCase(final String message) {
+ return "Hi REST!".toLowerCase();
+ }
+}
+....
+
+== Probando
+
+== Prueba para el servicio JAXRS
+
+Usamos el OpenEJB ApplicationComposer para facilitar la prueba.
+
+La idea primero es activar los servicios jaxrs. Esto se hace utilizando la
anotación ``@EnableServices``.
+
+Entonces creamos la aplicación simplemente devolviendo un objeto representando
el ``web.xml``. Aquí simplemente lo utilizamos para definir el contexto raíz,
pero también puede ser utilizado para definir la aplicación REST. Y para
completar la definición de la aplicación agregamos la anotación ``@Classes``
para definir el conjunto de clases a ser utilizado en esta app.
+
+Finalmente para probarlo utilizamos la API cliente de ``cxf`` para llamar el
servicio REST en los métodos ``get()`` y ``post()``.
+
+....
+package org.superbiz.rest;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+@EnableServices(value = "jaxrs")
+@RunWith(ApplicationComposer.class)
+public class GreetingServiceTest {
+ @Module
+ public SingletonBean app() {
+ return (SingletonBean) new
SingletonBean(GreetingService.class).localBean();
+ }
+
+ @Test
+ public void get() throws IOException {
+ final String message =
WebClient.create("http://localhost:4204").path("/GreetingServiceTest/greeting/").get(String.class);
+ assertEquals("Hi REST!", message);
+ }
+
+ @Test
+ public void post() throws IOException {
+ final String message =
WebClient.create("http://localhost:4204").path("/GreetingServiceTest/greeting/").post("Hi
REST!", String.class);
+ assertEquals("hi rest!", message);
+ }
+}
+....
+
+== Ejecución
+
+Ejecutar la aplicación es muy simple. En el directorio ``simple-rest`` ejecuta:
+
Review comment:
done!!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services