Add a simple Tuscany webapp project that could be used as the starting point for a Tuscany manager webapp (TUSCANY-3519)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1140984 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
44730b6cf8
commit
4d140a19d3
8 changed files with 403 additions and 0 deletions
32
collaboration/webapp/tuscany/README
Normal file
32
collaboration/webapp/tuscany/README
Normal file
|
@ -0,0 +1,32 @@
|
|||
Tuscany - Getting Started - Helloworld WebApp Sample
|
||||
----------------------------------------------------
|
||||
|
||||
This sample demonstrates how to use SCA contributions with Web Applications
|
||||
|
||||
See the README in the top-level samples folder for general information on the Tuscany samples.
|
||||
|
||||
This sample project creates a .war web application which includes Tuscany. The SCA contribution
|
||||
from the helloworld sample is included within the war and its SCA composite started by the webapp,
|
||||
and there is a JSP page which shows how to invoke SCA services by using the SCA taglib.
|
||||
|
||||
As this sample creates a web application .war archive there is a manual step to deploy the WAR file
|
||||
to your web application server. The archive is the helloworld-webapp-<version>.war in the target folder.
|
||||
Alternatively, you can run it by using the Maven Tomcat plugin by using the following command:
|
||||
|
||||
mvn tomcat:run
|
||||
|
||||
or if you prefer Jetty then:
|
||||
|
||||
mvn jetty:run
|
||||
|
||||
Once the web app is running use your browser to visit the following URL;
|
||||
|
||||
http://localhost:8080/helloworld-webapp
|
||||
|
||||
(The port and hostname will of course vary depending on your local installation)
|
||||
|
||||
You should then see the web page return the following:
|
||||
|
||||
Calling HelloworldService sayHello("world") returns:
|
||||
|
||||
Hello world
|
148
collaboration/webapp/tuscany/pom.xml
Normal file
148
collaboration/webapp/tuscany/pom.xml
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<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>
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.tuscany.sca.samples</groupId>
|
||||
<artifactId>tuscany-samples</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>tuscany</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
|
||||
<name>Apache Tuscany WebApp</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<properties>
|
||||
<tuscany.version>${project.version}</tuscany.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-base-runtime</artifactId>
|
||||
<version>${tuscany.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlunit</groupId>
|
||||
<artifactId>htmlunit</artifactId>
|
||||
<version>2.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
|
||||
<!-- this copies the SCA contribution from the helloworld sample into this webapp -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.apache.tuscany.sca.samples</groupId>
|
||||
<artifactId>helloworld</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<!-- should really go in the target folder but i can't get jetty:run or tomcat:run to work using that -->
|
||||
<outputDirectory>src/main/webapp/WEB-INF/sca-contributions</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- to support running thw webapp with mvn tuscany:run -->
|
||||
<plugin>
|
||||
<groupId>org.apache.tuscany.sca</groupId>
|
||||
<artifactId>tuscany-maven-plugin</artifactId>
|
||||
<version>${tuscany.version}</version>
|
||||
</plugin>
|
||||
|
||||
<!-- to support using mvn jetty:run and also to run the webapp for the integration test -->
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>maven-jetty-plugin</artifactId>
|
||||
<version>6.1.26</version>
|
||||
<configuration>
|
||||
<contextPath>helloworld-webapp</contextPath>
|
||||
<stopKey>foo</stopKey>
|
||||
<stopPort>9999</stopPort>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>process-test-classes</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
<connectors>
|
||||
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
|
||||
<port>8085</port>
|
||||
</connector>
|
||||
</connectors>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- to support using mvn tomcat:run -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>tomcat-maven-plugin</artifactId>
|
||||
<version>1.1</version>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
package sample;
|
||||
|
||||
import org.oasisopen.sca.annotation.Remotable;
|
||||
|
||||
@Remotable
|
||||
public interface Helloworld {
|
||||
|
||||
String sayHello(String name);
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
* 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.
|
||||
-->
|
||||
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
|
||||
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
|
||||
targetNamespace="http://samples"
|
||||
name="Helloworld">
|
||||
|
||||
<component name="foo">
|
||||
<implementation.web web-uri=""/>
|
||||
<reference name="service" target="HelloworldComponent"/>
|
||||
</component>
|
||||
|
||||
</composite>
|
45
collaboration/webapp/tuscany/src/main/webapp/WEB-INF/web.xml
Normal file
45
collaboration/webapp/tuscany/src/main/webapp/WEB-INF/web.xml
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
* 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 version="2.4"
|
||||
xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
|
||||
|
||||
<display-name>Apache Tuscany</display-name>
|
||||
|
||||
<listener>
|
||||
<listener-class>org.apache.tuscany.sca.host.webapp.TuscanyContextListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<filter>
|
||||
<filter-name>tuscany</filter-name>
|
||||
<filter-class>org.apache.tuscany.sca.host.webapp.TuscanyServletFilter</filter-class>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>tuscany</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<welcome-file-list id="WelcomeFileList">
|
||||
<welcome-file>hello.jsp</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
</web-app>
|
37
collaboration/webapp/tuscany/src/main/webapp/hello.jsp
Normal file
37
collaboration/webapp/tuscany/src/main/webapp/hello.jsp
Normal file
|
@ -0,0 +1,37 @@
|
|||
<!--
|
||||
* 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.
|
||||
-->
|
||||
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %>
|
||||
|
||||
<sca:reference name="service" type="sample.Helloworld" />
|
||||
|
||||
<html>
|
||||
<body >
|
||||
|
||||
<h2>Apache Tuscany Helloworld JSP Sample</h2>
|
||||
|
||||
Calling HelloworldService sayHello("world") returns:
|
||||
|
||||
<p>
|
||||
|
||||
<%= service.sayHello("world") %>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package itest;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlParagraph;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class HelloworldTestCase {
|
||||
|
||||
@Test
|
||||
public void testA() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
|
||||
HtmlPage page = (HtmlPage)new WebClient().getPage("http://localhost:8085/helloworld-webapp");
|
||||
Iterator<?> ss = page.getAllHtmlChildElements().iterator();
|
||||
while(ss.hasNext()) {
|
||||
HtmlElement htmlElement = (HtmlElement) ss.next();
|
||||
if( htmlElement instanceof HtmlParagraph) {
|
||||
assertEquals("Hello world", htmlElement.asText());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
30
collaboration/webapp/tuscany/src/test/resources/test-web.xml
Normal file
30
collaboration/webapp/tuscany/src/test/resources/test-web.xml
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
* 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 version="2.4"
|
||||
xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
|
||||
|
||||
<context-param>
|
||||
<param-name>org.apache.tuscany.sca.config</param-name>
|
||||
<param-value>uri:default?bind=127.0.0.1:54321</param-value>
|
||||
</context-param>
|
||||
|
||||
</web-app>
|
Loading…
Reference in a new issue