[CXF-5962] Make LogBrowser sample also run in OSGi
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4bddc1f4 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4bddc1f4 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4bddc1f4 Branch: refs/heads/3.0.x-fixes Commit: 4bddc1f4a2284f983e576e726cf381c30845192a Parents: a3e0716 Author: Akitoshi Yoshida <[email protected]> Authored: Tue Aug 19 19:23:36 2014 +0200 Committer: Akitoshi Yoshida <[email protected]> Committed: Wed Aug 20 14:21:54 2014 +0200 ---------------------------------------------------------------------- .../main/release/samples/logbrowser/README.txt | 20 ++- .../src/main/release/samples/logbrowser/pom.xml | 79 ++++++-- .../src/main/java/demo/service/Server.java | 2 +- .../logbrowser/src/main/webapp/WEB-INF/web.xml | 62 +++++++ .../src/main/webapp/customer-service.html | 179 +++++++++++++++++++ .../src/main/webapp/jquery-1.4.2.min.js | 154 ++++++++++++++++ .../samples/logbrowser/webapp/WEB-INF/web.xml | 62 ------- .../logbrowser/webapp/customer-service.html | 175 ------------------ .../logbrowser/webapp/jquery-1.4.2.min.js | 154 ---------------- .../features/src/main/resources/features.xml | 11 ++ rt/management-web/pom.xml | 4 + 11 files changed, 496 insertions(+), 406 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/4bddc1f4/distribution/src/main/release/samples/logbrowser/README.txt ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/logbrowser/README.txt b/distribution/src/main/release/samples/logbrowser/README.txt index 467becf..4b53588 100644 --- a/distribution/src/main/release/samples/logbrowser/README.txt +++ b/distribution/src/main/release/samples/logbrowser/README.txt @@ -6,7 +6,7 @@ located), the pom.xml file is used to build and run the demo. Using either UNIX or Windows: -1) Build the project by typing: +0) Build the project by typing: mvn clean install 1) Start the server: mvn -Pserver @@ -18,3 +18,21 @@ Using either UNIX or Windows: http://localhost:9002/customer-service.html To remove the .class files, run "mvn clean". + + +This sample project generates a war file which can be used in a servlet container +or even in an OSGi container. + +Assuming you have a freshly intalled Apache Karaf-3.x, +1) Start Karaf and at its console, type (note m.n corresponding the version numbers) + feature:repo-add cxf 3.m.n + feature:install war + feature:install cxf-management-web + install -s mvn:org.apache.cxf.samples/logbrowser/3.1.0-SNAPSHOT/war + +2) Open browser and go to: + http://localhost:8181/cxf-samples-logbrowser/log/browser/LogBrowser.html +3) Add new endpoint with URL: + http://localhost:8181/cxf-samples-logbrowser/log/logs +4) To generate custom log entry open new browser's window and go to: + http://localhost:8181/cxf-samples-logbrowser/customer-service.html http://git-wip-us.apache.org/repos/asf/cxf/blob/4bddc1f4/distribution/src/main/release/samples/logbrowser/pom.xml ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/logbrowser/pom.xml b/distribution/src/main/release/samples/logbrowser/pom.xml index 09332a3..3fcd6b9 100644 --- a/distribution/src/main/release/samples/logbrowser/pom.xml +++ b/distribution/src/main/release/samples/logbrowser/pom.xml @@ -20,14 +20,72 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>logbrowser</artifactId> - <name>LogBrowser</name> - <description>LogBrowser</description> + <packaging>war</packaging> + <name>Apache CXF Samples LogBrowser</name> + <description>Apacher CXF Samples LogBrowser</description> <parent> <groupId>org.apache.cxf.samples</groupId> <artifactId>cxf-samples</artifactId> <version>3.0.2-SNAPSHOT</version> <relativePath>..</relativePath> </parent> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.6</source> + <target>1.6</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <!-- excluding libs and classes/META-INF for OSGi --> + <packagingExcludes>WEB-INF/lib/,WEB-INF/classes/META-INF/</packagingExcludes> + <archive> + <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <executions> + <execution> + <id>bundle-manifest</id> + <phase>process-classes</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + <extensions>true</extensions> + <configuration> + <supportedProjectTypes> + <supportedProjectType>jar</supportedProjectType> + <supportedProjectType>bundle</supportedProjectType> + <supportedProjectType>war</supportedProjectType> + </supportedProjectTypes> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Bundle-Description>${project.description}</Bundle-Description> + <Web-ContextPath>/cxf-samples-logbrowser</Web-ContextPath> + <Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath> + <Export-Package /> + <Import-Package> + org.apache.cxf.jaxrs.servlet, + org.apache.abdera.parser.stax, + com.ctc.wstx.stax, + org.apache.abdera, + * + </Import-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> <profiles> <profile> <id>server</id> @@ -59,17 +117,6 @@ </build> </profile> </profiles> - <build> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.6</source> - <target>1.6</target> - </configuration> - </plugin> - </plugins> - </build> <dependencies> <dependency> <groupId>org.apache.cxf</groupId> @@ -98,6 +145,12 @@ <dependency> <groupId>org.apache.abdera</groupId> <artifactId>abdera-parser</artifactId> + <exclusions> + <exclusion> + <groupId>org.apache.james</groupId> + <artifactId>apache-mime4j-core</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> http://git-wip-us.apache.org/repos/asf/cxf/blob/4bddc1f4/distribution/src/main/release/samples/logbrowser/src/main/java/demo/service/Server.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/logbrowser/src/main/java/demo/service/Server.java b/distribution/src/main/release/samples/logbrowser/src/main/java/demo/service/Server.java index 2373433..53aed96 100644 --- a/distribution/src/main/release/samples/logbrowser/src/main/java/demo/service/Server.java +++ b/distribution/src/main/release/samples/logbrowser/src/main/java/demo/service/Server.java @@ -47,7 +47,7 @@ public class Server { WebAppContext webappcontext = new WebAppContext(); webappcontext.setContextPath("/"); - webappcontext.setWar("webapp"); + webappcontext.setWar("src/main/webapp"); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] {webappcontext, new DefaultHandler()}); http://git-wip-us.apache.org/repos/asf/cxf/blob/4bddc1f4/distribution/src/main/release/samples/logbrowser/src/main/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/logbrowser/src/main/webapp/WEB-INF/web.xml b/distribution/src/main/release/samples/logbrowser/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..cd164ea --- /dev/null +++ b/distribution/src/main/release/samples/logbrowser/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> + <servlet> + <servlet-name>CustomerService</servlet-name> + <display-name>CustomerService</display-name> + <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class> + <init-param> + <param-name>javax.ws.rs.Application</param-name> + <param-value>demo.service.App</param-value> + </init-param> + <init-param> + <param-name>jaxrs.inInterceptors</param-name> + <param-value> + org.apache.cxf.interceptor.LoggingInInterceptor + </param-value> + </init-param> + <init-param> + <param-name>jaxrs.outInterceptors</param-name> + <param-value> + org.apache.cxf.interceptor.LoggingOutInterceptor + </param-value> + </init-param> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet> + <servlet-name>BrowserServlet</servlet-name> + <display-name>BrowserServlet</display-name> + <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class> + <init-param> + <param-name>javax.ws.rs.Application</param-name> + <param-value>demo.logbrowser.App</param-value> + </init-param> + <load-on-startup>2</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>BrowserServlet</servlet-name> + <url-pattern>/log/*</url-pattern> + </servlet-mapping> + <servlet-mapping> + <servlet-name>CustomerService</servlet-name> + <url-pattern>/service/*</url-pattern> + </servlet-mapping> +</web-app> +<!-- END SNIPPET: webxml --> http://git-wip-us.apache.org/repos/asf/cxf/blob/4bddc1f4/distribution/src/main/release/samples/logbrowser/src/main/webapp/customer-service.html ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/logbrowser/src/main/webapp/customer-service.html b/distribution/src/main/release/samples/logbrowser/src/main/webapp/customer-service.html new file mode 100644 index 0000000..97c2ceb --- /dev/null +++ b/distribution/src/main/release/samples/logbrowser/src/main/webapp/customer-service.html @@ -0,0 +1,179 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> + <title>Customer Service</title> + + <style type="text/css"> + label { + width: 5em; + float: left; + text-align: right; + margin-right: 0.5em; + display: block; + } + .submit a { + margin-left: 5.5em; + } + .submit input { + margin-left: 8em; + } + </style> + + <script type="text/javascript" src="./jquery-1.4.2.min.js"></script> + + <script type="text/javascript"> + + var wloc = window.location.pathname; + wloc = wloc.substring(0, wloc.lastIndexOf('/')); + + function buildCustomerAsString(id, name) { + return "{ \"Customer\" : { \"id\" : \"" + id + "\", \"name\" : \"" + name +"\" } }"; + } + + $(document).ready(function() { + $("#addOrUpdateCustomerButton").click(function() { + var isError = false; + + var id = $("#addOrUpdateCustomerForm INPUT[name='customer.id']").val(); + if (id == null || id == "") { + alert("Field 'ID' can't be empty"); + isError = true; + } + + var name = $("#addOrUpdateCustomerForm INPUT[name='customer.name']").val(); + if (name == null || name == "") { + alert("Field 'Name' can't be empty"); + isError = true; + } + + if (isError) { + return; + } + + $.ajax({ + type: "POST", + url : wloc + "/service/customers/", + contentType : "application/json", + data : buildCustomerAsString(id, name), + complete : function(xhr) { + if (xhr.status == 200) { + alert("Customer added/updated successfully"); + } else { + alert("Error occurred"); + } + } + }); + }); + + $("#getCustomerButton").click(function() { + var id = $("#getCustomerForm INPUT[name='customer.id']").val(); + if (id == null || id == "") { + alert("Field 'ID' can't be empty"); + return; + } + + $.ajax({ + type: "GET", + url : wloc + "/service/customers/" + id, + dataType : "text", + complete : function(xhr) { + if (xhr.status == 200) { + alert(xhr.responseText); + } else if (xhr.status == 204) { + alert("Customer, with specified ID, doesn't exist"); + } else { + alert("Error occurred"); + } + } + }); + }); + + $("#deleteCustomerButton").click(function() { + var id = $("#deleteCustomerForm INPUT[name='customer.id']").val(); + if (id == null || id == "") { + alert("Field 'ID' can't be empty"); + return; + } + + $.ajax({ + type: "DELETE", + url : wloc + "/service/customers/" + id, + complete : function(xhr) { + if (xhr.status == 200) { + alert("Customer deleted successfully"); + } else if (xhr.status == 304) { + alert("Customer, with specified ID, doesn't exist"); + } else { + alert("Error occurred"); + } + } + }); + }); + + $("INPUT.digits").keyup(function () { + this.value = this.value.replace(/[^0-9\.]/g,''); + }); + }); + </script> +</head> +<body> + +<div> + <h1>Customer Service</h1> + + <h2>Add or update customer</h2> + <form id="addOrUpdateCustomerForm" action="#"> + <p> + <label>ID:</label> + <input name="customer.id" class="digits" type="text" size="3"/> + </p> + + <p> + <label>Name:</label> + <input name="customer.name" type="text" size="30"/> + </p> + + <p class="submit"><a id="addOrUpdateCustomerButton" href="#">Add or Update</a></p> + </form> + + <h2>Get customer</h2> + <form id="getCustomerForm" action="#"> + <p> + <label>ID:</label> + <input name="customer.id" class="digits" type="text" size="3"/> + </p> + + <p class="submit"><a id="getCustomerButton" href="#">Get</a></p> + </form> + + <h2>Delete customer</h2> + <form id="deleteCustomerForm" action="#"> + <p> + <label>ID:</label> + <input name="customer.id" class="digits" type="text" size="3"/> + </p> + + <p class="submit"><a id="deleteCustomerButton" href="#">Delete</a></p> + </form> +</div> +</body> +</html>
