Return-Path: X-Original-To: apmail-airavata-commits-archive@www.apache.org Delivered-To: apmail-airavata-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AABCCE769 for ; Mon, 3 Dec 2012 18:27:08 +0000 (UTC) Received: (qmail 21360 invoked by uid 500); 3 Dec 2012 18:27:08 -0000 Delivered-To: apmail-airavata-commits-archive@airavata.apache.org Received: (qmail 21305 invoked by uid 500); 3 Dec 2012 18:27:08 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 21294 invoked by uid 99); 3 Dec 2012 18:27:07 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Dec 2012 18:27:07 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Dec 2012 18:27:04 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A143B23888E4; Mon, 3 Dec 2012 18:26:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1416623 - in /airavata/trunk: ./ modules/server/ modules/server/src/ modules/server/src/main/ modules/server/src/main/java/ modules/server/src/main/java/org/ modules/server/src/main/java/org/apache/ modules/server/src/main/java/org/apache/... Date: Mon, 03 Dec 2012 18:26:44 -0000 To: commits@airavata.apache.org From: lahiru@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121203182644.A143B23888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lahiru Date: Mon Dec 3 18:26:39 2012 New Revision: 1416623 URL: http://svn.apache.org/viewvc?rev=1416623&view=rev Log: adding new server module to handle embedded tomcat startup. Added: airavata/trunk/modules/server/ airavata/trunk/modules/server/pom.xml airavata/trunk/modules/server/src/ airavata/trunk/modules/server/src/main/ airavata/trunk/modules/server/src/main/java/ airavata/trunk/modules/server/src/main/java/org/ airavata/trunk/modules/server/src/main/java/org/apache/ airavata/trunk/modules/server/src/main/java/org/apache/airavata/ airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/ airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java airavata/trunk/modules/server/src/main/resources/ airavata/trunk/modules/server/src/test/ airavata/trunk/modules/server/src/test/java/ airavata/trunk/modules/server/src/test/resources/ Modified: airavata/trunk/pom.xml Added: airavata/trunk/modules/server/pom.xml URL: http://svn.apache.org/viewvc/airavata/trunk/modules/server/pom.xml?rev=1416623&view=auto ============================================================================== --- airavata/trunk/modules/server/pom.xml (added) +++ airavata/trunk/modules/server/pom.xml Mon Dec 3 18:26:39 2012 @@ -0,0 +1,100 @@ + + + + + + + org.apache.airavata + airavata + 0.6-SNAPSHOT + ../../pom.xml + + + 4.0.0 + airavata-server + Airavata Embedded Tomcat Implementation + Module for starting embedded tomcat + + + org.apache.tomcat.embed + tomcat-embed-core + 7.0.22 + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + org.apache.tomcat.embed + tomcat-embed-logging-juli + 7.0.22 + + + org.apache.tomcat.embed + tomcat-embed-jasper + 7.0.22 + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-simple + + + junit + junit + 4.7 + test + + + org.apache.airavata + airavata-common-utils + ${project.version} + + + org.apache.tomcat + tomcat-jasper + 7.0.22 + + + org.apache.tomcat + tomcat-jasper-el + 7.0.22 + + + org.apache.tomcat + tomcat-jsp-api + 7.0.22 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + ${basedir}\src\test\java\ + + + + ${project.basedir}/src/test/java + ${project.build.directory}/test-classes + + + ${project.basedir}/src/test/resources + + + + Added: airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java?rev=1416623&view=auto ============================================================================== --- airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java (added) +++ airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcat.java Mon Dec 3 18:26:39 2012 @@ -0,0 +1,312 @@ +/* + * Copyright 2004,2005 The Apache Software Foundation. + * + * Licensed 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 org.apache.airavata.server; + + +import org.apache.catalina.*; +import org.apache.catalina.connector.Connector; +import org.apache.catalina.core.StandardHost; +import org.apache.catalina.startup.Embedded; +import org.apache.catalina.startup.Tomcat; +import org.apache.coyote.http11.AbstractHttp11JsseProtocol; +import org.apache.tomcat.util.IntrospectionUtils; + +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.util.HashMap; +import java.util.Map; + +/** + * This is an improvement to Embedded Tomcat. The objective is to provide a cleaner API for + * embedders. + */ +@SuppressWarnings("unused") +public class BetterTomcat { + private Tomcat tomcat = new Tomcat(); + private static Map connectors = new HashMap(); + private boolean unpackWars = true; + + public BetterTomcat() { + // Override the default Tomcat connector. Otherwise a Connector on 8080 will be started + tomcat.setConnector(new Connector(Protocol.HTTP_11.getProtocolName())); +// setDefaultHost("defaultHost"); +// setBaseDir("."); + } + + public BetterTomcat(int port) { + this(); + addConnector(Protocol.HTTP_11, null, port); + } + + /** + * Indicates whether WAR files should be unpacked or not + * + * @param unpackWars true - unpackWars + */ + public void setUnpackWars(boolean unpackWars) { + this.unpackWars = unpackWars; + } + + /** + * Start the server. + * + * @throws LifecycleException If an irrecoverable error occurs while starting + */ + public void start() throws LifecycleException { + tomcat.start(); + } + + /** + * Stop the server. + * + * @throws LifecycleException If an irrecoverable error occurs while stopping + */ + public void stop() throws LifecycleException { + tomcat.stop(); + } + + public Host getHost() { + Host host = tomcat.getHost(); + ((StandardHost) host).setUnpackWARs(unpackWars); + return host; + } + + /** + * Add a webapp using normal WEB-INF/web.xml if found. + * + * @param contextPath The context of the webapp, e.g., /foo + * @param webappFilePath The file path of the webapp. Can be the path to a WAR file or a + * directory, + * e.g., + * 1. /home/azeez/bettertomcat/foo.war + * 2. /home/azeez/bettertomcat/foo + * @return new Context The Context of the deployed webapp + * @throws BetterTomcatException If webapp deployment fails + */ + public Context addWebapp(String contextPath, + String webappFilePath) throws BetterTomcatException { + + Context context; + try { + context = tomcat.addWebapp(contextPath, webappFilePath); + if (context.getState().equals(LifecycleState.STOPPED)) { + throw new BetterTomcatException("Webapp " + context + " failed to deploy"); + } + if (!unpackWars) { + context.addParameter("antiJARLocking", "false"); + context.addParameter("antiResourceLocking", "false"); + } + return context; + } catch (ServletException e) { + throw new BetterTomcatException("Webapp failed to deploy", e); + } + } + + /** + * Add a webapp to a particular Host + * + * @param host The Host to which this webapp is added to + * @param contextPath The context of the webapp, e.g., /foo + * @param webappFilePath The file path of the webapp. Can be the path to a WAR file or a + * directory, + * e.g., + * 1. /home/azeez/bettertomcat/foo.war + * 2. /home/azeez/bettertomcat/foo + * @return new Context The Context of the deployed webapp + */ + public Context addWebapp(Host host, String contextPath, String webappFilePath) { + return tomcat.addWebapp(host, contextPath, webappFilePath); + } + + /** + * Add a context - programmatic mode, no web.xml used. + *

+ * API calls equivalent with web.xml: + *

+ * context-param + * ctx.addParameter("name", "value"); + *

+ *

+ * error-page + * ErrorPage ep = new ErrorPage(); + * ep.setErrorCode(500); + * ep.setLocation("/error.html"); + * ctx.addErrorPage(ep); + *

+ * ctx.addMimeMapping("ext", "type"); + *

+ * Note: If you reload the Context, all your configuration will be lost. If + * you need reload support, consider using a LifecycleListener to provide + * your configuration. + *

+ * + * @param contextPath The context of the webapp. "" for root context. + * @param baseDir base dir for the context, for static files. Must exist, + * relative to the server home + * @return new Context The Context of the deployed webapp + */ + public Context addContext(String contextPath, String baseDir) { + return tomcat.addContext(contextPath, baseDir); + } + + public Context addContext(Host host, String contextPath, String dir) { + return tomcat.addContext(host, contextPath, dir); + } + + /** + * Equivalent with + * . + *

+ * In general it is better/faster to use the method that takes a + * Servlet as param - this one can be used if the servlet is not + * commonly used, and want to avoid loading all deps. + * ( for example: jsp servlet ) + *

+ * You can customize the returned servlet, ex: + *

+ * wrapper.addInitParameter("name", "value"); + * + * @param contextPath Context to add Servlet to + * @param servletName Servlet name (used in mappings) + * @param servletClass The class to be used for the Servlet + * @return The wrapper for the servlet + */ + public Wrapper addServlet(String contextPath, + String servletName, + String servletClass) { + return tomcat.addServlet(contextPath, servletName, servletClass); + } + + /** + * Add an existing Servlet to the context with no class.forName or + * initialisation. + * + * @param contextPath Context to add Servlet to + * @param servletName Servlet name (used in mappings) + * @param servlet The Servlet to add + * @return The wrapper for the servlet + */ + public Wrapper addServlet(String contextPath, + String servletName, + Servlet servlet) { + return tomcat.addServlet(contextPath, servletName, servlet); + } + + /** + * Enables JNDI naming which is disabled by default. Server must implement + * {@link org.apache.catalina.Lifecycle} in order for the + * {@link org.apache.catalina.core.NamingContextListener} to be used. + */ + public void enableNaming() { + tomcat.enableNaming(); + } + + public Connector addConnector(int port) { + return addConnector(Protocol.HTTP_11, null, port); + } + + /** + * Get a Tomcat Connector. If a connector with the Tomcat connector does not exist, create a new + * one. + * + * @param protocol The protocol of the connector. + * @param address The IP address of the network interface to which this connector should bind + * to. Specify this as null if the connector should bind to all network interfaces. + * @param port The port on which this connector has to be run + * @return The Tomcat connector + */ + public Connector addConnector(Protocol protocol, String address, int port) { + Connector connector = connectors.get(protocol + "-" + address + "-" + port); + if (connector == null) { + connector = new Connector(protocol.getProtocolClass()); + if (address != null) { + IntrospectionUtils.setProperty(connector, "address", address); + } + connector.setPort(port); + connector.setEnableLookups(true); + connector.setProperty("bindOnInit", "false"); + if (protocol.equals(Protocol.HTTPS_11) || protocol.equals(Protocol.HTTPS_11_NIO)) { + connector.setSecure(true); + connector.setAttribute("SSLEnabled", "true"); + connector.setScheme("https"); + } + tomcat.getService().addConnector(connector); + } + return connector; + } + + public void setClientAuth(Connector connector, String clientAuth) { + ((AbstractHttp11JsseProtocol)connector.getProtocolHandler()).setClientAuth(clientAuth); + } + + public Connector getConnector(Protocol protocol, String address, int port) { + return addConnector(protocol, address, port); + } + + public void setBaseDir(String baseDir) { + tomcat.setBaseDir(baseDir); + } + + public void setDefaultHost(String defaultHostName) { + tomcat.setHostname(defaultHostName); + tomcat.getEngine().setDefaultHost(defaultHostName); + } + + public void setDefaultRealm(Realm realm) { + tomcat.setDefaultRealm(realm); + } + + /** + * The valid protocol types + */ + @SuppressWarnings("unused") + public static enum Protocol { + HTTP_11("HTTP/1.1", "HTTP/1.1"), + HTTPS_11("HTTPS/1.1", "HTTP/1.1"), + HTTP_11_NIO("HTTP/1.1/NIO", "org.apache.coyote.http11.Http11NioProtocol"), + HTTPS_11_NIO("HTTPS/1.1/NIO", "org.apache.coyote.http11.Http11NioProtocol"), + HTTP_11_APR("HTTP/1.1/APR","org.apache.coyote.http11.Http11AprProtocol"), + HTTPS_11_APR("HTTPS/1.1/APR", "org.apache.coyote.http11.Http11AprProtocol"), + MEMORY("memory", "org.apache.coyote.memory.MemoryProtocolHandler"), + AJP("ajp", "org.apache.coyote.ajp.AjpProtocol"); + + private String protocolName; + private String protocolClass; + + Protocol(String protocolName, String protocolClass) { + this.protocolName = protocolName; + this.protocolClass = protocolClass; + } + + public String getProtocolName() { + return protocolName; + } + + public String getProtocolClass() { + return protocolClass; + } + } + + /** + * Returns the wrapped Tomcat instance. This should be used only when advanced functionality + * is required + * + * @return The Tomcat instance which can be used by advanced users who wish to gain more control + */ + public Tomcat getTomcat() { + return tomcat; + } +} Added: airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java?rev=1416623&view=auto ============================================================================== --- airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java (added) +++ airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/BetterTomcatException.java Mon Dec 3 18:26:39 2012 @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. 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 org.apache.airavata.server; + + +/** + * BetterTomcatException + */ +public class BetterTomcatException extends Exception { + public BetterTomcatException() { + super(); + } + + public BetterTomcatException(String message) { + super(message); + } + + public BetterTomcatException(String message, Throwable cause) { + super(message, cause); + } + + public BetterTomcatException(Throwable cause) { + super(cause); + } +} Added: airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java URL: http://svn.apache.org/viewvc/airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java?rev=1416623&view=auto ============================================================================== --- airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java (added) +++ airavata/trunk/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java Mon Dec 3 18:26:39 2012 @@ -0,0 +1,93 @@ +/* + * + * 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 org.apache.airavata.server; + +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.catalina.Wrapper; +import java.io.File; +import org.apache.catalina.Host; +import org.apache.catalina.startup.Tomcat; + +public class ServerMain { + + private String path = null; + private Tomcat embedded = null; + private Host host = null; + + /** + * Default Constructor + */ + public ServerMain() { + } + + + /** + * This method Starts the Tomcat server. + */ + public void startTomcat() throws Exception { + + BetterTomcat tomcat = new BetterTomcat(Integer.parseInt(ServerSettings.getTomcatPort())); + tomcat.addContext("/axis2", System.getenv("AIRAVATA_HOME")); + Wrapper axis2Servlet = tomcat.addServlet("/axis2", "AxisServlet", "org.apache.axis2.transport.http.AxisServlet"); + axis2Servlet.addMapping("/servlet/AxisServlet"); + axis2Servlet.addMapping("*.jws"); + axis2Servlet.addMapping("/services/*"); + axis2Servlet.addInitParameter("axis2.repository.path",System.getenv("AIRAVATA_HOME") + File.separator + "repository"); + axis2Servlet.addInitParameter("axis2.xml.path", System.getenv("AIRAVATA_HOME") + + File.separator + "bin" + File.separator + "axis2.xml"); + axis2Servlet.setLoadOnStartup(1); + +// Wrapper registryServlet = tomcat.addServlet("/registry", "Airavata Web Application", "com.sun.jersey.spi.container.servlet.ServletContainer"); +// registryServlet.addInitParameter("com.sun.jersey.config.property.packages","org.apache.airavata.services.registry.rest;org.codehaus.jackson.jaxrs"); +// registryServlet.setLoadOnStartup(1); + tomcat.start(); + } + + /** + * This method Stops the Tomcat server. + */ + public void stopTomcat() throws Exception { + // Stop the embedded server + embedded.stop(); + } + + + public static void main(String args[]) { + try { + new Thread(){ + public void run(){ + ServerMain tomcat = new ServerMain(); + try { + tomcat.startTomcat(); + } catch (Exception e) { + e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + } + }.start(); + while(true){ + Thread.sleep(10000); + } + } catch (Exception e) { + + e.printStackTrace(); + } + } +} \ No newline at end of file Modified: airavata/trunk/pom.xml URL: http://svn.apache.org/viewvc/airavata/trunk/pom.xml?rev=1416623&r1=1416622&r2=1416623&view=diff ============================================================================== --- airavata/trunk/pom.xml (original) +++ airavata/trunk/pom.xml Mon Dec 3 18:26:39 2012 @@ -309,6 +309,10 @@ + + java.net + http://repository.jboss.com/maven2/ + central Maven Central @@ -596,6 +600,7 @@ samples/simple-math-service samples/complex-math-service samples/levenshtein-distance-service + modules/server modules/distribution modules/test-suite