http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/efed31f4/src/main/jbake/content/examples/rest-cdi.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/rest-cdi.adoc b/src/main/jbake/content/examples/rest-cdi.adoc deleted file mode 100755 index a2afbd4..0000000 --- a/src/main/jbake/content/examples/rest-cdi.adoc +++ /dev/null @@ -1,394 +0,0 @@ -= Simple REST with CDI -:jbake-date: 2016-09-06 -:jbake-type: page -:jbake-tomeepdf: -:jbake-status: published - -Example rest-cdi can be browsed at https://github.com/apache/tomee/tree/master/examples/rest-cdi - - -Defining a REST service is pretty easy, simply ad @Path annotation to a class then define on methods -the HTTP method to use (@GET, @POST, ...). - -= The Code - -== The REST service: @Path, @Produces, @Consumes - -Here we see a bean that uses the Bean-Managed Concurrency option as well as the @Startup annotation which causes the bean to be instantiated by the container when the application starts. Singleton beans with @ConcurrencyManagement(BEAN) are responsible for their own thread-safety. The bean shown is a simple properties "registry" and provides a place where options could be set and retrieved by all beans in the application. - -Actually lines: - - -[source,java] ----- -@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) -@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - -are optional since it is the default configuration. And these lines can be configured by method too -if you need to be more precise. - -@Path("/greeting") -@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) -@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) -public class GreetingService { - @GET - public Response message() { - return new Response("Hi REST!"); - } - - @POST - public Response lowerCase(final Request message) { - return new Response(message.getValue().toLowerCase()); - } -} ----- - - -= Testing - -== Test for the JAXRS service - -The test uses the OpenEJB ApplicationComposer to make it trivial. - -The idea is first to activate the jaxrs services. This is done using @EnableServices annotation. - -Then we create on the fly the application simply returning an object representing the web.xml. Here we simply -use it to define the context root but you can use it to define your REST Application too. And to complete the -application definition we add @Classes annotation to define the set of classes to use in this app. - -Finally to test it we use cxf client API to call the REST service in get() and post() methods. - -Side note: to show we use JSON or XML depending on the test method we activated on EnableServices the attribute httpDebug -which prints the http messages in the logs. - - -[source,java] ----- -package org.superbiz.rest; - -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.openejb.jee.WebApp; -import org.apache.openejb.junit.ApplicationComposer; -import org.apache.openejb.junit.Classes; -import org.apache.openejb.junit.EnableServices; -import org.apache.openejb.junit.Module; -import org.junit.Test; -import org.junit.runner.RunWith; - -import javax.ws.rs.core.MediaType; -import java.io.IOException; - -import static org.junit.Assert.assertEquals; - -@EnableServices(value = "jaxrs", httpDebug = true) -@RunWith(ApplicationComposer.class) -public class GreetingServiceTest { - @Module - @Classes(value = {GreetingService.class, Greeting.class}, cdi = true) //This enables the CDI magic - public WebApp app() { - return new WebApp().contextRoot("test"); - } - - @Test - public void getXml() throws IOException { - final String message = WebClient.create("http://localhost:4204").path("/test/greeting/") - .accept(MediaType.APPLICATION_XML_TYPE) - .get(Response.class).getValue(); - assertEquals("Hi REST!", message); - } - - @Test - public void postXml() throws IOException { - final String message = WebClient.create("http://localhost:4204").path("/test/greeting/") - .accept(MediaType.APPLICATION_XML_TYPE) - .post(new Request("Hi REST!"), Response.class).getValue(); - assertEquals("hi rest!", message); - } - - @Test - public void getJson() throws IOException { - final String message = WebClient.create("http://localhost:4204").path("/test/greeting/") - .accept(MediaType.APPLICATION_JSON_TYPE) - .get(Response.class).getValue(); - assertEquals("Hi REST!", message); - } - - @Test - public void postJson() throws IOException { - final String message = WebClient.create("http://localhost:4204").path("/test/greeting/") - .accept(MediaType.APPLICATION_JSON_TYPE) - .post(new Request("Hi REST!"), Response.class).getValue(); - assertEquals("hi rest!", message); - } -} ----- - - - -= Running - -Running the example is fairly simple. In the "rest-cdi" directory run: - - $ mvn clean install - -Which should create output like the following. - - /opt/softs/java/jdk1.6.0_30/bin/java -ea -Didea.launcher.port=7534 -Didea.launcher.bin.path=/opt/softs/idea/bin -Dfile.encoding=UTF-8 -classpath /opt/softs/idea/lib/idea_rt.jar:/opt/softs/idea/plugins/junit/lib/junit-rt.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/plugin.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/javaws.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/jce.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/charsets.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/resources.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/deploy.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/management-agent.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/jsse.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/rt.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/ext/localedata.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/ext/sunjce_provider.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/ext/sunpkcs11.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/ext/dnsns.jar:/opt/dev/openejb/openejb-trunk/examples/rest-cdi/target/test-classes:/opt/dev/openejb/openejb-trunk/examples/rest-cdi/tar get/classes:/home/rmannibucau/.m2/repository/org/apache/openejb/javaee-api/6.0-4/javaee-api-6.0-4.jar:/home/rmannibucau/.m2/repository/junit/junit/4.10/junit-4.10.jar:/home/rmannibucau/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-cxf-rs/4.5.1/openejb-cxf-rs-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-http/4.5.1/openejb-http-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-core/4.5.1/openejb-core-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/mbean-annotation-api/4.5.1/mbean-annotation-api-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-jpa-integration/4.5.1/openejb-jpa-integration-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-api/4.5.1/openejb-api-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/open ejb/openejb-loader/4.5.1/openejb-loader-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-javaagent/4.5.1/openejb-javaagent-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-jee/4.5.1/openejb-jee-4.5.1.jar:/home/rmannibucau/.m2/repository/com/sun/xml/bind/jaxb-impl/2.1.13/jaxb-impl-2.1.13.jar:/home/rmannibucau/.m2/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar:/home/rmannibucau/.m2/repository/org/apache/activemq/activemq-ra/5.7.0/activemq-ra-5.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/activemq/activemq-core/5.7.0/activemq-core-5.7.0.jar:/home/rmannibucau/.m2/repository/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar:/home/rmannibucau/.m2/repository/org/apache/activemq/kahadb/5.7.0/kahadb-5.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/activemq/protobuf/activemq-protobuf/1.1/activemq-protobuf-1.1.jar:/home/rmannibucau/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar:/home/rmannibucau/.m2/r epository/commons-net/commons-net/3.1/commons-net-3.1.jar:/home/rmannibucau/.m2/repository/org/apache/geronimo/components/geronimo-connector/3.1.1/geronimo-connector-3.1.1.jar:/home/rmannibucau/.m2/repository/org/apache/geronimo/components/geronimo-transaction/3.1.1/geronimo-transaction-3.1.1.jar:/home/rmannibucau/.m2/repository/org/apache/geronimo/specs/geronimo-j2ee-connector_1.6_spec/1.0/geronimo-j2ee-connector_1.6_spec-1.0.jar:/home/rmannibucau/.m2/repository/org/objectweb/howl/howl/1.0.1-1/howl-1.0.1-1.jar:/home/rmannibucau/.m2/repository/org/apache/geronimo/javamail/geronimo-javamail_1.4_mail/1.8.2/geronimo-javamail_1.4_mail-1.8.2.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbean-asm-shaded/3.12/xbean-asm-shaded-3.12.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbean-finder-shaded/3.12/xbean-finder-shaded-3.12.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbean-reflect/3.12/xbean-reflect-3.12.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbea n-naming/3.12/xbean-naming-3.12.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbean-bundleutils/3.12/xbean-bundleutils-3.12.jar:/home/rmannibucau/.m2/repository/org/hsqldb/hsqldb/2.2.8/hsqldb-2.2.8.jar:/home/rmannibucau/.m2/repository/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.jar:/home/rmannibucau/.m2/repository/commons-pool/commons-pool/1.5.7/commons-pool-1.5.7.jar:/home/rmannibucau/.m2/repository/org/codehaus/swizzle/swizzle-stream/1.6.1/swizzle-stream-1.6.1.jar:/home/rmannibucau/.m2/repository/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar:/home/rmannibucau/.m2/repository/org/quartz-scheduler/quartz/2.1.6/quartz-2.1.6.jar:/home/rmannibucau/.m2/repository/org/slf4j/slf4j-jdk14/1.7.2/slf4j-jdk14-1.7.2.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-impl/1.1.6/openwebbeans-impl-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-spi/1.1.6/openwebbeans-spi-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openw ebbeans-ejb/1.1.6/openwebbeans-ejb-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-ee/1.1.6/openwebbeans-ee-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-ee-common/1.1.6/openwebbeans-ee-common-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-web/1.1.6/openwebbeans-web-1.1.6.jar:/home/rmannibucau/.m2/repository/org/javassist/javassist/3.15.0-GA/javassist-3.15.0-GA.jar:/home/rmannibucau/.m2/repository/org/apache/openjpa/openjpa/2.2.0/openjpa-2.2.0.jar:/home/rmannibucau/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar:/home/rmannibucau/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar:/home/rmannibucau/.m2/repository/net/sourceforge/serp/serp/1.13.1/serp-1.13.1.jar:/home/rmannibucau/.m2/repository/asm/asm/3.2/asm-3.2.jar:/home/rmannibucau/.m2/repository/org/apache/bval/bval-core/0.5/bval-core-0.5.jar:/home/rmannibucau/.m2/repository/ commons-beanutils/commons-beanutils-core/1.8.3/commons-beanutils-core-1.8.3.jar:/home/rmannibucau/.m2/repository/org/apache/bval/bval-jsr303/0.5/bval-jsr303-0.5.jar:/home/rmannibucau/.m2/repository/org/fusesource/jansi/jansi/1.8/jansi-1.8.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-server/4.5.1/openejb-server-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-client/4.5.1/openejb-client-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-ejbd/4.5.1/openejb-ejbd-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-rest/4.5.1/openejb-rest-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-cxf-transport/4.5.1/openejb-cxf-transport-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-transports-http/2.7.0/cxf-rt-transports-http-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-api/2.7.0/cxf-api-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/ws/xmlschema/xmlschema-c ore/2.0.3/xmlschema-core-2.0.3.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-core/2.7.0/cxf-rt-core-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-frontend-jaxrs/2.7.0/cxf-rt-frontend-jaxrs-2.7.0.jar:/home/rmannibucau/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.0-m10/javax.ws.rs-api-2.0-m10.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-bindings-xml/2.7.0/cxf-rt-bindings-xml-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-rs-extension-providers/2.7.0/cxf-rt-rs-extension-providers-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-rs-extension-search/2.7.0/cxf-rt-rs-extension-search-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-rs-security-cors/2.7.0/cxf-rt-rs-security-cors-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-rs-security-oauth2/2.7.0/cxf-rt-rs-security-oauth2-2.7.0.jar:/home/rmannibucau/.m2/repository/org/codehaus/jettison/jettison/1.3/jettison-1.3.jar:/home/rman nibucau/.m2/repository/stax/stax-api/1.0.1/stax-api-1.0.1.jar com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 org.superbiz.rest.GreetingServiceTest - INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. - INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) - INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) - INFO - Creating TransactionManager(id=Default Transaction Manager) - INFO - Creating SecurityService(id=Default Security Service) - INFO - Initializing network services - INFO - Creating ServerService(id=httpejbd) - INFO - Using 'print=true' - INFO - Using 'indent.xml=true' - INFO - Creating ServerService(id=cxf-rs) - INFO - Initializing network services - INFO - Starting service httpejbd - INFO - Started service httpejbd - INFO - Starting service cxf-rs - INFO - Started service cxf-rs - INFO - ** Bound Services ** - INFO - NAME IP PORT - INFO - httpejbd 127.0.0.1 4204 - INFO - ------- - INFO - Ready! - INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest - INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) - INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container) - INFO - Creating Container(id=Default Managed Container) - INFO - Using directory /tmp for stateful session passivation - INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded. - INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest - INFO - Existing thread singleton service in SystemInstance() null - INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@54128635 - INFO - Succeeded in installing singleton service - INFO - OpenWebBeans Container is starting... - INFO - Adding OpenWebBeansPlugin : [CdiPlugin] - INFO - All injection points are validated successfully. - INFO - OpenWebBeans Container has started, it took 102 ms. - INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest) - INFO - Setting the server's publish address to be http://127.0.0.1:4204/test - INFO - REST Service: http://127.0.0.1:4204/test/greeting/.* -> Pojo org.superbiz.rest.GreetingService - FINE - ******************* REQUEST ****************** - GET http://localhost:4204/test/greeting/ - Host=localhost:4204 - User-Agent=Apache CXF 2.7.0 - Connection=keep-alive - Accept=application/xml - Content-Type=*/* - Pragma=no-cache - Cache-Control=no-cache - - - ********************************************** - - FINE - HTTP/1.1 200 OK - Date: Fri, 09 Nov 2012 11:59:00 GMT - Content-Length: 44 - Set-Cookie: EJBSESSIONID=fc5037fa-641c-495d-95ca-0755cfa50beb; Path=/ - Content-Type: application/xml - Connection: close - Server: OpenEJB/4.5.1 Linux/3.2.0-23-generic (amd64) - - -[source,xml] ----- -<response><value>Hi REST!</value></response> -INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Stopping network services -INFO - Stopping server services -INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. -INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) -INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) -INFO - Creating TransactionManager(id=Default Transaction Manager) -INFO - Creating SecurityService(id=Default Security Service) -INFO - Initializing network services -INFO - Creating ServerService(id=httpejbd) -INFO - Using 'print=true' -INFO - Using 'indent.xml=true' -INFO - Creating ServerService(id=cxf-rs) -INFO - Initializing network services -INFO - Starting service httpejbd -INFO - Started service httpejbd -INFO - Starting service cxf-rs -INFO - Started service cxf-rs -INFO - ** Bound Services ** -INFO - NAME IP PORT -INFO - httpejbd 127.0.0.1 4204 -INFO - ------- -INFO - Ready! -INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) -INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container) -INFO - Creating Container(id=Default Managed Container) -INFO - Using directory /tmp for stateful session passivation -INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded. -INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Existing thread singleton service in SystemInstance() null -INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@54128635 -INFO - Succeeded in installing singleton service -INFO - OpenWebBeans Container is starting... -INFO - Adding OpenWebBeansPlugin : [CdiPlugin] -INFO - All injection points are validated successfully. -INFO - OpenWebBeans Container has started, it took 11 ms. -INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest) -INFO - Setting the server's publish address to be http://127.0.0.1:4204/test -INFO - REST Service: http://127.0.0.1:4204/test/greeting/.* -> Pojo org.superbiz.rest.GreetingService -FINE - ******************* REQUEST ****************** -POST http://localhost:4204/test/greeting/ -Host=localhost:4204 -Content-Length=97 -User-Agent=Apache CXF 2.7.0 -Connection=keep-alive -Accept=application/xml -Content-Type=application/xml -Pragma=no-cache -Cache-Control=no-cache - -<?xml version="1.0" encoding="UTF-8" standalone="yes"?><request><value>Hi REST!</value></request> -********************************************** - -FINE - HTTP/1.1 200 OK -Date: Fri, 09 Nov 2012 11:59:00 GMT -Content-Length: 44 -Set-Cookie: EJBSESSIONID=7cb2246d-5738-4a85-aac5-c0fb5340d36a; Path=/ -Content-Type: application/xml -Connection: close -Server: OpenEJB/4.5.1 Linux/3.2.0-23-generic (amd64) - -<response><value>hi rest!</value></response> -INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Stopping network services -INFO - Stopping server services -INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. -INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) -INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) -INFO - Creating TransactionManager(id=Default Transaction Manager) -INFO - Creating SecurityService(id=Default Security Service) -INFO - Initializing network services -INFO - Creating ServerService(id=httpejbd) -INFO - Using 'print=true' -INFO - Using 'indent.xml=true' -INFO - Creating ServerService(id=cxf-rs) -INFO - Initializing network services -INFO - Starting service httpejbd -INFO - Started service httpejbd -INFO - Starting service cxf-rs -INFO - Started service cxf-rs -INFO - ** Bound Services ** -INFO - NAME IP PORT -INFO - httpejbd 127.0.0.1 4204 -INFO - ------- -INFO - Ready! -INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) -INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container) -INFO - Creating Container(id=Default Managed Container) -INFO - Using directory /tmp for stateful session passivation -INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded. -INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Existing thread singleton service in SystemInstance() null -INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@54128635 -INFO - Succeeded in installing singleton service -INFO - OpenWebBeans Container is starting... -INFO - Adding OpenWebBeansPlugin : [CdiPlugin] -INFO - All injection points are validated successfully. -INFO - OpenWebBeans Container has started, it took 10 ms. -INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest) -INFO - Setting the server's publish address to be http://127.0.0.1:4204/test -INFO - REST Service: http://127.0.0.1:4204/test/greeting/.* -> Pojo org.superbiz.rest.GreetingService -FINE - ******************* REQUEST ****************** -GET http://localhost:4204/test/greeting/ -Host=localhost:4204 -User-Agent=Apache CXF 2.7.0 -Connection=keep-alive -Accept=application/json -Content-Type=*/* -Pragma=no-cache -Cache-Control=no-cache - - -********************************************** - -FINE - HTTP/1.1 200 OK -Date: Fri, 09 Nov 2012 11:59:00 GMT -Content-Length: 33 -Set-Cookie: EJBSESSIONID=7112a057-fc4c-4f52-a556-1617320d2275; Path=/ -Content-Type: application/json -Connection: close -Server: OpenEJB/4.5.1 Linux/3.2.0-23-generic (amd64) - -{"response":{"value":"Hi REST!"}} -INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Stopping network services -INFO - Stopping server services -INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. -INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) -INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) -INFO - Creating TransactionManager(id=Default Transaction Manager) -INFO - Creating SecurityService(id=Default Security Service) -INFO - Initializing network services -INFO - Creating ServerService(id=httpejbd) -INFO - Using 'print=true' -INFO - Using 'indent.xml=true' -INFO - Creating ServerService(id=cxf-rs) -INFO - Initializing network services -INFO - Starting service httpejbd -INFO - Started service httpejbd -INFO - Starting service cxf-rs -INFO - Started service cxf-rs -INFO - ** Bound Services ** -INFO - NAME IP PORT -INFO - httpejbd 127.0.0.1 4204 -INFO - ------- -INFO - Ready! -INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) -INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container) -INFO - Creating Container(id=Default Managed Container) -INFO - Using directory /tmp for stateful session passivation -INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded. -INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Existing thread singleton service in SystemInstance() null -INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@54128635 -INFO - Succeeded in installing singleton service -INFO - OpenWebBeans Container is starting... -INFO - Adding OpenWebBeansPlugin : [CdiPlugin] -INFO - All injection points are validated successfully. -INFO - OpenWebBeans Container has started, it took 10 ms. -INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest) -INFO - Setting the server's publish address to be http://127.0.0.1:4204/test -INFO - REST Service: http://127.0.0.1:4204/test/greeting/.* -> Pojo org.superbiz.rest.GreetingService -FINE - ******************* REQUEST ****************** -POST http://localhost:4204/test/greeting/ -Host=localhost:4204 -Content-Length=97 -User-Agent=Apache CXF 2.7.0 -Connection=keep-alive -Accept=application/json -Content-Type=application/xml -Pragma=no-cache -Cache-Control=no-cache - -<?xml version="1.0" encoding="UTF-8" standalone="yes"?><request><value>Hi REST!</value></request> -********************************************** - -FINE - HTTP/1.1 200 OK -Date: Fri, 09 Nov 2012 11:59:01 GMT -Content-Length: 33 -Set-Cookie: EJBSESSIONID=50cf1d2b-a940-4afb-8993-fff7f9cc6d83; Path=/ -Content-Type: application/json -Connection: close -Server: OpenEJB/4.5.1 Linux/3.2.0-23-generic (amd64) - -{"response":{"value":"hi rest!"}} -INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Stopping network services -INFO - Stopping server services - - - - -
http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/efed31f4/src/main/jbake/content/examples/rest-example-with-application.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/rest-example-with-application.adoc b/src/main/jbake/content/examples/rest-example-with-application.adoc deleted file mode 100755 index 8b9d47a..0000000 --- a/src/main/jbake/content/examples/rest-example-with-application.adoc +++ /dev/null @@ -1,90 +0,0 @@ -= REST Example with Application -:jbake-date: 2016-09-06 -:jbake-type: page -:jbake-tomeepdf: -:jbake-status: published - -Example rest-example-with-application can be browsed at https://github.com/apache/tomee/tree/master/examples/rest-example-with-application - - -*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* - -== ApplicationConfig - - -[source,java] ----- -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -@ApplicationPath("/rest-prefix") -public class ApplicationConfig extends Application { - public Set<Class<?>> getClasses() { - return new HashSet<Class<?>>(Arrays.asList(SimpleRESTPojo.class, SimpleRESTEJB.class)); - } -} ----- - - -== SimpleRESTEJB - - -[source,java] ----- -import javax.ejb.Lock; -import javax.ejb.LockType; -import javax.ejb.Singleton; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import java.util.Date; - -@Singleton -@Lock(LockType.READ) -@Path("/ejb") -public class SimpleRESTEJB { - @GET - public String ejb() { - return "ejb ok @ " + new Date().toString(); - } -} ----- - - -== SimpleRESTPojo - - -[source,java] ----- -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import java.util.Date; - -@Path("/pojo") -public class SimpleRESTPojo { - @GET - public String pojo() { - return "pojo ok @ " + new Date().toString(); - } -} ----- - - -== web.xml - - -[source,xml] ----- -<web-app xmlns="http://java.sun.com/xml/ns/javaee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" - metadata-complete="false" - version="2.5"> - - <display-name>OpenEJB REST Example</display-name> -</web-app> ----- - - http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/efed31f4/src/main/jbake/content/examples/rest-example.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/rest-example.adoc b/src/main/jbake/content/examples/rest-example.adoc deleted file mode 100755 index c62eecb..0000000 --- a/src/main/jbake/content/examples/rest-example.adoc +++ /dev/null @@ -1,641 +0,0 @@ -= REST Example -:jbake-date: 2016-09-06 -:jbake-type: page -:jbake-tomeepdf: -:jbake-status: published - -Example rest-example can be browsed at https://github.com/apache/tomee/tree/master/examples/rest-example - - -*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* - -== CommentDAO - - -[source,java] ----- -package org.superbiz.rest.dao; - -import org.superbiz.rest.model.Comment; -import org.superbiz.rest.model.Post; - -import javax.ejb.EJB; -import javax.ejb.Stateless; -import java.util.Collections; -import java.util.List; - -@Stateless -public class CommentDAO extends DAO { - @EJB - private DAO dao; - - public List<Comment> list(long postId) { - Post post = dao.find(Post.class, postId); - if (post == null) { - throw new IllegalArgumentException("post with id " + postId + " not found"); - } - return Collections.unmodifiableList(post.getComments()); - } - - public Comment create(String author, String content, long postId) { - Post post = dao.find(Post.class, postId); - if (post == null) { - throw new IllegalArgumentException("post with id " + postId + " not found"); - } - - Comment comment = new Comment(); - comment.setAuthor(author); - comment.setContent(content); - dao.create(comment); - comment.setPost(post); - return comment; - } - - public void delete(long id) { - dao.delete(Comment.class, id); - } - - public Comment update(long id, String author, String content) { - Comment comment = dao.find(Comment.class, id); - if (comment == null) { - throw new IllegalArgumentException("comment with id " + id + " not found"); - } - - comment.setAuthor(author); - comment.setContent(content); - return dao.update(comment); - } -} ----- - - -== DAO - - -[source,java] ----- -package org.superbiz.rest.dao; - -import javax.ejb.Stateless; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.util.List; - -/** - * Simply maps the entitymanager. - * It simplifies refactoring (unitName change) and wraps some logic (limited queries). - * - */ -@Stateless -public class DAO { - @PersistenceContext(unitName = "blog") - private EntityManager em; - - public <E> E create(E e) { - em.persist(e); - return e; - } - - public <E> E update(E e) { - return em.merge(e); - } - - public <E> void delete(Class<E> clazz, long id) { - em.remove(em.find(clazz, id)); - } - - public <E> E find(Class<E> clazz, long id) { - return em.find(clazz, id); - } - - public <E> List<E> find(Class<E> clazz, String query, int min, int max) { - return queryRange(em.createQuery(query, clazz), min, max).getResultList(); - } - - public <E> List<E> namedFind(Class<E> clazz, String query, int min, int max) { - return queryRange(em.createNamedQuery(query, clazz), min, max).getResultList(); - } - - private static Query queryRange(Query query, int min, int max) { - if (max >= 0) { - query.setMaxResults(max); - } - if (min >= 0) { - query.setFirstResult(min); - } - return query; - } -} ----- - - -== PostDAO - - -[source,java] ----- -package org.superbiz.rest.dao; - -import org.superbiz.rest.model.Post; -import org.superbiz.rest.model.User; - -import javax.ejb.EJB; -import javax.ejb.Stateless; -import java.util.List; - -@Stateless -public class PostDAO { - @EJB - private DAO dao; - - public Post create(String title, String content, long userId) { - User user = dao.find(User.class, userId); - Post post = new Post(); - post.setTitle(title); - post.setContent(content); - post.setUser(user); - return dao.create(post); - } - - public Post find(long id) { - return dao.find(Post.class, id); - } - - public List<Post> list(int first, int max) { - return dao.namedFind(Post.class, "post.list", first, max); - } - - public void delete(long id) { - dao.delete(Post.class, id); - } - - public Post update(long id, long userId, String title, String content) { - User user = dao.find(User.class, userId); - if (user == null) { - throw new IllegalArgumentException("user id " + id + " not found"); - } - - Post post = dao.find(Post.class, id); - if (post == null) { - throw new IllegalArgumentException("post id " + id + " not found"); - } - - post.setTitle(title); - post.setContent(content); - post.setUser(user); - return dao.update(post); - } -} ----- - - -== UserDAO - - -[source,java] ----- -package org.superbiz.rest.dao; - -import org.superbiz.rest.model.User; - -import javax.ejb.EJB; -import javax.ejb.Stateless; -import java.util.List; - -@Stateless -public class UserDAO { - @EJB - private DAO dao; - - public User create(String name, String pwd, String mail) { - User user = new User(); - user.setFullname(name); - user.setPassword(pwd); - user.setEmail(mail); - return dao.create(user); - } - - public List<User> list(int first, int max) { - return dao.namedFind(User.class, "user.list", first, max); - } - - public User find(long id) { - return dao.find(User.class, id); - } - - public void delete(long id) { - dao.delete(User.class, id); - } - - public User update(long id, String name, String pwd, String mail) { - User user = dao.find(User.class, id); - if (user == null) { - throw new IllegalArgumentException("setUser id " + id + " not found"); - } - - user.setFullname(name); - user.setPassword(pwd); - user.setEmail(mail); - return dao.update(user); - } -} ----- - - -== Comment - - -[source,java] ----- -package org.superbiz.rest.model; - -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlTransient; - -@Entity -@NamedQueries({ - @NamedQuery(name = "comment.list", query = "select c from Comment c") -} ----- - - -== DatedModel - - -[source,java] ----- -package org.superbiz.rest.model; - -import javax.persistence.MappedSuperclass; -import javax.persistence.PrePersist; -import java.util.Date; - -@MappedSuperclass -public abstract class DatedModel extends Model { - private Date created; - - @PrePersist - public void create() { - created = new Date(); - } - - public Date getCreated() { - return created; - } - - public void setCreated(Date created) { - this.created = created; - } -} ----- - - -== Model - - -[source,java] ----- -package org.superbiz.rest.model; - -import javax.persistence.Access; -import javax.persistence.AccessType; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; - -@MappedSuperclass -@Access(AccessType.FIELD) -@XmlAccessorType(XmlAccessType.FIELD) -public abstract class Model { - - @Id - @GeneratedValue - protected long id; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } -} ----- - - -== Post - - -[source,java] ----- -package org.superbiz.rest.model; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Lob; -import javax.persistence.ManyToOne; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; -import java.util.ArrayList; -import java.util.List; - -@Entity -@NamedQueries({ - @NamedQuery(name = "post.list", query = "select p from Post p") -} ----- - - -== User - - -[source,java] ----- -package org.superbiz.rest.model; - -import javax.persistence.Entity; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; -import javax.xml.bind.annotation.XmlRootElement; - -@Entity -@NamedQueries({ - @NamedQuery(name = "user.list", query = "select u from User u") -} ----- - - -== CommentService - - -[source,java] ----- -package org.superbiz.rest.service; - -import org.superbiz.rest.dao.CommentDAO; -import org.superbiz.rest.model.Comment; - -import javax.ejb.EJB; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import java.util.List; - -@Path("/api/comment") -@Produces({"text/xml", "application/json"}) -public class CommentService { - @EJB - private CommentDAO commentDao; - - @Path("/create") - @PUT - public Comment create(@QueryParam("author") String author, - @QueryParam("content") String content, - @QueryParam("postId") long postId) { - return commentDao.create(author, content, postId); - } - - @Path("/list/{postId}") - @GET - public List<Comment> list(@PathParam("postId") long postId) { - return commentDao.list(postId); - } - - @Path("/delete/{id}") - @DELETE - public void delete(@PathParam("id") long id) { - commentDao.delete(id); - } - - @Path("/update/{id}") - @POST - public Comment update(@PathParam("id") long id, - @QueryParam("author") String author, - @QueryParam("content") String content) { - return commentDao.update(id, author, content); - } -} ----- - - -== PostService - - -[source,java] ----- -package org.superbiz.rest.service; - -import org.superbiz.rest.dao.PostDAO; -import org.superbiz.rest.model.Post; - -import javax.ejb.EJB; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import java.util.List; - -@Path("/api/post") -@Produces({"text/xml", "application/json"}) -public class PostService { - @EJB - private PostDAO dao; - - @Path("/create") - @PUT - public Post create(@QueryParam("title") String title, - @QueryParam("content") String content, - @QueryParam("userId") long userId) { - return dao.create(title, content, userId); - } - - @Path("/list") - @GET - public List<Post> list(@QueryParam("first") @DefaultValue("0") int first, - @QueryParam("max") @DefaultValue("20") int max) { - return dao.list(first, max); - } - - @Path("/show/{id}") - @GET - public Post show(@PathParam("id") long id) { - return dao.find(id); - } - - @Path("/delete/{id}") - @DELETE - public void delete(@PathParam("id") long id) { - dao.delete(id); - } - - @Path("/update/{id}") - @POST - public Post update(@PathParam("id") long id, - @QueryParam("userId") long userId, - @QueryParam("title") String title, - @QueryParam("content") String content) { - return dao.update(id, userId, title, content); - } -} ----- - - -== UserService - - -[source,java] ----- -package org.superbiz.rest.service; - -import org.superbiz.rest.dao.UserDAO; -import org.superbiz.rest.model.User; - -import javax.ejb.EJB; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import java.util.List; - -@Path("/api/user") -@Produces({"text/xml", "application/json"}) -public class UserService { - @EJB - private UserDAO dao; - - @Path("/create") - @PUT - public User create(@QueryParam("name") String name, - @QueryParam("pwd") String pwd, - @QueryParam("mail") String mail) { - return dao.create(name, pwd, mail); - } - - @Path("/list") - @GET - public List<User> list(@QueryParam("first") @DefaultValue("0") int first, - @QueryParam("max") @DefaultValue("20") int max) { - return dao.list(first, max); - } - - @Path("/show/{id}") - @GET - public User show(@PathParam("id") long id) { - return dao.find(id); - } - - @Path("/delete/{id}") - @DELETE - public void delete(@PathParam("id") long id) { - dao.delete(id); - } - - @Path("/update/{id}") - @POST - public User update(@PathParam("id") long id, - @QueryParam("name") String name, - @QueryParam("pwd") String pwd, - @QueryParam("mail") String mail) { - return dao.update(id, name, pwd, mail); - } -} ----- - - -== persistence.xml - - -[source,xml] ----- -<persistence version="2.0" - xmlns="http://java.sun.com/xml/ns/persistence" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence - http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> - <persistence-unit name="blog"> - <jta-data-source>My DataSource</jta-data-source> - <non-jta-data-source>My Unmanaged DataSource</non-jta-data-source> - <class>org.superbiz.rest.model.User</class> - <class>org.superbiz.rest.model.Post</class> - <class>org.superbiz.rest.model.Comment</class> - <class>org.superbiz.rest.model.Model</class> - <class>org.superbiz.rest.model.DatedModel</class> - <properties> - <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> - </properties> - </persistence-unit> -</persistence> ----- - - -== web.xml - - -[source,xml] ----- -<web-app xmlns="http://java.sun.com/xml/ns/javaee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" - metadata-complete="false" - version="2.5"> - - <display-name>OpenEJB REST Example</display-name> -</web-app> ----- - - - -== UserDaoTest - - -[source,java] ----- -packagenull -} ----- - - -== UserServiceTest - - -[source,java] ----- -packagenull -} ----- - http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/efed31f4/src/main/jbake/content/examples/rest-jaas.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/rest-jaas.adoc b/src/main/jbake/content/examples/rest-jaas.adoc deleted file mode 100755 index 7587b09..0000000 --- a/src/main/jbake/content/examples/rest-jaas.adoc +++ /dev/null @@ -1,9 +0,0 @@ -= rest-jaas -:jbake-date: 2016-09-06 -:jbake-type: page -:jbake-tomeepdf: -:jbake-status: published - -Example rest-jaas can be browsed at https://github.com/apache/tomee/tree/master/examples/rest-jaas - -No README.md yet, be the first to contribute one! http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/efed31f4/src/main/jbake/content/examples/rest-on-ejb.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/rest-on-ejb.adoc b/src/main/jbake/content/examples/rest-on-ejb.adoc deleted file mode 100755 index a9f344b..0000000 --- a/src/main/jbake/content/examples/rest-on-ejb.adoc +++ /dev/null @@ -1,360 +0,0 @@ -= REST on EJB -:jbake-date: 2016-09-06 -:jbake-type: page -:jbake-tomeepdf: -:jbake-status: published - -Example rest-on-ejb can be browsed at https://github.com/apache/tomee/tree/master/examples/rest-on-ejb - - -*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* - -== User - - -[source,java] ----- -package org.superbiz.rest; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.xml.bind.annotation.XmlRootElement; - -@Entity -@NamedQueries({ - @NamedQuery(name = "user.list", query = "select u from User u") -} ----- - - -== UserService - - -[source,java] ----- -package org.superbiz.rest; - -import javax.ejb.Lock; -import javax.ejb.LockType; -import javax.ejb.Singleton; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.ws.rs.DELETE; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.List; - -/** - * Outputs are copied because of the enhancement of OpenJPA. - * - */ -@Singleton -@Lock(LockType.WRITE) -@Path("/user") -@Produces(MediaType.APPLICATION_XML) -public class UserService { - @PersistenceContext - private EntityManager em; - - @Path("/create") - @PUT - public User create(@QueryParam("name") String name, - @QueryParam("pwd") String pwd, - @QueryParam("mail") String mail) { - User user = new User(); - user.setFullname(name); - user.setPassword(pwd); - user.setEmail(mail); - em.persist(user); - return user; - } - - @Path("/list") - @GET - public List<User> list(@QueryParam("first") @DefaultValue("0") int first, - @QueryParam("max") @DefaultValue("20") int max) { - List<User> users = new ArrayList<User>(); - List<User> found = em.createNamedQuery("user.list", User.class).setFirstResult(first).setMaxResults(max).getResultList(); - for (User u : found) { - users.add(u.copy()); - } - return users; - } - - @Path("/show/{id}") - @GET - public User find(@PathParam("id") long id) { - User user = em.find(User.class, id); - if (user == null) { - return null; - } - return user.copy(); - } - - @Path("/delete/{id}") - @DELETE - public void delete(@PathParam("id") long id) { - User user = em.find(User.class, id); - if (user != null) { - em.remove(user); - } - } - - @Path("/update/{id}") - @POST - public Response update(@PathParam("id") long id, - @QueryParam("name") String name, - @QueryParam("pwd") String pwd, - @QueryParam("mail") String mail) { - User user = em.find(User.class, id); - if (user == null) { - throw new IllegalArgumentException("user id " + id + " not found"); - } - - user.setFullname(name); - user.setPassword(pwd); - user.setEmail(mail); - em.merge(user); - - return Response.ok(user.copy()).build(); - } -} ----- - - -== persistence.xml - - -[source,xml] ----- -<persistence version="2.0" - xmlns="http://java.sun.com/xml/ns/persistence" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence - http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> - <persistence-unit name="user"> - <jta-data-source>My DataSource</jta-data-source> - <non-jta-data-source>My Unmanaged DataSource</non-jta-data-source> - <class>org.superbiz.rest.User</class> - <properties> - <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> - </properties> - </persistence-unit> -</persistence> ----- - - -== UserServiceTest - - -[source,java] ----- -package org.superbiz.rest; - -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.openejb.OpenEjbContainer; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.ejb.embeddable.EJBContainer; -import javax.naming.Context; -import javax.naming.NamingException; -import javax.ws.rs.core.Response; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Unmarshaller; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.fail; - -public class UserServiceTest { - private static Context context; - private static UserService service; - private static List<User> users = new ArrayList<User>(); - - @BeforeClass - public static void start() throws NamingException { - Properties properties = new Properties(); - properties.setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true"); - context = EJBContainer.createEJBContainer(properties).getContext(); - - // create some records - service = (UserService) context.lookup("java:global/rest-on-ejb/UserService"); - users.add(service.create("foo", "foopwd", "[email protected]")); - users.add(service.create("bar", "barpwd", "[email protected]")); - } - - @AfterClass - public static void close() throws NamingException { - if (context != null) { - context.close(); - } - } - - @Test - public void create() { - int expected = service.list(0, 100).size() + 1; - Response response = WebClient.create("http://localhost:4204") - .path("/user/create") - .query("name", "dummy") - .query("pwd", "unbreakable") - .query("mail", "[email protected]") - .put(null); - List<User> list = service.list(0, 100); - for (User u : list) { - if (!users.contains(u)) { - service.delete(u.getId()); - return; - } - } - fail("user was not added"); - } - - @Test - public void delete() throws Exception { - User user = service.create("todelete", "dontforget", "[email protected]"); - - WebClient.create("http://localhost:4204").path("/user/delete/" + user.getId()).delete(); - - user = service.find(user.getId()); - assertNull(user); - } - - @Test - public void show() { - User user = WebClient.create("http://localhost:4204") - .path("/user/show/" + users.iterator().next().getId()) - .get(User.class); - assertEquals("foo", user.getFullname()); - assertEquals("foopwd", user.getPassword()); - assertEquals("[email protected]", user.getEmail()); - } - - @Test - public void list() throws Exception { - String users = WebClient.create("http://localhost:4204") - .path("/user/list") - .get(String.class); - assertEquals( - "<users>" + - "<user>" + - "<email>[email protected]</email>" + - "<fullname>foo</fullname>" + - "<id>1</id>" + - "<password>foopwd</password>" + - "</user>" + - "<user>" + - "<email>[email protected]</email>" + - "<fullname>bar</fullname>" + - "<id>2</id>" + - "<password>barpwd</password>" + - "</user>" + - "</users>", users); - } - - @Test - public void update() throws Exception { - User created = service.create("name", "pwd", "mail"); - Response response = WebClient.create("http://localhost:4204") - .path("/user/update/" + created.getId()) - .query("name", "corrected") - .query("pwd", "userpwd") - .query("mail", "[email protected]") - .post(null); - - JAXBContext ctx = JAXBContext.newInstance(User.class); - Unmarshaller unmarshaller = ctx.createUnmarshaller(); - User modified = (User) unmarshaller.unmarshal(InputStream.class.cast(response.getEntity())); - - assertEquals("corrected", modified.getFullname()); - assertEquals("userpwd", modified.getPassword()); - assertEquals("[email protected]", modified.getEmail()); - } -} ----- - - -= Running - - - -[source] ----- -------------------------------------------------------- - T E S T S -------------------------------------------------------- -Running org.superbiz.rest.UserServiceTest -Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 -http://tomee.apache.org/ -INFO - openejb.home = /Users/dblevins/examples/rest-on-ejb -INFO - openejb.base = /Users/dblevins/examples/rest-on-ejb -INFO - Using 'javax.ejb.embeddable.EJBContainer=true' -INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) -INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) -INFO - Found EjbModule in classpath: /Users/dblevins/examples/rest-on-ejb/target/classes -INFO - Beginning load: /Users/dblevins/examples/rest-on-ejb/target/classes -INFO - Configuring enterprise application: /Users/dblevins/examples/rest-on-ejb -INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container) -INFO - Auto-creating a container for bean UserService: Container(type=SINGLETON, id=Default Singleton Container) -INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) -INFO - Auto-creating a container for bean org.superbiz.rest.UserServiceTest: Container(type=MANAGED, id=Default Managed Container) -INFO - Configuring PersistenceUnit(name=user) -INFO - Configuring Service(id=Default JDBC Database, type=Resource, provider-id=Default JDBC Database) -INFO - Auto-creating a Resource with id 'Default JDBC Database' of type 'DataSource for 'user'. -INFO - Configuring Service(id=Default Unmanaged JDBC Database, type=Resource, provider-id=Default Unmanaged JDBC Database) -INFO - Auto-creating a Resource with id 'Default Unmanaged JDBC Database' of type 'DataSource for 'user'. -INFO - Adjusting PersistenceUnit user <jta-data-source> to Resource ID 'Default JDBC Database' from 'My DataSource' -INFO - Adjusting PersistenceUnit user <non-jta-data-source> to Resource ID 'Default Unmanaged JDBC Database' from 'My Unmanaged DataSource' -INFO - Enterprise application "/Users/dblevins/examples/rest-on-ejb" loaded. -INFO - Assembling app: /Users/dblevins/examples/rest-on-ejb -INFO - PersistenceUnit(name=user, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 407ms -INFO - Jndi(name="java:global/rest-on-ejb/UserService!org.superbiz.rest.UserService") -INFO - Jndi(name="java:global/rest-on-ejb/UserService") -INFO - Jndi(name="java:global/EjbModule1789767313/org.superbiz.rest.UserServiceTest!org.superbiz.rest.UserServiceTest") -INFO - Jndi(name="java:global/EjbModule1789767313/org.superbiz.rest.UserServiceTest") -INFO - Created Ejb(deployment-id=org.superbiz.rest.UserServiceTest, ejb-name=org.superbiz.rest.UserServiceTest, container=Default Managed Container) -INFO - Created Ejb(deployment-id=UserService, ejb-name=UserService, container=Default Singleton Container) -INFO - Started Ejb(deployment-id=org.superbiz.rest.UserServiceTest, ejb-name=org.superbiz.rest.UserServiceTest, container=Default Managed Container) -INFO - Started Ejb(deployment-id=UserService, ejb-name=UserService, container=Default Singleton Container) -INFO - Deployed Application(path=/Users/dblevins/examples/rest-on-ejb) -INFO - Initializing network services -INFO - Creating ServerService(id=httpejbd) -INFO - Creating ServerService(id=admin) -INFO - Creating ServerService(id=ejbd) -INFO - Creating ServerService(id=ejbds) -INFO - Creating ServerService(id=cxf-rs) -INFO - Initializing network services - ** Starting Services ** - NAME IP PORT - httpejbd 127.0.0.1 4204 - admin thread 127.0.0.1 4200 - ejbd 127.0.0.1 4201 - ejbd 127.0.0.1 4203 -------- -Ready! -WARN - Query "select u from User u" is removed from cache excluded permanently. Query "select u from User u" is not cached because it uses pagination.. -Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.102 sec - -Results : - -Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 ----- - - http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/efed31f4/src/main/jbake/content/examples/rest-xml-json.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/rest-xml-json.adoc b/src/main/jbake/content/examples/rest-xml-json.adoc deleted file mode 100755 index 5628b87..0000000 --- a/src/main/jbake/content/examples/rest-xml-json.adoc +++ /dev/null @@ -1,394 +0,0 @@ -= Simple REST -:jbake-date: 2016-09-06 -:jbake-type: page -:jbake-tomeepdf: -:jbake-status: published - -Example rest-xml-json can be browsed at https://github.com/apache/tomee/tree/master/examples/rest-xml-json - - -Defining a REST service is pretty easy, simply ad @Path annotation to a class then define on methods -the HTTP method to use (@GET, @POST, ...). - -= The Code - -== The REST service: @Path, @Produces, @Consumes - -Here we see a bean that uses the Bean-Managed Concurrency option as well as the @Startup annotation which causes the bean to be instantiated by the container when the application starts. Singleton beans with @ConcurrencyManagement(BEAN) are responsible for their own thread-safety. The bean shown is a simple properties "registry" and provides a place where options could be set and retrieved by all beans in the application. - -Actually lines: - - -[source,java] ----- -@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) -@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - -are optional since it is the default configuration. And these lines can be configured by method too -if you need to be more precise. - -@Path("/greeting") -@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) -@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) -public class GreetingService { - @GET - public Response message() { - return new Response("Hi REST!"); - } - - @POST - public Response lowerCase(final Request message) { - return new Response(message.getValue().toLowerCase()); - } -} ----- - - -= Testing - -== Test for the JAXRS service - -The test uses the OpenEJB ApplicationComposer to make it trivial. - -The idea is first to activate the jaxrs services. This is done using @EnableServices annotation. - -Then we create on the fly the application simply returning an object representing the web.xml. Here we simply -use it to define the context root but you can use it to define your REST Application too. And to complete the -application definition we add @Classes annotation to define the set of classes to use in this app. - -Finally to test it we use cxf client API to call the REST service in get() and post() methods. - -Side note: to show we use JSON or XML depending on the test method we activated on EnableServices the attribute httpDebug -which prints the http messages in the logs. - - -[source,java] ----- -package org.superbiz.rest; - -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.openejb.jee.WebApp; -import org.apache.openejb.junit.ApplicationComposer; -import org.apache.openejb.junit.Classes; -import org.apache.openejb.junit.EnableServices; -import org.apache.openejb.junit.Module; -import org.junit.Test; -import org.junit.runner.RunWith; - -import javax.ws.rs.core.MediaType; -import java.io.IOException; - -import static org.junit.Assert.assertEquals; - -@EnableServices(value = "jaxrs", httpDebug = true) -@RunWith(ApplicationComposer.class) -public class GreetingServiceTest { - @Module - @Classes(GreetingService.class) - public WebApp app() { - return new WebApp().contextRoot("test"); - } - - @Test - public void getXml() throws IOException { - final String message = WebClient.create("http://localhost:4204").path("/test/greeting/") - .accept(MediaType.APPLICATION_XML_TYPE) - .get(Response.class).getValue(); - assertEquals("Hi REST!", message); - } - - @Test - public void postXml() throws IOException { - final String message = WebClient.create("http://localhost:4204").path("/test/greeting/") - .accept(MediaType.APPLICATION_XML_TYPE) - .post(new Request("Hi REST!"), Response.class).getValue(); - assertEquals("hi rest!", message); - } - - @Test - public void getJson() throws IOException { - final String message = WebClient.create("http://localhost:4204").path("/test/greeting/") - .accept(MediaType.APPLICATION_JSON_TYPE) - .get(Response.class).getValue(); - assertEquals("Hi REST!", message); - } - - @Test - public void postJson() throws IOException { - final String message = WebClient.create("http://localhost:4204").path("/test/greeting/") - .accept(MediaType.APPLICATION_JSON_TYPE) - .post(new Request("Hi REST!"), Response.class).getValue(); - assertEquals("hi rest!", message); - } -} ----- - - - -= Running - -Running the example is fairly simple. In the "rest-xml-json" directory run: - - $ mvn clean install - -Which should create output like the following. - - /opt/softs/java/jdk1.6.0_30/bin/java -ea -Didea.launcher.port=7534 -Didea.launcher.bin.path=/opt/softs/idea/bin -Dfile.encoding=UTF-8 -classpath /opt/softs/idea/lib/idea_rt.jar:/opt/softs/idea/plugins/junit/lib/junit-rt.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/plugin.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/javaws.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/jce.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/charsets.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/resources.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/deploy.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/management-agent.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/jsse.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/rt.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/ext/localedata.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/ext/sunjce_provider.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/ext/sunpkcs11.jar:/opt/softs/java/jdk1.6.0_30/jre/lib/ext/dnsns.jar:/opt/dev/openejb/openejb-trunk/examples/rest-xml-json/target/test-classes:/opt/dev/openejb/openejb-trunk/examples/rest-xm l-json/target/classes:/home/rmannibucau/.m2/repository/org/apache/openejb/javaee-api/6.0-4/javaee-api-6.0-4.jar:/home/rmannibucau/.m2/repository/junit/junit/4.10/junit-4.10.jar:/home/rmannibucau/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-cxf-rs/4.5.1/openejb-cxf-rs-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-http/4.5.1/openejb-http-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-core/4.5.1/openejb-core-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/mbean-annotation-api/4.5.1/mbean-annotation-api-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-jpa-integration/4.5.1/openejb-jpa-integration-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-api/4.5.1/openejb-api-4.5.1.jar:/home/rmannibucau/.m2/repository/org/a pache/openejb/openejb-loader/4.5.1/openejb-loader-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-javaagent/4.5.1/openejb-javaagent-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-jee/4.5.1/openejb-jee-4.5.1.jar:/home/rmannibucau/.m2/repository/com/sun/xml/bind/jaxb-impl/2.1.13/jaxb-impl-2.1.13.jar:/home/rmannibucau/.m2/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar:/home/rmannibucau/.m2/repository/org/apache/activemq/activemq-ra/5.7.0/activemq-ra-5.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/activemq/activemq-core/5.7.0/activemq-core-5.7.0.jar:/home/rmannibucau/.m2/repository/org/slf4j/slf4j-api/1.7.2/slf4j-api-1.7.2.jar:/home/rmannibucau/.m2/repository/org/apache/activemq/kahadb/5.7.0/kahadb-5.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/activemq/protobuf/activemq-protobuf/1.1/activemq-protobuf-1.1.jar:/home/rmannibucau/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar:/home/rmannib ucau/.m2/repository/commons-net/commons-net/3.1/commons-net-3.1.jar:/home/rmannibucau/.m2/repository/org/apache/geronimo/components/geronimo-connector/3.1.1/geronimo-connector-3.1.1.jar:/home/rmannibucau/.m2/repository/org/apache/geronimo/components/geronimo-transaction/3.1.1/geronimo-transaction-3.1.1.jar:/home/rmannibucau/.m2/repository/org/apache/geronimo/specs/geronimo-j2ee-connector_1.6_spec/1.0/geronimo-j2ee-connector_1.6_spec-1.0.jar:/home/rmannibucau/.m2/repository/org/objectweb/howl/howl/1.0.1-1/howl-1.0.1-1.jar:/home/rmannibucau/.m2/repository/org/apache/geronimo/javamail/geronimo-javamail_1.4_mail/1.8.2/geronimo-javamail_1.4_mail-1.8.2.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbean-asm-shaded/3.12/xbean-asm-shaded-3.12.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbean-finder-shaded/3.12/xbean-finder-shaded-3.12.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbean-reflect/3.12/xbean-reflect-3.12.jar:/home/rmannibucau/.m2/repository/org/apache/ xbean/xbean-naming/3.12/xbean-naming-3.12.jar:/home/rmannibucau/.m2/repository/org/apache/xbean/xbean-bundleutils/3.12/xbean-bundleutils-3.12.jar:/home/rmannibucau/.m2/repository/org/hsqldb/hsqldb/2.2.8/hsqldb-2.2.8.jar:/home/rmannibucau/.m2/repository/commons-dbcp/commons-dbcp/1.4/commons-dbcp-1.4.jar:/home/rmannibucau/.m2/repository/commons-pool/commons-pool/1.5.7/commons-pool-1.5.7.jar:/home/rmannibucau/.m2/repository/org/codehaus/swizzle/swizzle-stream/1.6.1/swizzle-stream-1.6.1.jar:/home/rmannibucau/.m2/repository/wsdl4j/wsdl4j/1.6.2/wsdl4j-1.6.2.jar:/home/rmannibucau/.m2/repository/org/quartz-scheduler/quartz/2.1.6/quartz-2.1.6.jar:/home/rmannibucau/.m2/repository/org/slf4j/slf4j-jdk14/1.7.2/slf4j-jdk14-1.7.2.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-impl/1.1.6/openwebbeans-impl-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-spi/1.1.6/openwebbeans-spi-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebb eans/openwebbeans-ejb/1.1.6/openwebbeans-ejb-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-ee/1.1.6/openwebbeans-ee-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-ee-common/1.1.6/openwebbeans-ee-common-1.1.6.jar:/home/rmannibucau/.m2/repository/org/apache/openwebbeans/openwebbeans-web/1.1.6/openwebbeans-web-1.1.6.jar:/home/rmannibucau/.m2/repository/org/javassist/javassist/3.15.0-GA/javassist-3.15.0-GA.jar:/home/rmannibucau/.m2/repository/org/apache/openjpa/openjpa/2.2.0/openjpa-2.2.0.jar:/home/rmannibucau/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar:/home/rmannibucau/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar:/home/rmannibucau/.m2/repository/net/sourceforge/serp/serp/1.13.1/serp-1.13.1.jar:/home/rmannibucau/.m2/repository/asm/asm/3.2/asm-3.2.jar:/home/rmannibucau/.m2/repository/org/apache/bval/bval-core/0.5/bval-core-0.5.jar:/home/rmannibucau/.m2/r epository/commons-beanutils/commons-beanutils-core/1.8.3/commons-beanutils-core-1.8.3.jar:/home/rmannibucau/.m2/repository/org/apache/bval/bval-jsr303/0.5/bval-jsr303-0.5.jar:/home/rmannibucau/.m2/repository/org/fusesource/jansi/jansi/1.8/jansi-1.8.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-server/4.5.1/openejb-server-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-client/4.5.1/openejb-client-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-ejbd/4.5.1/openejb-ejbd-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-rest/4.5.1/openejb-rest-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/openejb/openejb-cxf-transport/4.5.1/openejb-cxf-transport-4.5.1.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-transports-http/2.7.0/cxf-rt-transports-http-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-api/2.7.0/cxf-api-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/ws/xmlschema/x mlschema-core/2.0.3/xmlschema-core-2.0.3.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-core/2.7.0/cxf-rt-core-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-frontend-jaxrs/2.7.0/cxf-rt-frontend-jaxrs-2.7.0.jar:/home/rmannibucau/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.0-m10/javax.ws.rs-api-2.0-m10.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-bindings-xml/2.7.0/cxf-rt-bindings-xml-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-rs-extension-providers/2.7.0/cxf-rt-rs-extension-providers-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-rs-extension-search/2.7.0/cxf-rt-rs-extension-search-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-rs-security-cors/2.7.0/cxf-rt-rs-security-cors-2.7.0.jar:/home/rmannibucau/.m2/repository/org/apache/cxf/cxf-rt-rs-security-oauth2/2.7.0/cxf-rt-rs-security-oauth2-2.7.0.jar:/home/rmannibucau/.m2/repository/org/codehaus/jettison/jettison/1.3/jettison-1.3.jar: /home/rmannibucau/.m2/repository/stax/stax-api/1.0.1/stax-api-1.0.1.jar com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 org.superbiz.rest.GreetingServiceTest - INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. - INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) - INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) - INFO - Creating TransactionManager(id=Default Transaction Manager) - INFO - Creating SecurityService(id=Default Security Service) - INFO - Initializing network services - INFO - Creating ServerService(id=httpejbd) - INFO - Using 'print=true' - INFO - Using 'indent.xml=true' - INFO - Creating ServerService(id=cxf-rs) - INFO - Initializing network services - INFO - Starting service httpejbd - INFO - Started service httpejbd - INFO - Starting service cxf-rs - INFO - Started service cxf-rs - INFO - ** Bound Services ** - INFO - NAME IP PORT - INFO - httpejbd 127.0.0.1 4204 - INFO - ------- - INFO - Ready! - INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest - INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) - INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container) - INFO - Creating Container(id=Default Managed Container) - INFO - Using directory /tmp for stateful session passivation - INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded. - INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest - INFO - Existing thread singleton service in SystemInstance() null - INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@54128635 - INFO - Succeeded in installing singleton service - INFO - OpenWebBeans Container is starting... - INFO - Adding OpenWebBeansPlugin : [CdiPlugin] - INFO - All injection points are validated successfully. - INFO - OpenWebBeans Container has started, it took 102 ms. - INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest) - INFO - Setting the server's publish address to be http://127.0.0.1:4204/test - INFO - REST Service: http://127.0.0.1:4204/test/greeting/.* -> Pojo org.superbiz.rest.GreetingService - FINE - ******************* REQUEST ****************** - GET http://localhost:4204/test/greeting/ - Host=localhost:4204 - User-Agent=Apache CXF 2.7.0 - Connection=keep-alive - Accept=application/xml - Content-Type=*/* - Pragma=no-cache - Cache-Control=no-cache - - - ********************************************** - - FINE - HTTP/1.1 200 OK - Date: Fri, 09 Nov 2012 11:59:00 GMT - Content-Length: 44 - Set-Cookie: EJBSESSIONID=fc5037fa-641c-495d-95ca-0755cfa50beb; Path=/ - Content-Type: application/xml - Connection: close - Server: OpenEJB/4.5.1 Linux/3.2.0-23-generic (amd64) - - -[source,xml] ----- -<response><value>Hi REST!</value></response> -INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Stopping network services -INFO - Stopping server services -INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. -INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) -INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) -INFO - Creating TransactionManager(id=Default Transaction Manager) -INFO - Creating SecurityService(id=Default Security Service) -INFO - Initializing network services -INFO - Creating ServerService(id=httpejbd) -INFO - Using 'print=true' -INFO - Using 'indent.xml=true' -INFO - Creating ServerService(id=cxf-rs) -INFO - Initializing network services -INFO - Starting service httpejbd -INFO - Started service httpejbd -INFO - Starting service cxf-rs -INFO - Started service cxf-rs -INFO - ** Bound Services ** -INFO - NAME IP PORT -INFO - httpejbd 127.0.0.1 4204 -INFO - ------- -INFO - Ready! -INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) -INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container) -INFO - Creating Container(id=Default Managed Container) -INFO - Using directory /tmp for stateful session passivation -INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded. -INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Existing thread singleton service in SystemInstance() null -INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@54128635 -INFO - Succeeded in installing singleton service -INFO - OpenWebBeans Container is starting... -INFO - Adding OpenWebBeansPlugin : [CdiPlugin] -INFO - All injection points are validated successfully. -INFO - OpenWebBeans Container has started, it took 11 ms. -INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest) -INFO - Setting the server's publish address to be http://127.0.0.1:4204/test -INFO - REST Service: http://127.0.0.1:4204/test/greeting/.* -> Pojo org.superbiz.rest.GreetingService -FINE - ******************* REQUEST ****************** -POST http://localhost:4204/test/greeting/ -Host=localhost:4204 -Content-Length=97 -User-Agent=Apache CXF 2.7.0 -Connection=keep-alive -Accept=application/xml -Content-Type=application/xml -Pragma=no-cache -Cache-Control=no-cache - -<?xml version="1.0" encoding="UTF-8" standalone="yes"?><request><value>Hi REST!</value></request> -********************************************** - -FINE - HTTP/1.1 200 OK -Date: Fri, 09 Nov 2012 11:59:00 GMT -Content-Length: 44 -Set-Cookie: EJBSESSIONID=7cb2246d-5738-4a85-aac5-c0fb5340d36a; Path=/ -Content-Type: application/xml -Connection: close -Server: OpenEJB/4.5.1 Linux/3.2.0-23-generic (amd64) - -<response><value>hi rest!</value></response> -INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Stopping network services -INFO - Stopping server services -INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. -INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) -INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) -INFO - Creating TransactionManager(id=Default Transaction Manager) -INFO - Creating SecurityService(id=Default Security Service) -INFO - Initializing network services -INFO - Creating ServerService(id=httpejbd) -INFO - Using 'print=true' -INFO - Using 'indent.xml=true' -INFO - Creating ServerService(id=cxf-rs) -INFO - Initializing network services -INFO - Starting service httpejbd -INFO - Started service httpejbd -INFO - Starting service cxf-rs -INFO - Started service cxf-rs -INFO - ** Bound Services ** -INFO - NAME IP PORT -INFO - httpejbd 127.0.0.1 4204 -INFO - ------- -INFO - Ready! -INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) -INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container) -INFO - Creating Container(id=Default Managed Container) -INFO - Using directory /tmp for stateful session passivation -INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded. -INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Existing thread singleton service in SystemInstance() null -INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@54128635 -INFO - Succeeded in installing singleton service -INFO - OpenWebBeans Container is starting... -INFO - Adding OpenWebBeansPlugin : [CdiPlugin] -INFO - All injection points are validated successfully. -INFO - OpenWebBeans Container has started, it took 10 ms. -INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest) -INFO - Setting the server's publish address to be http://127.0.0.1:4204/test -INFO - REST Service: http://127.0.0.1:4204/test/greeting/.* -> Pojo org.superbiz.rest.GreetingService -FINE - ******************* REQUEST ****************** -GET http://localhost:4204/test/greeting/ -Host=localhost:4204 -User-Agent=Apache CXF 2.7.0 -Connection=keep-alive -Accept=application/json -Content-Type=*/* -Pragma=no-cache -Cache-Control=no-cache - - -********************************************** - -FINE - HTTP/1.1 200 OK -Date: Fri, 09 Nov 2012 11:59:00 GMT -Content-Length: 33 -Set-Cookie: EJBSESSIONID=7112a057-fc4c-4f52-a556-1617320d2275; Path=/ -Content-Type: application/json -Connection: close -Server: OpenEJB/4.5.1 Linux/3.2.0-23-generic (amd64) - -{"response":{"value":"Hi REST!"}} -INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Stopping network services -INFO - Stopping server services -INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt to create one for the beans deployed. -INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) -INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) -INFO - Creating TransactionManager(id=Default Transaction Manager) -INFO - Creating SecurityService(id=Default Security Service) -INFO - Initializing network services -INFO - Creating ServerService(id=httpejbd) -INFO - Using 'print=true' -INFO - Using 'indent.xml=true' -INFO - Creating ServerService(id=cxf-rs) -INFO - Initializing network services -INFO - Starting service httpejbd -INFO - Started service httpejbd -INFO - Starting service cxf-rs -INFO - Started service cxf-rs -INFO - ** Bound Services ** -INFO - NAME IP PORT -INFO - httpejbd 127.0.0.1 4204 -INFO - ------- -INFO - Ready! -INFO - Configuring enterprise application: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) -INFO - Auto-creating a container for bean org.superbiz.rest.GreetingServiceTest: Container(type=MANAGED, id=Default Managed Container) -INFO - Creating Container(id=Default Managed Container) -INFO - Using directory /tmp for stateful session passivation -INFO - Enterprise application "/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest" loaded. -INFO - Assembling app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Existing thread singleton service in SystemInstance() null -INFO - Created new singletonService org.apache.openejb.cdi.ThreadSingletonServiceImpl@54128635 -INFO - Succeeded in installing singleton service -INFO - OpenWebBeans Container is starting... -INFO - Adding OpenWebBeansPlugin : [CdiPlugin] -INFO - All injection points are validated successfully. -INFO - OpenWebBeans Container has started, it took 10 ms. -INFO - Deployed Application(path=/opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest) -INFO - Setting the server's publish address to be http://127.0.0.1:4204/test -INFO - REST Service: http://127.0.0.1:4204/test/greeting/.* -> Pojo org.superbiz.rest.GreetingService -FINE - ******************* REQUEST ****************** -POST http://localhost:4204/test/greeting/ -Host=localhost:4204 -Content-Length=97 -User-Agent=Apache CXF 2.7.0 -Connection=keep-alive -Accept=application/json -Content-Type=application/xml -Pragma=no-cache -Cache-Control=no-cache - -<?xml version="1.0" encoding="UTF-8" standalone="yes"?><request><value>Hi REST!</value></request> -********************************************** - -FINE - HTTP/1.1 200 OK -Date: Fri, 09 Nov 2012 11:59:01 GMT -Content-Length: 33 -Set-Cookie: EJBSESSIONID=50cf1d2b-a940-4afb-8993-fff7f9cc6d83; Path=/ -Content-Type: application/json -Connection: close -Server: OpenEJB/4.5.1 Linux/3.2.0-23-generic (amd64) - -{"response":{"value":"hi rest!"}} -INFO - Undeploying app: /opt/dev/openejb/openejb-trunk/examples/GreetingServiceTest -INFO - Stopping network services -INFO - Stopping server services - - - - - http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/efed31f4/src/main/jbake/content/examples/scala-basic.adoc ---------------------------------------------------------------------- diff --git a/src/main/jbake/content/examples/scala-basic.adoc b/src/main/jbake/content/examples/scala-basic.adoc deleted file mode 100755 index e60894c..0000000 --- a/src/main/jbake/content/examples/scala-basic.adoc +++ /dev/null @@ -1,9 +0,0 @@ -= scala-basic -:jbake-date: 2016-09-06 -:jbake-type: page -:jbake-tomeepdf: -:jbake-status: published - -Example scala-basic can be browsed at https://github.com/apache/tomee/tree/master/examples/scala-basic - -No README.md yet, be the first to contribute one!
