From: <st...@us...> - 2010-02-01 16:39:42
|
Revision: 8174 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8174&view=rev Author: steve_l Date: 2010-02-01 16:38:55 +0000 (Mon, 01 Feb 2010) Log Message: ----------- SFOS-1425 create separate jdom and restlet components Modified Paths: -------------- trunk/core/components/ec2/ivy.xml trunk/core/components/ec2/project-template.pom trunk/core/components/libraries.properties trunk/core/components/restlet/project-template.pom trunk/core/components/xml/ivy.xml Added Paths: ----------- trunk/core/components/json/ trunk/core/components/json/build.xml trunk/core/components/json/ivy.xml trunk/core/components/json/project-template.pom trunk/core/components/json/src/ trunk/core/components/json/src/org/ trunk/core/components/json/src/org/smartfrog/ trunk/core/components/json/src/org/smartfrog/services/ trunk/core/components/json/src/org/smartfrog/services/json/ trunk/core/components/json/src/org/smartfrog/services/json/components.sf trunk/core/components/json/test/ Modified: trunk/core/components/ec2/ivy.xml =================================================================== --- trunk/core/components/ec2/ivy.xml 2010-02-01 15:02:11 UTC (rev 8173) +++ trunk/core/components/ec2/ivy.xml 2010-02-01 16:38:55 UTC (rev 8174) @@ -80,6 +80,11 @@ rev="latest.integration" conf="daemon,compile->default;runtime->runtime;redist->redist"/> + <dependency org="org.smartfrog" + name="sf-json" + changing="true" + rev="latest.integration" + conf="daemon,compile->default,runtime;runtime->runtime;redist->redist"/> <dependency org="org.smartfrog" name="sf-testharness" Modified: trunk/core/components/ec2/project-template.pom =================================================================== --- trunk/core/components/ec2/project-template.pom 2010-02-01 15:02:11 UTC (rev 8173) +++ trunk/core/components/ec2/project-template.pom 2010-02-01 16:38:55 UTC (rev 8174) @@ -11,7 +11,7 @@ <artifactId>sf-ec2</artifactId> <packaging>jar</packaging> <version>${smartfrog.version}</version> - <description>SmartFrog EC2/Restlet components</description> + <description>SmartFrog EC2 components</description> <dependencies> <dependency> <groupId>org.smartfrog</groupId> @@ -23,28 +23,16 @@ <artifactId>sf-www</artifactId> <version>${smartfrog.version}</version> </dependency> - <!--restlet api--> <dependency> - <groupId>org.restlet</groupId> - <artifactId>org.restlet</artifactId> - <version>${restlet.version}</version> + <groupId>org.smartfrog</groupId> + <artifactId>sf-restlet</artifactId> + <version>${smartfrog.version}</version> </dependency> - <!--this is the implementation and java.net integration--> <dependency> - <groupId>com.noelios.restlet</groupId> - <artifactId>com.noelios.restlet</artifactId> - <version>${restlet.version}</version> + <groupId>org.smartfrog</groupId> + <artifactId>sf-json</artifactId> + <version>${smartfrog.version}</version> </dependency> - <dependency> - <groupId>com.noelios.restlet</groupId> - <artifactId>com.noelios.restlet.ext.net</artifactId> - <version>${restlet.version}</version> - </dependency> - <dependency> - <groupId>commons-fileupload</groupId> - <artifactId>commons-fileupload</artifactId> - <version>${commons-fileupload.version}</version> - </dependency> <!--typica--> Copied: trunk/core/components/json/build.xml (from rev 8172, trunk/core/components/loggingservices/build.xml) =================================================================== --- trunk/core/components/json/build.xml (rev 0) +++ trunk/core/components/json/build.xml 2010-02-01 16:38:55 UTC (rev 8174) @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<project name="json" default="default"> + +<!-- +/** (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +--> + +<description> + Build file for JSON libraries and components +</description> + + + <!-- override point --> + <property file="build.properties" /> + <property name="root.dir" location="../../" /> + <property name="ivy.enabled" value="true"/> + <property name="system.tests" value="false"/> + + <!-- Import common stuff --> + <import file="${root.dir}/common.xml"/> + + <property name="is.component" value="true" /> + + <echo message="==================================================================="/> + <echo message="= ${ant.project.name}"/> + + +</project> Copied: trunk/core/components/json/ivy.xml (from rev 8172, trunk/core/components/loggingservices/ivy.xml) =================================================================== --- trunk/core/components/json/ivy.xml (rev 0) +++ trunk/core/components/json/ivy.xml 2010-02-01 16:38:55 UTC (rev 8174) @@ -0,0 +1,65 @@ +<?xml version="1.0" ?> +<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?> +<ivy-module version="1.0"> + <info organisation="org.smartfrog" module="sf-json"> + <license name="LGPL"/> + <ivyauthor name="Hewlett-Packard" url="http://www.smartfrog.org"/> + <description> + SmartFrog JSON services + </description> + </info> +<!-- FIXME: Ivy 1.4.1 buildlist bug + <configurations defaultconfmapping="default"> + <include file="../../antbuild/ivy/configurations.xml"/> + </configurations> + --> +<configurations defaultconfmapping="default"> + <conf name="default" extends="master,runtime" + description="default configuration contains artifacts and runtime dependencies"/> + <conf name="build" visibility="private" + description="artifacts needed to build the application"/> + <conf name="compile" visibility="private" extends="runtime" + description="artifacts needed to compile the application"/> + <conf name="daemon" visibility="private" + description="the classpath needed to run smartfrog daemons"/> + <conf name="test" extends="default,compile" + description="the classpath needed to run tests"/> + <conf name="master" description="contains the artifact but no dependencies"/> + <conf name="redist" description="redistributals excluding smartfrog artifacts" /> + <conf name="runtime" description="runtime but not the artifact" + extends="redist"/> + <conf name="documentation" + description="all documentation artifacts"/> +</configurations> + + <publications> + <!--get the artifact from our module name--> + <artifact conf="master"/> + <artifact name="sf-json-javadocs" conf="documentation" ext="zip"/> + <artifact name="sf-json-documentation" conf="documentation" ext="zip"/> + </publications> + <dependencies> + <dependency org="org.smartfrog" + name="smartfrog" + changing="true" + rev="latest.integration" + conf="compile,runtime,daemon->services"/> + <dependency org="org.smartfrog" + name="sf-tasks" + changing="true" + rev="latest.integration" + conf="build->default"/> + <dependency org="org.smartfrog" + name="sf-testharness" + changing="true" + rev="latest.integration" + conf="test->default"/> + + <dependency org="net.sf.json" + name="json-lib" + rev="${json-lib.version}" + conf="redist->default"/> + + + </dependencies> +</ivy-module> \ No newline at end of file Copied: trunk/core/components/json/project-template.pom (from rev 8172, trunk/core/components/loggingservices/project-template.pom) =================================================================== --- trunk/core/components/json/project-template.pom (rev 0) +++ trunk/core/components/json/project-template.pom 2010-02-01 16:38:55 UTC (rev 8174) @@ -0,0 +1,32 @@ +<!-- This POM file is authored by the SmartFrog project. + --> +<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"> + <!-- + ${pom.comments} + --> + <modelVersion>4.0.0</modelVersion> + <groupId>org.smartfrog</groupId> + <artifactId>sf-json</artifactId> + <packaging>jar</packaging> + <version>${smartfrog.version}</version> + <description> + SmartFrog JSON services + </description> + + + <dependencies> + + <dependency> + <groupId>net.sf.json</groupId> + <artifactId>json-lib</artifactId> + <version>${json-lib.version}</version> + </dependency> + <dependency> + <groupId>org.smartfrog</groupId> + <artifactId>smartfrog</artifactId> + <version>${smartfrog.version}</version> + </dependency> + </dependencies> +</project> Added: trunk/core/components/json/src/org/smartfrog/services/json/components.sf =================================================================== --- trunk/core/components/json/src/org/smartfrog/services/json/components.sf (rev 0) +++ trunk/core/components/json/src/org/smartfrog/services/json/components.sf 2010-02-01 16:38:55 UTC (rev 8174) @@ -0,0 +1,26 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/filesystem/components.sf" +#include "/org/smartfrog/services/assertions/components.sf" +#include "/org/smartfrog/services/os/java/components.sf" + +sfConfig extends Compound { + +} Modified: trunk/core/components/libraries.properties =================================================================== --- trunk/core/components/libraries.properties 2010-02-01 15:02:11 UTC (rev 8173) +++ trunk/core/components/libraries.properties 2010-02-01 16:38:55 UTC (rev 8174) @@ -49,6 +49,7 @@ jetty.servlet.version=2.5 jets3t.version=0.7.1 jsch.version=0.1.42 +json-lib.version=2.3 jsp-api.version=2.0 junit3.version=3.8.2 junit4.version=4.5 Modified: trunk/core/components/restlet/project-template.pom =================================================================== --- trunk/core/components/restlet/project-template.pom 2010-02-01 15:02:11 UTC (rev 8173) +++ trunk/core/components/restlet/project-template.pom 2010-02-01 16:38:55 UTC (rev 8174) @@ -8,10 +8,10 @@ --> <modelVersion>4.0.0</modelVersion> <groupId>org.smartfrog</groupId> - <artifactId>sf-jetty</artifactId> + <artifactId>sf-restlet</artifactId> <packaging>jar</packaging> <version>${smartfrog.version}</version> - <description>SmartFrog Jetty components</description> + <description>SmartFrog Restlet components</description> <dependencies> <dependency> <groupId>org.smartfrog</groupId> @@ -28,68 +28,29 @@ <artifactId>servlet-api</artifactId> <version>${servletapi.version}</version> </dependency> + <!--restlet api--> <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty</artifactId> - <version>${jetty.version}</version> + <groupId>org.restlet</groupId> + <artifactId>org.restlet</artifactId> + <version>${restlet.version}</version> </dependency> + <!--this is the implementation and java.net integration--> <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty-util</artifactId> - <version>${jetty.version}</version> + <groupId>com.noelios.restlet</groupId> + <artifactId>com.noelios.restlet</artifactId> + <version>${restlet.version}</version> </dependency> - - - <!-- Jetty is used to serve up the application. It is marked as optional because -clients do not need it. All server-side deployments will need - all of these files.--> <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>${servletapi.version}</version> - <scope>optional</scope> + <groupId>com.noelios.restlet</groupId> + <artifactId>com.noelios.restlet.ext.net</artifactId> + <version>${restlet.version}</version> </dependency> <dependency> - <groupId>jetty</groupId> - <artifactId>org.mortbay.jetty</artifactId> - <version>${jetty.version}</version> - <scope>optional</scope> + <groupId>commons-fileupload</groupId> + <artifactId>commons-fileupload</artifactId> + <version>${commons-fileupload.version}</version> </dependency> - <!--JSP support --> - - - <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jsp-2.1</artifactId> - <version>${jetty.version}</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jsp-api-2.1</artifactId> - <version>${jetty.version}</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jsp-api-2.1</artifactId> - <version>${jetty.version}</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.smartfrog</groupId> - <artifactId>sf-ant</artifactId> - <version>${smartfrog.version}</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.eclipse.jdt</groupId> - <artifactId>core</artifactId> - <version>${org.eclipse.jdt.core.version}</version> - <optional>true</optional> - </dependency> - </dependencies> </project> Modified: trunk/core/components/xml/ivy.xml =================================================================== --- trunk/core/components/xml/ivy.xml 2010-02-01 15:02:11 UTC (rev 8173) +++ trunk/core/components/xml/ivy.xml 2010-02-01 16:38:55 UTC (rev 8174) @@ -82,9 +82,11 @@ name="xalan" rev="${xalan.version}" conf="compile,xslt->master"/> + <dependency org="jdom" name="jdom" rev="${jdom.version}" conf="compile,redist->master"/> + </dependencies> </ivy-module> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-02-19 14:21:24
|
Revision: 8211 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8211&view=rev Author: steve_l Date: 2010-02-19 14:20:34 +0000 (Fri, 19 Feb 2010) Log Message: ----------- SFOS-1438 json-lib depends on other things that the RPM doesn't expect Modified Paths: -------------- trunk/core/components/json/ivy.xml trunk/core/components/libraries.properties Modified: trunk/core/components/json/ivy.xml =================================================================== --- trunk/core/components/json/ivy.xml 2010-02-19 11:47:40 UTC (rev 8210) +++ trunk/core/components/json/ivy.xml 2010-02-19 14:20:34 UTC (rev 8211) @@ -68,7 +68,10 @@ name="commons-collections" rev="${commons-collections.version}" conf="redist->master"/> - + <dependency org="commons-beanutils" + name="commons-beanutils" + rev="${commons-beanutils.version}" + conf="redist->master"/> <dependency org="commons-lang" name="commons-lang" rev="${commons-lang.version}" Modified: trunk/core/components/libraries.properties =================================================================== --- trunk/core/components/libraries.properties 2010-02-19 11:47:40 UTC (rev 8210) +++ trunk/core/components/libraries.properties 2010-02-19 14:20:34 UTC (rev 8211) @@ -13,7 +13,7 @@ bsh.version=1.3.0 bsh-core.version=${bsh.version} cargo.version=0.9 -commons-beanutils.version=1.8.0 +commons-beanutils.version=1.8.2 commons-dbcp.version=1.2.2 commons-dbutils.version=1.0 commons-cli.version=1.2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-05-18 15:57:24
|
Revision: 8280 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8280&view=rev Author: steve_l Date: 2010-05-18 15:57:17 +0000 (Tue, 18 May 2010) Log Message: ----------- SFOS-1476 add tests for big data upload/download and long-lived connections Modified Paths: -------------- trunk/core/components/jetty/build.xml trunk/core/components/jetty/ivy.xml trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/war/components.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf trunk/core/components/www/src/org/smartfrog/services/www/HttpAttributes.java trunk/core/components/www/src/org/smartfrog/services/www/webapplication.sf Added Paths: ----------- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/war/testwar.sf trunk/core/components/rpmtools/src/org/smartfrog/services/rpm/sshup/ trunk/core/components/rpmtools/src/org/smartfrog/services/rpm/sshup/components.sf trunk/core/components/www/src/org/smartfrog/services/www/bulkio/ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ApacheBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/resources/ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/resources/index.html Modified: trunk/core/components/jetty/build.xml =================================================================== --- trunk/core/components/jetty/build.xml 2010-05-18 15:56:19 UTC (rev 8279) +++ trunk/core/components/jetty/build.xml 2010-05-18 15:57:17 UTC (rev 8280) @@ -53,25 +53,25 @@ - <!-- ========================================================== --> - <!-- parse the file --> - <!-- ========================================================== --> - <target name="parse" depends="ready-to-test" - description="parse the deployment descriptor"> + <!-- ========================================================== --> + <!-- parse the file --> + <!-- ========================================================== --> + <target name="parse" depends="ready-to-test" + description="parse the deployment descriptor"> - <sf-parse quiet="true" file="${src.dir}/${deploy.sf}" - classpathref="exec.classpath"> - </sf-parse> - <sf-parse quiet="true" file="${src.dir}/${example.path}/example2.sf" - classpathref="exec.classpath"> - </sf-parse> - <sf-parse quiet="true" file="${src.dir}/${example.path}/example3.sf" - classpathref="exec.classpath"> - </sf-parse> - <sf-parse quiet="true" file="${src.dir}/${example.path}/dynamicexample.sf" - classpathref="exec.classpath"> - </sf-parse> - </target> + <sf-parse quiet="true" file="${src.dir}/${deploy.sf}" + classpathref="exec.classpath"> + </sf-parse> + <sf-parse quiet="true" file="${src.dir}/${example.path}/example2.sf" + classpathref="exec.classpath"> + </sf-parse> + <sf-parse quiet="true" file="${src.dir}/${example.path}/example3.sf" + classpathref="exec.classpath"> + </sf-parse> + <sf-parse quiet="true" file="${src.dir}/${example.path}/dynamicexample.sf" + classpathref="exec.classpath"> + </sf-parse> + </target> <target name="ready-to-deploy" depends="common.ready-to-deploy,testwar"> @@ -104,4 +104,14 @@ </fail> </target> + + <target name="bulkio" depends="ready-to-deploy" + description="Deploy a Jetty server that supports bulk IO" > + <deploy> + <application name="bulkio" + descriptor="/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf"/> + </deploy> + </target> + + </project> Modified: trunk/core/components/jetty/ivy.xml =================================================================== --- trunk/core/components/jetty/ivy.xml 2010-05-18 15:56:19 UTC (rev 8279) +++ trunk/core/components/jetty/ivy.xml 2010-05-18 15:57:17 UTC (rev 8280) @@ -49,7 +49,7 @@ name="sf-www" changing="true" rev="latest.integration" - conf="compile,redist,test,daemon->default,servletapi;testwar->testwar"/> + conf="compile,redist,daemon->default,servletapi;testwar->testwar;test->efault,servletapi,httpclient"/> <!-- depend on logging services, to pick up commons-logging and bindings --> @@ -102,9 +102,9 @@ rev="${jetty.version}" conf="jsp->master"/> <dependency org="commons-el" - name="commons-el" - rev="${commons-el.version}" - conf="jsp->master"/> + name="commons-el" + rev="${commons-el.version}" + conf="jsp->master"/> <!--this is the compiler stage--> <dependency org="org.smartfrog" name="sf-ant" Copied: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf (from rev 8274, trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf) =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf (rev 0) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,39 @@ +/** (C) Copyright 1998-2007 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +#include "/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf" +#include "/org/smartfrog/services/www/bulkio/server/components.sf" + + +BulkIOJetty extends JettySocketHttpServerCompound { + + host CoreJettyServer:ANY_HOST; + + bulkIOSupport extends BulkIOSupport { + server LAZY PARENT:server; + + defaultServlet extends DefaultContentServlet { + context LAZY PARENT:context; + } + + } +} + +sfConfig extends BulkIOJetty; Property changes on: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf 2010-05-18 15:56:19 UTC (rev 8279) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -18,14 +18,10 @@ */ -#include "/org/smartfrog/services/filesystem/file.sf" #include "/org/smartfrog/services/jetty/components.sf"; #include "/org/smartfrog/services/jetty/examples/ports.sf" -//the war file must be present - TestWar extends FileMustExist { - filename PROPERTY test.testwar.war; - } + LocalJettyServer extends JettySocketHttpServerCompound { @@ -41,8 +37,6 @@ */ server:jettyhome PARENT:jettyhome; - - } JettyOnNIO extends LocalJettyServer { Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/war/components.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/war/components.sf 2010-05-18 15:56:19 UTC (rev 8279) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/war/components.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -32,16 +32,10 @@ #include "/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf" -#include "/org/smartfrog/services/filesystem/file.sf" #include "/org/smartfrog/services/jetty/examples/war/waitforpages.sf" +#include "/org/smartfrog/services/jetty/examples/war/testwar.sf" -//the war file must be present - TestWar extends FileMustExist { - filename PROPERTY test.testwar.war; - } - - JettyWarServer extends LocalJettyServer { description ("A jetty server with the war deployed to " ++ contextPath); Added: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/war/testwar.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/war/testwar.sf (rev 0) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/war/testwar.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,26 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/filesystem/file.sf" + + +//the war file must be present + TestWar extends FileMustExist { + filename PROPERTY test.testwar.war; + } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf 2010-05-18 15:56:19 UTC (rev 8279) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -251,6 +251,10 @@ } +/** + * this is a compound defining the server at server, default port bindings, but nothing + * actually listening for connections + */ JettyHttpServerCompound extends Compound { port AbstractConnector:port; @@ -262,6 +266,9 @@ } +/** + * Listen for connections using sockets + */ JettySocketHttpServerCompound extends JettyHttpServerCompound { @@ -273,7 +280,9 @@ } - +/** + * Listen for connections using HTTPS sockets + */ JettySocketHttpsServerCompound extends JettyHttpServerCompound { port JettySSLSocketConnector:port; @@ -286,6 +295,9 @@ } +/** + * Listen for connections Select operations and NIO channels + */ JettySelectChannelHttpServerCompound extends JettyHttpServerCompound { connector extends JettySelectChannelConnector { Added: trunk/core/components/rpmtools/src/org/smartfrog/services/rpm/sshup/components.sf =================================================================== --- trunk/core/components/rpmtools/src/org/smartfrog/services/rpm/sshup/components.sf (rev 0) +++ trunk/core/components/rpmtools/src/org/smartfrog/services/rpm/sshup/components.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,26 @@ +/* (C) Copyright 2009 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/filesystem/components.sf" +#include "/org/smartfrog/services/assertions/components.sf" +#include "/org/smartfrog/services/ssh/scp.sf" + +sfConfig extends Compound { + +} Modified: trunk/core/components/www/src/org/smartfrog/services/www/HttpAttributes.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/HttpAttributes.java 2010-05-18 15:56:19 UTC (rev 8279) +++ trunk/core/components/www/src/org/smartfrog/services/www/HttpAttributes.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -106,4 +106,13 @@ String HTTP = "http"; /** {@value} */ String HTTPS = "https"; + + String METHOD_PUT = "PUT"; + String METHOD_POST = "POST"; + String METHOD_GET = "GET"; + String METHOD_DELETE = "DELETE"; + String METHOD_HEAD = "HEAD"; + + + String CONTENT_LENGTH = "Content-Length"; } Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,128 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio.client; + +import org.smartfrog.services.www.HttpAttributes; + +import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLConnection; + +/** + * Created 17-May-2010 17:35:44 + */ + +public abstract class AbstractBulkIOClient { + + public URL url; + + public long size; + + public String operation = HttpAttributes.METHOD_POST; + + public boolean useFormUpload = false; + + public int connectTimeout = -1; + + public boolean chunked = false; + + public int chunkLength = 8192; + + + protected AbstractBulkIOClient() { + } + + public URL getUrl() { + return url; + } + + public void setUrl(URL url) { + this.url = url; + } + + public long execute() throws IOException, InterruptedException { + if ("POST".equals(operation) + || "PUT".equals(operation)) { + return doUpload(size); + } else if ("GET".equals(operation)) { + return doDownload(size); + } else { + throw new IOException("Unsupported operation: \"" + operation + "\""); + } + } + + public long doUpload(long size) throws IOException, InterruptedException { + return notImplemented(); + } + + private long notImplemented() throws IOException { + throw new IOException("Not Implemented"); + } + + public long doUpload(File f) throws IOException, InterruptedException { + return notImplemented(); + } + + public long doDownload(long size) throws IOException, InterruptedException { + return notImplemented(); + } + + public long doDownload(long size, File f) throws IOException, InterruptedException { + return notImplemented(); + } + + /** + * Interrupt the operation + */ + public void interrupt() { + + } + + /** + * Open a connection. The connection is not yet "connected" -you can do some last minute tuning + * + * @return an HTTP connection. + * @throws IOException + */ + protected HttpURLConnection openConnection() throws IOException { + HttpURLConnection connection; + URL targetURL = getUrl(); + if (targetURL == null) { + throw new IOException("No URL to connect to"); + } + URLConnection rawConnection = targetURL.openConnection(); + if (!(rawConnection instanceof HttpURLConnection)) { + throw new IOException("Could not open an HTTP connection to " + targetURL); + } + connection = (HttpURLConnection) rawConnection; + connection.setInstanceFollowRedirects(true); + connection.setRequestMethod(operation); + if (connectTimeout >= 0) { + connection.setConnectTimeout(connectTimeout); + } + if (chunked) { + connection.setChunkedStreamingMode(chunkLength); + } + + return connection; + } +} Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ApacheBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ApacheBulkIOClient.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ApacheBulkIOClient.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,54 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio.client; + +/** + * Created 17-May-2010 16:46:34 + */ + +public class ApacheBulkIOClient extends AbstractBulkIOClient { +/* + + @Override + public long doUpload(long size) throws IOException, InterruptedException { + return 0; + } + + @Override + public long doUpload(File f) throws IOException, InterruptedException { + return 0; + } + + @Override + public long doDownload(long size) throws IOException, InterruptedException { + return 0; + } + + @Override + public long doDownload(long size, File f) throws IOException, InterruptedException { + return 0; + } +*/ + + @Override + public void interrupt() { + + } +} Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,38 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio.client; + +import org.smartfrog.services.www.HttpAttributes; + + +/** + * Created 18-May-2010 12:08:38 + */ + +public interface BulkIOClient extends HttpAttributes { + + String ATTR_USE_FORM_UPLOAD = "useFormUpload"; + String ATTR_CHUNKED = "chunked"; + String ATTR_CHUNK_LENGTH = "chunkLength"; + String ATTR_IOCLASS = "ioClass"; + String ATTR_SIZE = "size"; + String ATTR_OPERATION = "operation"; + //String ATTR_ = ""; +} Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,115 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio.client; + +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.security.SFClassLoader; +import org.smartfrog.sfcore.utils.SmartFrogThread; +import org.smartfrog.sfcore.utils.WorkerThreadPrimImpl; +import org.smartfrog.sfcore.utils.WorkflowThread; + +import java.net.MalformedURLException; +import java.net.URL; +import java.rmi.RemoteException; + +/** + * Created 18-May-2010 12:08:59 + */ + +public class BulkIOClientImpl extends WorkerThreadPrimImpl implements BulkIOClient { + + public BulkIOClientImpl() throws RemoteException { + } + + /** + * Instantiate and start a bulk IO operation + * + * @throws SmartFrogException SF problems + * @throws RemoteException network problems + */ + @Override + public void sfStart() throws SmartFrogException, RemoteException { + super.sfStart(); + BulkIOWorkerThread ioworker = new BulkIOWorkerThread(); + ioworker.start(); + } + + /** + * Ask for the thread to die + * + * @param workflowThread a non-null thread + */ + @Override + protected void terminateWorkerThread(WorkflowThread workflowThread) { + BulkIOWorkerThread ioWorker = (BulkIOWorkerThread) workflowThread; + ioWorker.interrupt(); + SmartFrogThread.requestThreadTermination(workflowThread); + } + + /** + * The worker + */ + class BulkIOWorkerThread extends WorkflowThread { + private AbstractBulkIOClient ioclient; + + /** + * Create the worker; includes reading in all parameters + * + * @throws SmartFrogException resolution/instantiation problems + * @throws RemoteException network problems + */ + BulkIOWorkerThread() throws SmartFrogException, RemoteException { + super(BulkIOClientImpl.this, true); + String ioclass = sfResolve(ATTR_IOCLASS, "", true); + try { + Class ioclassFactory = SFClassLoader.forName(ioclass); + ioclient = (AbstractBulkIOClient) ioclassFactory.newInstance(); + } catch (Throwable e) { + throw new SmartFrogResolutionException("Failed to instantiate a AbstractBulkIOClient instance " + + "from the classname " + ioclass + ": " + e, + e, + BulkIOClientImpl.this); + } + ioclient.size = sfResolve(ATTR_SIZE, 0L, true); + ioclient.connectTimeout = sfResolve(ATTR_CONNECT_TIMEOUT, 0, true); + ioclient.chunked = sfResolve(ATTR_CHUNKED, true, true); + ioclient.chunkLength = sfResolve(ATTR_CHUNK_LENGTH, 0, true); + ioclient.operation = sfResolve(ATTR_OPERATION, "", true); + ioclient.useFormUpload = sfResolve(ATTR_USE_FORM_UPLOAD, true, true); + String targetURLpath = sfResolve(ATTR_URL, "", true); + + try { + ioclient.setUrl(new URL(targetURLpath)); + } catch (MalformedURLException e) { + throw new SmartFrogResolutionException("Bad URL \"" + targetURLpath + "\" : " + e, + e, + BulkIOClientImpl.this); + } + } + + /** + * Interrupt the worker + */ + public void interrupt() { + ioclient.interrupt(); + } + } +} Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,64 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio.client; + +import org.smartfrog.services.www.HttpAttributes; + +import java.io.IOException; +import java.io.OutputStream; +import java.net.HttpURLConnection; + +/** + * This class uses the Sun Java APIs to do bulk upload. + */ + +public class SunJavaBulkIOClient extends AbstractBulkIOClient { + + private volatile boolean interrupted; + + + @Override + public long doUpload(long size) throws IOException, InterruptedException { + HttpURLConnection connection = openConnection(); + connection.setRequestProperty(HttpAttributes.CONTENT_LENGTH, Long.toString(size)); + OutputStream outputStream = connection.getOutputStream(); + for (long bytes = 0; bytes < size; bytes++) { + outputStream.write(32); + if (interrupted) { + throw new InterruptedException("Interrupted after sending " + bytes + " bytes"); + } + } + return size; + } +/* + + @Override + public long doUpload(File f) throws IOException, InterruptedException { + return 0; + } + + +*/ + + @Override + public void interrupt() { + interrupted = true; + } +} Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,84 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +/** + bulk IO client to test bulk operations + */ +BulkIOClient extends WorkflowPrim { + + sfClass "org.smartfrog.services.www.bulkio.client.BulkIOClientImpl"; + sfShouldTerminate true; + + ioClass TBD; + + url TBD; + + size TBD; + + operation TBD; + + useFormUpload false; + + connectTimeout 30000; + + chunked false; + + chunkLength 4096; + + SUN_IO_CLASS "org.smartfrog.services.www.bulkio.client.SunJavaBulkIOClient"; + APACHE_IO_CLASS "org.smartfrog.services.www.bulkio.client.ApacheBulkIOClient"; + +} + +BulkIOUpload extends BulkIOClient { + operation "POST"; +} + +BulkIODownload extends BulkIOClient { + operation "GET"; +} + +/** + * do a bulk download using Sun's API + */ +SunBulkIODownload extends BulkIODownload { + ioClass SUN_IO_CLASS; +} + +/** + * do a bulk download using HttpClient + */ +ApacheBulkIODownload extends BulkIODownload { + ioClass APACHE_IO_CLASS; +} + +/** + * do a bulk download using Sun's API + */ +SunBulkIODownload extends BulkIODownload { + ioClass SUN_IO_CLASS; +} + +/** + * do a bulk download using HttpClient + */ +ApacheBulkIODownload extends BulkIODownload { + ioClass APACHE_IO_CLASS; +} Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,122 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio.server; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.smartfrog.services.www.HttpAttributes; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.Closeable; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Servlet base for bulk IO. This servlet is designed to live outside SmartFrog; logs through commons-logging Created + * 17-May-2010 15:02:27 + */ + +public abstract class AbstractBulkioServlet extends HttpServlet { + + public static final String ATTR_LIMIT = "limit"; + public static final String ATTR_SIZE = "size"; + public static final String ATTR_FORMAT = "format"; + public static final String FORMAT_BINARY = "application/binary"; + + protected static final Log log = LogFactory.getLog(AbstractBulkioServlet.class); + protected static final String TEXT_HTML = "text/html"; + protected static final String TEXT_PLAIN = "text/plain"; + + protected long getLimit() { + return Long.valueOf(getInitParameter(ATTR_LIMIT)); + } + + protected void disableCaching(HttpServletResponse response) { + response.addHeader("Cache-Control","none"); + response.addHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT"); + } + + /** + * Get the request size + * + * @param request request + * @return the value or -1 for no value supplied. + * @throws ServletException if the parse failed + */ + protected long getSize(HttpServletRequest request) throws ServletException { + return getParameterAsLong(request, ATTR_SIZE); + } + + protected long getContentLength(HttpServletRequest request) throws ServletException { + String contentL = request.getHeader(HttpAttributes.CONTENT_LENGTH); + return contentL == null ? -1 : + parseToLong(" the header " + HttpAttributes.CONTENT_LENGTH, contentL); + } + + /** + * Get some parameter as long + * + * @param request + * @param param + * @return + * @throws ServletException + */ + protected long getParameterAsLong(HttpServletRequest request, String param) throws ServletException { + return parseToLong(" the parameter " + ATTR_SIZE, request.getParameter(param)); + } + + protected long parseToLong(String source, String longValue) throws ServletException { + try { + return longValue == null ? -1 : Long.valueOf(longValue); + } catch (NumberFormatException e) { + throw new ServletException("Failed to parse the value of " + + source + + " to a long :\"" + longValue + "\"" + e, e); + } + } + + protected void returnPlainText(HttpServletResponse response, String message) throws IOException { + response.setContentType(TEXT_PLAIN); + PrintWriter writer = response.getWriter(); + try { + writer.append(message); + } finally { + closeQuietly(writer); + } + } + + /** + * Close quietly, log on an exception, do nothing on null + * + * @param c thing to close + */ + protected void closeQuietly(Closeable c) { + if (c != null) { + try { + c.close(); + } catch (IOException e) { + log.warn(e); + } + } + } +} Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,86 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio.server; + +import org.smartfrog.services.www.HttpAttributes; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Bulk D/L Servlet serves bullk quantities of data + */ + +public class BulkDownloadServlet extends AbstractBulkioServlet { + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + disableCaching(response); + long size = getSize(request); + if (size == -1) { + //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No " + ATTR_SIZE + " parameter"); + response.setContentType(TEXT_HTML); + ServletOutputStream out = null; + try { + out = response.getOutputStream(); + out.println("<html>"); + out.println("<head><title>Download</title></head>"); + out.println("<body><h1>Download</h1>"); + out.println(" <form method='get'><h2>Download a file</h2>"); + out.println(" <p> Size:"); + out.println(" <input type='text'name='"+ ATTR_SIZE+"'/>"); + out.println(" <p>"); + out.println(" <p> Format:"); + out.println(" <input type='text'name='"+ ATTR_FORMAT+"' value='text/plain'/>"); + out.println(" <p>"); + out.println(" <button type='submit'>submit</button>"); + out.println(" <p>"); + out.println(" </form>"); + out.println("</body>"); + out.println("</html>"); + } finally { + closeQuietly(out); + } + } else { + String format = request.getParameter(ATTR_FORMAT); + if (format == null) { + format = TEXT_PLAIN; + } + response.setContentType(format); + response.setHeader(HttpAttributes.CONTENT_LENGTH, Long.toString(size)); + response.setHeader("X-" + HttpAttributes.CONTENT_LENGTH, Long.toString(size)); + ServletOutputStream outputStream = null; + try { + outputStream = response.getOutputStream(); + for (long bytes = 0; bytes < size; bytes++) { + outputStream.write('0'+(int)(bytes%10)); + } + } finally { + closeQuietly(outputStream); + } + } + + } + +} \ No newline at end of file Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,94 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio.server; + +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Created 17-May-2010 15:03:10 + */ + +public class BulkUploadServlet extends AbstractBulkioServlet { + + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + long size = getSize(request); + long contentLength = getContentLength(request); + if (size >= 0 && size != contentLength) { + throw new ServletException( + "Content-Length header of " + contentLength + " does not equal the size parameter " + size); + } + ServletInputStream inStream = null; + long bytes; + try { + inStream = request.getInputStream(); + for (bytes = 0; bytes < size; bytes++) { + int value = inStream.read(); + } + } finally { + closeQuietly(inStream); + } + returnPlainText(response,"Read "+ bytes + " bytes; expected + " + size); + } + + @Override + protected void doPut(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doPost(request, response); + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + disableCaching(response); + response.setContentType(TEXT_HTML); + ServletOutputStream out = null; + try { + out = response.getOutputStream(); + out.println("<html>"); + out.println("<head><title>Upload</title></head>"); + out.println("<body><h1>Upload</h1>"); + out.println(" <form ><h2>Upload a file</h2>"); + out.println(" <p>"); + out.println(" <input type='file'></input>"); + out.println(" <p>"); + out.println(" <button type='submit'>submit</button>"); + out.println(" <p>"); + out.println(" </form>"); + out.println(" <form method='post'><h2>POST a file</h2>"); + out.println(" <p>"); + out.println(" <input type='file'></input>"); + out.println(" <p>"); + out.println(" <button type='submit'>submit</button>"); + out.println(" <p>"); + out.println(" </form>"); + out.println("</body>"); + out.println("</html>"); + } finally { + closeQuietly(out); + } + } +} Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,69 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +/** + include this file after pulling in + #include "/org/smartfrog/services/www/webapplication.sf" +*/ + +BulkIoServlet extends Servlet { + //optional limit on IO, can be used to test client handling of limit being reached + limit -1; + initParams [ + ["limit", limit] + ]; +} + + +BulkUploadServlet extends BulkIoServlet { + name "BulkUploadServlet"; + pathSpec "/upload"; + className "org.smartfrog.services.www.bulkio.server.BulkUploadServlet"; +} + +BulkDownloadServlet extends BulkIoServlet { + name "BulkDownloadServlet"; + pathSpec "/download"; + className "org.smartfrog.services.www.bulkio.server.BulkDownloadServlet"; +} + +/** + * A compound that deploys the servlet context and two servlets + */ +BulkIOSupport extends Compound { + server TBD; + contextPath "/"; + + context extends ServletContext { + server LAZY PARENT:server; + contextPath PARENT:contextPath; + resourcePackage "/org/smartfrog/services/www/bulkio/server/resources/"; + } + + uploadServlet extends BulkUploadServlet { + context LAZY PARENT:context; + } + + downloadServlet extends BulkDownloadServlet { + context LAZY PARENT:context; + } + +} + Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/resources/index.html =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/resources/index.html (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/resources/index.html 2010-05-18 15:57:17 UTC (rev 8280) @@ -0,0 +1,17 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> + <title>Bulk IO</title> +</head> +<body> +<ol> + <li><a href="upload">Upload</a></li> + <li><a href="download">Download</a></li> + +</ol> +<!--<form action=""> + <input type="text"name="size"/> +</form>--> +</body> +</html> \ No newline at end of file Modified: trunk/core/components/www/src/org/smartfrog/services/www/webapplication.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/webapplication.sf 2010-05-18 15:56:19 UTC (rev 8279) +++ trunk/core/components/www/src/org/smartfrog/services/www/webapplication.sf 2010-05-18 15:57:17 UTC (rev 8280) @@ -118,7 +118,7 @@ /** * a servlet context is where servlets can be deployed. * Any derivative of ServletContextComponent can be bound - to this + * to this */ ServletContext extends ApplicationServerContext { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-05-19 15:56:53
|
Revision: 8284 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8284&view=rev Author: steve_l Date: 2010-05-19 15:56:46 +0000 (Wed, 19 May 2010) Log Message: ----------- SFOS-1476 add tests for big data upload/download and long-lived connections Modified Paths: -------------- trunk/core/components/jetty/build.xml trunk/core/components/jetty/ivy.xml trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/components.sf trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/functional/JettyFunctionalTest.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ApacheBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf Added Paths: ----------- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPutTest.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkioget.sf trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkiopost.sf trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkioput.sf trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/components.sf Modified: trunk/core/components/jetty/build.xml =================================================================== --- trunk/core/components/jetty/build.xml 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/jetty/build.xml 2010-05-19 15:56:46 UTC (rev 8284) @@ -40,8 +40,8 @@ <property file="build.properties" /> <property name="root.dir" location="../../" /> <property name="ivy.enabled" value="true"/> - <property name="system.tests" value="true" /> - + <property name="system.tests" value="true" /> + <property name="test.timeout.execute" value="1800000" /> <echo message="==================================================================="/> <echo message="= ${ant.project.name}"/> Modified: trunk/core/components/jetty/ivy.xml =================================================================== --- trunk/core/components/jetty/ivy.xml 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/jetty/ivy.xml 2010-05-19 15:56:46 UTC (rev 8284) @@ -49,7 +49,7 @@ name="sf-www" changing="true" rev="latest.integration" - conf="compile,redist,daemon->default,servletapi;testwar->testwar;test->efault,servletapi,httpclient"/> + conf="compile,redist,daemon->default,servletapi;testwar->testwar;test->default,servletapi,httpclient"/> <!-- depend on logging services, to pick up commons-logging and bindings --> Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -0,0 +1,58 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + +/** + * Created 19-May-2010 10:54:20 + */ + +public class JettyBulkIoGetTest extends BulkIoTestCase { + + + public JettyBulkIoGetTest(String name) { + super(name); + } + + protected String getFile() { + return "bulkioget"; + } + + public void testBulkIoSmall() throws Throwable { + expectBulkIoRun(getFile(), SMALL); + } + + public void testBulkIoMedium() throws Throwable { + expectBulkIoRun(getFile(), MEDIUM); + } + + public void testBulkIoLarge() throws Throwable { + expectBulkIoRun(getFile(), LARGE); + } + + public void testBulkIoVeryLarge() throws Throwable { + expectBulkIoRun(getFile(), VERY_LARGE); + } + +/* + public void testBulkIoGet() throws Throwable { + expectSuccessfulTestRun(BULKIO, getFile()); + }*/ + +} \ No newline at end of file Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -0,0 +1,37 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + +/** + * Created 19-May-2010 10:54:20 + */ + +public class JettyBulkIoPostTest extends BulkIoTestCase { + + public JettyBulkIoPostTest(String name) { + super(name); + } + + protected String getFile() { + return "bulkiopost"; + } + + +} Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPutTest.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPutTest.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPutTest.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -0,0 +1,37 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + + +/** + * Created 19-May-2010 10:54:20 + */ + +public class JettyBulkIoPutTest extends BulkIoTestCase { + + public JettyBulkIoPutTest(String name) { + super(name); + } + + protected String getFile() { + return "bulkioput"; + } + +} \ No newline at end of file Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkioget.sf =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkioget.sf (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkioget.sf 2010-05-19 15:56:46 UTC (rev 8284) @@ -0,0 +1,24 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/www/jetty/test/system/bulkio/components.sf" + +sfConfig extends BulkIoGet { + +} Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkiopost.sf =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkiopost.sf (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkiopost.sf 2010-05-19 15:56:46 UTC (rev 8284) @@ -0,0 +1,24 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/www/jetty/test/system/bulkio/components.sf" + +sfConfig extends BulkIoPost { + +} Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkioput.sf =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkioput.sf (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/bulkioput.sf 2010-05-19 15:56:46 UTC (rev 8284) @@ -0,0 +1,24 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/www/jetty/test/system/bulkio/components.sf" + +sfConfig extends BulkIoPut { + +} Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/components.sf =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/components.sf (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/components.sf 2010-05-19 15:56:46 UTC (rev 8284) @@ -0,0 +1,73 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/filesystem/components.sf" +#include "/org/smartfrog/services/assertions/components.sf" +#include "/org/smartfrog/services/os/java/components.sf" + + +#include "/org/smartfrog/services/www/jetty/test/system/components.sf" + +BulkIoTestCase extends JettyTestCompound { + + MB (1024*1024L); + GB (1024*MB); + SizeMB OPTIONAL(4) IPROPERTY test.bulkio.size; + size (MB * SizeMB); + operation BulkIOClient:GET; + servlet BulkIoServlet:DOWNLOAD; + ioClass BulkIOClient:SUN_IO_CLASS; + action extends BulkIOJetty; + + + //wait for the port, then talk to it. The waiting operation + //also sets up the target URL for the bulk operation + tests extends Sequence { + url "http://localhost"; + + wait extends waitForAnyHttpResponse { + port PARENT:PARENT:action:port; + path PARENT:PARENT:servlet; + urlTargetComponent LAZY PARENT:PARENT:tests; + //sfShouldTerminate false; + } + + bulkOperation extends BulkIOClient { + operation PARENT:PARENT:operation; + ioClass PARENT:PARENT:ioClass; + size PARENT:PARENT:size; + //get the URL + url LAZY PARENT:url; + } + } + +} + +BulkIoGet extends BulkIoTestCase { + +} + +BulkIoPost extends BulkIoTestCase { + operation BulkIOClient:POST; + servlet BulkIoServlet:UPLOAD; +} + +BulkIoPut extends BulkIoPost { + operation BulkIOClient:PUT; +} \ No newline at end of file Modified: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/components.sf =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/components.sf 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/components.sf 2010-05-19 15:56:46 UTC (rev 8284) @@ -28,6 +28,8 @@ #include "/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf" #include "/org/smartfrog/services/jetty/examples/war/waitforpages.sf" #include "/org/smartfrog/services/www/jetty/test/system/htmlpage.sf" +#include "/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf" +#include "/org/smartfrog/services/www/bulkio/client/components.sf" /* @@ -120,7 +122,7 @@ } - RunFailingTests extends IsPropertySet { - property "run.failing.tests"; - } +RunFailingTests extends IsPropertySet { + property "run.failing.tests"; +} Modified: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/functional/JettyFunctionalTest.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/functional/JettyFunctionalTest.java 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/functional/JettyFunctionalTest.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -73,11 +73,4 @@ expectSuccessfulTestRun(FUNCTIONAL_FILES, "tcp20test"); } - public void NotestSecurity() throws Throwable { - expectSuccessfulTestRun(FUNCTIONAL_FILES, "testSecurity"); - } - - public void NotestSecurityUnauth() throws Throwable { - expectSuccessfulTestRun(FUNCTIONAL_FILES, "testSecurityUnauth"); - } } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -19,8 +19,11 @@ */ package org.smartfrog.services.www.bulkio.client; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.smartfrog.services.www.HttpAttributes; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; @@ -47,10 +50,25 @@ public int chunkLength = 8192; + public String format = "application/binary"; + + private Log log = LogFactory.getLog(AbstractBulkIOClient.class); + protected AbstractBulkIOClient(Log log) { + this.log = log; + } + protected AbstractBulkIOClient() { } + public void setLog(Log log) { + this.log = log; + } + + public Log getLog() { + return log; + } + public URL getUrl() { return url; } @@ -58,12 +76,23 @@ public void setUrl(URL url) { this.url = url; } + + public URL createFullURL(long size, String format) throws IOException { + validateURL(); + StringBuilder fullPath = new StringBuilder(url.getFile()); + fullPath.append('?'); + fullPath.append("size="); + fullPath.append(Long.toString(size)); + fullPath.append("&format="); + fullPath.append(format); + return new URL(url.getProtocol(), url.getHost(), url.getPort(), fullPath.toString()); + } public long execute() throws IOException, InterruptedException { - if ("POST".equals(operation) - || "PUT".equals(operation)) { + if (HttpAttributes.METHOD_POST.equals(operation) + || HttpAttributes.METHOD_PUT.equals(operation)) { return doUpload(size); - } else if ("GET".equals(operation)) { + } else if (HttpAttributes.METHOD_GET.equals(operation)) { return doDownload(size); } else { throw new IOException("Unsupported operation: \"" + operation + "\""); @@ -98,17 +127,36 @@ } /** + * Validate the URL we are connecting to + * @throws IOException if there is no valid URL + */ + protected void validateURL() throws IOException { + if (getUrl() == null) { + throw new IOException("No URL to connect to"); + } + } + + /** + * Open a connection. The connection is not yet "connected" -you can do some last minute tuning + * + * @return an HTTP connection. + * @throws IOException + */ + protected HttpURLConnection openConnection() throws IOException { + HttpURLConnection connection; + validateURL(); + URL targetURL = getUrl(); + return openConnection(targetURL); + } + + /** * Open a connection. The connection is not yet "connected" -you can do some last minute tuning * * @return an HTTP connection. * @throws IOException */ - protected HttpURLConnection openConnection() throws IOException { + protected HttpURLConnection openConnection(URL targetURL) throws IOException { HttpURLConnection connection; - URL targetURL = getUrl(); - if (targetURL == null) { - throw new IOException("No URL to connect to"); - } URLConnection rawConnection = targetURL.openConnection(); if (!(rawConnection instanceof HttpURLConnection)) { throw new IOException("Could not open an HTTP connection to " + targetURL); @@ -125,4 +173,28 @@ return connection; } + + public String getName() { + return "IOClient"; + } + + @Override + public String toString() { + return getName() + " connected to \""+ getUrl() + "\"; Operation is "+operation; + } + + /** + * Close quietly, log on an exception, do nothing on null + * + * @param c thing to close + */ + protected void closeQuietly(Closeable c) { + if (c != null) { + try { + c.close(); + } catch (IOException e) { + log.warn(e); + } + } + } } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ApacheBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ApacheBulkIOClient.java 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/ApacheBulkIOClient.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -19,36 +19,52 @@ */ package org.smartfrog.services.www.bulkio.client; +import org.apache.commons.logging.Log; + /** * Created 17-May-2010 16:46:34 */ public class ApacheBulkIOClient extends AbstractBulkIOClient { -/* + + public ApacheBulkIOClient(Log log) { + super(log); + } - @Override - public long doUpload(long size) throws IOException, InterruptedException { - return 0; + public ApacheBulkIOClient() { } + /* + + @Override + public long doUpload(long size) throws IOException, InterruptedException { + return 0; + } + + @Override + public long doUpload(File f) throws IOException, InterruptedException { + return 0; + } + + @Override + public long doDownload(long size) throws IOException, InterruptedException { + return 0; + } + + @Override + public long doDownload(long size, File f) throws IOException, InterruptedException { + return 0; + } + */ + @Override - public long doUpload(File f) throws IOException, InterruptedException { - return 0; - } + public void interrupt() { - @Override - public long doDownload(long size) throws IOException, InterruptedException { - return 0; } @Override - public long doDownload(long size, File f) throws IOException, InterruptedException { - return 0; + public String getName() { + return "IOClient using Apache Httpclient library"; } -*/ - @Override - public void interrupt() { - - } } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -35,4 +35,5 @@ String ATTR_SIZE = "size"; String ATTR_OPERATION = "operation"; //String ATTR_ = ""; + String ATTR_FORMAT = "format"; } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -19,13 +19,16 @@ */ package org.smartfrog.services.www.bulkio.client; +import org.smartfrog.services.logging.jcl.front.CommonsLogFactory; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.reference.Reference; import org.smartfrog.sfcore.security.SFClassLoader; import org.smartfrog.sfcore.utils.SmartFrogThread; import org.smartfrog.sfcore.utils.WorkerThreadPrimImpl; import org.smartfrog.sfcore.utils.WorkflowThread; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; @@ -88,12 +91,14 @@ e, BulkIOClientImpl.this); } + ioclient.setLog(CommonsLogFactory.createInstance(sfLog())); ioclient.size = sfResolve(ATTR_SIZE, 0L, true); ioclient.connectTimeout = sfResolve(ATTR_CONNECT_TIMEOUT, 0, true); ioclient.chunked = sfResolve(ATTR_CHUNKED, true, true); ioclient.chunkLength = sfResolve(ATTR_CHUNK_LENGTH, 0, true); ioclient.operation = sfResolve(ATTR_OPERATION, "", true); ioclient.useFormUpload = sfResolve(ATTR_USE_FORM_UPLOAD, true, true); + ioclient.format = sfResolve(ATTR_FORMAT, "", true); String targetURLpath = sfResolve(ATTR_URL, "", true); try { @@ -106,6 +111,21 @@ } /** + * do the operation + * + * @throws Throwable + */ + @Override + public void execute() throws Throwable { + try { + ioclient.execute(); + } catch (IOException e) { + sfLog().error("Failed to execute " + ioclient + ": " + e, e); + throw e; + } + } + + /** * Interrupt the worker */ public void interrupt() { Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -19,11 +19,15 @@ */ package org.smartfrog.services.www.bulkio.client; +import org.apache.commons.logging.Log; import org.smartfrog.services.www.HttpAttributes; +import org.smartfrog.services.www.LivenessPageChecker; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.net.URL; /** * This class uses the Sun Java APIs to do bulk upload. @@ -33,18 +37,33 @@ private volatile boolean interrupted; + public SunJavaBulkIOClient(Log log) { + super(log); + } + public SunJavaBulkIOClient() { + } + @Override public long doUpload(long size) throws IOException, InterruptedException { + validateURL(); + getLog().info("Uploading " + size + " bytes to " + getUrl()); HttpURLConnection connection = openConnection(); - connection.setRequestProperty(HttpAttributes.CONTENT_LENGTH, Long.toString(size)); - OutputStream outputStream = connection.getOutputStream(); - for (long bytes = 0; bytes < size; bytes++) { - outputStream.write(32); - if (interrupted) { - throw new InterruptedException("Interrupted after sending " + bytes + " bytes"); + connection.setRequestProperty(HttpAttributes.HEADER_CONTENT_LENGTH, Long.toString(size)); + connection.setDoOutput(true); + connection.connect(); + OutputStream stream = connection.getOutputStream(); + try { + for (long bytes = 0; bytes < size; bytes++) { + stream.write(32); + if (interrupted) { + throw new InterruptedException("Interrupted after sending " + bytes + " bytes"); + } } + } finally { + closeQuietly(stream); } + return size; } /* @@ -58,7 +77,54 @@ */ @Override + public long doDownload(long size) throws IOException, InterruptedException { + validateURL(); + URL target = createFullURL(size, format); + getLog().info("Downloading " + size + " bytes from " + target); + HttpURLConnection connection = openConnection(target); + int status = connection.getResponseCode(); + if (status != HttpURLConnection.HTTP_OK) { + String errorText = LivenessPageChecker.getInputOrErrorText(connection); + throw new IOException("Wrong status code " + status + " from " + target + ":\n" + errorText); + } + String contentLengthHeader = connection.getHeaderField(HttpAttributes.HEADER_CONTENT_LENGTH); + long contentLength = Long.parseLong(contentLengthHeader); + if (contentLength != size) { + throw new IOException("Wrong content length returned from " + target + + " - expected " + size + " but got " + contentLength); + } + String formatHeader = connection.getHeaderField(HttpAttributes.HEADER_CONTENT_TYPE); + if (!format.equals(formatHeader)) { + throw new IOException("Wrong content type returned from " + target + + " - expected " + format + " but got " + formatHeader); + } + InputStream stream = connection.getInputStream(); + long bytes = 0; + try { + for (bytes = 0; bytes < size; bytes++) { + stream.read(); + if (interrupted) { + throw new InterruptedException("Interrupted after reading" + bytes + " bytes"); + } + } + } finally { + getLog().info("Download finished after " + bytes + " bytes "); + closeQuietly(stream); + } + if (bytes != size) { + throw new IOException("Wrong content length downloaded from " + target + + " - requested " + size + " but got " + bytes); + } + return bytes; + } + + @Override public void interrupt() { interrupted = true; } + + @Override + public String getName() { + return "IOClient using Sun API"; + } } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf 2010-05-19 15:56:46 UTC (rev 8284) @@ -42,30 +42,37 @@ chunkLength 4096; + format FORMAT_BINARY ; + FORMAT_BINARY "application/octet-stream"; + SUN_IO_CLASS "org.smartfrog.services.www.bulkio.client.SunJavaBulkIOClient"; APACHE_IO_CLASS "org.smartfrog.services.www.bulkio.client.ApacheBulkIOClient"; + POST "POST"; + GET "GET"; + PUT "PUT"; + } BulkIOUpload extends BulkIOClient { - operation "POST"; + operation POST; } BulkIODownload extends BulkIOClient { - operation "GET"; + operation GET; } /** - * do a bulk download using Sun's API + * do a bulk upload using Sun's API */ -SunBulkIODownload extends BulkIODownload { +SunBulkIOUpload extends BulkIOUpload { ioClass SUN_IO_CLASS; } /** - * do a bulk download using HttpClient + * do a bulk upload using HttpClient */ -ApacheBulkIODownload extends BulkIODownload { +ApacheBulkIOUpload extends BulkIOUpload { ioClass APACHE_IO_CLASS; } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -68,9 +68,9 @@ } protected long getContentLength(HttpServletRequest request) throws ServletException { - String contentL = request.getHeader(HttpAttributes.CONTENT_LENGTH); + String contentL = request.getHeader(HttpAttributes.HEADER_CONTENT_LENGTH); return contentL == null ? -1 : - parseToLong(" the header " + HttpAttributes.CONTENT_LENGTH, contentL); + parseToLong(" the header " + HttpAttributes.HEADER_CONTENT_LENGTH, contentL); } /** Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java 2010-05-19 15:56:46 UTC (rev 8284) @@ -68,8 +68,8 @@ format = TEXT_PLAIN; } response.setContentType(format); - response.setHeader(HttpAttributes.CONTENT_LENGTH, Long.toString(size)); - response.setHeader("X-" + HttpAttributes.CONTENT_LENGTH, Long.toString(size)); + response.setHeader(HttpAttributes.HEADER_CONTENT_LENGTH, Long.toString(size)); + response.setHeader("X-" + HttpAttributes.HEADER_CONTENT_LENGTH, Long.toString(size)); ServletOutputStream outputStream = null; try { outputStream = response.getOutputStream(); Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf 2010-05-19 15:05:29 UTC (rev 8283) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf 2010-05-19 15:56:46 UTC (rev 8284) @@ -29,18 +29,20 @@ initParams [ ["limit", limit] ]; + UPLOAD "/upload"; + DOWNLOAD "/download"; } BulkUploadServlet extends BulkIoServlet { name "BulkUploadServlet"; - pathSpec "/upload"; + pathSpec UPLOAD; className "org.smartfrog.services.www.bulkio.server.BulkUploadServlet"; } BulkDownloadServlet extends BulkIoServlet { name "BulkDownloadServlet"; - pathSpec "/download"; + pathSpec DOWNLOAD; className "org.smartfrog.services.www.bulkio.server.BulkDownloadServlet"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-05-19 16:07:27
|
Revision: 8285 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8285&view=rev Author: steve_l Date: 2010-05-19 16:07:16 +0000 (Wed, 19 May 2010) Log Message: ----------- SFOS-1476 add tests for big data upload/download and long-lived connections Modified Paths: -------------- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/ports.sf trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf Added Paths: ----------- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/ports.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/ports.sf 2010-05-19 15:56:46 UTC (rev 8284) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/ports.sf 2010-05-19 16:07:16 UTC (rev 8285) @@ -38,7 +38,7 @@ test.tempdir LAZY PROPERTY java.io.tmpdir; -test.timeout 15000; +test.timeout OPTIONAL(15000) IPROPERTY test.timeout.execute; test.waitForTimeout 5000; Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java 2010-05-19 16:07:16 UTC (rev 8285) @@ -0,0 +1,45 @@ +package org.smartfrog.services.www.jetty.test.system.bulkio; + +import org.smartfrog.services.www.jetty.test.system.JettyTestBase; + +public abstract class BulkIoTestCase extends JettyTestBase { + + public static final String BULKIO = "/org/smartfrog/services/www/jetty/test/system/bulkio/"; + public static final String TEST_BULKIO_SIZE = "test.bulkio.size"; + + public static final long MB = 1; + public static final long GB = 1024L * MB; + public static long SMALL = 8 * MB; + public static long MEDIUM = 128 * MB; + public static long LARGE = 1 * GB; + public static long VERY_LARGE = 5L * GB; + + public BulkIoTestCase(String name) { + super(name); + } + + public void expectBulkIoRun(String filename, long size) throws Throwable { + System.setProperty(TEST_BULKIO_SIZE, Long.toString(size)); + expectSuccessfulTestRun(BULKIO, filename); + } + + protected abstract String getFile(); + + public void testBulkIoSmall() throws Throwable { + expectBulkIoRun(getFile(), SMALL); + } + + public void testBulkIoMedium() throws Throwable { + expectBulkIoRun(getFile(), MEDIUM); + } + + public void testBulkIoLarge() throws Throwable { + expectBulkIoRun(getFile(), LARGE); + } + + public void testBulkIoVeryLarge() throws Throwable { + expectBulkIoRun(getFile(), VERY_LARGE); + } + + +} \ No newline at end of file Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf 2010-05-19 15:56:46 UTC (rev 8284) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf 2010-05-19 16:07:16 UTC (rev 8285) @@ -38,7 +38,7 @@ connectTimeout 30000; - chunked false; + chunked true; chunkLength 4096; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-05-20 16:08:35
|
Revision: 8288 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8288&view=rev Author: steve_l Date: 2010-05-20 16:08:28 +0000 (Thu, 20 May 2010) Log Message: ----------- SFOS-1476 add tests for big data upload/download and long-lived connections Modified Paths: -------------- trunk/core/components/jetty/build.xml trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPutTest.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java Added Paths: ----------- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BaseBulkIoTestCase.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCaseWithBigOperations.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoSmallPostTest.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoSmallPutTest.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettySmallIoGetTest.java trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/SmallIoTestCase.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/IoAttributes.java Removed Paths: ------------- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java Modified: trunk/core/components/jetty/build.xml =================================================================== --- trunk/core/components/jetty/build.xml 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/jetty/build.xml 2010-05-20 16:08:28 UTC (rev 8288) @@ -47,7 +47,7 @@ <!-- Import common stuff --> <import file="../../common.xml"/> - + <property name="org.mortbay.log.class" value="org.smartfrog.services.jetty.log.JettyLogger" /> <property name="example.path" value="/org/smartfrog/services/jetty/examples"/> <property name="deploy.sf" value="org/smartfrog/services/jetty/examples/war/secureWarServer.sf"/> Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BaseBulkIoTestCase.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BaseBulkIoTestCase.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BaseBulkIoTestCase.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -0,0 +1,50 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + +import org.smartfrog.services.www.jetty.test.system.JettyTestBase; + +/** + * Created 20-May-2010 12:46:43 + */ + +public abstract class BaseBulkIoTestCase extends JettyTestBase { + public static final String BULKIO = "/org/smartfrog/services/www/jetty/test/system/bulkio/"; + public static final String TEST_BULKIO_SIZE = "test.bulkio.size"; + public static final long MB = 1; + public static final long GB = 1024L * MB; + public static long SIZE_8MB = 8 * MB; + public static long SIZE_128MB = 128 * MB; + public static long LARGE_1GB = 1 * GB; + public static long LARGE_3GB = 3 * GB; + public static long LARGE_4GB = 4 * GB; + public static long LARGE_5GB = 5L * GB; + + public BaseBulkIoTestCase(String name) { + super(name); + } + + public void expectBulkIoRun(String filename, long size) throws Throwable { + System.setProperty(TEST_BULKIO_SIZE, Long.toString(size)); + expectSuccessfulTestRun(BULKIO, filename); + } + + protected abstract String getFile(); +} Deleted: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -1,45 +0,0 @@ -package org.smartfrog.services.www.jetty.test.system.bulkio; - -import org.smartfrog.services.www.jetty.test.system.JettyTestBase; - -public abstract class BulkIoTestCase extends JettyTestBase { - - public static final String BULKIO = "/org/smartfrog/services/www/jetty/test/system/bulkio/"; - public static final String TEST_BULKIO_SIZE = "test.bulkio.size"; - - public static final long MB = 1; - public static final long GB = 1024L * MB; - public static long SMALL = 8 * MB; - public static long MEDIUM = 128 * MB; - public static long LARGE = 1 * GB; - public static long VERY_LARGE = 5L * GB; - - public BulkIoTestCase(String name) { - super(name); - } - - public void expectBulkIoRun(String filename, long size) throws Throwable { - System.setProperty(TEST_BULKIO_SIZE, Long.toString(size)); - expectSuccessfulTestRun(BULKIO, filename); - } - - protected abstract String getFile(); - - public void testBulkIoSmall() throws Throwable { - expectBulkIoRun(getFile(), SMALL); - } - - public void testBulkIoMedium() throws Throwable { - expectBulkIoRun(getFile(), MEDIUM); - } - - public void testBulkIoLarge() throws Throwable { - expectBulkIoRun(getFile(), LARGE); - } - - public void testBulkIoVeryLarge() throws Throwable { - expectBulkIoRun(getFile(), VERY_LARGE); - } - - -} \ No newline at end of file Copied: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCaseWithBigOperations.java (from rev 8285, trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCase.java) =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCaseWithBigOperations.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCaseWithBigOperations.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -0,0 +1,72 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + + +/** + * Base class for tests that do IO operations -includes a base set of ops + */ +public abstract class BulkIoTestCaseWithBigOperations extends BaseBulkIoTestCase { + + public BulkIoTestCaseWithBigOperations(String name) { + super(name); + } + + public void testBulkIo1MB() throws Throwable { + expectBulkIoRun(getFile(), MB); + } + + public void testBulkIo8MB() throws Throwable { + expectBulkIoRun(getFile(), SIZE_8MB); + } + + public void testBulkIo128MB() throws Throwable { + expectBulkIoRun(getFile(), SIZE_128MB); + } + + public void testBulkIo1GB() throws Throwable { + expectBulkIoRun(getFile(), LARGE_1GB); + } + + public void testBulk3GB() throws Throwable { + expectBulkIoRun(getFile(), LARGE_3GB); + } + + public void testBulk4GB() throws Throwable { + expectBulkIoRun(getFile(), LARGE_4GB); + } + + public void testBulkIo5GB() throws Throwable { + expectBulkIoRun(getFile(), LARGE_5GB); + } + +} \ No newline at end of file Modified: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -23,7 +23,7 @@ * Created 19-May-2010 10:54:20 */ -public class JettyBulkIoGetTest extends BulkIoTestCase { +public class JettyBulkIoGetTest extends BulkIoTestCaseWithBigOperations { public JettyBulkIoGetTest(String name) { @@ -34,25 +34,7 @@ return "bulkioget"; } - public void testBulkIoSmall() throws Throwable { - expectBulkIoRun(getFile(), SMALL); - } - public void testBulkIoMedium() throws Throwable { - expectBulkIoRun(getFile(), MEDIUM); - } - public void testBulkIoLarge() throws Throwable { - expectBulkIoRun(getFile(), LARGE); - } - public void testBulkIoVeryLarge() throws Throwable { - expectBulkIoRun(getFile(), VERY_LARGE); - } - -/* - public void testBulkIoGet() throws Throwable { - expectSuccessfulTestRun(BULKIO, getFile()); - }*/ - } \ No newline at end of file Modified: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -23,7 +23,7 @@ * Created 19-May-2010 10:54:20 */ -public class JettyBulkIoPostTest extends BulkIoTestCase { +public class JettyBulkIoPostTest extends BulkIoTestCaseWithBigOperations { public JettyBulkIoPostTest(String name) { super(name); Modified: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPutTest.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPutTest.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPutTest.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -24,7 +24,7 @@ * Created 19-May-2010 10:54:20 */ -public class JettyBulkIoPutTest extends BulkIoTestCase { +public class JettyBulkIoPutTest extends BulkIoTestCaseWithBigOperations { public JettyBulkIoPutTest(String name) { super(name); Copied: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoSmallPostTest.java (from rev 8284, trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoPostTest.java) =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoSmallPostTest.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoSmallPostTest.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -0,0 +1,37 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + +/** + * Created 19-May-2010 10:54:20 + */ + +public class JettyBulkIoSmallPostTest extends SmallIoTestCase { + + public JettyBulkIoSmallPostTest(String name) { + super(name); + } + + protected String getFile() { + return "bulkiopost"; + } + + +} \ No newline at end of file Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoSmallPutTest.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoSmallPutTest.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoSmallPutTest.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -0,0 +1,37 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + +/** + * Created 19-May-2010 10:54:20 + */ + +public class JettyBulkIoSmallPutTest extends SmallIoTestCase { + + public JettyBulkIoSmallPutTest(String name) { + super(name); + } + + protected String getFile() { + return "bulkioput"; + } + + +} \ No newline at end of file Copied: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettySmallIoGetTest.java (from rev 8284, trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettyBulkIoGetTest.java) =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettySmallIoGetTest.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/JettySmallIoGetTest.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -0,0 +1,37 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + +/** + * Created 19-May-2010 10:54:20 + */ + +public class JettySmallIoGetTest extends SmallIoTestCase { + + + public JettySmallIoGetTest(String name) { + super(name); + } + + protected String getFile() { + return "bulkioget"; + } + +} \ No newline at end of file Added: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/SmallIoTestCase.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/SmallIoTestCase.java (rev 0) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/SmallIoTestCase.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -0,0 +1,38 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.jetty.test.system.bulkio; + +/** + * Created 19-May-2010 10:54:20 + */ + +public abstract class SmallIoTestCase extends BaseBulkIoTestCase { + + + public SmallIoTestCase(String name) { + super(name); + } + + + public void testBulkIo1MB() throws Throwable { + expectBulkIoRun(getFile(), MB); + } + +} \ No newline at end of file Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/IoAttributes.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/IoAttributes.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/IoAttributes.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -0,0 +1,32 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.www.bulkio; + +/** + * Created 20-May-2010 12:01:13 + */ + +public interface IoAttributes { + String BYTES_READ = "bytes.read"; + String BYTES_EXPECTED = "bytes.expected"; + String CONTENT_TYPE = "content.type"; + String CONTENT_LENGTH = "content.length"; + String CHECKSUM = "checksum"; +} Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/AbstractBulkIOClient.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -29,6 +29,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import java.util.Properties; /** * Created 17-May-2010 17:35:44 @@ -51,6 +52,10 @@ public int chunkLength = 8192; public String format = "application/binary"; + + public boolean parseResults; + + public long expectedChecksumFromGet; private Log log = LogFactory.getLog(AbstractBulkIOClient.class); @@ -76,7 +81,7 @@ public void setUrl(URL url) { this.url = url; } - + public URL createFullURL(long size, String format) throws IOException { validateURL(); StringBuilder fullPath = new StringBuilder(url.getFile()); @@ -91,7 +96,7 @@ public long execute() throws IOException, InterruptedException { if (HttpAttributes.METHOD_POST.equals(operation) || HttpAttributes.METHOD_PUT.equals(operation)) { - return doUpload(size); + return doUpload(operation, size); } else if (HttpAttributes.METHOD_GET.equals(operation)) { return doDownload(size); } else { @@ -99,7 +104,7 @@ } } - public long doUpload(long size) throws IOException, InterruptedException { + public long doUpload(String method, long ioSize) throws IOException, InterruptedException { return notImplemented(); } @@ -107,15 +112,15 @@ throw new IOException("Not Implemented"); } - public long doUpload(File f) throws IOException, InterruptedException { + public long doUpload(String method, File f) throws IOException, InterruptedException { return notImplemented(); } - public long doDownload(long size) throws IOException, InterruptedException { + public long doDownload(long ioSize) throws IOException, InterruptedException { return notImplemented(); } - public long doDownload(long size, File f) throws IOException, InterruptedException { + public long doDownload(long ioSize, File f) throws IOException, InterruptedException { return notImplemented(); } @@ -128,6 +133,7 @@ /** * Validate the URL we are connecting to + * * @throws IOException if there is no valid URL */ protected void validateURL() throws IOException { @@ -137,11 +143,11 @@ } /** - * Open a connection. The connection is not yet "connected" -you can do some last minute tuning - * - * @return an HTTP connection. - * @throws IOException - */ + * Open a connection. The connection is not yet "connected" -you can do some last minute tuning + * + * @return an HTTP connection. + * @throws IOException + */ protected HttpURLConnection openConnection() throws IOException { HttpURLConnection connection; validateURL(); @@ -167,11 +173,18 @@ if (connectTimeout >= 0) { connection.setConnectTimeout(connectTimeout); } + return connection; + } + + /** + * Set chunking. <i>DO NOT DO THIS ON A GET AS the JDK CANNOT HANDLE IT</i> + * + * @param connection + */ + protected void maybeSetChunking(HttpURLConnection connection) { if (chunked) { connection.setChunkedStreamingMode(chunkLength); } - - return connection; } public String getName() { @@ -180,7 +193,7 @@ @Override public String toString() { - return getName() + " connected to \""+ getUrl() + "\"; Operation is "+operation; + return getName() + " connected to \"" + getUrl() + "\"; Operation is " + operation; } /** @@ -197,4 +210,23 @@ } } } + + /** + * Get a long property value + * @param props property instance + * @param key key + * @return the long value + * @throws IOException if the + */ + long getLongPropValue(Properties props, String key) throws IOException { + String value = props.getProperty(key); + if (value == null) { + throw new IOException("Failed to find property key " + key); + } + try { + return Long.parseLong(value); + } catch (NumberFormatException e) { + throw new IOException("Failed to parse property "+ key + " = \"" + value + "\": " + e, e); + } + } } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClient.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -36,4 +36,7 @@ String ATTR_OPERATION = "operation"; //String ATTR_ = ""; String ATTR_FORMAT = "format"; + String ATTR_PARSE_RESULTS ="parseResults"; + + String ATTR_EXPECTED_CHECKSUM_FROM_GET = "expectedChecksumFromGet"; } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/BulkIOClientImpl.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -22,7 +22,6 @@ import org.smartfrog.services.logging.jcl.front.CommonsLogFactory; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogResolutionException; -import org.smartfrog.sfcore.reference.Reference; import org.smartfrog.sfcore.security.SFClassLoader; import org.smartfrog.sfcore.utils.SmartFrogThread; import org.smartfrog.sfcore.utils.WorkerThreadPrimImpl; @@ -99,6 +98,8 @@ ioclient.operation = sfResolve(ATTR_OPERATION, "", true); ioclient.useFormUpload = sfResolve(ATTR_USE_FORM_UPLOAD, true, true); ioclient.format = sfResolve(ATTR_FORMAT, "", true); + ioclient.parseResults = sfResolve(ATTR_PARSE_RESULTS, true, true); + ioclient.expectedChecksumFromGet = sfResolve(ATTR_EXPECTED_CHECKSUM_FROM_GET, 0L, false); String targetURLpath = sfResolve(ATTR_URL, "", true); try { Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -22,12 +22,16 @@ import org.apache.commons.logging.Log; import org.smartfrog.services.www.HttpAttributes; import org.smartfrog.services.www.LivenessPageChecker; +import org.smartfrog.services.www.bulkio.IoAttributes; +import org.smartfrog.services.www.bulkio.server.AbstractBulkioServlet; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; +import java.util.Properties; +import java.util.zip.CRC32; /** * This class uses the Sun Java APIs to do bulk upload. @@ -45,17 +49,24 @@ } @Override - public long doUpload(long size) throws IOException, InterruptedException { + public long doUpload(String method, long ioSize) throws IOException, InterruptedException { validateURL(); - getLog().info("Uploading " + size + " bytes to " + getUrl()); + CRC32 checksum = new CRC32(); + URL targetUrl = getUrl(); + getLog().info("Uploading " + ioSize + " bytes to " + targetUrl); HttpURLConnection connection = openConnection(); - connection.setRequestProperty(HttpAttributes.HEADER_CONTENT_LENGTH, Long.toString(size)); + connection.setRequestMethod(method); + connection.setRequestProperty(HttpAttributes.HEADER_CONTENT_LENGTH, Long.toString(ioSize)); connection.setDoOutput(true); + maybeSetChunking(connection); connection.connect(); OutputStream stream = connection.getOutputStream(); + long bytes = 0; try { - for (long bytes = 0; bytes < size; bytes++) { - stream.write(32); + for (bytes = 0; bytes < ioSize; bytes++) { + int octet = (AbstractBulkioServlet.getByteFromCounter(bytes)); + stream.write(octet); + checksum.update(octet); if (interrupted) { throw new InterruptedException("Interrupted after sending " + bytes + " bytes"); } @@ -63,35 +74,61 @@ } finally { closeQuietly(stream); } + getLog().info("Upload complete, checking results"); + checkStatusCode(targetUrl, connection, HttpURLConnection.HTTP_OK); + long expectedChecksum = checksum.getValue(); + getLog().info("Uploaded " + bytes + " bytes to " + targetUrl + " checksum=" + expectedChecksum); + if (bytes != ioSize) { + throw new IOException("Wrong content length uploaded from " + + " - put " + ioSize + " but got " + bytes); + } + if (parseResults) { + InputStream inStream = null; + Properties props = new Properties(); + try { + inStream = connection.getInputStream(); + props.load(inStream); + } finally { + closeQuietly(inStream); + } - return size; - } -/* + long actualChecksum = getLongPropValue(props, IoAttributes.CHECKSUM); + if (actualChecksum != expectedChecksum) { + throw new IOException("Expected checksum from upload of " + ioSize + " bytes " + + "was " + expectedChecksum + " but got " + actualChecksum + + "\n Properties: " + props.toString()); + } - @Override - public long doUpload(File f) throws IOException, InterruptedException { - return 0; + } + return ioSize; } + /* + + @Override + public long doUpload(File f) throws IOException, InterruptedException { + return 0; + } + + + */ -*/ - @Override - public long doDownload(long size) throws IOException, InterruptedException { + public long doDownload(long ioSize) throws IOException, InterruptedException { validateURL(); - URL target = createFullURL(size, format); - getLog().info("Downloading " + size + " bytes from " + target); + URL target = createFullURL(ioSize, format); + getLog().info("Downloading " + ioSize + " bytes from " + target); + CRC32 checksum = new CRC32(); HttpURLConnection connection = openConnection(target); - int status = connection.getResponseCode(); - if (status != HttpURLConnection.HTTP_OK) { - String errorText = LivenessPageChecker.getInputOrErrorText(connection); - throw new IOException("Wrong status code " + status + " from " + target + ":\n" + errorText); - } + connection.setRequestMethod(HttpAttributes.METHOD_GET); + connection.setDoOutput(false); + connection.connect(); + checkStatusCode(target, connection, HttpURLConnection.HTTP_OK); String contentLengthHeader = connection.getHeaderField(HttpAttributes.HEADER_CONTENT_LENGTH); long contentLength = Long.parseLong(contentLengthHeader); - if (contentLength != size) { + if (contentLength != ioSize) { throw new IOException("Wrong content length returned from " + target - + " - expected " + size + " but got " + contentLength); + + " - expected " + ioSize + " but got " + contentLength); } String formatHeader = connection.getHeaderField(HttpAttributes.HEADER_CONTENT_TYPE); if (!format.equals(formatHeader)) { @@ -101,23 +138,37 @@ InputStream stream = connection.getInputStream(); long bytes = 0; try { - for (bytes = 0; bytes < size; bytes++) { - stream.read(); + for (bytes = 0; bytes < ioSize; bytes++) { + int octet = stream.read(); + checksum.update(octet); if (interrupted) { throw new InterruptedException("Interrupted after reading" + bytes + " bytes"); } } } finally { - getLog().info("Download finished after " + bytes + " bytes "); closeQuietly(stream); } - if (bytes != size) { + long actualChecksum = checksum.getValue(); + getLog().info("Download finished after " + bytes + " bytes, checksum=" + actualChecksum); + if (bytes != ioSize) { throw new IOException("Wrong content length downloaded from " + target - + " - requested " + size + " but got " + bytes); + + " - requested " + ioSize + " but got " + bytes); } + if (expectedChecksumFromGet >= 0 && expectedChecksumFromGet != actualChecksum) { + throw new IOException("Expected checksum from download of " + ioSize + " bytes " + + "was " + expectedChecksumFromGet + " but got " + actualChecksum); + } return bytes; } + private void checkStatusCode(URL target, HttpURLConnection connection, int expectedStatus) throws IOException { + int status = connection.getResponseCode(); + if (status != expectedStatus) { + String errorText = LivenessPageChecker.getInputOrErrorText(connection); + throw new IOException("Wrong status code " + status + " from " + target + ":\n" + errorText); + } + } + @Override public void interrupt() { interrupted = true; Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/components.sf 2010-05-20 16:08:28 UTC (rev 8288) @@ -42,7 +42,14 @@ chunkLength 4096; + //checksum to expect on a get, if >=0 this is checked against the CRC of the downloaded content + expectedChecksumFromGet -1; + + //should the client look for and parse the results + parseResults true; + format FORMAT_BINARY ; + FORMAT_BINARY "application/octet-stream"; SUN_IO_CLASS "org.smartfrog.services.www.bulkio.client.SunJavaBulkIOClient"; @@ -72,9 +79,11 @@ /** * do a bulk upload using HttpClient */ +/* ApacheBulkIOUpload extends BulkIOUpload { ioClass APACHE_IO_CLASS; } +*/ /** * do a bulk download using Sun's API @@ -86,6 +95,8 @@ /** * do a bulk download using HttpClient */ +/* ApacheBulkIODownload extends BulkIODownload { ioClass APACHE_IO_CLASS; } +*/ Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -56,6 +56,10 @@ response.addHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT"); } + public Log getLog() { + return log; + } + /** * Get the request size * @@ -119,4 +123,8 @@ } } } + + public static int getByteFromCounter(long position) { + return '0' + (int) (position % 10); + } } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -74,7 +74,7 @@ try { outputStream = response.getOutputStream(); for (long bytes = 0; bytes < size; bytes++) { - outputStream.write('0'+(int)(bytes%10)); + outputStream.write(getByteFromCounter(bytes)); } } finally { closeQuietly(outputStream); Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java 2010-05-20 16:07:20 UTC (rev 8287) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java 2010-05-20 16:08:28 UTC (rev 8288) @@ -19,12 +19,15 @@ */ package org.smartfrog.services.www.bulkio.server; +import org.smartfrog.services.www.bulkio.IoAttributes; + import javax.servlet.ServletException; import javax.servlet.ServletInputStream; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.zip.CRC32; /** * Created 17-May-2010 15:03:10 @@ -36,8 +39,13 @@ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - long size = getSize(request); + CRC32 checksum = new CRC32(); + long size = -1; + // size = getSize(request); long contentLength = getContentLength(request); + String type = request.getContentType(); + + getLog().info(request.getMethod() + " operation receiving " + contentLength + " bytes of type " + type); if (size >= 0 && size != contentLength) { throw new ServletException( "Content-Length header of " + contentLength + " does not equal the size parameter " + size); @@ -46,13 +54,23 @@ long bytes; try { inStream = request.getInputStream(); - for (bytes = 0; bytes < size; bytes++) { - int value = inStream.read(); + for (bytes = 0; bytes < contentLength; bytes++) { + int octet = inStream.read(); + checksum.update(octet); } } finally { closeQuietly(inStream); } - returnPlainText(response,"Read "+ bytes + " bytes; expected + " + size); + long checksumValue = checksum.getValue(); + getLog().info("Checksum : " + checksumValue); + String summary = "#summary\n" + + IoAttributes.BYTES_READ + "=" + bytes + "\n" + + IoAttributes.BYTES_EXPECTED + "=" + size + "\n" + + IoAttributes.CONTENT_LENGTH + "=" + contentLength + "\n" + + IoAttributes.CONTENT_TYPE + "=" + type + "\n" + + IoAttributes.CHECKSUM + "=" + checksumValue + "\n"; + getLog().info(summary); + returnPlainText(response,summary); } @Override @@ -62,7 +80,8 @@ } @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { disableCaching(response); response.setContentType(TEXT_HTML); ServletOutputStream out = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-05-25 12:56:46
|
Revision: 8293 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8293&view=rev Author: steve_l Date: 2010-05-25 12:56:39 +0000 (Tue, 25 May 2010) Log Message: ----------- SFOS-1486 Add support for filters in the servlet context and jetty Modified Paths: -------------- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateServletContext.java trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateWebApplicationContext.java trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyServletDelegate.java trunk/core/components/www/src/org/smartfrog/services/www/ServletContextIntf.java trunk/core/components/www/src/org/smartfrog/services/www/context/ServletComponentImpl.java trunk/core/components/www/src/org/smartfrog/services/www/context/ServletContextImpl.java trunk/core/components/www/src/org/smartfrog/services/www/webapplication.sf Added Paths: ----------- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/AbstractJettyServletContextDelegate.java trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyFilterDelegate.java trunk/core/components/www/src/org/smartfrog/services/www/FilterComponent.java trunk/core/components/www/src/org/smartfrog/services/www/context/DelegatedServletComponentImpl.java trunk/core/components/www/src/org/smartfrog/services/www/context/FilterComponentImpl.java trunk/core/components/www/src/org/smartfrog/services/www/filters/ trunk/core/components/www/src/org/smartfrog/services/www/filters/components.sf Added: trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/AbstractJettyServletContextDelegate.java =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/AbstractJettyServletContextDelegate.java (rev 0) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/AbstractJettyServletContextDelegate.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -0,0 +1,235 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +package org.smartfrog.services.jetty.contexts.delegates; + +import org.mortbay.jetty.servlet.Context; +import org.mortbay.jetty.servlet.Holder; +import org.smartfrog.services.www.ServletComponent; +import org.smartfrog.services.www.ServletContextComponentDelegate; +import org.smartfrog.sfcore.common.SmartFrogDeploymentException; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.logging.Log; +import org.smartfrog.sfcore.logging.LogFactory; +import org.smartfrog.sfcore.prim.Prim; +import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.utils.ListUtils; + +import java.rmi.RemoteException; +import java.util.Iterator; +import java.util.Vector; + +/** + * abstract base class for anything that goes into a jetty servlet context, binds to the context etc. This class doesnt + * do anything in its constructor and doesnt implement the delegated lifecycle methods, that is a task for the + * implementations. + */ + +public abstract class AbstractJettyServletContextDelegate implements ServletContextComponentDelegate { + /** + * context within which the servlet deploys. + */ + protected DelegateServletContext context; + protected Prim owner; + private static final Reference nameRef = new Reference(ServletComponent.ATTR_NAME); + private static final Reference classNameRef = new Reference(ServletComponent.ATTR_CLASSNAME); + protected String name = null; + protected String className = null; + /** + * a log + */ + protected Log log; + protected Holder jettyHolder = null; + public static final String ERROR_NO_SERVLET_CONTEXT = "No servlet context is currently live"; + protected static final Reference initParamsRef = new Reference(ServletComponent.ATTR_INIT_PARAMS); + protected static final Reference pathSpecRef = new Reference(ServletComponent.ATTR_PATH_SPEC); + protected static final Reference initOptionsRef = new Reference(ServletComponent.ATTR_INIT_OPTIONS); + protected static final Reference mappingsRef = new Reference(ServletComponent.ATTR_MAPPINGS); + + public AbstractJettyServletContextDelegate(Prim owner, DelegateServletContext context) { + log = LogFactory.getOwnerLog(owner); + this.context = context; + this.owner = owner; + } + + public DelegateServletContext getContext() { + return context; + } + + public Prim getOwner() { + return owner; + } + + public String getName() { + return name; + } + + public String getClassName() { + return className; + } + + public Log getLog() { + return log; + } + + + public Holder getJettyHolder() { + return jettyHolder; + } + + protected void setJettyHolder(Holder jettyHolder) { + this.jettyHolder = jettyHolder; + } + + + /** + * Returns a the name and classname of the delegate + * + * @return a string representation of the object. + */ + @Override + public String toString() { + return "name=" + name + + "; className=" + className; + } + + /** + * From the delegate servlet context, resolve the real servlet context. Contains an assert that the argument is not + * null. + * + * @param delegateServletContext the delegate context, must not be null + * @return the jetty context + * @throws SmartFrogDeploymentException if there is no jetty context + */ + protected Context resolveJettyServletContext(DelegateServletContext delegateServletContext) + throws SmartFrogDeploymentException { + assert delegateServletContext != null : "no DelegateServletContext parameter"; + Context servletContext; + servletContext = delegateServletContext.getServletContext(); + if (servletContext == null) { + throw new SmartFrogDeploymentException(ERROR_NO_SERVLET_CONTEXT); + } + return servletContext; + } + + /** + * bind the name and classname parameters + * + * @param prim owner + * @throws SmartFrogResolutionException resolution failure + * @throws RemoteException network problems + */ + protected void bindNameAndClassname(Prim prim) throws SmartFrogResolutionException, RemoteException { + assert prim != null : "no prim parameter"; + name = prim.sfResolve(nameRef, name, true); + className = prim.sfResolve(classNameRef, className, true); + } + + /** + * Bind initialisation options from the owner prim, and set the jetty holder attribute + * @param holder holder + * @throws SmartFrogResolutionException resolution failure + * @throws RemoteException network problems + */ + protected void bindAndInitHolder(Holder holder) throws SmartFrogResolutionException, RemoteException { + setJettyHolder(holder); + Prim prim = getOwner(); + bindNameAndClassname(prim); + holder.setName(name); + holder.setClassName(className); + //apply initialisation params from the list + Iterable<Vector<String>> paramTuples = ListUtils.resolveStringTupleList(prim, initParamsRef, true); + for (Vector<String> tuple : paramTuples) { + holder.setInitParameter(tuple.firstElement(), tuple.get(1)); + } + //apply initialisation params from the context + ComponentDescription optionsCD = prim.sfResolve(initOptionsRef, (ComponentDescription) null, true); + org.smartfrog.sfcore.common.Context optionsContext = optionsCD.sfContext(); + Iterator iterator = optionsContext.sfAttributes(); + while (iterator.hasNext()) { + Object key = iterator.next(); + Object value = optionsContext.get(key); + holder.setInitParameter(key.toString(), value.toString()); + } + } + + /** + * noop + * + * @throws SmartFrogException smartfrog problems + * @throws RemoteException network problems + */ + @Override + public void deploy() throws SmartFrogException, RemoteException { + + } + + /** + * start the component + * + * @throws SmartFrogException smartfrog problems + * @throws RemoteException network problems + */ + @Override + public void start() throws SmartFrogException, RemoteException { + try { + log.info("Starting " + toString()); + getJettyHolder().start(); + } catch (Exception e) { + throw new SmartFrogException(e); + } + } + + /** + * this method is here for server-specific implementation classes, + * + * @throws SmartFrogException smartfrog problems + * @throws RemoteException network problems + */ + @Override + public synchronized void terminate() throws RemoteException, SmartFrogException { + try { + if (jettyHolder != null) { + jettyHolder.stop(); + jettyHolder = null; + } + } catch (Exception e) { + throw SmartFrogException.forward(e); + } + } + + protected boolean isJettyHolderStarted() { + return jettyHolder == null || !jettyHolder.isStarted(); + } +} Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateServletContext.java =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateServletContext.java 2010-05-25 11:35:26 UTC (rev 8292) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateServletContext.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -21,24 +21,25 @@ import org.mortbay.jetty.Handler; import org.mortbay.jetty.MimeTypes; +import org.mortbay.jetty.handler.AbstractHandlerContainer; import org.mortbay.jetty.handler.ContextHandlerCollection; import org.mortbay.jetty.handler.HandlerCollection; import org.mortbay.jetty.handler.ResourceHandler; -import org.mortbay.jetty.handler.AbstractHandlerContainer; import org.mortbay.jetty.servlet.Context; import org.mortbay.jetty.servlet.HashSessionManager; -import org.mortbay.jetty.servlet.SessionHandler; import org.mortbay.jetty.servlet.ServletHandler; import org.mortbay.jetty.servlet.ServletMapping; +import org.mortbay.jetty.servlet.SessionHandler; import org.mortbay.resource.Resource; import org.smartfrog.services.filesystem.FileSystem; import org.smartfrog.services.jetty.JettyHelper; import org.smartfrog.services.jetty.JettyImpl; import org.smartfrog.services.jetty.JettyToSFLifecycle; +import org.smartfrog.services.jetty.internal.ExtendedErrorHandler; +import org.smartfrog.services.jetty.internal.ExtendedResourceHandler; import org.smartfrog.services.jetty.internal.ExtendedSecurityHandler; import org.smartfrog.services.jetty.internal.ExtendedServletHandler; -import org.smartfrog.services.jetty.internal.ExtendedErrorHandler; -import org.smartfrog.services.jetty.internal.ExtendedResourceHandler; +import org.smartfrog.services.www.FilterComponent; import org.smartfrog.services.www.ServletComponent; import org.smartfrog.services.www.ServletContextComponentDelegate; import org.smartfrog.services.www.ServletContextIntf; @@ -46,16 +47,16 @@ import org.smartfrog.sfcore.common.SmartFrogDeploymentException; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogLifecycleException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; import org.smartfrog.sfcore.logging.Log; import org.smartfrog.sfcore.logging.LogFactory; import org.smartfrog.sfcore.prim.Prim; import org.smartfrog.sfcore.reference.Reference; -import org.smartfrog.sfcore.componentdescription.ComponentDescription; import java.io.IOException; import java.rmi.RemoteException; +import java.util.Iterator; import java.util.Map; -import java.util.Iterator; /** * This is a helper servlet context; it gets stuff delegated to it. It is remotable, but not a Prim-derived class. @@ -83,7 +84,7 @@ /** * Constructor * - * @param server server that is creating this + * @param server server that is creating this * @param declaration the servlet declaration */ public DelegateServletContext(JettyImpl server, Prim declaration) { @@ -105,7 +106,7 @@ * do all deployment short of starting the thing * * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems + * @throws RemoteException network problems */ @Override public void deploy() throws SmartFrogException, RemoteException { @@ -127,7 +128,7 @@ * start: create and deploy this context * * @throws SmartFrogException In case of error while starting - * @throws RemoteException In case of network/rmi error + * @throws RemoteException In case of network/rmi error */ @Override public void start() throws SmartFrogException, RemoteException { @@ -186,7 +187,7 @@ throw new SmartFrogLifecycleException("Cannot start " + this + " as the server is not yet deployed"); } contextHandler.addHandler(handlerSet); - + //now read in the options //apply initialisation params from the context ComponentDescription optionsCD = owner.sfResolve(ATTR_OPTIONS, (ComponentDescription) null, true); @@ -201,28 +202,29 @@ log.info("Starting Jetty servlet context"); handlerLifecycle.start(); - if(log.isInfoEnabled()) { + if (log.isInfoEnabled()) { dumpHandlers(getServerContextHandler().getHandlers()); } } /** * Dump our handler chain, make things meaningful. This is a recursive function and logs to info - * @param handlers handlers to dump. + * + * @param handlers handlers to dump. */ private void dumpHandlers(Handler[] handlers) { - + for (Handler handler : handlers) { log.info(handler.toString()); if (handler instanceof ServletHandler) { ServletHandler sh = (ServletHandler) handler; ServletMapping[] servletMappings = sh.getServletMappings(); - if(servletMappings!=null) { + if (servletMappings != null) { for (ServletMapping mapping : servletMappings) { log.info(mapping.toString()); } } else { - + } } else { if (handler instanceof AbstractHandlerContainer) { @@ -237,7 +239,7 @@ * undeploy a the servlet by stopping it and removing it from the server context handler * * @throws SmartFrogException SmartFrog problems - * @throws RemoteException In case of network/rmi error + * @throws RemoteException In case of network/rmi error */ @Override public void terminate() throws RemoteException, SmartFrogException { @@ -291,9 +293,9 @@ * Add a mime mapping * * @param extension extension to map (no '.') - * @param mimeType mimetype to generate + * @param mimeType mimetype to generate * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems + * @throws RemoteException network problems */ @Override public void addMimeMapping(String extension, String mimeType) throws RemoteException, SmartFrogException { @@ -308,7 +310,7 @@ * @param extension extension to unmap * @return true if the unmapping was successful * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems + * @throws RemoteException network problems */ @Override public boolean removeMimeMapping(String extension) throws RemoteException, SmartFrogException { @@ -327,7 +329,7 @@ * @param servletDeclaration component declaring the servlet * @return the delegate that implements the servlet binding * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems + * @throws RemoteException network problems */ @Override public ServletContextComponentDelegate addServlet(ServletComponent servletDeclaration) @@ -336,13 +338,21 @@ return servletDelegate; } + /** + * {@inheritDoc} + */ + @Override + public ServletContextComponentDelegate addFilter(FilterComponent declaration) + throws RemoteException, SmartFrogException { + return new JettyFilterDelegate(this, (Prim) declaration); + } /** * add a handler to the server * * @param handler handler * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems + * @throws RemoteException network problems */ public void addHandler(Handler handler) throws SmartFrogException, RemoteException { @@ -354,7 +364,7 @@ * * @param handler handler * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems + * @throws RemoteException network problems */ public void removeHandler(Handler handler) throws SmartFrogException, RemoteException { try { Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateWebApplicationContext.java =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateWebApplicationContext.java 2010-05-25 11:35:26 UTC (rev 8292) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateWebApplicationContext.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -20,8 +20,8 @@ package org.smartfrog.services.jetty.contexts.delegates; +import org.mortbay.jetty.servlet.AbstractSessionManager; import org.mortbay.jetty.servlet.ServletHandler; -import org.mortbay.jetty.servlet.AbstractSessionManager; import org.mortbay.jetty.webapp.WebAppContext; import org.smartfrog.services.filesystem.FileSystem; import org.smartfrog.services.jetty.JettyImpl; @@ -100,10 +100,13 @@ application = new WebAppContext(webApp, contextPath); - ServletHandler servlethandler = application.getServletHandler(); -/* AbstractSessionManager sessionmanager = (AbstractSessionManager) + + /* commented out as the request ID stuff has gone away in Jetty 6 + ServletHandler servlethandler = application.getServletHandler(); + AbstractSessionManager sessionmanager = (AbstractSessionManager) servlethandler.getSessionManager(); - sessionmanager.setUseRequestedId(requestId);*/ + sessionmanager.setUseRequestedId(requestId); + */ setContext(application); Added: trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyFilterDelegate.java =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyFilterDelegate.java (rev 0) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyFilterDelegate.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -0,0 +1,141 @@ +package org.smartfrog.services.jetty.contexts.delegates; + +import org.mortbay.jetty.servlet.Context; +import org.mortbay.jetty.servlet.FilterHolder; +import org.mortbay.jetty.servlet.ServletHandler; +import org.mortbay.jetty.servlet.ServletHolder; +import org.mortbay.jetty.servlet.ServletMapping; +import org.smartfrog.services.jetty.JettyHelper; +import org.smartfrog.services.www.ApplicationServerContext; +import org.smartfrog.services.www.FilterComponent; +import org.smartfrog.services.www.WebApplicationHelper; +import org.smartfrog.sfcore.common.SmartFrogDeploymentException; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.common.SmartFrogLivenessException; +import org.smartfrog.sfcore.prim.Prim; +import org.smartfrog.sfcore.utils.ListUtils; + +import java.rmi.RemoteException; +import java.util.Vector; + +/** + * Created 24-May-2010 17:59:25 + */ + +public class JettyFilterDelegate extends AbstractJettyServletContextDelegate + implements FilterComponent { + + /** + * default inititialisation order {@value} + */ + + private String pathSpec = null; + + private FilterHolder holder = null; + private String absolutePath; + + /** + * Create the delegate and configure the {@link org.mortbay.jetty.servlet.Context} of Jetty that is the real + * context + * + * @param context sevlet context + * @param owner owner component + * @throws SmartFrogException smartfrog problems + * @throws RemoteException network problems + */ + public JettyFilterDelegate(DelegateServletContext context, Prim owner) + throws SmartFrogException, RemoteException { + super(owner, context); + bind(owner, context); + } + + /** + * Read in state, bind to the owner + * + * @param ctx sevlet context + * @param prim owner component + * @throws SmartFrogException smartfrog problems + * @throws RemoteException network problems + */ + private void bind(Prim prim, DelegateServletContext ctx) throws RemoteException, SmartFrogException { + Context servletContext = resolveJettyServletContext(ctx); + pathSpec = prim.sfResolve(pathSpecRef, pathSpec, true); + + holder = new FilterHolder(); + + bindAndInitHolder(holder); + + + //update our path attribute + String ancestorPath = ctx.getAbsolutePath(); + absolutePath = WebApplicationHelper.deregexpPath(JettyHelper.concatPaths( + ancestorPath, + pathSpec)); + prim.sfReplaceAttribute(ApplicationServerContext.ATTR_ABSOLUTE_PATH, + absolutePath); + int dispatches = 0; + //add the filter + servletContext.addFilter(holder, pathSpec, dispatches); +/* + ServletHandler servletHandler = servletContext.getServletHandler(); + ServletHolder resolvedHolder = servletHandler.getServlet(name); + if (resolvedHolder == null) { + //oops. no servlets, make a list + StringBuilder message = new StringBuilder("Failed to register the servlet with jetty."); + ServletHolder[] holders = servletHandler.getServlets(); + for (ServletHolder entry : holders) { + message.append("\n\""); + message.append(entry.getDisplayName()); + message.append("\" "); + message.append(entry.getClassName()); + } + throw new SmartFrogDeploymentException(message.toString()); + } +*/ + + //now start it up if the context is already live. + if (servletContext.isStarted()) { + start(); + } + + } + + public String getAbsolutePath() { + return absolutePath; + } + + /** + * Returns a string representation of the object. + * + * @return a string representation of the object. + */ + @Override + public String toString() { + return "name=" + name + + "; className=" + className + + "; pathSpec=" + pathSpec + + "; absolutePath=" + absolutePath; + } + + /** + * start the component + * + * @throws SmartFrogException smartfrog problems + * @throws RemoteException network problems + */ + + /** + * liveness check + * + * @throws SmartFrogLivenessException smartfrog problems + * @throws RemoteException network problems + */ + @Override + public void ping() throws SmartFrogLivenessException, RemoteException { + if (isJettyHolderStarted()) { + throw new SmartFrogLivenessException("Filter " + + name + + " is not running under" + getAbsolutePath()); + } + } +} Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyServletDelegate.java =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyServletDelegate.java 2010-05-25 11:35:26 UTC (rev 8292) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyServletDelegate.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -1,3 +1,35 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + package org.smartfrog.services.jetty.contexts.delegates; import org.mortbay.jetty.servlet.Context; @@ -7,55 +39,31 @@ import org.smartfrog.services.jetty.JettyHelper; import org.smartfrog.services.www.ApplicationServerContext; import org.smartfrog.services.www.ServletComponent; -import org.smartfrog.services.www.ServletContextComponentDelegate; import org.smartfrog.services.www.WebApplicationHelper; import org.smartfrog.sfcore.common.SmartFrogDeploymentException; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogLivenessException; -import org.smartfrog.sfcore.logging.Log; -import org.smartfrog.sfcore.logging.LogFactory; import org.smartfrog.sfcore.prim.Prim; -import org.smartfrog.sfcore.reference.Reference; import org.smartfrog.sfcore.utils.ListUtils; -import org.smartfrog.sfcore.componentdescription.ComponentDescription; import java.rmi.RemoteException; import java.util.Vector; -import java.util.Iterator; /** + * servlet within a Jetty servlet context */ -public class JettyServletDelegate - implements ServletContextComponentDelegate, ServletComponent { +public class JettyServletDelegate extends AbstractJettyServletContextDelegate + implements ServletComponent { /** * default inititialisation order {@value} */ public static final int DEFAULT_INIT_ORDER = -1; - /** - * context within which the servlet deploys. - */ - private DelegateServletContext context; - private Prim owner; - - private static final Reference nameRef = new Reference(ServletComponent.ATTR_NAME); - private static final Reference pathSpecRef = new Reference(ServletComponent.ATTR_PATH_SPEC); - private static final Reference classNameRef = new Reference(ServletComponent.ATTR_CLASSNAME); - private static final Reference initParamsRef = new Reference(ServletComponent.ATTR_INIT_PARAMS); - private static final Reference initOptionsRef = new Reference(ServletComponent.ATTR_INIT_OPTIONS); - - private String name = null; private String pathSpec = null; - private String className = null; private ServletHolder holder = null; private String absolutePath; - /** - * a log - */ - private Log log; - private static final Reference mappingsRef = new Reference(ATTR_MAPPINGS); /** * Create the delegate and configure the {@link org.mortbay.jetty.servlet.Context} of Jetty that is the real @@ -68,9 +76,7 @@ */ public JettyServletDelegate(DelegateServletContext context, Prim owner) throws SmartFrogException, RemoteException { - this.context = context; - this.owner = owner; - log = LogFactory.getOwnerLog(owner); + super(owner, context); bind(owner, context); } @@ -83,21 +89,10 @@ * @throws RemoteException network problems */ private void bind(Prim prim, DelegateServletContext ctx) throws RemoteException, SmartFrogException { - assert prim != null : "no prim parameter"; - assert ctx != null : "no DelegateServletContext parameter"; - name = prim.sfResolve(nameRef, name, true); + Context servletContext = resolveJettyServletContext(ctx); pathSpec = prim.sfResolve(pathSpecRef, pathSpec, true); - className = prim.sfResolve(classNameRef, className, true); - Context servletContext; - servletContext = ctx.getServletContext(); - if (servletContext == null) { - throw new SmartFrogDeploymentException("No servlet context is currently live"); - } - holder = new ServletHolder(); - holder.setName(name); - holder.setClassName(className); //get and apply init order int initOrder = prim.sfResolve(ATTR_INIT_ORDER, @@ -109,19 +104,7 @@ } //apply initialisation params from the list - Vector<Vector<String>> paramTuples = ListUtils.resolveStringTupleList(prim, initParamsRef, true); - for (Vector<String> tuple : paramTuples) { - holder.setInitParameter(tuple.firstElement(), tuple.get(1)); - } - //apply initialisation params from the context - ComponentDescription optionsCD = prim.sfResolve(initOptionsRef, (ComponentDescription) null, true); - org.smartfrog.sfcore.common.Context optionsContext = optionsCD.sfContext(); - Iterator iterator = optionsContext.sfAttributes(); - while (iterator.hasNext()) { - Object key = iterator.next(); - Object value = optionsContext.get(key); - holder.setInitParameter(key.toString(), value.toString()); - } + bindAndInitHolder(holder); //update our path attribute @@ -129,7 +112,7 @@ absolutePath = WebApplicationHelper.deregexpPath(JettyHelper.concatPaths( ancestorPath, pathSpec)); - prim.sfReplaceAttribute(ApplicationServerContext.ATTR_ABSOLUTE_PATH, + owner.sfReplaceAttribute(ApplicationServerContext.ATTR_ABSOLUTE_PATH, absolutePath); //add the servlet @@ -182,59 +165,12 @@ */ @Override public String toString() { - return "name=" + name - + "; className=" + className + return super.toString() + "; pathSpec=" + pathSpec + "; absolutePath=" + absolutePath; } /** - * noop - * - * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems - */ - @Override - public void deploy() throws SmartFrogException, RemoteException { - - } - - /** - * start the component - * - * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems - */ - @Override - public void start() throws SmartFrogException, RemoteException { - try { - log.info("Starting servlet on jetty; " - + toString()); - holder.start(); - } catch (Exception e) { - throw new SmartFrogException(e); - } - } - - /** - * this method is here for server-specific implementation classes, - * - * @throws SmartFrogException smartfrog problems - * @throws RemoteException network problems - */ - @Override - public void terminate() throws RemoteException, SmartFrogException { - try { - if (holder != null) { - holder.stop(); - holder = null; - } - } catch (Exception e) { - throw SmartFrogException.forward(e); - } - } - - /** * liveness check * * @throws SmartFrogLivenessException smartfrog problems @@ -242,10 +178,11 @@ */ @Override public void ping() throws SmartFrogLivenessException, RemoteException { - if (holder == null || !holder.isStarted()) { + if (isJettyHolderStarted()) { throw new SmartFrogLivenessException("Servlet " + name + " is not running under" + getAbsolutePath()); } } + } Copied: trunk/core/components/www/src/org/smartfrog/services/www/FilterComponent.java (from rev 8274, trunk/core/components/www/src/org/smartfrog/services/www/ServletComponent.java) =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/FilterComponent.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/FilterComponent.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -0,0 +1,59 @@ +/** (C) Copyright 2005 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.services.www; + + +/** + * Interface defining a filter + */ + + +public interface FilterComponent extends ServletContextComponent { + /** + * {@value} + */ + String ATTR_NAME = ServletComponent.ATTR_NAME; + + /** + * {@value} + */ + String ATTR_CLASSNAME = ServletComponent.ATTR_CLASSNAME; + + String ATTR_PATTERN = "pattern"; + + /** + * {@value } + */ + String ATTR_DISPATCH_REQUEST = "dispatchRequest"; + /** + * {@value } + */ + String ATTR_DISPATCH_FORWARD = "dispatchForward"; + /** + * {@value } + */ + String ATTR_DISPATCH_INCLUDE = "dispatchInclude"; + /** + * {@value } + */ + String ATTR_DISPATCH_ERROR = "dispatchError"; + + +} \ No newline at end of file Modified: trunk/core/components/www/src/org/smartfrog/services/www/ServletContextIntf.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/ServletContextIntf.java 2010-05-25 11:35:26 UTC (rev 8292) +++ trunk/core/components/www/src/org/smartfrog/services/www/ServletContextIntf.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -83,5 +83,16 @@ */ public ServletContextComponentDelegate addServlet(ServletComponent servletDeclaration) throws RemoteException, SmartFrogException; + /** + * add a filter + * + * @param servletDeclaration component declaring the servlet + * @return the delegate that implements the servlet binding + * @throws SmartFrogException for deployment problems + * @throws RemoteException for RMI/Networking problems + */ + public ServletContextComponentDelegate addFilter(FilterComponent declaration) + throws RemoteException, SmartFrogException; + } Added: trunk/core/components/www/src/org/smartfrog/services/www/context/DelegatedServletComponentImpl.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/context/DelegatedServletComponentImpl.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/context/DelegatedServletComponentImpl.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -0,0 +1,93 @@ +package org.smartfrog.services.www.context; + +import org.smartfrog.services.os.java.LoadClassImpl; +import org.smartfrog.services.www.ServletComponent; +import org.smartfrog.services.www.ServletContextComponentDelegate; +import org.smartfrog.services.www.ServletContextIntf; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.common.SmartFrogLivenessException; +import org.smartfrog.sfcore.prim.TerminationRecord; +import org.smartfrog.sfcore.reference.Reference; + +import java.rmi.RemoteException; + +/** + * Created 25-May-2010 12:43:57 + */ + +public abstract class DelegatedServletComponentImpl extends ServletContextComponentImpl { + /** + * our delegate + */ + private ServletContextComponentDelegate delegate; + private static final Reference REF_CLASSNAME = new Reference(ServletComponent.ATTR_CLASSNAME); + + + protected DelegatedServletComponentImpl() throws RemoteException { + } + + /** + * Can be called to start components. Subclasses should override to provide + * functionality Do not block in this call, but spawn off any main loops! + * + * @throws SmartFrogException failure while starting + * @throws RemoteException In case of network/rmi error + */ + public synchronized void sfStart() + throws SmartFrogException, RemoteException { + super.sfStart(); + //here we are bound to our context + ServletContextIntf servletContext = getServletContext(); + + //validate our classpath + String classname=sfResolve(REF_CLASSNAME,"",true); + Class clazz = LoadClassImpl.loadClass(this, classname); + Object instance = LoadClassImpl.createInstance(clazz); + + //create and bind the delegate + delegate = addComponent(servletContext); + delegate.start(); + } + + protected abstract ServletContextComponentDelegate addComponent(ServletContextIntf servletContext) + throws RemoteException, SmartFrogException; + + /** + * Liveness call in to check if this component is still alive. + * + * @param source source of call + * + * @throws SmartFrogLivenessException component is terminated + * @throws RemoteException for consistency with the {@link + * org.smartfrog.sfcore.prim.Liveness} interface + */ + public void sfPing(Object source) + throws SmartFrogLivenessException, RemoteException { + super.sfPing(source); + if (delegate == null) { + throw new SmartFrogLivenessException("Not live"); + } else { + delegate.ping(); + } + } + + /** + * Provides hook for subclasses to implement useful termination behavior. + * Deregisters component from local process compound (if ever registered) + * + * @param status termination status + */ + public synchronized void sfTerminateWith(TerminationRecord status) { + super.sfTerminateWith(status); + if (delegate != null) { + try { + delegate.terminate(); + } catch (RemoteException ignored) { + //swallowed + + } catch (SmartFrogException ignored) { + //swallowed + } + } + } +} Copied: trunk/core/components/www/src/org/smartfrog/services/www/context/FilterComponentImpl.java (from rev 8274, trunk/core/components/www/src/org/smartfrog/services/www/context/ServletComponentImpl.java) =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/context/FilterComponentImpl.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/context/FilterComponentImpl.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -0,0 +1,50 @@ +/** (C) Copyright 2005 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.services.www.context; + +import org.smartfrog.services.www.FilterComponent; +import org.smartfrog.services.www.ServletContextComponentDelegate; +import org.smartfrog.services.www.ServletContextIntf; +import org.smartfrog.sfcore.common.SmartFrogException; + +import java.rmi.RemoteException; + +/** + * This component adds a servlet declaration to the servlet context, + * removing it when terminated. + */ +public class FilterComponentImpl extends DelegatedServletComponentImpl + implements FilterComponent { + + /** + * constructor + * @throws RemoteException from the superclass + */ + public FilterComponentImpl() throws RemoteException { + } + + + @Override + protected ServletContextComponentDelegate addComponent(ServletContextIntf servletContext) + throws RemoteException, SmartFrogException { + return servletContext.addFilter(this); + } + +} \ No newline at end of file Modified: trunk/core/components/www/src/org/smartfrog/services/www/context/ServletComponentImpl.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/context/ServletComponentImpl.java 2010-05-25 11:35:26 UTC (rev 8292) +++ trunk/core/components/www/src/org/smartfrog/services/www/context/ServletComponentImpl.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -19,14 +19,10 @@ */ package org.smartfrog.services.www.context; -import org.smartfrog.services.os.java.LoadClassImpl; import org.smartfrog.services.www.ServletComponent; import org.smartfrog.services.www.ServletContextComponentDelegate; import org.smartfrog.services.www.ServletContextIntf; import org.smartfrog.sfcore.common.SmartFrogException; -import org.smartfrog.sfcore.common.SmartFrogLivenessException; -import org.smartfrog.sfcore.prim.TerminationRecord; -import org.smartfrog.sfcore.reference.Reference; import java.rmi.RemoteException; @@ -34,16 +30,10 @@ * This component adds a servlet declaration to the servlet context, * removing it when terminated. */ -public class ServletComponentImpl extends ServletContextComponentImpl +public class ServletComponentImpl extends DelegatedServletComponentImpl implements ServletComponent { /** - * our delegate - */ - private ServletContextComponentDelegate delegate; - private static final Reference REF_CLASSNAME = new Reference(ATTR_CLASSNAME); - - /** * constructor * @throws RemoteException from the superclass */ @@ -51,80 +41,10 @@ } - /** - * Called after instantiation for deployment purposes. Heart monitor is - * started and if there is a parent the deployed component is added to the - * heartbeat. Subclasses can override to provide additional deployment - * behavior. - * - * @throws SmartFrogException error while deploying - * @throws RemoteException In case of network/rmi error - */ - public synchronized void sfDeploy() - throws SmartFrogException, RemoteException { - super.sfDeploy(); - + @Override + protected ServletContextComponentDelegate addComponent(ServletContextIntf servletContext) + throws RemoteException, SmartFrogException { + return servletContext.addServlet(this); } - /** - * Can be called to start components. Subclasses should override to provide - * functionality Do not block in this call, but spawn off any main loops! - * - * @throws SmartFrogException failure while starting - * @throws RemoteException In case of network/rmi error - */ - public synchronized void sfStart() - throws SmartFrogException, RemoteException { - super.sfStart(); - //here we are bound to our context - ServletContextIntf servletContext = getServletContext(); - - //validate our classpath - String classname=sfResolve(REF_CLASSNAME,"",true); - Class clazz = LoadClassImpl.loadClass(this, classname); - Object instance = LoadClassImpl.createInstance(clazz); - - //create and bind the delegate - delegate = servletContext.addServlet(this); - delegate.start(); - } - - /** - * Liveness call in to check if this component is still alive. - * - * @param source source of call - * - * @throws SmartFrogLivenessException component is terminated - * @throws RemoteException for consistency with the {@link - * org.smartfrog.sfcore.prim.Liveness} interface - */ - public void sfPing(Object source) - throws SmartFrogLivenessException, RemoteException { - super.sfPing(source); - if (delegate == null) { - throw new SmartFrogLivenessException("Not live"); - } else { - delegate.ping(); - } - } - - /** - * Provides hook for subclasses to implement useful termination behavior. - * Deregisters component from local process compound (if ever registered) - * - * @param status termination status - */ - public synchronized void sfTerminateWith(TerminationRecord status) { - super.sfTerminateWith(status); - if (delegate != null) { - try { - delegate.terminate(); - } catch (RemoteException ignored) { - //swallowed - - } catch (SmartFrogException ignored) { - //swallowed - } - } - } } Modified: trunk/core/components/www/src/org/smartfrog/services/www/context/ServletContextImpl.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/context/ServletContextImpl.java 2010-05-25 11:35:26 UTC (rev 8292) +++ trunk/core/components/www/src/org/smartfrog/services/www/context/ServletContextImpl.java 2010-05-25 12:56:39 UTC (rev 8293) @@ -20,6 +20,7 @@ package org.smartfrog.services.www.context; import org.smartfrog.services.www.ApplicationServerContext; +import org.smartfrog.services.www.FilterComponent; import org.smartfrog.services.www.ServletComponent; import org.smartfrog.services.www.ServletContextComponentDelegate; import org.smartfrog.services.www.ServletContextIntf; @@ -99,6 +100,15 @@ } /** + * {@inheritDoc} + */ + @Override + public ServletContextComponentDelegate addFilter(FilterComponent declaration) + throws RemoteException, SmartFrogException { + return getContext().addFilter(declaration); + } + + /** * Check the target file exists * * @throws SmartFrogException error while validating Added: trunk/core/components/www/src/org/smartfrog/services/www/filters/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/filters/components.sf (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/filters/components.sf 2010-05-25 12:56:39 UTC (rev 8293) @@ -0,0 +1,8 @@ + +#include "/org/smartfrog/services/filesystem/components.sf" +#include "/org/smartfrog/services/assertions/components.sf" +#include "/org/smartfrog/services/os/java/components.sf" + +sfConfig extends Compound { + +} Modified: trunk/core/components/www/src/org/smartfrog/services/www/webapplication.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/webapplication.sf 2010-05-25 11:35:26 UTC (rev 8292) +++ trunk/core/components/www/src/org/smartfrog/services/www/webapplication.sf 2010-05-25 12:56:39 UTC (rev 8293) @@ -187,20 +187,79 @@ /** * declare an abstract servlet */ -Servlet extends ServletContextComponent { +ServletContextComponentWithInitParams extends ServletContextComponent { + initParams []; + //initialisation options name -> value mappings + initOptions extends DATA {} +} + +/** + * declare a servlet + */ +Servlet extends ServletContextComponentWithInitParams { servletSchema extends ServletSchema; //implementation class sfClass "org.smartfrog.services.www.context.ServletComponentImpl"; //order of initialisation; -1 means on demand. initOrder -1; - //initial parameters - initParams []; - //initialisation options name -> value mappings - initOptions extends DATA {} } +/** + * this servlet declaration defines + * the servlet information + */ +FilterSchema extends Schema { + //name + name extends String; + //path + pattern extends String; + //the class that implements the servlet + className extends String; + //initialisation parameters as a list of [name,value] pairs + initParams extends OptionalVector; +} + /** + * declare a filter with default dispatch options set to "no dispatch" + */ +Filter extends ServletContextComponentWithInitParams { + filterSchema extends FilterSchema; + //implementation class + sfClass "org.smartfrog.services.www.context.FilterComponentImpl"; + PATTERN_EVERYTHING "/*"; + pattern PATTERN_EVERYTHING; + dispatchRequest false; + dispatchForward false; + dispatchInclude false; + dispatchError false; +} + +RequestFilter extends Filter { + dispatchRequest true; +} + +ForwardFilter extends Filter { + dispatchForward true; +} + +IncludeFilter extends Filter { + dispatchInclude true; +} + +ErrorFilter extends Filter { + dispatchError true; +} + +AllFilter extends Filter { + dispatchRequest true; + dispatchForward true; + dispatchInclude true; + dispatchError true; +} + + +/** A mime is a tuple of name,value. that is bound to a servlet context It does not get cleaned up after; you need to terminate the context */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-05-25 16:12:40
|
Revision: 8295 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8295&view=rev Author: steve_l Date: 2010-05-25 16:12:34 +0000 (Tue, 25 May 2010) Log Message: ----------- SFOS-1486 filters are added and some basic tests show that they are approximately working. Approximately: more use needed. Modified Paths: -------------- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateWebApplicationContext.java trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyFilterDelegate.java trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/components.sf trunk/core/components/www/src/org/smartfrog/services/www/FilterComponent.java trunk/core/components/www/src/org/smartfrog/services/www/HttpAttributes.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java trunk/core/components/www/src/org/smartfrog/services/www/context/DelegatedServletComponentImpl.java trunk/core/components/www/src/org/smartfrog/services/www/filters/components.sf Added Paths: ----------- trunk/core/components/jetty/src/org/smartfrog/services/jetty/filters/ trunk/core/components/www/src/org/smartfrog/services/www/HttpHeaders.java trunk/core/components/www/src/org/smartfrog/services/www/filters/BaseFilter.java trunk/core/components/www/src/org/smartfrog/services/www/filters/NoCacheFilter.java trunk/core/components/www/src/org/smartfrog/services/www/filters/RequestCounterFilter.java Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateWebApplicationContext.java =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateWebApplicationContext.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/DelegateWebApplicationContext.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -20,8 +20,6 @@ package org.smartfrog.services.jetty.contexts.delegates; -import org.mortbay.jetty.servlet.AbstractSessionManager; -import org.mortbay.jetty.servlet.ServletHandler; import org.mortbay.jetty.webapp.WebAppContext; import org.smartfrog.services.filesystem.FileSystem; import org.smartfrog.services.jetty.JettyImpl; Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyFilterDelegate.java =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyFilterDelegate.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/contexts/delegates/JettyFilterDelegate.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -1,22 +1,14 @@ package org.smartfrog.services.jetty.contexts.delegates; +import org.mortbay.jetty.Handler; import org.mortbay.jetty.servlet.Context; import org.mortbay.jetty.servlet.FilterHolder; -import org.mortbay.jetty.servlet.ServletHandler; -import org.mortbay.jetty.servlet.ServletHolder; -import org.mortbay.jetty.servlet.ServletMapping; -import org.smartfrog.services.jetty.JettyHelper; -import org.smartfrog.services.www.ApplicationServerContext; import org.smartfrog.services.www.FilterComponent; -import org.smartfrog.services.www.WebApplicationHelper; -import org.smartfrog.sfcore.common.SmartFrogDeploymentException; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogLivenessException; import org.smartfrog.sfcore.prim.Prim; -import org.smartfrog.sfcore.utils.ListUtils; import java.rmi.RemoteException; -import java.util.Vector; /** * Created 24-May-2010 17:59:25 @@ -25,15 +17,8 @@ public class JettyFilterDelegate extends AbstractJettyServletContextDelegate implements FilterComponent { - /** - * default inititialisation order {@value} - */ + private String pattern; - private String pathSpec = null; - - private FilterHolder holder = null; - private String absolutePath; - /** * Create the delegate and configure the {@link org.mortbay.jetty.servlet.Context} of Jetty that is the real * context @@ -59,23 +44,36 @@ */ private void bind(Prim prim, DelegateServletContext ctx) throws RemoteException, SmartFrogException { Context servletContext = resolveJettyServletContext(ctx); - pathSpec = prim.sfResolve(pathSpecRef, pathSpec, true); - holder = new FilterHolder(); + FilterHolder holder = new FilterHolder(); bindAndInitHolder(holder); - //update our path attribute - String ancestorPath = ctx.getAbsolutePath(); - absolutePath = WebApplicationHelper.deregexpPath(JettyHelper.concatPaths( - ancestorPath, - pathSpec)); - prim.sfReplaceAttribute(ApplicationServerContext.ATTR_ABSOLUTE_PATH, - absolutePath); - int dispatches = 0; + pattern = prim.sfResolve(ATTR_PATTERN, pattern, true); + + //build the dispatch mask + boolean dispatchRequest = prim.sfResolve(ATTR_DISPATCH_REQUEST, true, true); + boolean dispatchForward = prim.sfResolve(ATTR_DISPATCH_FORWARD, true, true); + boolean dispatchInclude = prim.sfResolve(ATTR_DISPATCH_INCLUDE, true, true); + boolean dispatchError = prim.sfResolve(ATTR_DISPATCH_ERROR, true, true); + int dispatches = Handler.DEFAULT; + + if (dispatchRequest) { + dispatches |= Handler.REQUEST; + } + if (dispatchForward) { + dispatches |= Handler.FORWARD; + } + if (dispatchInclude) { + dispatches |= Handler.INCLUDE; + } + if (dispatchError) { + dispatches |= Handler.ERROR; + } + //add the filter - servletContext.addFilter(holder, pathSpec, dispatches); + servletContext.addFilter(holder, pattern, dispatches); /* ServletHandler servletHandler = servletContext.getServletHandler(); ServletHolder resolvedHolder = servletHandler.getServlet(name); @@ -100,9 +98,6 @@ } - public String getAbsolutePath() { - return absolutePath; - } /** * Returns a string representation of the object. @@ -111,10 +106,8 @@ */ @Override public String toString() { - return "name=" + name - + "; className=" + className - + "; pathSpec=" + pathSpec - + "; absolutePath=" + absolutePath; + return super.toString() + + "; pattern=" + pattern; } /** @@ -135,7 +128,7 @@ if (isJettyHolderStarted()) { throw new SmartFrogLivenessException("Filter " + name + - " is not running under" + getAbsolutePath()); + " is not running under" + pattern); } } } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf 2010-05-25 16:12:34 UTC (rev 8295) @@ -20,6 +20,7 @@ #include "/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf" #include "/org/smartfrog/services/www/bulkio/server/components.sf" +#include "/org/smartfrog/services/www/filters/components.sf" BulkIOJetty extends LocalJettyServer { @@ -33,6 +34,14 @@ context LAZY PARENT:context; } + noCaching extends NoCacheFilter { + context LAZY PARENT:context; + } + + requestCounter extends RequestCounterFilter { + context LAZY PARENT:context; + } + } } Modified: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/components.sf =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/components.sf 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/components.sf 2010-05-25 16:12:34 UTC (rev 8295) @@ -28,8 +28,8 @@ #include "/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf" #include "/org/smartfrog/services/jetty/examples/war/waitforpages.sf" #include "/org/smartfrog/services/www/jetty/test/system/htmlpage.sf" +#include "/org/smartfrog/services/www/bulkio/client/components.sf" #include "/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf" -#include "/org/smartfrog/services/www/bulkio/client/components.sf" /* Modified: trunk/core/components/www/src/org/smartfrog/services/www/FilterComponent.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/FilterComponent.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/www/src/org/smartfrog/services/www/FilterComponent.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -35,9 +35,13 @@ * {@value} */ String ATTR_CLASSNAME = ServletComponent.ATTR_CLASSNAME; - + + /** + * {@value } + */ String ATTR_PATTERN = "pattern"; + String ATTR_dispatchType = "dispatchType"; /** * {@value } */ Modified: trunk/core/components/www/src/org/smartfrog/services/www/HttpAttributes.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/HttpAttributes.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/www/src/org/smartfrog/services/www/HttpAttributes.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -119,8 +119,4 @@ String METHOD_HEAD = "HEAD"; - /** {@value} */ - String HEADER_CONTENT_LENGTH = "Content-Length"; - /** {@value} */ - String HEADER_CONTENT_TYPE = "Content-TYPE"; } Added: trunk/core/components/www/src/org/smartfrog/services/www/HttpHeaders.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/HttpHeaders.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/HttpHeaders.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -0,0 +1,55 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +package org.smartfrog.services.www; + +/** + * Any useful Http Headers + */ + + +public interface HttpHeaders { + /** {@value} */ + String CONTENT_LENGTH = "Content-Length"; + /** {@value} */ + String CONTENT_TYPE = "Content-Type"; + /** + */ + String EXPIRES = "expires"; + + String CACHE_CONTROL = "Cache-Control"; + + String NO_CACHE = "no-cache"; + String FORMAT_BINARY = "application/binary"; + String TEXT_HTML = "text/html"; + String TEXT_PLAIN = "text/plain"; +} Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/client/SunJavaBulkIOClient.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.smartfrog.services.www.HttpAttributes; +import org.smartfrog.services.www.HttpHeaders; import org.smartfrog.services.www.LivenessPageChecker; import org.smartfrog.services.www.bulkio.IoAttributes; import org.smartfrog.services.www.bulkio.server.AbstractBulkioServlet; @@ -56,7 +57,7 @@ getLog().info("Uploading " + ioSize + " bytes to " + targetUrl); HttpURLConnection connection = openConnection(); connection.setRequestMethod(method); - connection.setRequestProperty(HttpAttributes.HEADER_CONTENT_LENGTH, Long.toString(ioSize)); + connection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Long.toString(ioSize)); connection.setDoOutput(true); maybeSetChunking(connection); connection.connect(); @@ -124,13 +125,13 @@ connection.setDoOutput(false); connection.connect(); checkStatusCode(target, connection, HttpURLConnection.HTTP_OK); - String contentLengthHeader = connection.getHeaderField(HttpAttributes.HEADER_CONTENT_LENGTH); + String contentLengthHeader = connection.getHeaderField(HttpHeaders.CONTENT_LENGTH); long contentLength = Long.parseLong(contentLengthHeader); if (contentLength != ioSize) { throw new IOException("Wrong content length returned from " + target + " - expected " + ioSize + " but got " + contentLength); } - String formatHeader = connection.getHeaderField(HttpAttributes.HEADER_CONTENT_TYPE); + String formatHeader = connection.getHeaderField(HttpHeaders.CONTENT_TYPE); if (!format.equals(formatHeader)) { throw new IOException("Wrong content type returned from " + target + " - expected " + format + " but got " + formatHeader); Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/AbstractBulkioServlet.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -21,7 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.smartfrog.services.www.HttpAttributes; +import org.smartfrog.services.www.HttpHeaders; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -36,24 +36,21 @@ * 17-May-2010 15:02:27 */ -public abstract class AbstractBulkioServlet extends HttpServlet { +public abstract class AbstractBulkioServlet extends HttpServlet implements HttpHeaders { public static final String ATTR_LIMIT = "limit"; public static final String ATTR_SIZE = "size"; public static final String ATTR_FORMAT = "format"; - public static final String FORMAT_BINARY = "application/binary"; protected static final Log log = LogFactory.getLog(AbstractBulkioServlet.class); - protected static final String TEXT_HTML = "text/html"; - protected static final String TEXT_PLAIN = "text/plain"; protected long getLimit() { return Long.valueOf(getInitParameter(ATTR_LIMIT)); } protected void disableCaching(HttpServletResponse response) { - response.addHeader("Cache-Control","none"); - response.addHeader("Expires", "Thu, 01 Dec 1994 16:00:00 GMT"); + response.addHeader(CACHE_CONTROL, NO_CACHE); + response.addHeader(EXPIRES, "Thu, 01 Dec 1994 16:00:00 GMT"); } public Log getLog() { @@ -72,9 +69,9 @@ } protected long getContentLength(HttpServletRequest request) throws ServletException { - String contentL = request.getHeader(HttpAttributes.HEADER_CONTENT_LENGTH); + String contentL = request.getHeader(CONTENT_LENGTH); return contentL == null ? -1 : - parseToLong(" the header " + HttpAttributes.HEADER_CONTENT_LENGTH, contentL); + parseToLong(" the header " + CONTENT_LENGTH, contentL); } /** @@ -100,7 +97,7 @@ } protected void returnPlainText(HttpServletResponse response, String message) throws IOException { - response.setContentType(TEXT_PLAIN); + response.setContentType(HttpHeaders.TEXT_PLAIN); PrintWriter writer = response.getWriter(); try { writer.append(message); Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkDownloadServlet.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -19,7 +19,7 @@ */ package org.smartfrog.services.www.bulkio.server; -import org.smartfrog.services.www.HttpAttributes; +import org.smartfrog.services.www.HttpHeaders; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; @@ -34,12 +34,23 @@ public class BulkDownloadServlet extends AbstractBulkioServlet { @Override + protected void doHead(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + long size = getSize(request); + getAndSetFormat(request, response); + setXContentLength(response, size); + } + + private void getAndSetFormat(HttpServletRequest request, HttpServletResponse response) { + String format = getRequestedFormat(request); + response.setContentType(format); + } + + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - disableCaching(response); long size = getSize(request); if (size == -1) { - //response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No " + ATTR_SIZE + " parameter"); response.setContentType(TEXT_HTML); ServletOutputStream out = null; try { @@ -49,10 +60,10 @@ out.println("<body><h1>Download</h1>"); out.println(" <form method='get'><h2>Download a file</h2>"); out.println(" <p> Size:"); - out.println(" <input type='text'name='"+ ATTR_SIZE+"'/>"); + out.println(" <input type='text'name='" + ATTR_SIZE + "'/>"); out.println(" <p>"); out.println(" <p> Format:"); - out.println(" <input type='text'name='"+ ATTR_FORMAT+"' value='text/plain'/>"); + out.println(" <input type='text'name='" + ATTR_FORMAT + "' value='text/plain'/>"); out.println(" <p>"); out.println(" <button type='submit'>submit</button>"); out.println(" <p>"); @@ -63,13 +74,9 @@ closeQuietly(out); } } else { - String format = request.getParameter(ATTR_FORMAT); - if (format == null) { - format = TEXT_PLAIN; - } - response.setContentType(format); - response.setHeader(HttpAttributes.HEADER_CONTENT_LENGTH, Long.toString(size)); - response.setHeader("X-" + HttpAttributes.HEADER_CONTENT_LENGTH, Long.toString(size)); + getAndSetFormat(request, response); + response.setHeader(CONTENT_LENGTH, Long.toString(size)); + setXContentLength(response, size); ServletOutputStream outputStream = null; try { outputStream = response.getOutputStream(); @@ -83,4 +90,16 @@ } + private void setXContentLength(HttpServletResponse response, long size) { + response.setHeader("X-" + CONTENT_LENGTH, Long.toString(size)); + } + + private String getRequestedFormat(HttpServletRequest request) { + String format = request.getParameter(ATTR_FORMAT); + if (format == null) { + format = TEXT_PLAIN; + } + return format; + } + } \ No newline at end of file Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/BulkUploadServlet.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -19,6 +19,7 @@ */ package org.smartfrog.services.www.bulkio.server; +import org.smartfrog.services.www.HttpHeaders; import org.smartfrog.services.www.bulkio.IoAttributes; import javax.servlet.ServletException; @@ -82,8 +83,8 @@ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - disableCaching(response); - response.setContentType(TEXT_HTML); + // disableCaching(response); + response.setContentType(HttpHeaders.TEXT_HTML); ServletOutputStream out = null; try { out = response.getOutputStream(); Modified: trunk/core/components/www/src/org/smartfrog/services/www/context/DelegatedServletComponentImpl.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/context/DelegatedServletComponentImpl.java 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/www/src/org/smartfrog/services/www/context/DelegatedServletComponentImpl.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -42,7 +42,12 @@ //validate our classpath String classname=sfResolve(REF_CLASSNAME,"",true); Class clazz = LoadClassImpl.loadClass(this, classname); + //create an instance which is then debugged + Object instance = LoadClassImpl.createInstance(clazz); + if(sfLog().isDebugEnabled()) { + sfLog().debug("Created delegate instance " + instance); + } //create and bind the delegate delegate = addComponent(servletContext); @@ -65,7 +70,7 @@ throws SmartFrogLivenessException, RemoteException { super.sfPing(source); if (delegate == null) { - throw new SmartFrogLivenessException("Not live"); + throw new SmartFrogLivenessException("Not live", this); } else { delegate.ping(); } Added: trunk/core/components/www/src/org/smartfrog/services/www/filters/BaseFilter.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/filters/BaseFilter.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/filters/BaseFilter.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -0,0 +1,104 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ +package org.smartfrog.services.www.filters; + +import org.smartfrog.services.www.HttpHeaders; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Base filter class, saves the configuration and has a default method that just dispatches everything down + */ + +public class BaseFilter implements Filter, HttpHeaders { + + protected FilterConfig config; + + /** + * {@inheritDoc} + */ + @Override + public void init(FilterConfig filterConfig) throws ServletException { + config = filterConfig; + } + + /** + * {@inheritDoc} + */ + @Override + public void destroy() { + config = null; + } + + /** + * {@inheritDoc} + */ + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + + try { + doFilter((HttpServletRequest) request, (HttpServletResponse) response, chain); + } catch (ClassCastException e) { + throw new ServletException("Bad incoming request type: " + request + " or " + response, e); + } + dispatchRequest(chain, request, response); + } + + /** + * This is the useful filter, the one which works with the HttpServlet types parameters + * + * @param request incoming request + * @param response outgoing response + * @param chain filter chain + * @throws IOException IO problems + * @throws ServletException any servlet problem + */ + public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) + throws IOException, ServletException { + dispatchRequest(chain, request, response); + } + + + protected void dispatchRequest(FilterChain chain, ServletRequest request, ServletResponse response) + throws IOException, ServletException { + chain.doFilter(request, response); + } +} Added: trunk/core/components/www/src/org/smartfrog/services/www/filters/NoCacheFilter.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/filters/NoCacheFilter.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/filters/NoCacheFilter.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -0,0 +1,58 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ +package org.smartfrog.services.www.filters; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Created 25-May-2010 15:51:05 + */ + +public class NoCacheFilter extends BaseFilter { + public static final String A_DATE_IN_THE_PAST = "Thu, 01 Dec 1994 16:00:00 GMT"; + + /** + * {@inheritDoc} + */ + + @Override + public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) + throws IOException, ServletException { + response.addHeader(CACHE_CONTROL, NO_CACHE); + response.addHeader(EXPIRES, A_DATE_IN_THE_PAST); + super.doFilter(request, response, chain); + } +} Added: trunk/core/components/www/src/org/smartfrog/services/www/filters/RequestCounterFilter.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/filters/RequestCounterFilter.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/filters/RequestCounterFilter.java 2010-05-25 16:12:34 UTC (rev 8295) @@ -0,0 +1,81 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + + +package org.smartfrog.services.www.filters; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * count the number of requests; there's a shared counter and a per-instance counter + */ + +public class RequestCounterFilter extends BaseFilter { + + private static AtomicLong sharedCounter = new AtomicLong(); + private AtomicLong counter = new AtomicLong(); + + private long inc() { + sharedCounter.incrementAndGet(); + return counter.incrementAndGet(); + } + + public long getCounterValue() { + return counter.longValue(); + } + + public static long getSharedCounterValue() { + return sharedCounter.longValue(); + } + + public void reset() { + counter = new AtomicLong(); + } + + public static void resetSharedCounter() { + sharedCounter = new AtomicLong(); + } + + @Override + public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) + throws IOException, ServletException { + + response.addHeader("X-RequestCount", Long.toString(inc())); + super.doFilter(request, response, chain); + } +} Modified: trunk/core/components/www/src/org/smartfrog/services/www/filters/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/filters/components.sf 2010-05-25 13:13:35 UTC (rev 8294) +++ trunk/core/components/www/src/org/smartfrog/services/www/filters/components.sf 2010-05-25 16:12:34 UTC (rev 8295) @@ -1,8 +1,53 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP -#include "/org/smartfrog/services/filesystem/components.sf" -#include "/org/smartfrog/services/assertions/components.sf" -#include "/org/smartfrog/services/os/java/components.sf" +Disclaimer of Warranty -sfConfig extends Compound { +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +/* +This defines some basic filters +*/ + +BaseFilter extends Filter { + name "BaseFilter"; + description "A filter that does nothing; can be a base class for useful filters"; + className "org.smartfrog.services.www.filters.BaseFilter"; } + +NoCacheFilter extends Filter { + name "NoCacheFilter"; + description "set the cache-control header to no-cache, and so disable any caching"; + className "org.smartfrog.services.www.filters.NoCacheFilter"; +} + +RequestCounterFilter extends Filter { + name "RequestCounterFilter"; + description "Filter that counts the number of requests in and out"; + className "org.smartfrog.services.www.filters.RequestCounterFilter"; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-05-26 15:03:59
|
Revision: 8299 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8299&view=rev Author: steve_l Date: 2010-05-26 15:03:52 +0000 (Wed, 26 May 2010) Log Message: ----------- SFOS-1130 jersey application and tests. tests that fail; disabled in hudson Modified Paths: -------------- trunk/core/components/jersey/build.xml trunk/core/components/jersey/src/org/smartfrog/services/www/servers/java6/Java6HttpServerImpl.java trunk/core/components/jersey/src/org/smartfrog/services/www/servers/java6/components.sf trunk/core/components/restapi/src/org/smartfrog/services/restapi/jersey/components.sf trunk/core/components/restapi/src/org/smartfrog/services/restapi/resources/ComponentState.java Added Paths: ----------- trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/ trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsApplication.java trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsLocalServices.java trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsServices.java trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsServicesImpl.java trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/components.sf trunk/core/components/jersey/test/org/ trunk/core/components/jersey/test/org/smartfrog/ trunk/core/components/jersey/test/org/smartfrog/services/ trunk/core/components/jersey/test/org/smartfrog/services/www/ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/JerseyApplicationTest.java trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/components.sf trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/jerseyapplicationtest.sf trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/AbstractJaxRsResource.java trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/EchoResource.java trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/ErrorResource.java trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/components.sf trunk/core/components/restapi/src/org/smartfrog/services/restapi/bulkio/ trunk/core/components/restapi/src/org/smartfrog/services/restapi/bulkio/BulkIoResource.java Removed Paths: ------------- trunk/core/components/restapi/src/org/smartfrog/services/www/ Modified: trunk/core/components/jersey/build.xml =================================================================== --- trunk/core/components/jersey/build.xml 2010-05-26 10:32:07 UTC (rev 8298) +++ trunk/core/components/jersey/build.xml 2010-05-26 15:03:52 UTC (rev 8299) @@ -34,7 +34,7 @@ <property file="build.properties" /> <property name="root.dir" location="../../" /> <property name="ivy.enabled" value="true"/> - <property name="system.tests" value="true" /> + <!--<property name="system.tests" value="true" /> --> <echo message="==================================================================="/> <echo message="= ${ant.project.name}"/> @@ -43,30 +43,4 @@ <import file="../../common.xml"/> - <target name="ready-to-test" depends="common.ready-to-test,testwar"> - <property name="jetty.component.dir" location="../jetty" /> - <property name="test.jetty.home" - location="${jetty.component.dir}/test/files/jettyhome"/> - <property name="test.demo.webapp" - location="${jetty.component.dir}/test/files/jettyhome/demo/webapps/root"/> - <echo level="verbose"> - test.jetty.home=${test.jetty.home} - test.demo.webapp=${test.demo.webapp} - test.testwar.war=${test.testwar.war} - system.tests=${system.tests} - </echo> - </target> - - <!--pick up the test war from Ivy--> - <target name="testwar" depends="ivy-retrieve"> - <property name="test.testwar.war" - location="${ivy.lib.dir}/testwar/sf-www-testwar-${smartfrog.version}.war" /> - <fail> - <condition > - <not><available file="${test.testwar.war}"/></not> - </condition> - Not found: ${test.testwar.war} - </fail> - </target> - </project> Added: trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsApplication.java =================================================================== --- trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsApplication.java (rev 0) +++ trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsApplication.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,70 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +package org.smartfrog.services.www.jaxrs; + +import org.smartfrog.sfcore.logging.Log; +import org.smartfrog.sfcore.logging.LogSF; +import org.smartfrog.sfcore.prim.Prim; + +import javax.ws.rs.core.Application; + +/** + * Created 26-May-2010 14:03:48 + */ + +public class JaxRsApplication extends Application { + + private final JaxRsServicesImpl owner; + private LogSF log; + + public JaxRsApplication(JaxRsServicesImpl owner) { + this.owner = owner; + this.log = owner.sfLog(); + } + + public JaxRsServices getServices() { + return owner; + } + + public JaxRsLocalServices getLocalServices() { + return owner; + } + + public Prim getOwner() { + return owner; + } + + public LogSF getLog() { + return log; + } +} Added: trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsLocalServices.java =================================================================== --- trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsLocalServices.java (rev 0) +++ trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsLocalServices.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,76 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +package org.smartfrog.services.www.jaxrs; + +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.ext.RuntimeDelegate; + +/** + * An interface for all JaxRS local/in-VM services. + */ + + +public interface JaxRsLocalServices { + + /** + * Get the local JAX-RS runtime + * @return a runtime found using the JAX-RS specification's algorithm. Nothing special is tried here. + * Note that a VM with javax.ws.rs.ext.RuntimeDelegate set to a classname is used if nothing is + * set in the JVM's lib/jaxrs.properties file or any classname in the resource + * META-INF/services/javax.ws.rs.ext.RuntimeDelegate. + * + * Using the JVM properties component to change the property is the recommended technique here, as it ensures + * that however JAX-RS is started, it gets the right class. + * + * @return a JAX-RS runtime + */ + RuntimeDelegate getRuntime(); + + /** + * Create a URI builder + * @return a URI builder + */ + UriBuilder createUriBuilder(); + + /** + * @param tClass a class to register + * @param <T> the class which implements an endpoint + * @return the deployed instance + * @throws IllegalArgumentException bad argument + * @throws UnsupportedOperationException an unsupported operation + */ + public <T> T createEndpoint(java.lang.Class<T> tClass) + throws IllegalArgumentException, UnsupportedOperationException; + + JaxRsApplication getApplication(); +} Added: trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsServices.java =================================================================== --- trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsServices.java (rev 0) +++ trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsServices.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,45 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +package org.smartfrog.services.www.jaxrs; + +import java.rmi.Remote; + +/** + * Created 26-May-2010 13:27:50 + */ + + +public interface JaxRsServices extends Remote { + + String ATTR_ENDPOINT_CLASSES = "endpointClasses"; +} Added: trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsServicesImpl.java =================================================================== --- trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsServicesImpl.java (rev 0) +++ trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/JaxRsServicesImpl.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,151 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +package org.smartfrog.services.www.jaxrs; + +import org.smartfrog.sfcore.common.SmartFrogDeploymentException; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.prim.PrimImpl; +import org.smartfrog.sfcore.prim.TerminationRecord; +import org.smartfrog.sfcore.security.SFClassLoader; + +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.ext.RuntimeDelegate; +import java.rmi.RemoteException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * This represents a JAX RS application + */ + +public class JaxRsServicesImpl extends PrimImpl implements JaxRsServices, JaxRsLocalServices { + + private JaxRsApplication application; + private Map<String, Object> endpoints; + public static final String ERROR_NOT_LOCAL = "The application provided is not local"; + + public JaxRsServicesImpl() throws RemoteException { + } + + /** + * {@inheritDoc} + */ + @Override + public void sfStart() throws SmartFrogException, RemoteException { + super.sfStart(); + application = new JaxRsApplication(this); + ComponentDescription classes = null; + classes = sfResolve(ATTR_ENDPOINT_CLASSES, classes, true); + endpoints = new HashMap<String, Object>(); + Iterator attrs = classes.sfAttributes(); + while (attrs.hasNext()) { + String name = attrs.next().toString(); + String classname = classes.sfResolve(name, "", true); + Class aClass = null; + try { + sfLog().info("Deploying JAX-RS endpoint " + classname); + aClass = SFClassLoader.forName(classname); + } catch (ClassNotFoundException e) { + throw new SmartFrogDeploymentException( + "Endpoint class " + name + " value \"" + classname + "\" does not load", + e, + this); + } + endpoints.put(classname, createEndpoint(aClass)); + } + + } + + /** + * {@inheritDoc} + */ + @Override + protected void sfTerminateWith(TerminationRecord status) { + super.sfTerminateWith(status); + endpoints = null; + } + + /** + * {@inheritDoc} + */ + @Override + public RuntimeDelegate getRuntime() { + return RuntimeDelegate.getInstance(); + } + + /** + * {@inheritDoc} + */ + @Override + public JaxRsApplication getApplication() { + return application; + } + + /** + * {@inheritDoc} + */ + @Override + public UriBuilder createUriBuilder() { + return getRuntime().createUriBuilder(); + } + + /** + * {@inheritDoc} + */ + @Override + public <T> T createEndpoint(java.lang.Class<T> tClass) + throws java.lang.IllegalArgumentException, java.lang.UnsupportedOperationException { + return getRuntime().createEndpoint(application, tClass); + } + + /** + * Get the local services API + * + * @param appStub the application stub + * @return the local api + * @throws RemoteException if the application is remote + */ + public static JaxRsLocalServices getLocalServices(JaxRsServices appStub) throws RemoteException { + if (appStub instanceof JaxRsLocalServices) { + return (JaxRsLocalServices) appStub; + } else { + throw new RemoteException(ERROR_NOT_LOCAL); + } + } + + public Map<String, Object> getEndpoints() { + return endpoints; + } +} Added: trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/components.sf =================================================================== --- trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/components.sf (rev 0) +++ trunk/core/components/jersey/src/org/smartfrog/services/www/jaxrs/components.sf 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,42 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +#include "/org/smartfrog/sfcore/prim/prim.sf" + +JaxRsServices extends Prim { + + sfClass "org.smartfrog.services.www.jaxrs.JaxRsServicesImpl"; + + endpointClasses extends DATA { + + } +} \ No newline at end of file Modified: trunk/core/components/jersey/src/org/smartfrog/services/www/servers/java6/Java6HttpServerImpl.java =================================================================== --- trunk/core/components/jersey/src/org/smartfrog/services/www/servers/java6/Java6HttpServerImpl.java 2010-05-26 10:32:07 UTC (rev 8298) +++ trunk/core/components/jersey/src/org/smartfrog/services/www/servers/java6/Java6HttpServerImpl.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -34,7 +34,7 @@ import com.sun.net.httpserver.HttpServer; /** - * Component that represents a Jser + * Component that represents a Java 6 server */ public class Java6HttpServerImpl extends PrimImpl { @@ -66,7 +66,8 @@ throw new SmartFrogDeploymentException("No method 'create(String)' in class " + factoryClassName, e); } try { - createMethod.invoke(null, serverURL); + Object result = createMethod.invoke(null, serverURL); + server = (HttpServer) result; } catch (InvocationTargetException e) { Throwable thrown = e; if (e.getCause() != null) { @@ -80,6 +81,10 @@ throw new SmartFrogDeploymentException("Could not start the server on " + serverURL + ": " + e, e); + } catch (ClassCastException e) { + throw new SmartFrogDeploymentException("Could not start the server on " + + serverURL + ": " + e, + e); } server.start(); } Modified: trunk/core/components/jersey/src/org/smartfrog/services/www/servers/java6/components.sf =================================================================== --- trunk/core/components/jersey/src/org/smartfrog/services/www/servers/java6/components.sf 2010-05-26 10:32:07 UTC (rev 8298) +++ trunk/core/components/jersey/src/org/smartfrog/services/www/servers/java6/components.sf 2010-05-26 15:03:52 UTC (rev 8299) @@ -18,6 +18,8 @@ */ +#include "/org/smartfrog/sfcore/prim/prim.sf" + /** * This is the minimal HTTP server that ships with Java6. * It is not a servlet engine and has minimal compatibility with the mainstream @@ -25,7 +27,7 @@ */ Java6HttpServer extends Prim { - sfClass "org.smartfrog.services.www.java6.Java6HttpServerImpl"; + sfClass "org.smartfrog.services.www.servers.java6.Java6HttpServerImpl"; LOCALHOST "localhost"; ALL_HOSTS "0.0.0.0"; host ALL_HOSTS; @@ -37,3 +39,10 @@ factoryClass TBD; } + +/** + * The jersey server has its own factory + */ +JerseyHttpServer extends Java6HttpServer { + factoryClass "com.sun.jersey.api.container.httpserver.HttpServerFactory"; +} Added: trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/JerseyApplicationTest.java =================================================================== --- trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/JerseyApplicationTest.java (rev 0) +++ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/JerseyApplicationTest.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,49 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ +package org.smartfrog.services.www.jaxrs.test; + +import org.smartfrog.test.DeployingTestBase; + +/** + * Created 26-May-2010 15:42:43 + */ + +public class JerseyApplicationTest extends DeployingTestBase { + public static final String PACKAGE = "/org/smartfrog/services/www/jaxrs/test/"; + public JerseyApplicationTest(String name) { + super(name); + } + + public void testJerseyApplication() throws Throwable { + deployExpectingSuccess(PACKAGE+ "jerseyapplicationtest.sf","jerseyapplicationtest"); + } +} Added: trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/components.sf =================================================================== --- trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/components.sf (rev 0) +++ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/components.sf 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,49 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ +#include "/org/smartfrog/services/www/components.sf" +#include "/org/smartfrog/services/www/servers/java6/components.sf" +#include "/org/smartfrog/services/www/jaxrs/test/testapp/components.sf" +#include "/org/smartfrog/services/assertions/components.sf" + +JerseyApplication extends Compound { + + jerseyServer extends JerseyHttpServer { + port 5050; + } + + jaxRsApp extends TestJaxRsApp; + +} + +JerseyApplicationTest extends ExpectDeploy { + action extends JerseyApplication; +} Added: trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/jerseyapplicationtest.sf =================================================================== --- trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/jerseyapplicationtest.sf (rev 0) +++ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/jerseyapplicationtest.sf 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,35 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ +#include "/org/smartfrog/services/www/jaxrs/test/components.sf" + + +sfConfig extends JerseyApplicationTest; Added: trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/AbstractJaxRsResource.java =================================================================== --- trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/AbstractJaxRsResource.java (rev 0) +++ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/AbstractJaxRsResource.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,22 @@ +package org.smartfrog.services.www.jaxrs.test.testapp; + +import org.smartfrog.services.www.jaxrs.JaxRsApplication; + +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Context; + +public abstract class AbstractJaxRsResource { + @Context + Application application; + + public Application getApplication() { + return application; + } + + public AbstractJaxRsResource() { + } + + protected JaxRsApplication getJaxRsApplication() { + return (JaxRsApplication) application; + } +} \ No newline at end of file Added: trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/EchoResource.java =================================================================== --- trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/EchoResource.java (rev 0) +++ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/EchoResource.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,19 @@ +package org.smartfrog.services.www.jaxrs.test.testapp; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +/** + * Created 26-May-2010 15:22:29 + */ +@Path("/echo/{message:.+}") +public class EchoResource extends AbstractJaxRsResource { + + @GET + @Produces("text/plain") + public String doGet(@PathParam("message") String message) { + return message; + } +} \ No newline at end of file Added: trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/ErrorResource.java =================================================================== --- trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/ErrorResource.java (rev 0) +++ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/ErrorResource.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,24 @@ +package org.smartfrog.services.www.jaxrs.test.testapp; + +import org.smartfrog.services.www.jaxrs.JaxRsApplication; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +/** + * Created 26-May-2010 15:22:29 + */ +@Path("/error/{code:.+}") +public class ErrorResource extends AbstractJaxRsResource { + + @GET + public Response doGet(@PathParam("code") int code) { + JaxRsApplication app = getJaxRsApplication(); + app.getLog().info("Getting error "+ code); + Response.ResponseBuilder builder = Response.status(code); + Response response = builder.build(); + return response; + } +} Added: trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/components.sf =================================================================== --- trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/components.sf (rev 0) +++ trunk/core/components/jersey/test/org/smartfrog/services/www/jaxrs/test/testapp/components.sf 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,41 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ +#include "/org/smartfrog/services/www/components.sf" +#include "/org/smartfrog/services/www/jaxrs/components.sf" + +TestJaxRsApp extends JaxRsServices { + + endpointClasses extends DATA { + error "org.smartfrog.services.www.jaxrs.test.testapp.ErrorResource"; + echo "org.smartfrog.services.www.jaxrs.test.testapp.EchoResource"; + } +} Added: trunk/core/components/restapi/src/org/smartfrog/services/restapi/bulkio/BulkIoResource.java =================================================================== --- trunk/core/components/restapi/src/org/smartfrog/services/restapi/bulkio/BulkIoResource.java (rev 0) +++ trunk/core/components/restapi/src/org/smartfrog/services/restapi/bulkio/BulkIoResource.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -0,0 +1,62 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.restapi.bulkio; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +/** + * Created 20-May-2010 17:08:30 + */ + +/** + * The size path entry controls how much you expect to put/get + */ +@Path("/bulkio/{size}") + + +/** + * + */ +public class BulkIoResource { + + public static final int BLOCK_SIZE = 1024; + /** + * There is wrongness with Java and signs of things like byte. + */ + private static byte[] block; + + static { + block = new byte[BLOCK_SIZE]; + for (int i=0; i<BLOCK_SIZE; i++) { + block[i]=(byte)(i%256); + } + } + + @GET + @Produces("application/octet-stream") + public String doGet(@PathParam("size") String size) { + + return "undefined"; + } + +} Modified: trunk/core/components/restapi/src/org/smartfrog/services/restapi/jersey/components.sf =================================================================== --- trunk/core/components/restapi/src/org/smartfrog/services/restapi/jersey/components.sf 2010-05-26 10:32:07 UTC (rev 8298) +++ trunk/core/components/restapi/src/org/smartfrog/services/restapi/jersey/components.sf 2010-05-26 15:03:52 UTC (rev 8299) @@ -19,9 +19,3 @@ */ #include "/org/smartfrog/services/www/servers/java6/components.sf" -/** - * The jersey server has its own factory - */ -JerseyHttpServer extends Java6HttpServer { - factoryClass "com.sun.jersey.api.container.httpserver.HttpServerFactory"; -} \ No newline at end of file Modified: trunk/core/components/restapi/src/org/smartfrog/services/restapi/resources/ComponentState.java =================================================================== --- trunk/core/components/restapi/src/org/smartfrog/services/restapi/resources/ComponentState.java 2010-05-26 10:32:07 UTC (rev 8298) +++ trunk/core/components/restapi/src/org/smartfrog/services/restapi/resources/ComponentState.java 2010-05-26 15:03:52 UTC (rev 8299) @@ -26,11 +26,10 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; -// The Java class will be hosted at the URI path "/helloworld" /** * */ -@Path("/components/{path:.+}\"") +@Path("/components/{path:.+}") public class ComponentState extends AbstractRestResource { // The Java method will process HTTP GET requests @@ -38,7 +37,6 @@ // The Java method will produce content identified by the MIME Media type "text/plain" @Produces("text/plain") public String getState(@PathParam("path") String path) { - // Return some cliched textual content return "undefined"; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-06-22 09:51:53
|
Revision: 8338 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8338&view=rev Author: steve_l Date: 2010-06-22 09:51:47 +0000 (Tue, 22 Jun 2010) Log Message: ----------- SFOS-1476 now looking at long-lived connections. The connections last, but buffering is a concern Modified Paths: -------------- trunk/core/components/cloudfarmer/test/org/smartfrog/services/cloudfarmer/test/client/web/components.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf Added Paths: ----------- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/SlowGetServlet.java Modified: trunk/core/components/cloudfarmer/test/org/smartfrog/services/cloudfarmer/test/client/web/components.sf =================================================================== --- trunk/core/components/cloudfarmer/test/org/smartfrog/services/cloudfarmer/test/client/web/components.sf 2010-06-14 16:49:43 UTC (rev 8337) +++ trunk/core/components/cloudfarmer/test/org/smartfrog/services/cloudfarmer/test/client/web/components.sf 2010-06-22 09:51:47 UTC (rev 8338) @@ -22,8 +22,11 @@ #include "/org/smartfrog/services/cloudfarmer/client/web/deploy/components.sf" JettyAndMock extends Compound { - jetty extends StrutsOnJetty; cluster extends MockCluster; + + jetty extends StrutsOnJetty { + + } } @@ -31,6 +34,7 @@ description "A test with jetty and the mock cluster farmer"; action extends JettyAndMock; + farmer LAZY action:cluster; } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf 2010-06-14 16:49:43 UTC (rev 8337) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf 2010-06-22 09:51:47 UTC (rev 8338) @@ -246,6 +246,7 @@ */ socketLingerTime -1; headerBufferSize (4 * 1024); + //request and response buffers are only used if the request or response is bigger than the header buffer requestBufferSize (8 * 1024); responseBufferSize (24 * 1024); Added: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/SlowGetServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/SlowGetServlet.java (rev 0) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/SlowGetServlet.java 2010-06-22 09:51:47 UTC (rev 8338) @@ -0,0 +1,103 @@ +/* (C) Copyright 2010 Hewlett-Packard Development Company, LP + +Disclaimer of Warranty + +The Software is provided "AS IS," without a warranty of any kind. ALL +EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE HEREBY +EXCLUDED. SmartFrog is not a Hewlett-Packard Product. The Software has +not undergone complete testing and may contain errors and defects. It +may not function properly and is subject to change or withdrawal at +any time. The user must assume the entire risk of using the +Software. No support or maintenance is provided with the Software by +Hewlett-Packard. Do not install the Software if you are not accustomed +to using experimental software. + +Limitation of Liability + +TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL HEWLETT-PACKARD +OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR +FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, +HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF +OR RELATED TO THE FURNISHING, PERFORMANCE, OR USE OF THE SOFTWARE, OR +THE INABILITY TO USE THE SOFTWARE, EVEN IF HEWLETT-PACKARD HAS BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. FURTHERMORE, SINCE THE +SOFTWARE IS PROVIDED WITHOUT CHARGE, YOU AGREE THAT THERE HAS BEEN NO +BARGAIN MADE FOR ANY ASSUMPTIONS OF LIABILITY OR DAMAGES BY +HEWLETT-PACKARD FOR ANY REASON WHATSOEVER, RELATING TO THE SOFTWARE OR +ITS MEDIA, AND YOU HEREBY WAIVE ANY CLAIM IN THIS REGARD. + +*/ + +package org.smartfrog.services.www.bulkio.server; + +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.OutputStream; + +/** + * This servlet does long lived GET operations + */ + +public class SlowGetServlet extends AbstractBulkioServlet { + + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + long hours = getParameterAsLong(request, "hours"); + if (hours <= 0) { + hours = 0; + } + long minutes = getParameterAsLong(request, "minutes"); + if (minutes <= 0) { + minutes = 0; + } + long seconds = getParameterAsLong(request, "seconds"); + if (seconds <= 0) { + seconds = 0; + } + long millis = getParameterAsLong(request, "milliseconds"); + if (millis <= 0) { + millis = 0; + } + + long events = getParameterAsLong(request, "events"); + if (events <= 0) { + throw new ServletException("Missing or wrong events parameter " + events); + } + + long time = millis + 1000 * (seconds + minutes * 60 + hours * 3600); + long interval = time / events; + if (interval <= 0) { + throw new ServletException("Bad time interval " + interval); + } + getLog().info("Serving an event every " + interval + " milliseconds " + + " for " + events + " events; " + + " total time:" + time + " milliseconds"); + response.setContentType(TEXT_PLAIN); + + ServletOutputStream outputStream = null; + outputStream = response.getOutputStream(); + long count = 0; + try { + for (count = 1; count <= events; count++) { + Thread.sleep(interval); + outputStream.println("Event " + count + " of " + events); + outputStream.flush(); + response.flushBuffer(); + } + } catch (InterruptedException ie) { + String message = "Interrupted at event " + count; + getLog().info(message); + throw new ServletException(message, ie); + } finally { + closeQuietly(outputStream); + } + } +} Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf 2010-06-14 16:49:43 UTC (rev 8337) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/components.sf 2010-06-22 09:51:47 UTC (rev 8338) @@ -31,6 +31,7 @@ ]; UPLOAD "/upload"; DOWNLOAD "/download"; + SLOW "/slow"; } @@ -46,6 +47,12 @@ className "org.smartfrog.services.www.bulkio.server.BulkDownloadServlet"; } +SlowGetServlet extends BulkIoServlet { + name "SlowGetServlet"; + pathSpec SLOW; + className "org.smartfrog.services.www.bulkio.server.SlowGetServlet"; +} + /** * A compound that deploys the servlet context and two servlets */ @@ -67,5 +74,9 @@ context LAZY PARENT:context; } + slowGetServlet extends SlowGetServlet { + context LAZY PARENT:context; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-06-22 15:24:50
|
Revision: 8341 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8341&view=rev Author: steve_l Date: 2010-06-22 15:24:43 +0000 (Tue, 22 Jun 2010) Log Message: ----------- SFOS-1476 big data upload/download and long-lived connections. Tests are currently failing Modified Paths: -------------- trunk/core/components/jetty/build.xml trunk/core/components/jetty/ivy.xml trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/dynamicexample.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example1.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example2.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example3.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-complete.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-legacy-components.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/jettyjsp.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/log/components.sf trunk/core/components/jetty/src/org/smartfrog/services/jetty/securityrealm.sf trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCaseWithBigOperations.java trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/SlowGetServlet.java Modified: trunk/core/components/jetty/build.xml =================================================================== --- trunk/core/components/jetty/build.xml 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/build.xml 2010-06-22 15:24:43 UTC (rev 8341) @@ -45,7 +45,8 @@ <property name="junit.timeout" value="60000000" /> <property name="functional.test.timeout" value="600000" /> <property name="test.timeout" value="${test.timeout.execute}" /> - +<!-- <property name="org.apache.commons.logging.Log" value="org.smartfrog.services.logging.jcl.front.CommonsLogFrontEnd" /> + --> <echo message="==================================================================="/> <echo message="= ${ant.project.name}"/> Modified: trunk/core/components/jetty/ivy.xml =================================================================== --- trunk/core/components/jetty/ivy.xml 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/ivy.xml 2010-06-22 15:24:43 UTC (rev 8341) @@ -52,12 +52,8 @@ conf="compile,redist,daemon->default,servletapi;testwar->testwar;test->default,servletapi,httpclient"/> - <!-- depend on logging services, to pick up commons-logging and bindings --> - <dependency org="org.smartfrog" - name="sf-loggingservices" - rev="latest.integration" - conf="jsp->default"/> + <dependency org="org.smartfrog" name="sf-tasks" changing="true" @@ -90,7 +86,7 @@ name="sf-loggingservices" changing="true" rev="latest.integration" - conf="compile,runtime->default;redist->redist"/> + conf="compile,runtime,jsp->default;redist->redist"/> <!--JSP support --> <dependency org="org.mortbay.jetty" Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/dynamicexample.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/dynamicexample.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/dynamicexample.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -28,23 +28,23 @@ */ context extends ServletContext { - contextPath "/test3"; - resourceBase LAZY PROPERTY java.io.tmpdir; + contextPath "/test3"; + resourceBase LAZY PROPERTY java.io.tmpdir; } listener extends JettyListener { - listenerPort 8086; + listenerPort 8086; } sfConfig extends Compound { - - server LAZY HOST localhost:rootProcess:ex1:server1; - - newlistener extends listener { - server LAZY PARENT:server; - } - newcontext extends context { - server LAZY PARENT:server; - } + + server LAZY HOST localhost:rootProcess:ex1:server1; + + newlistener extends listener { + server LAZY PARENT:server; + } + newcontext extends context { + server LAZY PARENT:server; + } } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example1.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example1.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example1.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -34,6 +34,6 @@ sfConfig extends Compound { - server extends JettyHttpServer { - } + server extends JettyHttpServer { + } } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example2.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example2.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example2.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -18,11 +18,11 @@ listenerPort 8081; // mandatory } server1 extends JettyHttpServer { - jettyhome ROOT:jetty_home; + //jettyhome ROOT:jetty_home; } server2 extends CoreJettyServer { - jettyhome ROOT:jetty_home; + //jettyhome ROOT:jetty_home; serverHost "localhost"; //mandatory contexts extends JettySampleContexts { server LAZY PARENT; Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example3.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example3.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/example3.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -29,22 +29,22 @@ /** * Specify the jetty home path as the property jetty.home *at the destination* */ -jetty_home LAZY PROPERTY jetty.home; +//jetty_home LAZY PROPERTY jetty.home; sfConfig extends Compound { adminServer extends HttpServerAdmin { - httpserverHost "localhost"; // mandatory - listenerPort 8081; // mandatory + httpserverHost "localhost"; // mandatory + listenerPort 8081; // mandatory } server1 extends CoreJettyServer { - jettyhome ROOT:jetty_home; + //jettyhome ROOT:jetty_home; contexts extends JettySampleContexts { server LAZY PARENT; } list1 extends ApacheHttpdListener { - listenerPort 8011; - server LAZY PARENT; + listenerPort 8011; + server LAZY PARENT; } } server2 extends CoreJettyServer { @@ -53,25 +53,25 @@ server LAZY PARENT; } list2 extends ApacheHttpdListener { - listenerPort 8012; - server LAZY PARENT; + listenerPort 8012; + server LAZY PARENT; } } //out of band instance list1 extends JettyListener { - listenerPort 8083; - server LAZY server2; + listenerPort 8083; + server LAZY server2; } list3 extends JettyListener { - listenerPort 8085; - server LAZY server1; + listenerPort 8085; + server LAZY server1; } context extends ServletContext { - contextPath "/test2"; - resourceBase LAZY PROPERTY java.io.tmpdir; - server LAZY server2; + contextPath "/test2"; + resourceBase LAZY PROPERTY java.io.tmpdir; + server LAZY server2; } } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/jetty_bulkio_servlets.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -21,12 +21,16 @@ #include "/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf" #include "/org/smartfrog/services/www/bulkio/server/components.sf" #include "/org/smartfrog/services/www/filters/components.sf" +#include "/org/smartfrog/services/logging/jcl/components.sf" BulkIOJetty extends LocalJettyServer { host CoreJettyServer:ANY_HOST; + commonsLoggingBridge extends BindCommonsLogging; + + bulkIOSupport extends BulkIOSupport { server LAZY PARENT:server; Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/examples/local_test_jetty_server.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -45,6 +45,7 @@ server LAZY PARENT:server; port PARENT:port; host PARENT:host; + } } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-complete.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-complete.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-complete.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -40,19 +40,22 @@ CompleteJettyHttpServer extends Compound { - jettyhome TBD; + //jettyhome TBD; //integrate logging with smartfrog logging extends IntegrateJettyLogging; server extends CoreJettyServer { - //if logging is enabled, then it logs to jettyhome/logs. + //if logging is enabled, then it logs to logDir enableLogging false; port PARENT:port; - jettyhome PARENT:jettyhome; + //jettyhome PARENT:jettyhome; } port 8080; + //extended idletime for manual interaction + maxIdleTime 20000; + /** * this listens on a direct port @@ -60,6 +63,8 @@ connector extends JettySocketConnector { server LAZY PARENT:server; port PARENT:port; + maxIdleTime PARENT:maxIdleTime ; + host PARENT:host; } } @@ -73,4 +78,14 @@ } } +JettyOnNIO extends LocalJettyServer { + connector extends JettySelectChannelConnector { + server LAZY PARENT:server; + port PARENT:port; + host PARENT:host; + maxIdleTime PARENT:maxIdleTime ; + } +} + + Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-core.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -135,7 +135,7 @@ name "JettyServer"; minThreads 4; maxThreads 32; - maxIdleTime 1000; + maxIdleTime 10000; //should the date header be sent in a response? sendDateHeader true; Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-legacy-components.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-legacy-components.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/jetty-legacy-components.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -57,67 +57,67 @@ server TBD; jettyDemo extends JettyDemo { - server LAZY PARENT:server; + server LAZY PARENT:server; } jettyExamples extends JettyExamples { - server LAZY PARENT:server; + server LAZY PARENT:server; } jettyJavadoc extends JettyJavadoc { - server LAZY PARENT:server; + server LAZY PARENT:server; } jettyCGIBIN extends JettyCGIBIN { - server LAZY PARENT:server; + server LAZY PARENT:server; } } JettyExampleWar extends WebApplication { - server LAZY PARENT:server; + server LAZY PARENT:server; } RootWAR extends JettyExampleWar { - contextPath "/"; - filename "demo/webapps/root"; + contextPath "/"; + filename "demo/webapps/root"; } JettyDemo extends JettyExampleWar { - contextPath "/jetty"; - filename "demo/webapps/jetty"; + contextPath "/jetty"; + filename "demo/webapps/jetty"; } JettyExamples extends JettyExampleWar { - contextPath "/examples"; - filename "demo/webapps/examples"; - requestId true; //optional + contextPath "/examples"; + filename "demo/webapps/examples"; + requestId true; //optional } JettyServletContexts extends ServletContext { - server LAZY PARENT:server; - contextPath "/demo"; - resourceBase "/demo/docroot"; - classpath "demo/servlets"; - handlers extends Handlers { - context LAZY PARENT; + server LAZY PARENT:server; + contextPath "/demo"; + resourceBase "/demo/docroot"; + classpath "demo/servlets"; + handlers extends Handlers { + context LAZY PARENT; } - servlets extends BuiltInServlets { - context LAZY PARENT; + servlets extends BuiltInServlets { + context LAZY PARENT; } } JettyJavadoc extends ServletContext { - contextPath "/javadoc"; - resourceBase "javadoc"; + contextPath "/javadoc"; + resourceBase "javadoc"; } JettyCGIBIN extends ServletContext { - contextPath "/cgi-bin"; - resourceBase "cgi-bin"; - - servlets extends CGIservlet { - //server LAZY PARENT:server; - context LAZY PARENT; - } + contextPath "/cgi-bin"; + resourceBase "cgi-bin"; + + servlets extends CGIservlet { + //server LAZY PARENT:server; + context LAZY PARENT; + } } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/jettyjsp.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/jettyjsp.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/jettyjsp.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -145,11 +145,11 @@ </servlet-mapping> */ JettyJSPServlet extends Servlet { - name "JettyJSPServlet"; - pathSpec "/*"; - mappings ["*.jsp","*.jspx","*.jspf","*.xsp","*.JSP","*.JSPX","*.JSPF","*.XSP"]; - className "org.apache.jasper.servlet.JspServlet"; - errorText "This servlet needs the jsp-api and jsp implementation JARs on the classpath"; - initOrder 1; + name "JettyJSPServlet"; + pathSpec "/*"; + mappings ["*.jsp","*.jspx","*.jspf","*.xsp","*.JSP","*.JSPX","*.JSPF","*.XSP"]; + className "org.apache.jasper.servlet.JspServlet"; + errorText "This servlet needs the jsp-api and jsp implementation JARs on the classpath"; + initOrder 1; } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/log/components.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/log/components.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/log/components.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -20,10 +20,10 @@ #include "/org/smartfrog/services/utils/setproperty/components.sf" IntegrateJettyLogging extends SystemProperties { - properties [ + properties [ ["org.mortbay.log.class","org.smartfrog.services.jetty.log.JettyLogger"] - ]; - setOnEarlyDeploy true; - setOnDeploy false; - unsetOnTerminate false; + ]; + setOnEarlyDeploy true; + setOnDeploy false; + unsetOnTerminate false; } Modified: trunk/core/components/jetty/src/org/smartfrog/services/jetty/securityrealm.sf =================================================================== --- trunk/core/components/jetty/src/org/smartfrog/services/jetty/securityrealm.sf 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/src/org/smartfrog/services/jetty/securityrealm.sf 2010-06-22 15:24:43 UTC (rev 8341) @@ -20,53 +20,53 @@ #include "/org/smartfrog/services/www/webapplication.sf" JettySecurityRealm extends Prim { - sfClass "org.smartfrog.services.jetty.JettySecurityRealmImpl"; - name TBD; - contextPath TBD; - //lazy link to server - server TBD; - checkWelcomeFiles true; - BASIC_AUTH "BASIC"; - FORM_AUTH "FORM"; - DIGEST_AUTH "DIGEST"; - CERT_AUTH "CLIENT_CERT"; - - authentication BASIC_AUTH; - - //list of [name, credential, role1, role2,...] elements - users []; - - //list of tuples of paths and lists of name, role pairs. - // Each entry should be - // [constraint Name, Path/pattern, method, user role - constraints []; - - METHOD_GET "GET"; - METHOD_PUT "GET"; - METHOD_POST "POST"; - METHOD_DELETE "DELETE"; - METHOD_HEAD "HEAD"; - METHOD_ANY ""; - - PATH_EVERYTHING "/*"; - - //public - CONSTRAINT_PUBLIC ["Public", PATH_EVERYTHING, METHOD_ANY, "*"]; + sfClass "org.smartfrog.services.jetty.JettySecurityRealmImpl"; + name TBD; + contextPath TBD; + //lazy link to server + server TBD; + checkWelcomeFiles true; + BASIC_AUTH "BASIC"; + FORM_AUTH "FORM"; + DIGEST_AUTH "DIGEST"; + CERT_AUTH "CLIENT_CERT"; + + authentication BASIC_AUTH; + + //list of [name, credential, role1, role2,...] elements + users []; + + //list of tuples of paths and lists of name, role pairs. + // Each entry should be + // [constraint Name, Path/pattern, method, user role + constraints []; + + METHOD_GET "GET"; + METHOD_PUT "GET"; + METHOD_POST "POST"; + METHOD_DELETE "DELETE"; + METHOD_HEAD "HEAD"; + METHOD_ANY ""; + + PATH_EVERYTHING "/*"; + + //public + CONSTRAINT_PUBLIC ["Public", PATH_EVERYTHING, METHOD_ANY, "*"]; } AdminSecurityRealm extends JettySecurityRealm { - contextPath PATH_EVERYTHING; - name "AdminSecurityRealm"; - adminPassword "password"; - - - - users [ - ["admin", adminPassword, name], - ["test", "test", name] - ]; - - constraints [ - ["Admin", contextPath, METHOD_ANY, name] - ]; + contextPath PATH_EVERYTHING; + name "AdminSecurityRealm"; + adminPassword "password"; + + + + users [ + ["admin", adminPassword, name], + ["test", "test", name] + ]; + + constraints [ + ["Admin", contextPath, METHOD_ANY, name] + ]; } \ No newline at end of file Modified: trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCaseWithBigOperations.java =================================================================== --- trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCaseWithBigOperations.java 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/jetty/test/org/smartfrog/services/www/jetty/test/system/bulkio/BulkIoTestCaseWithBigOperations.java 2010-06-22 15:24:43 UTC (rev 8341) @@ -65,7 +65,7 @@ expectBulkIoRun(getFile(), LARGE_4GB); } - public void testBulkIo5GB() throws Throwable { + public void NotestBulkIo5GB() throws Throwable { expectBulkIoRun(getFile(), LARGE_5GB); } Modified: trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/SlowGetServlet.java =================================================================== --- trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/SlowGetServlet.java 2010-06-22 14:11:14 UTC (rev 8340) +++ trunk/core/components/www/src/org/smartfrog/services/www/bulkio/server/SlowGetServlet.java 2010-06-22 15:24:43 UTC (rev 8341) @@ -32,12 +32,16 @@ package org.smartfrog.services.www.bulkio.server; +import org.apache.log4j.helpers.ISO8601DateFormat; + import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; +import java.text.DateFormat; +import java.util.Date; /** * This servlet does long lived GET operations @@ -84,11 +88,21 @@ ServletOutputStream outputStream = null; outputStream = response.getOutputStream(); + DateFormat dateFormatter = new ISO8601DateFormat(); long count = 0; try { for (count = 1; count <= events; count++) { Thread.sleep(interval); - outputStream.println("Event " + count + " of " + events); + long now = System.currentTimeMillis(); + Date date = new Date(now); + StringBuilder message = new StringBuilder(); + message.append(now).append(", "); + message.append(count).append(", "); + message.append(events).append(", "); + message.append('"').append(dateFormatter.format(date)).append("\""); + String text = message.toString(); + getLog().info(text); + outputStream.println(text); outputStream.flush(); response.flushBuffer(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-09-01 16:50:52
|
Revision: 8373 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8373&view=rev Author: steve_l Date: 2010-09-01 16:50:46 +0000 (Wed, 01 Sep 2010) Log Message: ----------- SFOS-1516 Move sf-www up to commons-codec 1.4 Modified Paths: -------------- trunk/core/components/libraries.properties trunk/core/components/www/ivy.xml Modified: trunk/core/components/libraries.properties =================================================================== --- trunk/core/components/libraries.properties 2010-09-01 10:15:12 UTC (rev 8372) +++ trunk/core/components/libraries.properties 2010-09-01 16:50:46 UTC (rev 8373) @@ -19,7 +19,7 @@ commons-dbutils.version=1.3 commons-cli.version=1.2 commons-chain.version=1.2 -commons-codec.version=1.3 +commons-codec.version=1.4 commons-collections.version=3.2.1 commons-digester.version=1.8 commons-el.version=1.0 Modified: trunk/core/components/www/ivy.xml =================================================================== --- trunk/core/components/www/ivy.xml 2010-09-01 10:15:12 UTC (rev 8372) +++ trunk/core/components/www/ivy.xml 2010-09-01 16:50:46 UTC (rev 8373) @@ -77,6 +77,7 @@ conf="compile->master;httpclient->default"> <exclude org="commons-logging"/> <exclude org="junit"/> + <exclude org="commons-codec"/> </dependency> <dependency org="commons-codec" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2010-12-03 11:53:18
|
Revision: 8432 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8432&view=rev Author: steve_l Date: 2010-12-03 11:53:12 +0000 (Fri, 03 Dec 2010) Log Message: ----------- SFOS-1545 SFOS-1513 clean up some ivy files Modified Paths: -------------- trunk/core/components/database/ivy.xml trunk/core/components/loggingservices/ivy.xml trunk/core/components/xml/ivy.xml Modified: trunk/core/components/database/ivy.xml =================================================================== --- trunk/core/components/database/ivy.xml 2010-12-03 11:51:34 UTC (rev 8431) +++ trunk/core/components/database/ivy.xml 2010-12-03 11:53:12 UTC (rev 8432) @@ -44,7 +44,7 @@ name="smartfrog" changing="true" rev="latest.integration" - conf="compile->services;runtime->services;daemon->services"/> + conf="compile,runtime,daemon->services"/> <dependency org="org.smartfrog" name="sf-tasks" changing="true" Modified: trunk/core/components/loggingservices/ivy.xml =================================================================== --- trunk/core/components/loggingservices/ivy.xml 2010-12-03 11:51:34 UTC (rev 8431) +++ trunk/core/components/loggingservices/ivy.xml 2010-12-03 11:53:12 UTC (rev 8432) @@ -62,7 +62,7 @@ rev="latest.integration" conf="test->default"/> - <!--it is essential that only the master JAR of commons logging + <!--it is essential that only the master JAR of Log4j is pulled in, as its dependencies are usually a mess, including things like a version of JMX that isn't in the repository --> Modified: trunk/core/components/xml/ivy.xml =================================================================== --- trunk/core/components/xml/ivy.xml 2010-12-03 11:51:34 UTC (rev 8431) +++ trunk/core/components/xml/ivy.xml 2010-12-03 11:53:12 UTC (rev 8432) @@ -83,12 +83,12 @@ <dependency org="xalan" name="xalan" rev="${xalan.version}" - conf="compile,xslt->master"/> + conf="compile,xslt->default"/> <dependency org="jdom" name="jdom" rev="${jdom.version}" - conf="compile,redist->master"/> + conf="compile,redist->default"/> </dependencies> </ivy-module> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2011-03-17 17:07:08
|
Revision: 8532 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8532&view=rev Author: anfarr Date: 2011-03-17 17:06:58 +0000 (Thu, 17 Mar 2011) Log Message: ----------- SFOS-1573: Complete check-in of dependencies stuff (in new location) Added Paths: ----------- trunk/core/components/dependencies/ trunk/core/components/dependencies/build.xml trunk/core/components/dependencies/ivy.xml trunk/core/components/dependencies/src/ trunk/core/components/dependencies/src/org/ trunk/core/components/dependencies/src/org/smartfrog/ trunk/core/components/dependencies/src/org/smartfrog/examples/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/Apache.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/ApacheImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/components.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Balancer.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/BalancerImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Connection.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/ConnectionRelay.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/LoadBalancerBinding.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/LoadBalancerBindingImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Server.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/ServerInstance.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/ServerInstanceImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/ServerSelector.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/components.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/filetester/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/filetester/FileTester.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/filetester/FileTesterImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/filetester/components.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/CompleteGraphPanel.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/DataSource.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/Graph.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/GraphImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/GraphPanel.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/ThresholdPanel.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/TideMarkPanel.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/TideMeter.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/TideMeterImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/barLo.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/barMiddle.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/barTop.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/barUp.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/bottom.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/components.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/lowerSlider.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/middle.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/top.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/graphpanel/upperSlider.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/ProgressBars.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/ProgressBarsImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/ProgressPanel.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/components.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/example.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/grn_bullet.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/red_bullet.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/gui/progresspanel/yel_bullet.gif trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/monitor/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/monitor/CPUMonitor.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/monitor/CPUMonitorImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/monitor/components.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/sf/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/sf/ServiceOrchestration.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/sf/loadGeneratorTemplate.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/sf/serviceTemplate.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/sf/system.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/sf/webTemplate.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/stresstest/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/stresstest/StressControlGui.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/stresstest/StressControlGuiImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/stresstest/StressManagerFrame.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/stresstest/StressTester.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/stresstest/StressTesterImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/stresstest/components.sf trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/svn-commit.tmp trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/thresholder/ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/thresholder/AdjustableThresholdPanel.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/thresholder/DisplayThresholder.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/thresholder/DisplayThresholderImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/thresholder/Thresholder.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/thresholder/ThresholderImpl.java trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/thresholder/components.sf trunk/core/components/dependencies/src/org/smartfrog/services/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/components.sf trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/modelcheck/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/modelcheck/ModelCheck.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/modelcheck/ModelCheckResults.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/modelcheck/NuSMVInterface.h trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/modelcheck/NuSMVInterface.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/modelcheck/Resolver.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/components.sf trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/connector/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/connector/AndConnector.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/connector/Connector.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/connector/OrConnector.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/connector/XorConnector.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/dependency/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/dependency/Dependency.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/dependency/DependencyValidation.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/Composite.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/Constants.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/InvokeAsynchronousStateChange.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/NWayComposite.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/NilStateComponent.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/QueryMetaData.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/RunSynchronisation.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/SimpleStateComponent.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/StateChangeNotification.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/StateComponent.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/StateComponentManagement.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/StateComponentTransitionException.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/StateDependencies.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/state/SynchedComposite.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/termination/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/statemodel/termination/CompositeTermination.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/threadpool/ trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/threadpool/SimpleThreadPoolImpl.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/threadpool/ThreadPool.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/threadpool/ThreadPoolTester.java trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/threadpool/components.sf trunk/core/components/dependencies/src/org/smartfrog/services/dependencies/threadpool/simpletp.sf trunk/core/components/dependencies/test/ trunk/core/components/dependencies/test/org/ trunk/core/components/dependencies/test/org/smartfrog/ trunk/core/components/dependencies/test/org/smartfrog/test/ trunk/core/components/dependencies/test/org/smartfrog/test/system/ trunk/core/components/dependencies/test/org/smartfrog/test/system/dependencies/ trunk/core/components/dependencies/test/org/smartfrog/test/system/dependencies/DependenciesTest.java trunk/core/components/dependencies/test/org/smartfrog/test/system/dependencies/WaitForTerminated.java trunk/core/components/dependencies/test/org/smartfrog/test/system/dependencies/components.sf trunk/core/components/dependencies/test/org/smartfrog/test/system/dependencies/testSimpleStateComponent.sf trunk/core/components/dependencies/test/org/smartfrog/test/system/dependencies/testThreeUpDown.sf Added: trunk/core/components/dependencies/build.xml =================================================================== --- trunk/core/components/dependencies/build.xml (rev 0) +++ trunk/core/components/dependencies/build.xml 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,53 @@ +<?xml version="1.0"?> + +<!-- +/** (C) Copyright 1998-2009 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +--> + +<project name="dependencies" default="dist" basedir="."> + +<description> +Introduction +============ +SmartFrog Orch Extensions + +</description> + + <!-- override point --> + <property file="build.properties" /> + <property name="root.dir" location="../../" /> + + + <property name="is.component" value="true" /> + <property name="ivy.enabled" value="true"/> + <property name="system.tests" value="true"/> + + <!-- Import common stuff --> + <!--available file="../../common.xml" property="root.dir" value="../.."/--> + <import file="${root.dir}/common.xml"/> + + <echo message="==================================================================="/> + <echo message="= ${ant.project.name}"/> + +</project> + +<!-- End of file --> + Property changes on: trunk/core/components/dependencies/build.xml ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/dependencies/ivy.xml =================================================================== --- trunk/core/components/dependencies/ivy.xml (rev 0) +++ trunk/core/components/dependencies/ivy.xml 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,56 @@ +<?xml version="1.0" ?> +<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?> +<ivy-module version="1.0"> + <info organisation="org.smartfrog" module="sf-constraints"> + <license name="LGPL"/> + <ivyauthor name="Hewlett-Packard" url="http://www.smartfrog.org"/> + <description> + Solver specific constraint extensions + </description> + </info> +<!-- FIXME: Ivy 1.4.1 buildlist bug + <configurations defaultconfmapping="default"> + <include file="../../antbuild/ivy/configurations.xml"/> + </configurations> + --> +<configurations defaultconfmapping="default"> + <conf name="default" extends="master,runtime" + description="default configuration contains artifacts and runtime dependencies"/> + <conf name="build" visibility="private" + description="artifacts needed to build the application"/> + <conf name="compile" visibility="private" extends="runtime" + description="artifacts needed to compile the application"/> + <conf name="daemon" visibility="private" + description="the classpath needed to run smartfrog daemons"/> + <conf name="test" extends="default,compile" + description="the classpath needed to run tests"/> + <conf name="master" description="contains the artifact but no dependencies"/> + <conf name="redist" description="redistributals excluding smartfrog artifacts"/> + <conf name="runtime" description="runtime but not the artifact" + extends="redist"/> + <conf name="documentation" + description="all documentation artifacts"/> +</configurations> + + <publications> + <!--get the artifact from our module name--> + <artifact conf="master"/> + </publications> + <dependencies> + <dependency org="org.smartfrog" + name="smartfrog" + changing="true" + rev="latest.integration" + conf="compile->services;runtime->services;daemon->services"/> + <dependency org="org.smartfrog" + name="sf-tasks" + changing="true" + rev="latest.integration" + conf="build->default"/> + <dependency org="org.smartfrog" + name="sf-testharness" + changing="true" + rev="latest.integration" + conf="test->default"/> + </dependencies> +</ivy-module> Property changes on: trunk/core/components/dependencies/ivy.xml ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/Apache.java =================================================================== --- trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/Apache.java (rev 0) +++ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/Apache.java 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,73 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +package org.smartfrog.examples.orchdws.apache; + +import java.rmi.Remote; +import java.rmi.RemoteException; + + +/** + * This interface defines the methods that can be called upon Apache by a + * Remote client. + */ +public interface Apache extends Remote { + public final String LOCATION = "location"; + public final String BASECONFIGLOCATION = "baseConfigLocation"; + public final String CONFIGLOCATION = "configLocation"; + public final String BASECONFIGFILENAME = "baseConfigFileName"; + public final String CONFIGFILENAME = "configFileName"; + public final String ENVVARS = "envVars"; + public final String APACHECTLLOCATION = "apachectlLocation"; + public final String INTERCHECKTIME = "interCheckTime"; + public final String LOGTO = "logTo"; + public final String MANAGEDAEMON = "manageDaemon"; + public final String SFSERVERINSTANCE = "instance"; + + /** + * As the method name indicates, this simply starts the httpd daemon + * @throws RemoteException in case of Remote/network error + */ + public void startDaemon() throws RemoteException; + + /** + * As the method name indicates, this simply stops the httpd daemon + * @throws RemoteException in case of Remote/network error + */ + public void stopDaemon() throws RemoteException; + + /** + * This refreshes the httpd daemon and therfore updates the current + * configuration. (Activates any changes)) + * @throws RemoteException in case of Remote/network error + */ + public void refreshDaemon() throws RemoteException; + + /** + * This would be used to reset/update the configuration of Apache. + * @param scriptURL script url + * @param fileName file name + * @throws RemoteException in case of Remote/network error + */ + public void refreshConfig(String scriptURL, String fileName) + throws RemoteException; + + public void setApacheState(boolean newState) throws RemoteException; +} Property changes on: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/Apache.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/ApacheImpl.java =================================================================== --- trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/ApacheImpl.java (rev 0) +++ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/ApacheImpl.java 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,314 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ + + +package org.smartfrog.examples.orchdws.apache; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.rmi.RemoteException; +import java.util.Vector; + +import org.smartfrog.examples.dynamicwebserver.gui.graphpanel.DataSource; +import org.smartfrog.examples.orchdws.balancer.ServerInstance; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.compound.Compound; +import org.smartfrog.sfcore.compound.CompoundImpl; +import org.smartfrog.sfcore.prim.TerminationRecord; + + +/** + * This class implements the Compound interface because it can "contain" + * Virtual Hosts components. The Apache interface is the Remoteable interface + * and the Runnable interface is used to monitor the httpd process. The httpd + * process is started in sfStart by setting the apacheState variable to true + * and ended in sfTerminate by setting the apacheState variable to false. + */ +public class ApacheImpl extends CompoundImpl implements Compound, Apache, + DataSource, Runnable { + + private String location = ""; + private String baseConfigLocation = ""; + private String configLocation = ""; + private String apachectlLocation = ""; + private boolean manageDaemon = true; + + private int interCheckTime; + + private Vector envVars; + private boolean terminated = false; + private boolean apacheState = false; + private boolean shouldRefresh = false; + private Thread thread; + private int threadCount = 0; + + /** + * Standard Remotable constructor + * + * @throws RemoteException in case of Remote/network error + */ + public ApacheImpl() throws RemoteException { + } + + /** + * This method retrieves the paramters from the .sf file. + * + * @throws SmartFrogException error in deploying the component + * @throws RemoteException in case of Remote/network error + */ + public synchronized void sfDeploy() throws SmartFrogException, RemoteException { + super.sfDeploy(); + + if (sfLog().isDebugEnabled()) sfLog().debug("apache deploying"); + + interCheckTime = sfResolve(INTERCHECKTIME, 15, false); + + location = sfResolve(LOCATION, "", true); + baseConfigLocation = sfResolve(BASECONFIGLOCATION, "", true); + configLocation = sfResolve(CONFIGLOCATION, "", true); + envVars = (Vector) sfResolve(ENVVARS, true); + apachectlLocation = sfResolve(APACHECTLLOCATION, "", true); + manageDaemon = sfResolve(MANAGEDAEMON, manageDaemon, false); + + if (sfLog().isInfoEnabled()) sfLog().info("apache deployed"); + } + + /** + * This sets a flag that will start the httpd process running. + * + * @throws SmartFrogException error in starting the component + * @throws RemoteException in case of Remote/network error + */ + public synchronized void sfStart() throws SmartFrogException, RemoteException { + super.sfStart(); + if (sfLog().isDebugEnabled()) sfLog().debug("apache starting"); + setApacheState(true); + if (sfLog().isInfoEnabled()) sfLog().info("apache started"); + } + + /** + * This shuts down Apache by requesting that the ApacheState variable be + * set to false. + * + * @param tr TerminationRecord object + */ + public synchronized void sfTerminateWith(TerminationRecord tr) { + if (sfLog().isInfoEnabled()) sfLog().info("terminating apache - setting runstate to false"); + try{ setApacheState(false); } catch(RemoteException re){/*Shouldn't happen*/} + terminated = true; + super.sfTerminateWith(tr); + } + + /** + * The logic behind this is: if Apache is not running and the desired state + * is to be running then Set Apaches state to running call start() else + * Set Apaches state to the required state end It is not possible to + * simply change the variable to true and start a new thread because it + * may already be running and you would end up starting too many httpd + * processes. + * + * @param newState new state of Apache + */ + public synchronized void setApacheState(boolean newState) throws RemoteException{ + if (sfLog().isDebugEnabled()) sfLog().debug("setting apache state to " + newState + " from " + apacheState); + + if ((!apacheState) && (newState)) { + apacheState = newState; + if (sfLog().isDebugEnabled()) sfLog().debug("starting apache thread"); + thread = new Thread(this); + thread.start(); + if (sfLog().isDebugEnabled()) sfLog().debug("started apache thread"); + } else { + if (sfLog().isDebugEnabled()) sfLog().debug("really setting apache to " + newState); + apacheState = newState; + } + } + + /** + * Get Apache state + * @return boolean + */ + public synchronized boolean getApacheState() { + return apacheState; + } + + /** + * This method is used to 'maintain' a processes desired state. In the case + * of the Apache httpd if the number of httpd listener threads is 0 then + * the process is restarted This method is linux/unix specific since it + * uses the command: "ps -A | grep httpd" This is not possible to do on + * windows without writing lots of messy W32 code and using JNI. + */ + public void run() { + boolean needRestart = false; + Process p; + if (sfLog().isInfoEnabled()) sfLog().info("apache monitor thread running"); + + try { + if (manageDaemon) + p = Runtime.getRuntime().exec(apachectlLocation + " start"); + } catch (Exception e) { + if (sfLog().isErrorEnabled()) sfLog().error (e); + } + + if (sfLog().isInfoEnabled()) sfLog().info( "httpd started"); + + while (getApacheState()) { + if (needRestart) { + try { + if (sfLog().isDebugEnabled()) sfLog().debug("restarting apache"); + if (manageDaemon) + p = Runtime.getRuntime().exec(apachectlLocation + " start"); + needRestart = false; + } catch (IOException e) { + if (sfLog().isErrorEnabled()) sfLog().error (e); + } + } + //end if (needRestart) + + try { + Thread.sleep(interCheckTime * 1000); + } catch (InterruptedException ignored) { + if (sfLog().isIgnoreEnabled()) sfLog().ignore (ignored); + } + + try { + String test = null; + String shellLocation = "/bin/bash"; + Process p2 = Runtime.getRuntime().exec(shellLocation); + BufferedReader pOut2 = new BufferedReader(new InputStreamReader(p2.getInputStream())); + DataOutputStream dos2 = new DataOutputStream(p2.getOutputStream()); + + dos2.writeBytes("ps -A | grep httpd" + ((char) 10)); + dos2.writeBytes("exit 0" + ((char) 10)); + dos2.flush(); + dos2.close(); + + p2.waitFor(); + + test = pOut2.readLine(); + + int count = 0; + + while (test != null) { + count++; + test = pOut2.readLine(); + } + + pOut2.close(); + threadCount = count; + if (sfLog().isDebugEnabled()) sfLog().debug("Currently " + count + " httpd threads are running."); + + /** + * If the count is 0 is means there are no daemon processes + * running. This sets the needRestart flag to true which will + * be picked up in the next iteration. + */ + if (count == 0) { + needRestart = true; + } + + if (shouldRefresh) { + if (manageDaemon) { + Process pGraceful = Runtime.getRuntime().exec(apachectlLocation + " graceful"); + pGraceful.waitFor(); + } + shouldRefresh = false; + } + } catch (Exception e) { + if (sfLog().isErrorEnabled()) sfLog().error (" Error checking for processes - ignored",e); + } + } + + try { + synchronized (this) { + // kill only if we still want to kill apache + // someone may have restarted it with a new thread + if (!getApacheState()) { + if (sfLog().isDebugEnabled()) sfLog().debug("stopping apache"); + if (manageDaemon) + p = Runtime.getRuntime().exec(apachectlLocation + " stop"); + ServerInstance si = (ServerInstance) ApacheImpl.this.sfResolve(SFSERVERINSTANCE); + si.switchToDown(); + + if (sfLog().isInfoEnabled()) sfLog().info("apache stopped"); + } + } + } catch (Exception e) { + if (sfLog().isErrorEnabled()) sfLog().error (e); + } + } + + /** + * This method is not used by the ApacheImpl class but would be used by a + * Remote client. + * + * @throws RemoteException in case of Remote/network error + */ + public void startDaemon() throws RemoteException { + setApacheState(true); + } + + /** + * This method is not used by the ApacheImpl class but would be used by a + * Remote client. + * + * @throws RemoteException in case of Remote/network error + */ + public void stopDaemon() throws RemoteException { + setApacheState(false); + } + + /** + * This method is not used by the ApacheImpl class but would be used by a + * Remote client. + * + * @throws RemoteException in case of Remote/network error + */ + public void refreshDaemon() throws RemoteException { + shouldRefresh = true; + } + + /** + * This method is not currently used but could be used to maintain a + * desired configuration of Apache and then periodically refresh Apache to + * this state. + * + * @param scriptURL script url + * @param fileName file name + * @throws RemoteException in case of Remote/network error + */ + public void refreshConfig(String scriptURL, String fileName) + throws RemoteException { + } + + /** + * Returns an int containing the number of threads - implementation of + * DataSource interface + * + * @return int + * @throws RemoteException in case of Remote/network error + */ + public int getData() throws RemoteException { + return threadCount; + } +} Property changes on: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/ApacheImpl.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/components.sf =================================================================== --- trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/components.sf (rev 0) +++ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/components.sf 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,58 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +#include "org/smartfrog/components.sf" +#include "org/smartfrog/functions.sf" + +Apache extends Compound { + instance LAZY PARENT:ATTRIB instance; + + sfClass "org.smartfrog.examples.orchdws.apache.ApacheImpl"; + + location extends concat { + -- "/usr/local/apache/"; + filepath ""; + } + + baseConfigLocation extends location { + filepath "conf/"; + } + + configLocation extends location { + filepath "conf/"; + } + + apachectlLocation extends location { + filepath "bin/apachectl"; + } + + baseConfigFileName "httpd.conf"; + configFileName "httpd.conf"; + envVars ["ACTIVATOR_CFG_FILE=/usr/local/apache/conf/httpd.conf", + "ACTIVATOR_TMP_FILE=/usr/local/apache/conf/httpd.tmp", + "ACTIVATOR_APACHE_CTL_CMD=/usr/local/apache/bin/apachectl"]; + + + + //interCheckTime; + //logTo; + //manageDaemon true; + +} Property changes on: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/apache/components.sf ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Balancer.java =================================================================== --- trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Balancer.java (rev 0) +++ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Balancer.java 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,51 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +package org.smartfrog.examples.orchdws.balancer; + +import java.rmi.Remote; +import java.rmi.RemoteException; + + +/** + * <p> + * Description: Balancer defines the remote interface to the balancer + * component, allowing a client to add to or remove servers from the set of + * servers that the balancer uses to balance the load from clients. + * </p> + * + */ +public interface Balancer extends Remote { + // + // Definition of SmartFrog parameter names for the component + public final String NAME = "name"; + public final String PORT = "port"; + public final String HOSTSPORT = "hostsPort"; + public final String LOGTO = "logTo"; + public final String SERVERHOSTS = "serverHosts"; + public final String LBBPREFIX = "lbbs:server"; + public final String LBBSUFFIX = ":binding"; + public final String TIMER = "timerstop"; + public final String SLEEP = "sleep"; + + public void enableServerInstance(int instance) throws RemoteException; + public boolean disableServerInstance(int instance) throws RemoteException; + public String lookUpHost(int instance) throws RemoteException; +} Property changes on: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Balancer.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/BalancerImpl.java =================================================================== --- trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/BalancerImpl.java (rev 0) +++ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/BalancerImpl.java 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,360 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +package org.smartfrog.examples.orchdws.balancer; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.rmi.RemoteException; +import java.util.Timer; +import java.util.TimerTask; +import java.util.Vector; + +import org.smartfrog.examples.dynamicwebserver.gui.graphpanel.DataSource; +import org.smartfrog.services.dependencies.statemodel.state.InvokeAsynchronousStateChange; +import org.smartfrog.services.dependencies.statemodel.state.StateComponent; +import org.smartfrog.services.dependencies.statemodel.state.StateComponentTransitionException; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.prim.TerminationRecord; +import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.utils.ListUtils; + + +/** + * <p> + * Title: BalancerImpl. + * </p> + * + * <p> + * Description: BalancerImpl is the main class for a software load balancer for + * socket connections between a set of clients and a set of servers. The + * clients connect to a specific port on the balancer host and the balancer + * selects a server to handle the client session. The balancer opens a socket + * connection to the selected server and relays data between the client and + * the server. The balancer listens for client connections on a well-known + * port, specified by the "port" SmartFrog parameter. + * </p> + * + * <p> + * The Balancer maintains a set of servers that are included in the selection + * algorithm for balancing. The curent selection algorithm is round-robin. An + * initial set of servers can be specified via the "hosts" SmartFrog + * parameter; if "hosts" is specified, the parameter "hostsPort" is used to + * specify the port number to connect to on the servers. Subsequent changes to + * the set of servers can be made at run-time via the Balancer remote + * interface; in this case the port number for each host can be specified + * individually. + * </p> + * + */ +public class BalancerImpl extends StateComponent implements Balancer, DataSource { + // + // Other instance variables + private ServerSelector serverSelector; // Object that does the load balancing to select a server from a list + private volatile BalancerThread balancerThread = null; // The main Balancer thread + private volatile boolean stopping = false; // Used to signal the Balancer server thread to terminate + private int port; // port number to register balancer server socket + private int hostsPort; // port number for connections to remote hosts + private int connectionCount = 0; // number of connections made since last time this was accessed through getdata() + private Vector<String> serverHosts; //the set of server hosts + private int sleep = 0; + + /** + * Constructor for the Balancer component + * + * @throws RemoteException in case of Remote/network error + */ + public BalancerImpl() throws RemoteException { + } + + + //This need rechecking... + protected boolean threadBody() throws StateComponentTransitionException { + if (asyncResponse) return true; //timer still going... + + Timer timer = new Timer(); + timer.schedule(new TimerTask(){ + public void run(){ + BalancerImpl.this.sfLog().info("TIMER: In Timer, time to do something..."); + try { + invokeAsynchronousStateChange(new InvokeAsynchronousStateChange(){ + public void actOn(StateComponent _lb) { + BalancerImpl.this.sfLog().info("actOn(...)"); + try { + _lb.go(TIMER); + }catch (StateComponentTransitionException scte){/*Shouldn't happen*/} + BalancerImpl.this.sfLog().info("actOn(...): LEAVING!"); + } + }); + } catch (StateComponentTransitionException e) { + sfLog().error(e); + throw new RuntimeException(e); //propagate up... + } catch (RemoteException e) { + sfLog().error(e); + throw new RuntimeException(e); + } + BalancerImpl.this.sfLog().info("TIMER: Now going to terminate timer instance..."); + cancel() ; //Terminate the timer... + } + }, sleep); + return false; + } + + /** implementation of DataSource interface + * resets the data after every request - so only suited to single requestor + * + * @return the number of connections since last request + * @throws RemoteException in case of Remote/network error + */ + public int getData() throws RemoteException { + int tmp = connectionCount; + connectionCount = 0; + return tmp; + } + + + /** + * Start the load balancer. + */ + private synchronized void start() { + stopping = false; + + // Start the Server Selector + serverSelector = new ServerSelector(sfCompleteNameSafe().toString()); + serverSelector.start(); + + // + //Create a thread to accept new connections + if (balancerThread == null) { + balancerThread = new BalancerThread(); + balancerThread.start(); + } + } + + /** + * Stop the load balancer. + */ + public synchronized void stop() { + stopping = true; + + // + // Stop accepting new connections. + if (balancerThread != null) { + balancerThread.stop(); + balancerThread = null; + } + + // + // Close all open connections and terminate all threads. + serverSelector.close(); + } + + // + // SmartFrog Component interface + // + + /** + * Returns textual representation. + * + * @return textual representation + */ + public String toString() { + StringBuffer str = new StringBuffer(); + + str.append("LoadBalancer - name: " + sfCompleteNameSafe()); + str.append(", port: " + port); + str.append(", hostsPort: " + hostsPort); + + return (str.toString()); + } + + /** + * Reads SF description. + * + * @throws SmartFrogException error while reading + * @throws RemoteException In case of network/rmi error + */ + private void readSFAttributes() throws SmartFrogException, RemoteException { + // + // Optional attributes. + // + + //System.out.println("Reading serverHosts..."); + serverHosts = ListUtils.resolveStringList(this,new Reference(SERVERHOSTS), false); + //System.out.println("Reading serverHosts ..."+serverHosts); + port = sfResolve(PORT, port, false); + hostsPort = sfResolve(HOSTSPORT, hostsPort, false); + sleep = sfResolve(SLEEP, 0, true); + + if (sfLog().isInfoEnabled()) sfLog().info(this.toString()); + } + + /** + * Standard sfDeploy(). + * + * @exception SmartFrogException error while deploying + * @throws RemoteException In case of network/rmi error + */ + public synchronized void sfDeploy() throws SmartFrogException, RemoteException { + super.sfDeploy(); + + // any component-specific init code + readSFAttributes(); + + // Simply invoke the instance start method + // This needs to be done here, so that others can invoke the addServer methods, etc + // during their sfStarts. + + start(); + + // Any error - propagate and hance fail to deploy + } + + /** + * Standard sfTerminateWith() + * + * @param tr TerminationRecord object + */ + public synchronized void sfTerminateWith(TerminationRecord tr) { + // Simply invoke the instance stop method + stop(); + super.sfTerminateWith(tr); + } + + public void enableServerInstance(int instance) { + if (!stopping) { + String hostname = serverHosts.get(instance); + LoadBalancerBindingImpl lbb = null; + //System.out.println("LBB REFERENCE***"+new Reference(LBBPREFIX+instance+LBBSUFFIX).toString()); + try { + lbb=(LoadBalancerBindingImpl) sfResolve(Reference.fromString(LBBPREFIX+instance+LBBSUFFIX)); + } catch (Exception e){System.out.println(e);} + //System.out.println("Adding a server..."); + serverSelector.addServer(hostname, hostsPort, lbb); + } + } + + public boolean disableServerInstance(int instance) { + String hostname = serverHosts.get(instance); + return serverSelector.removeServerZeroClose(hostname); + } + + public String lookUpHost(int instance) { + return serverHosts.get(instance); + } + + /** + * The main thread of the Balancer. + */ + private class BalancerThread implements Runnable { + private Thread thread = null; + private volatile boolean stopRequested = false; + + /** + * Constructor + */ + BalancerThread() { + } + + /** + * Start the thread + */ + void start() { + if (thread == null) { + // Create writer thread. + thread = new Thread(this, "SFBalancerThread"); + thread.start(); + } + } + + /** + * Stop the thread + */ + void stop() { + if (thread != null) { + stopRequested = true; + thread.interrupt(); + + try { + thread.join(); + } catch (InterruptedException ie) { + if (sfLog().isIgnoreEnabled()) sfLog().ignore(ie); + } + + thread = null; + } + } + + /** + * Accept new connections from clients and perform balancing to connect + * them to one of the servers. + */ + public void run() { + ServerSocketChannel server = null; // Server socket to accept connections from clients + try { + + try { + server = ServerSocketChannel.open(); + + InetSocketAddress address = new InetSocketAddress(port); + server.socket().bind(address); + } catch (IOException e) { + if (sfLog().isErrorEnabled()) sfLog().error("Error creating server socket: " + e.getMessage(),e); + + // Exit thread because encountered a severe problem + return; + } + + // + // Now loop to wait for connections from clients. + + while (!stopRequested) { + try { + SocketChannel client = server.accept(); + connectionCount += 1; + if (sfLog().isInfoEnabled()) sfLog().info(" - Accepted connection from " + client); + + // Select a server to handle the new client socket, and hand off processing to it. + serverSelector.addClient(client); + } catch (IOException ioe) { + if (sfLog().isErrorEnabled()) sfLog().error("Error accepting connection from client" +ioe.getMessage(),ioe); + } + } + + // + + } finally { + // Clean up the socket when we stop. + try { + if( server != null) { + server.close(); + } + } catch (IOException ioe) { + if (sfLog().isErrorEnabled()) sfLog().error("Error closing server socket " + ioe.getMessage(),ioe); + } + //and remove our self-reference + balancerThread = null; + } + if (sfLog().isDebugEnabled()) sfLog().debug("BalancerThread terminated."); + } + } +} Property changes on: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/BalancerImpl.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Connection.java =================================================================== --- trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Connection.java (rev 0) +++ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Connection.java 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,129 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +package org.smartfrog.examples.orchdws.balancer; + + +import java.io.IOException; +import java.nio.channels.SocketChannel; + +/** + + * <p> + * Description: Connection is used to maintain an association between the + * paired sockets connected to the client and server for a single client + * session. + * </p> + * + */ +class Connection { + private SocketChannel client; // The socket connection to the client + private SocketChannel server; // The socket connection to the server + private Server serverHost; // The parent Server object + boolean terminated; // Has this connection been terminated + + /** + * Constructor + * @param client The socket connection to the client + * @param server The socket connection to the server + * @param serverHost The parent Server object + */ + Connection(SocketChannel client, SocketChannel server, Server serverHost) { + this.client = client; + this.server = server; + this.serverHost = serverHost; + + terminated = false; + } + + /** + * Get socket connection to the client + * @return The socket connection to the client + */ + SocketChannel getClientSocket() { + return client; + } + + /** + * Get socket connection to the server + * @return The socket connection to the server + */ + SocketChannel getServerSocket() { + return server; + } + + /** + * Get parent Server Object + * @return The parent Server object + */ + Server getServer() { + return serverHost; + } + + /** + * If not already terminated, close the client and server socket + * connections. + */ + void terminate() { + if (!terminated) { + //Logger.log("Terminate connection " + toString()); + // Explicitly close the connections + try { + if (client.isOpen()) { + client.close(); + } + } catch (IOException ioe) { + // Ignore + //Logger.err("Error closing channels: " + ioe.getMessage()); + } + + try { + if (server.isOpen()) { + server.close(); + } + } catch (IOException ioe) { + // Ignore + //Logger.err("Error closing channel: " + ioe.getMessage()); + } + + terminated = true; + + // Tell the Server to clean up its state + serverHost.connectionClosed(this); + } + } + + /** + * Is connection closed? + * @return boolean + */ + boolean isTerminated() { + return terminated; + } + + /** + * Returns textual representation. + * + * @return textual representation + */ + public String toString() { + return "Connection from " + client + " to " + server; + } +} Property changes on: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/Connection.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/ConnectionRelay.java =================================================================== --- trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/ConnectionRelay.java (rev 0) +++ trunk/core/components/dependencies/src/org/smartfrog/examples/orchdws/balancer/ConnectionRelay.java 2011-03-17 17:06:58 UTC (rev 8532) @@ -0,0 +1,787 @@ +/* (C) Copyright 2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.examples.orchdws.balancer; + +import java.io.IOException; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.nio.channels.CancelledKeyException; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * ConnectionRelay moves data between all of the paired client and server + * socket connections for a specifc Server. It uses asynchronous IO functions + * to minimize the number of threads in the system. It works by using a + * selector to detect when either a client or server socket is available for + * reading. It then reads the data from the socket and attempts to write the + * data to the paired socket. If the data cannot be written, because the write + * buffer of the paired socket is full, it deselects the socket just read from + * from the selector to prevent additional data from being read, and shedules + * a write operation with the DelayedWriter instance. DelayedWriter waits for + * the paired socket to become writable again and writes the data to it. When + * all of the data has been written, the original socket is reenabled for + * reading to read more data. There is one instance of + * ConnectionRelay/DelayedWriter for each Server. ConnectionRelay and + * DelayedWriter each have their own thread to handle data movement between + * the paired sockets for clients connected to the coresponding server. There + * 2 threads are started per server in the system. + */ +class ConnectionRelay implements Runnable { + private Server server; // The parent Server + private boolean halfClose; // Close reading and writing independently + private Selector selector; // Selector used to detect data to be read on all sockets for all current Connections + private Map<SocketChannel,Connection> clients; // Map from client socket to corresponding Connection instance + private Map<SocketChannel, Connection> servers; // Map from ... [truncated message content] |
From: <an...@us...> - 2011-03-17 17:31:58
|
Revision: 8533 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8533&view=rev Author: anfarr Date: 2011-03-17 17:31:49 +0000 (Thu, 17 Mar 2011) Log Message: ----------- SFOS-1572: Check-in of moved constraints component logic Added Paths: ----------- trunk/core/components/constraints/ trunk/core/components/constraints/build.xml trunk/core/components/constraints/ivy.xml trunk/core/components/constraints/src/ trunk/core/components/constraints/src/org/ trunk/core/components/constraints/src/org/smartfrog/ trunk/core/components/constraints/src/org/smartfrog/sfcore/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseSolver.java trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseStatus.java trunk/core/components/constraints/test/ trunk/core/components/constraints/test/org/ trunk/core/components/constraints/test/org/smartfrog/ trunk/core/components/constraints/test/org/smartfrog/test/ trunk/core/components/constraints/test/org/smartfrog/test/system/ trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ConstraintsTest.java trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/CoreSolverTest.java trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/MockSolver.java trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/components.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn1.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn10.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn11.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn12.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn13.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn14.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn15.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn16.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn17.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn18.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn19.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn2.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn3.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn4.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn5.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn6.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn7.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctn9.sf trunk/core/components/constraints/test/org/smartfrog/test/system/constraints/ctnuv.sf Added: trunk/core/components/constraints/build.xml =================================================================== --- trunk/core/components/constraints/build.xml (rev 0) +++ trunk/core/components/constraints/build.xml 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,53 @@ +<?xml version="1.0"?> + +<!-- +/** (C) Copyright 1998-2009 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +--> + +<project name="constraints" default="dist" basedir="."> + +<description> +Introduction +============ +Constraint Extensions for SF: the parts that are specific to certain solvers such as Eclipse + +</description> + + <!-- override point --> + <property file="build.properties" /> + <property name="root.dir" location="../../" /> + + + <property name="is.component" value="true" /> + <property name="ivy.enabled" value="true"/> + <property name="system.tests" value="true"/> + + <!-- Import common stuff --> + <!--available file="../../common.xml" property="root.dir" value="../.."/--> + <import file="${root.dir}/common.xml"/> + + <echo message="==================================================================="/> + <echo message="= ${ant.project.name}"/> + +</project> + +<!-- End of file --> + Property changes on: trunk/core/components/constraints/build.xml ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/ivy.xml =================================================================== --- trunk/core/components/constraints/ivy.xml (rev 0) +++ trunk/core/components/constraints/ivy.xml 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,60 @@ +<?xml version="1.0" ?> +<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?> +<ivy-module version="1.0"> + <info organisation="org.smartfrog" module="sf-constraints"> + <license name="LGPL"/> + <ivyauthor name="Hewlett-Packard" url="http://www.smartfrog.org"/> + <description> + Solver specific constraint extensions + </description> + </info> +<!-- FIXME: Ivy 1.4.1 buildlist bug + <configurations defaultconfmapping="default"> + <include file="../../antbuild/ivy/configurations.xml"/> + </configurations> + --> +<configurations defaultconfmapping="default"> + <conf name="default" extends="master,runtime" + description="default configuration contains artifacts and runtime dependencies"/> + <conf name="build" visibility="private" + description="artifacts needed to build the application"/> + <conf name="compile" visibility="private" extends="runtime" + description="artifacts needed to compile the application"/> + <conf name="daemon" visibility="private" + description="the classpath needed to run smartfrog daemons"/> + <conf name="test" extends="default,compile" + description="the classpath needed to run tests"/> + <conf name="master" description="contains the artifact but no dependencies"/> + <conf name="redist" description="redistributals excluding smartfrog artifacts"/> + <conf name="runtime" description="runtime but not the artifact" + extends="redist"/> + <conf name="documentation" + description="all documentation artifacts"/> +</configurations> + + <publications> + <!--get the artifact from our module name--> + <artifact conf="master"/> + </publications> + <dependencies> + <dependency org="org.smartfrog" + name="smartfrog" + changing="true" + rev="latest.integration" + conf="compile->services;runtime->services;daemon->services"/> + <dependency org="org.smartfrog" + name="sf-tasks" + changing="true" + rev="latest.integration" + conf="build->default"/> + <dependency org="org.smartfrog" + name="sf-testharness" + changing="true" + rev="latest.integration" + conf="test->default"/> + <dependency org="eclipse-clp" + name="eclipse-clp" + rev="${eclipse-clp.version}" + conf="redist->default"/> + </dependencies> +</ivy-module> Property changes on: trunk/core/components/constraints/ivy.xml ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,53 @@ +/** (C) Copyright 1998-2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + +/** + * Interface for Component Description browsers used to display sfComfig hierarchy for the purpose of setting user variables + * @author anfarr + * + */ +public interface CDBrowser { + + /** + * Sets EclipseStatus object pertaining to status information for browser + * @param es + */ + void setES(EclipseStatus es); + + /** + * Add attribute to the hierarchy to be displayed + * @param d -- my parent as unspecified object + * @param av -- my attribute name / value as unspecified object + * @param showme -- am I in the immediate component description to be displayed? + * @return tree node which will be used later on to add child attributes to + */ + Object attr(Object d, Object av, boolean showme); + + /** + * Redraw the browser + */ + void redraw(); + + /** + * Kill the browser... + */ + void kill(); +} Property changes on: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/CDBrowser.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,156 @@ +/** (C) Copyright 1998-2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ + +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + +import java.util.Collection; +import java.util.Iterator; + +import org.smartfrog.sfcore.languages.sf.constraints.FreeVar; + +import com.parctechnologies.eclipse.Atom; +import com.parctechnologies.eclipse.CompoundTermImpl; + +/** + * Records information for a single attribute, used in EclipseSolver's sfConfig browser for user variables + * @author anfarr + * + */ +class EclipseCDAttr { + /** + * Name of attribute + */ + private String name; + + /** + * Value of attribute + */ + private Object val; + + /** + * Range of attribute + */ + private Object range; + + /** + * Whether set + */ + private boolean set; + + /** + * Eclipse Solver + */ + private EclipseSolver solver; + + /** + * Constructor, + * @param solver Eclipse Solver + * @param name Name of attribute + * @param val Value of attribute + */ + EclipseCDAttr(EclipseSolver solver, String name, Object val){ + this.solver = solver; + this.name = name; + this.val = val; + } + + /** + * Is attribute value set + * @return Is value set? + */ + boolean isSet(){ + return set; + } + + /** + * Set whether attribute value is set + * @param set Is set? + */ + void set(boolean set){ + this.set =set; + } + + /** + * Set range of attribute + * @param range + */ + void setRange(Object range){ + this.range =range; + } + + /** + * Set value of attribute + * @param val + */ + void setValue(Object val){ + this.val =val; + } + + /** + * Process setting of attribute value (from range) + * @param entry Attribute value + * @return Whether processing is successful + */ + boolean process_sel(String entry){ + solver.setEclipseCDAttr(this); + Collection c = (Collection) range; + Iterator iter = c.iterator(); + while (iter.hasNext()){ + String el = iter.next().toString(); + if (el.equals(entry)){ + if (val instanceof FreeVar && ((FreeVar)val).getRange() instanceof Boolean){ + if (entry.equals("true")) entry="1"; + else entry="0"; + } + solver.javaToEclipse(new CompoundTermImpl("set", new Atom(name), new Atom(entry))); + return true; + } + } + return false; + } + + /** + * Gets range of attribute as a string + * @return range as string + */ + public String getRangeAsString(){ + return range.toString(); + } + + /** + * Gets attribute name + * @return attribute name + */ + public String getAttrName(){ + return name; + } + + public Object getValue(){ + return val; + } + + public String toString(){ + if (set){ + return name +" has value: "+ val; + } else { + return name +" ranges over: "+ range; + } + } +} Property changes on: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDAttr.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,283 @@ +/** (C) Copyright 1998-2008 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + + +import javax.swing.*; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.net.URL; + + +/** + * Browser for displaying sfComfig hierarchy for the purpose of setting user variables + * + * @author anfarr + */ +public class EclipseCDBrowser extends JFrame implements CDBrowser { + private JScrollPane scrollPane; + private JLabel label; + private JLabel undoLabel; + private JTextField entry; + private JButton setButton; + private JButton undoButton; + private JButton doneButton; + private EclipseStatus eclipseStatus; + private EclipseCDAttr eclipseCDAttr; + private DefaultMutableTreeNode visnode; + private DefaultMutableTreeNode root; + private DefaultTreeModel model; + private JTree tree; + private static final int DEFAULT_WIDTH = 600; + private static final int DEFAULT_HEIGHT = 400; + /** + * Kill the browser... + */ + public void kill() { + setVisible(false); + } + + /** + * Sets EclipseStatus object pertaining to status information for browser + * + * @param est + */ + public void setES(EclipseStatus est) { + eclipseStatus = est; + } + + /** + * Add attribute to the hierarchy to be displayed + * + * @param d -- my parent as unspecified object + * @param av -- my attribute name / value as unspecified object + * @param showme -- am I in the immediate component description to be displayed? + * @return tree node which will be used later on to add child attributes to + */ + public Object attr(Object d, Object av, boolean showme) { + DefaultMutableTreeNode node = new DefaultMutableTreeNode(av); + + if (showme && visnode == null) { + visnode = node; + } + + if (root == null) { + root = node; + } else { + ((DefaultMutableTreeNode) d).add(node); + } + return node; + } + + /** + * Redraws browser... + */ + public void redraw() { + if (!isVisible()) { + init(); + } else { + + if (eclipseStatus.isBack()) { + eclipseStatus.setBack(false); + label.setText("Attribute setting undone. " + label.getText()); + setButton.setEnabled(false); + } + int undo = eclipseStatus.getUndo(); + if (undo > 0) { + undoLabel.setText(eclipseStatus.getUndoLabel()); + undoButton.setText("Undo (" + undo + ")"); + undoButton.setEnabled(true); + } else { + undoLabel.setText(""); + undoButton.setText("Undo"); + undoButton.setEnabled(false); + } + doneButton.setEnabled(eclipseStatus.isDone()); + + repaint(); + } + } + + /** + * Reset browser to initial look... + */ + void reset_display() { + label.setText("Click on an attribute with range to set its value"); + entry.setText(""); + setButton.setEnabled(false); + entry.setEnabled(false); + } + + /** + * Initialise browser... + */ + void init() { + setTitle("sfConfig Browser"); + setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); + + // the root of the class tree is Object + model = new DefaultTreeModel(root); + tree = new JTree(model); + + // set up selection mode + tree.addTreeSelectionListener(new + TreeSelectionListener() { + public void valueChanged(TreeSelectionEvent event) { + // the user selected a different node--update description + TreePath path = tree.getSelectionPath(); + if (path == null) { + return; + } + DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); + Object uobj = selectedNode.getUserObject(); + if (uobj instanceof EclipseCDAttr) { + eclipseCDAttr = (EclipseCDAttr) uobj; + if (eclipseCDAttr.isSet()) { + reset_display(); + } else { + setButton.setEnabled(false); + label.setText(eclipseCDAttr.toString()); + entry.setEnabled(true); + } + } else { + reset_display(); + } + } + }); + + + int mode = TreeSelectionModel.SINGLE_TREE_SELECTION; + tree.getSelectionModel().setSelectionMode(mode); + + Box vbox = Box.createVerticalBox(); + add(vbox, BorderLayout.CENTER); + scrollPane = new JScrollPane(tree); + vbox.add(scrollPane); + + label = new JLabel(); + Box labelbox = Box.createHorizontalBox(); + labelbox.add(Box.createHorizontalGlue()); + labelbox.add(label); + labelbox.add(Box.createHorizontalGlue()); + vbox.add(labelbox); + + vbox.add(Box.createVerticalStrut(10)); + entry = new JTextField(); + vbox.add(Box.createVerticalGlue()); + vbox.add(entry); + vbox.add(Box.createVerticalStrut(10)); + + //set up selection mode + entry.addKeyListener(new KeyAdapter() { + public void keyTyped(KeyEvent event) { + setButton.setEnabled(true); + repaint(); + } + }); + + + JPanel hbox = new JPanel(); + hbox.setLayout(new GridLayout(2, 3)); + vbox.add(hbox); + + setButton = new JButton("Set"); + Box setbox = Box.createHorizontalBox(); + setbox.add(setButton); + setbox.add(Box.createHorizontalGlue()); + hbox.add(setbox); + + undoButton = new JButton("Undo"); + undoButton.setEnabled(false); + Box undobox = Box.createHorizontalBox(); + undobox.add(Box.createHorizontalGlue()); + undobox.add(undoButton); + undobox.add(Box.createHorizontalGlue()); + hbox.add(undobox); + + doneButton = new JButton("Done"); + doneButton.setEnabled(false); + Box donebox = Box.createHorizontalBox(); + donebox.add(Box.createHorizontalGlue()); + donebox.add(doneButton); + hbox.add(donebox); + + undoLabel = new JLabel(""); + hbox.add(new JPanel()); + hbox.add(undoLabel); + + System.out.println("init..4"); + + + reset_display(); + + setButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + boolean succ = eclipseCDAttr.process_sel(entry.getText()); + if (succ) { + label.setText("Attribute set successfully"); + setButton.setEnabled(false); + entry.setEnabled(false); + } else { + label.setText( + "Value selected not in range:" + eclipseCDAttr.getRangeAsString() + ". Please try again"); + } + entry.setText(""); + } + }); + + undoButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + eclipseStatus.undo(); + } + }); + + doneButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + eclipseStatus.done(); + } + }); + + tree.makeVisible(new TreePath(model.getPathToRoot(visnode))); + + URL url = getClass().getResource("HP_ICON.PNG"); + if (url != null) { + Image image = Toolkit.getDefaultToolkit().getImage(url); + if (image != null) { + setIconImage(image); + } + } + + //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + setVisible(true); + } + + + } + Property changes on: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseCDBrowser.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,113 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + +import com.parctechnologies.eclipse.CompoundTerm; +import com.parctechnologies.eclipse.EclipseEngine; +import com.parctechnologies.eclipse.EclipseException; +import org.smartfrog.sfcore.languages.sf.constraints.*; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedHashMap; + +/** + * created 20-Sep-2010 15:34:10 + */ + +public class EclipseModelMatcher extends BaseModelMatcher{ + + /** + * Property prefix for theory files... + */ + private static final String MATCHERS_DIR_PREFIX = "matchers/"; + private static final String MATCHERS_FILE_SUFFIX = ".ecl"; + private static final String MATCHERS_DEFAULT = "default"; + + private static final String E_INCOMPATIBLECAPREQ = "Incompatible types: cap to req:"; + + + private EclipseEngine eclipse; + private String eclipseDir; + + + public EclipseModelMatcher() throws ModelMatcherEngineNotFound, ModelMatcherSelectFailure { + CoreSolver solver = CoreSolver.getInstance(); + if (solver instanceof EclipseSolver){ + eclipse=((EclipseSolver)solver).getEngine(); + eclipseDir= ((EclipseSolver) solver).getEclipseDir(); + } else throw ModelMatcherEngineNotFound.forward(); + + selectDefaultMatcher(); + } + + @Override + public void selectDefaultMatcher() throws ModelMatcherSelectFailure { + selectMatcher(MATCHERS_DEFAULT); + } + + //Need to check that compiling in a new one overwrites existing... + public void selectMatcher(String name) throws ModelMatcherSelectFailure { + try { + eclipse.compile(new File(eclipseDir + EclipseSolver.ECLIPSE_SWITCH + MATCHERS_DIR_PREFIX + name + MATCHERS_FILE_SUFFIX)); + } catch (Exception e) { + throw ModelMatcherSelectFailure.forward(e); + } + } + + @Override + public boolean match(LinkedHashMap<String, Object> componentData, LinkedHashMap<String, Object> modelData) throws IOException, IncompatibleMatchingCapsToReqs { + + HashMap<String, Object[]> current = getCurrentCapacitiesRecord(); + + String imageCapsList = processCapsIntoPrologList(current); + String componentsList = processIntoPrologList(componentData); + String modelList = processIntoPrologList(modelData); + + String goal = "match(" + componentsList + ", " + modelList + ", " + imageCapsList + ")"; + System.out.println("GOAL: "+goal); + + try { + CompoundTerm result = eclipse.rpc(goal); + //We ignore result for now... + } catch (EclipseException e) { + return false; + } + + //Subtract from image capacities... + for (String key: current.keySet()){ + Object[] record = current.get(key); + Object sub = componentData.get(key); + + if (record[1] instanceof Integer){ + if (sub instanceof Integer){ + record[1] = (Integer)record[1] - (Integer)sub; + } else throw IncompatibleMatchingCapsToReqs.forward(E_INCOMPATIBLECAPREQ+" key:"+key); + } else if (record[1] instanceof Float) { + if (sub instanceof Float) { + record[1] = (Float) record[1] - (Float) sub; + } else throw IncompatibleMatchingCapsToReqs.forward(E_INCOMPATIBLECAPREQ + " key:" + key); + } + } + + return true; + } +} Property changes on: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseModelMatcher.java ___________________________________________________________________ Added: svn:executable + * Added: trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseSolver.java =================================================================== --- trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseSolver.java (rev 0) +++ trunk/core/components/constraints/src/org/smartfrog/sfcore/languages/sf/constraints/eclipse/EclipseSolver.java 2011-03-17 17:31:49 UTC (rev 8533) @@ -0,0 +1,1071 @@ +/** (C) Copyright 1998-2008 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.sfcore.languages.sf.constraints.eclipse; + + +import java.io.File; +import java.io.IOException; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Vector; + +import org.smartfrog.SFParse; +import org.smartfrog.SFSystem; +import org.smartfrog.sfcore.common.Context; +import org.smartfrog.sfcore.common.SFNull; +import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.common.SmartFrogRuntimeException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.languages.sf.DefaultParser; +import org.smartfrog.sfcore.languages.sf.constraints.ConstraintResolutionState; +import org.smartfrog.sfcore.languages.sf.constraints.CoreSolver; +import org.smartfrog.sfcore.languages.sf.constraints.FreeVar; +import org.smartfrog.sfcore.languages.sf.constraints.ConstraintResolutionState.ConstraintContext; +import org.smartfrog.sfcore.languages.sf.functions.Constraint; +import org.smartfrog.sfcore.languages.sf.sfcomponentdescription.SFComponentDescriptionImpl; +import org.smartfrog.sfcore.languages.sf.sfreference.SFApplyReference; +import org.smartfrog.sfcore.languages.sf.sfreference.SFReference; +import org.smartfrog.sfcore.reference.AttribReferencePart; +import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.reference.ReferencePart; +import org.smartfrog.sfcore.reference.ReferenceResolver; +import org.smartfrog.sfcore.security.SFClassLoader; + +import com.parctechnologies.eclipse.Atom; +import com.parctechnologies.eclipse.CompoundTerm; +import com.parctechnologies.eclipse.CompoundTermImpl; +import com.parctechnologies.eclipse.EXDRInputStream; +import com.parctechnologies.eclipse.EXDROutputStream; +import com.parctechnologies.eclipse.EclipseEngine; +import com.parctechnologies.eclipse.EclipseEngineOptions; +import com.parctechnologies.eclipse.EmbeddedEclipse; +import com.parctechnologies.eclipse.FromEclipseQueue; +import com.parctechnologies.eclipse.QueueListener; +import com.parctechnologies.eclipse.ToEclipseQueue; + +/** + * Implementation of solver for Eclipse + */ +public class EclipseSolver extends CoreSolver implements Runnable, QueueListener { + + /** + * Default Eclipse options + */ + private EclipseEngineOptions eclipseEngineOptions; + + /** + * Eclipse engine + */ + private EclipseEngine eclipse; + + /** + * Object to send to eclipse side + */ + private Object get_value; + + /** + * Thread for main eclipse goal + */ + private Thread goalThread; + + /** + * sfConfig browser for purpose of setting user variables + */ + private CDBrowser cdBrowser; + + /** + * Are there user variables? + */ + private boolean isUserVars; + + /** + * Component description pertaining to Constraint type being solved + */ + private ComponentDescription solveCD; + + /** + * Queue for coms TO eclipse + */ + private ToEclipseQueue javaToEclipseQueue; + + /** + * Queue for coms FROM eclipse + */ + private FromEclipseQueue eclipseToJavaQueue; + + /** + * Latest constraint goal has finished? + */ + private boolean consFinished = false; + + /** + * Stores any exception thrown from Eclipse thread + */ + private Exception generalError = null; + + /** + * Location (relative switch) of eclipse theory file specific to smartfrog constraint solving within Eclipse + * installation + */ + static final String ECLIPSE_SWITCH = "/smartfrog/"; + + /** + * Property prefix for theory files... + */ + private static final String THEORYFILE_PREFIX = "org.smartfrog.sfcore.languages.sf.constraints.theoryFile"; + + /** + * Property indicating where to find eclipse installation + */ + public static final String ECLIPSEDIR_SPECIFIER = "org.smartfrog.sfcore.languages.sf.constraints.eclipseDir"; + //NOTE: eclipseDir property is a temporary solution pending resolution of best way to include eclipse in release... + + /** + * Property indicating the CD Browser to use + */ + private static final String USERVAR_BROWSER = "org.smartfrog.sfcore.languages.sf.constraints.CDBrowser"; + + /** + * Resolution state for constraint solving... + */ + private ConstraintResolutionState resolutionState; + + /** + * Status of solving for reflection in user var sfConfig browser + */ + private EclipseStatus eclipseStatus; + + /** + * Attributes with ranges to be sought... + */ + private Vector<EclipseCDAttr> rangeAttrs = new Vector<EclipseCDAttr>(); + + /** + * Current attribute in user var sfConfig browser being manipulated + */ + private EclipseCDAttr currentCDAttr; + private static final String DEFAULT_THEORY = "core.ecl"; + + private static long g_count=0x0; + private Calendar g_start; + private String eclipseDir; + + /** + * Protected constructor + */ + public EclipseSolver() throws SmartFrogRuntimeException { + try { + prepareSolver(); + } catch (SmartFrogResolutionException e) { + SFSystem.sfLog().debug("EXCEPTION: "+e); + throw e; + } + } + + public EclipseEngine getEngine(){ + return eclipse; + } + + public String getEclipseDir() { + return eclipseDir; + } + + /** + * Set cuurrent attribute in user var sfConfig browser being manipulated + */ + public void setEclipseCDAttr(EclipseCDAttr ecda) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + currentCDAttr = ecda; + } + + /** + * Eclipse main goal to run in secondary thread + */ + public void run() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + try { + eclipse.rpc("sfsolve"); + } catch (Exception e) { + + generalError = e; + yieldLockFromECRThread(); + } + } + + + /** + * Constraints are possible (ie supported) if this class is loaded... + */ + @Override + public boolean getConstraintsPossible() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + return true; + } + + /** + * Prepare the solver + */ + private void prepareSolver() throws SmartFrogResolutionException { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //Prepare theory... + + String unable = "Unable to load Eclipse-based solver:"; + + // Get Eclipse Installation Directory... + eclipseDir = System.getProperty(ECLIPSEDIR_SPECIFIER); + if (eclipseDir == null) { + eclipseDir = System.getenv("ECLIPSEDIRECTORY"); + } + + //Throw on lack of info re eclipse directory... + if (eclipseDir == null) { + throw new SmartFrogResolutionException( + unable + " eclipse directory property unspecified (" + ECLIPSEDIR_SPECIFIER + + ")"); + } + + //Set up eclipse... + eclipseEngineOptions = new EclipseEngineOptions(new File(eclipseDir)); + + // Connect the Eclipse's standard streams to the JVMs + eclipseEngineOptions.setUseQueues(false); + + // Initialise Eclipse + try { + eclipse = EmbeddedEclipse.getInstance(eclipseEngineOptions); + } catch (Throwable e) { + throw new SmartFrogResolutionException(unable + " can not get eclipse instance, " + e, e); + } + + int idx = 0; + String theoryFile = System.getProperty(THEORYFILE_PREFIX + idx); + if (theoryFile == null) { + theoryFile = DEFAULT_THEORY; + } + + while (theoryFile != null) { + //Consult core theory files + //eclipseDir/... is not necessarily the best place to put the theory files... + try { + eclipse.compile(new File(eclipseDir + ECLIPSE_SWITCH + theoryFile)); + } catch (Exception e) { + throw new SmartFrogResolutionException( + unable + " can not compile theory source: " + theoryFile + " , " + e, e); + } + idx++; + theoryFile = System.getProperty(THEORYFILE_PREFIX + idx); + } + + // Set up the java representation of two queue streams + try { + javaToEclipseQueue = eclipse.getToEclipseQueue("java_to_eclipse"); + eclipseToJavaQueue = eclipse.getFromEclipseQueue("eclipse_to_java"); + eclipseToJavaQueue.setListener(this); + } catch (Exception e) { + throw new SmartFrogResolutionException(unable + " general queue exception, " + e, e); + } + + resetResolutionState(); + } + + + public void doConstraintsWork(Object key) throws SmartFrogResolutionException { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + SFSystem.sfLog().debug("key: "+key); + + //if (resolutionState != null){ + Vector<FreeVar> vec = resolutionState.removeLabellingRecordVector(key); + if (vec!=null) { + Constraint constraint = new Constraint(); + ComponentDescription comp = new SFComponentDescriptionImpl(); + comp.sfContext().setOriginatingDescr(comp); + + //Add vars... + try { + for (FreeVar fv: vec){ + String id="unique"+DefaultParser.nextId++; + comp.sfAddAttribute(id, fv); + comp.sfAddTag(id, "sfConstraintAutoVar"); + } + } catch (SmartFrogRuntimeException sfre){ throw new SmartFrogResolutionException(sfre);} + + constraint.doit(comp.sfContext(), null, (ReferenceResolver)null); + } + //} + } + + public void addAutoVar(Object key, FreeVar var) throws SmartFrogResolutionException { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + resolutionState.addLabellingRecord(key, var); + } + + + /** + * Reset "backtracked to" Context information + */ + @Override + public void resetDoneBacktracking() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) { + resolutionState.resetDoneBacktracking(); + //} + } + + /** + * On backtracking, we have backtracked to the returned context + * + * @return Context to which backtracking has unwound to, null if no backtracking + */ + @Override + public ConstraintContext hasBacktrackedTo() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) + return resolutionState.hasBacktrackedTo(); + //else return null; + } + + /** + * Should we undo actions involving contexts and FreeVars? + * + * @param undo Should we? + */ + @Override + public void setShouldUndo(boolean undo) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) { + resolutionState.setConstraintsShouldUndo(undo); + //} + } + + /** + * Adds single undo action to current lhr for undo attribute setting in a Context + * + * @param ctxt context for undo action + * @param key key to undo put value + * @param value value to restore + */ + @Override + public void addUndoPut(Context ctxt, Object key, Object value) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + SFSystem.sfLog().debug("key:"+key+", value"+value); + + //if (resolutionState != null) { + resolutionState.addUndoPut(ctxt, key, value); + //} + } + + /** + * Adds single undo action to current lhr for undoing FreeVar info setting + * + * @param fv FreeVar + */ + @Override + public void addUndoFVInfo(FreeVar fv) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) { + resolutionState.addUndoFVInfo(fv); + //} + } + + /** + * Adds single undo action to current lhr for undoing FreeVar type string setting + * + * @param fv FreeVar + */ + @Override + public void addUndoFVTypeStr(FreeVar fv) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //if (resolutionState != null) { + resolutionState.addUndoFVTypeStr(fv); + //} + } + + @Override + public void addUndoFVAutoVarEffect(FreeVar fv, Vector<Reference> autoEffects){ + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + resolutionState.addUndoFVAutoVarEffect(fv, autoEffects); + } + + @Override + public void addUndoFVAutoVarEffect(FreeVar fv){ + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + resolutionState.addUndoFVAutoVarEffect(fv); + } + + + /** + * Stop solving altogether + */ + @Override + public void stopSolving() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + javaToEclipse("sfstop"); + goalThread = null; + resetResolutionState(); + Calendar stop = new GregorianCalendar(); + if (isVerbose()){ + System.out.println("Start:"+g_start); + System.out.println("Stop:"+stop); + System.out.println("Label counts:"+g_count); + } + } + + private boolean isVerbose() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + return false; + } + + public void fail() throws Exception { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //Assume that we are up... + get_value = "fail"; + + //Let rip... + doIt(); + } + + + public void doIt() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + consFinished = false; + javaToEclipse(); + + //Lock me to make sure I don't complete before constraint eval does... + synchronized(this){ + while (!consFinished){ + try { + wait(); + }catch (Exception e){}; + } + } + + //Has Eclipse solver thread failed? + if (generalError != null) { + Exception generalErrorold = generalError; + goalThread = null; + generalError = null; + resetResolutionState(); + throw new CoreSolverFatalError(generalErrorold); + } + } + + void resetResolutionState(){ + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + resolutionState = new ConstraintResolutionState(); + g_count=0; + g_start = new GregorianCalendar(); + } + + /** + * Solve a Constraint goal + */ + @Override + public void solve(ConstraintContext cc, Vector attrs, Vector values, Vector goal, Vector autos, + boolean isuservars, HashMap<FreeVar,Object> assigns) throws Exception { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + + //Set comp as current solving comp descr + solveCD = cc.getCD(); + + //Set is user vars? + isUserVars = isuservars; + + //Construct goal + String _attrs = mapValueJE(attrs); + String _values = mapValueJE(values); + String _goal = mapValueJE(goal); + String _autos = mapValueJE(autos); + String verbose = (isVerbose() ? "true" : "false"); + + String assign_s="["; + boolean first=true; + Iterator iter = assigns.keySet().iterator(); + while (iter.hasNext()){ + FreeVar fv = (FreeVar) iter.next(); + Object val = assigns.get(fv); + if (first) first=false; + else assign_s += ", "; + assign_s += "("+val+","+mapValueJE(fv)+")"; + } + assign_s +="]"; + + get_value = "sfsolve(" + _attrs + ", " + _values + ", " + + resolutionState.addConstraintEval(cc) + ", " + _goal + ", " + _autos + ", " + verbose + ", "+ assign_s + + ")"; + + if (isVerbose()) System.out.println(get_value); + + //Allocate new thread for goal and start it + if (goalThread == null) { + goalThread = new Thread(this); + goalThread.start(); + } + + //Let rip + doIt(); + + } + + /** + * Maps Java object to String for transfer to Eclipse + * + * @param v object to be transformed + * @return eclipse string + */ + private String mapValueJE(Object v) throws SmartFrogResolutionException { + return mapValueJE(v, false); + } + + /** + * Maps Java object to String for transfer to Eclipse + * + * @param v object to be transformed + * @param quoted indicates whether Strings should be double quoted + * @return eclipse string + */ + public String mapValueJE(Object v, boolean quoted) throws SmartFrogResolutionException { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + SFSystem.sfLog().debug("VALUE: "+v); + + if (v instanceof FreeVar) { + FreeVar fv = (FreeVar) v; + if (fv.getConsEvalKey() != null) { + if (fv.getConsEvalIdx() == -1) { + fv.setConsEvalIdx(resolutionState.getConsEvalIdx() + 1); //+1 as yet to add entry + + String range_s = "null"; + Object range = fv.getRange(); + if (range != null) { + if (range instanceof String) { + range_s = (String) range; + } else if (range instanceof Vector) { + range_s = mapValueJE(range); + } else if (range instanceof Integer || range instanceof Boolean) { + range_s = "integer"; + } else { + throw new SmartFrogResolutionException("Invalid range specifier for FreeVar: " + v); + } + } + + Object defVal = fv.getDefVal(); + String defVal_s = (defVal != null ? ", " + defVal.toString() : ""); + return "sfvar(" + range_s + defVal_s + ")"; + + } else { + return "sfref(" + fv.getConsEvalIdx() + ", " + fv.getConsEvalKey() + ")"; + } + } else { + return v.toString(); + } + } else if (v instanceof Number) { + return v.toString(); + } else if (v instanceof Vector) { + String val = "["; + boolean first = true; + Iterator it = ((Vector) v).iterator(); + while (it.hasNext()) { + if (first) { + first = false; + } else { + val += ", "; + } + + val += mapValueJE(it.next(), quoted); + } + val += "]"; + return val; + } else if (v instanceof String) { + if (quoted) { + return "\"" + v + "\""; + } else { + return (String) v; + } + } else if (v instanceof SFNull) { + return "sfnull"; + } else if (v instanceof SFReference) { + SFReference vref = (SFReference)v; + if (vref.size()==0) return null; + ReferencePart rp = ((SFReference) v).firstElement(); + if (rp instanceof AttribReferencePart) { + String ret_s = ((AttribReferencePart) rp).getValue().toString(); + if (quoted) ret_s = "\"" + ret_s + "\""; + return ret_s; + } else { + return null; + } + } else if (v instanceof ComponentDescription) { + return "sfcd"; + } else if (v instanceof Boolean) { + return ((Boolean) v).booleanValue()?"1":"0"; + } else { + return null; + } + } + + + /** + * Maps Eclipse object to Java object after transfer from Eclipse + * + * @param v object to be transformed + * @return transformed object + */ + private Object mapValueEJ(Object v) { + return mapValueEJ(v, false); + } + + /** + * Maps Eclipse object to Java object after transfer from Eclipse + * + * @param v object to be transformed + * @param ref_create indicates whether references should be created for atoms -- used for subtyping directives + * @return transformed object + */ + private Object mapValueEJ(Object v, boolean ref_create) { + SFSystem.sfLog().debug("VALUE: " + v); + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + if (v == null) { + return new FreeVar(); + } else if (v.equals(Collections.EMPTY_LIST)) { + return new Vector(); + } else if (v instanceof Number) { + return v; + } else if (v instanceof Collection) { + Vector result = new Vector(); + Iterator it = ((Collection) v).iterator(); + while (it.hasNext()) { + result.add(mapValueEJ(it.next(), ref_create)); + } + return result; + } else if (v instanceof String) { + return v; + } else if (v instanceof Atom) { + Atom va = (Atom) v; + if (va.functor().equals("sfnull")) { + return SFNull.get(); + } else { + String va_s = va.functor(); + try { + if (ref_create) { + return Reference.fromString(va_s); + } + return va_s; + } catch (SmartFrogResolutionException sfre) { + throw new RuntimeException( + "mapValueEJ: Trouble in creating reference from attribute string for subtyping. ", + sfre); + } + } + } else { + throw new RuntimeException("mapValueEJ: unknown data *from* solver " + v); + } + } + + + /** + * Populate sfConfig browser for setting user variables... + */ + private void populateBrowser() { + Object root = cdBrowser.attr(null, "sfConfig", false); + populateBrowser(orig, root, false); + } + + /** + * Populate sfConfig browser for setting user variables... + * + * @param cd current component description being added to browser + * @param root browser object corresponding to sfConfig + * @param showme whether I should be shown -- determined by whether I am the Constraint component description + * currently being solved... + */ + private void populateBrowser(ComponentDescription cd, Object root, boolean showme) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + Iterator attriter = cd.sfAttributes(); + Context cxt = cd.sfContext(); + //String cxts = create_ref_str(cd); + while (attriter.hasNext()) { + Object attr = attriter.next(); + Object val = null; + + try { + val = cxt.sfResolveAttribute(attr); + } catch (Exception e) { + throw new RuntimeException("Can not resolve attribute when populating browser with attribute "+attr, e); + } + + if (val instanceof SFApplyReference) { + SFApplyReference val_ar = (SFApplyReference) val; + val = val_ar.getComponentDescription(); + } + + if (val instanceof ComponentDescription) { + boolean showkids = (!showme && solveCD == val); + Object chroot = cdBrowser.attr(root, attr.toString(), showme); + populateBrowser((ComponentDescription) val, chroot, showkids); + } else { + EclipseCDAttr ecda = new EclipseCDAttr(this, attr.toString(), val); + + cdBrowser.attr(root, ecda, showme); + try { + if (cd == solveCD && cxt.sfContainsTag(attr, "sfConstraintUserVar") && val instanceof FreeVar) { + rangeAttrs.add(ecda); + ecda.set(false); + } else { + ecda.set(true); + } + } catch (Exception e) { + throw new RuntimeException("Can not check attribute for tag", e); + } + + } + + } + + } + + /** + * Kill sfConfig browser for user variables + */ + public void killBrowser() { + cdBrowser.kill(); + } + + /** + * Communicate supplied parameter to Eclipse side + * + * @param val Object to be sent + */ + public void javaToEclipse(Object val) { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + get_value = val; + javaToEclipse(); + } + + /** + * Communicate m_get_val to Eclipse side + */ + public void javaToEclipse() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + try { + javaToEclipseQueue.setListener(this); + } catch (Exception e) { + throw new RuntimeException("Unanable to reset JtoE listener", e); + } + } + + + /** + * Initiated by Eclipse side -- process user variables in Constraint description... + */ + void sfuser() { + if (SFSystem.sfLog().isDebugEnabled()) SFSystem.sfLog().debug(Thread.currentThread().getStackTrace()[1]); + + //If no user variables, then we are done... + if (!isUserVars) { + javaToEclipse(new Atom("done")); + return; + } + + //Get sfConfig browser class + String classname = System.getProperty(USERVAR_BROWSER); + if (classname == null) { + throw new RuntimeException("Can not instantiate CD Browser, classname property not set..."); + } + + try { + cdBrowser = (CDBrowser) SFClassLoader.forName(classname).newInstance(); + } catch (Exception e) { + throw new RuntimeException("Can not instantiate CD Browser", e); + } + + //Populate the browser + + populateBrowser(); + + //User variables to be set in m_rangeAttrs, communicate these to eclipse side to get ranges... + if (rangeAttrs.size() != 0) { + + List ranges = new LinkedList(); + Iterator raiter = rangeAttrs.iterator(); + while (raiter.hasNext()) { + EclipseCDAttr ecda = (EclipseCDAttr) raiter.next(); + ranges.add(ecda.getAttrName()); + ... [truncated message content] |
From: <st...@us...> - 2011-06-07 16:23:29
|
Revision: 8594 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8594&view=rev Author: steve_l Date: 2011-06-07 16:23:22 +0000 (Tue, 07 Jun 2011) Log Message: ----------- SFOS-1598 Create grinstall Groovy Installer component Added Paths: ----------- trunk/core/components/grinstall/ trunk/core/components/grinstall/build.xml trunk/core/components/grinstall/doc/ trunk/core/components/grinstall/doc/README.txt trunk/core/components/grinstall/doc/dependencies.txt trunk/core/components/grinstall/ivy.xml trunk/core/components/grinstall/src/ trunk/core/components/grinstall/src/org/ trunk/core/components/grinstall/src/org/smartfrog/ trunk/core/components/grinstall/src/org/smartfrog/services/ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/Component.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/ComponentState.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/IComponent.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/base.sf trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/ISource.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/Source.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/DelegatingScript.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/GroovyTask.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/Helper.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/ITask.groovy Added: trunk/core/components/grinstall/build.xml =================================================================== --- trunk/core/components/grinstall/build.xml (rev 0) +++ trunk/core/components/grinstall/build.xml 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<project name="grinstaller" default="default"> + + <description> + This build file exists to build and test the SmartFrog installer + + It generates + * installer-${installer.version}.jar, containing the binaries of installer and the default + * SF description files. + + These artifacts can be published locally, or written to the + ${antbuild.dir}/repository/internal repository, where + ${antbuild.dir} defaults to ../antbuild + </description> + + <!-- override point --> + <property file="build.properties"/> + <property name="root.dir" location="../../"/> + <property name="ivy.enabled" value="true"/> + <property name="system.tests" value="false"/> + + <!-- Import common stuff --> + <import file="${root.dir}/common.xml"/> + + <property name="is.component" value="true"/> + <property name="org.apache.commons.logging.diagnostics.dest" value="STDERR"/> + + <echo message="==================================================================="/> + <echo message="= ${ant.project.name}"/> + + + <target name="pre-compile" depends="common.pre-compile, ivy-classpaths"> + <taskdef name="groovyc" + classname="org.codehaus.groovy.ant.Groovyc" + classpathref="compile.classpath"/> + + <!-- define a new groovyc task with new default options --> + <presetdef name="sf-groovyc"> + <groovyc fork="true" + memoryMaximumSize="${javac.max.memory}"> + </groovyc> + </presetdef> + </target> + + <!-- override the compile target to use groovyc instead of javac --> + <target name="compile" depends="common.compile"> + <echo>compiling groovy source</echo> + <sf-groovyc classpathref="compile.classpath" + srcdir="${src.dir}" + destdir="${build.classes.dir}"/> + </target> + +</project> \ No newline at end of file Added: trunk/core/components/grinstall/doc/README.txt =================================================================== --- trunk/core/components/grinstall/doc/README.txt (rev 0) +++ trunk/core/components/grinstall/doc/README.txt 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,79 @@ +Author: Benjamin Koenig +E-Mail: ben...@hp... +State: Basically working, able to deploy Hadoop, no tests yet + +This project provides a SmartFrog addon which enable users to deploy diverse applications (i.e. Hadoop, Ganglia). + +HOW TO BUILD +------------ + +ant clean +ant package // creates installer jar (dist/lib) +ant ivy-retrieve // retrieves 3rdparty jars (build/ivy/lib/runtime) + +Each VM has to have the installer jar and all its dependencies! You can set SFUSERHOME, SFUSERHOME1, etc., +to set the classpath of the SmartFrog daemon. + +The following files have to be in the classpath: + +- installer jar (all daemons) +- 3rdparty jars (all daemons) +- the .sf file of each component you use (only initial daemon) + +HOW TO DEPLOY +------------- + +You have to write a SmartFrog component description file (see components/example.sf) describing your +application landscape or "Architecture". An "Architecture" is a SmartFrog Compound consisting of several +"Component" subcomponents. The description for a "Component" may contain: + +- An "sfProcessHost" attribute which defines the destination host. Querying a service for a deployment destination is +planned but not yet implemented. + +- The "directory" attribute defines a directory on the destination host for all source downloads and task files. + +- a variable number of ISource subcomponents (see base.sf) which take care of downloading files before installation. +Currently, "installer.download.Source" is the only Java class implementing ISource. It wraps the Apache Commons VFS API +and you can use it to download the contents of a directory, tar or jar file, or files individually. +The following file systems are currently supported: + + * FTP + * Local Files + * HTTP and HTTPS + * SFTP + * Temporary Files + * Zip, Jar and Tar (uncompressed, tgz or tbz2) + * gzip and bzip2 + * res + * ram + * mime + +(see: http://commons.apache.org/vfs/filesystems.html) + +- A task file for each step in the installation process. By default the following Groovy scripts are executed in order: + +install.groovy, preConfigure.groovy, start.groovy, and postConfigure.groovy + +Within task files you can execute sfResolve to retrieve attributes from the component description and use helper +methods which are defined in the Java class "install.task.Helper". You may also resolve remote references by +refering to remote components by their name, e.g.: + +sfResolve("master:iBrix") + +Some more examples of what you can do in a task file: + +def host = command("hostname").text // executes the command "hostname" on the shell and retrieves the output + +def baseDir = sfResolve("directory") + +sfLog().info("Installing Application on $host") + +sfLog().debug("Some VFS functions") + +move("$baseDir/example.txt", "$baseDir/example2.txt") + +copy("$baseDir/example2.txt", "$baseDir/example3.txt") + +delete("$baseDir/example2.txt") + +If you have any questions or suggestions for further development, please feel free to contact me. \ No newline at end of file Added: trunk/core/components/grinstall/doc/dependencies.txt =================================================================== --- trunk/core/components/grinstall/doc/dependencies.txt (rev 0) +++ trunk/core/components/grinstall/doc/dependencies.txt 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,12 @@ + Using: Ivy Repository: +Antlr 2.7.7 2.7.7 +Asm 3.2 - check if needed +Commons codec 1.4 1.4 +Commons httpclient 4.1 4.1 +Commons httpclient-cache 4.1 - check if needed +Commons httpcore 4.1 4.1 +Commons httpmime 4.1 - check if needed +Jsch 0.1.44 0.1.42 check if compatible +JUnit 4.8.2 - not yet needed +Groovy 1.7.7 1.7.6 +Commons net 2.2 2.2 check if needed Added: trunk/core/components/grinstall/ivy.xml =================================================================== --- trunk/core/components/grinstall/ivy.xml (rev 0) +++ trunk/core/components/grinstall/ivy.xml 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,52 @@ +<?xml version="1.0" ?> +<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?> +<ivy-module version="1.0"> + <info organisation="org.smartfrog" module="grinstall"> + <ivyauthor name="Hewlett-Packard" url="http://www.hp.com"/> + <description> + grinstall: Groovy Installer components + Created 21-Feb-2011 by koenigbe + </description> + </info> + + <configurations defaultconfmapping="default"> + <conf name="default" extends="master,runtime" + description="default configuration contains artifacts and runtime dependencies"/> + <conf name="build" visibility="private" + description="artifacts needed to build the application"/> + <conf name="compile" visibility="private" extends="runtime" + description="artifacts needed to compile the application"/> + <conf name="daemon" visibility="private" + description="the classpath needed to run smartfrog daemons"/> + <conf name="test" extends="default,compile" + description="the classpath needed to run tests"/> + <conf name="master" description="contains the artifact but no dependencies"/> + <conf name="redist" description="redistributals excluding smartfrog artifacts"/> + <conf name="runtime" description="runtime but not the artifact" + extends="redist"/> + <conf name="documentation" + description="all documentation artifacts"/> + </configurations> + + <publications> + <!--get the artifact from our module name--> + <artifact conf="master" type="jar"/> + </publications> + + <dependencies> + <dependency org="org.smartfrog" name="smartfrog" rev="latest.integration" changing="true" + conf="runtime->services"/> + <dependency org="org.smartfrog" name="sf-groovy" rev="latest.integration" changing="true" + conf="runtime->default"/> + <dependency org="org.smartfrog" name="sf-ssh" rev="latest.integration" changing="true" + conf="runtime->default"/> + <dependency org="org.smartfrog" name="sf-www" rev="latest.integration" changing="true" + conf="runtime->default"/> + <dependency org="commons-vfs" name="commons-vfs" rev="svn1069844" force="true" + conf="runtime->default"> + <exclude org="httpclient"/> + <exclude org="commons-codec"/> + </dependency> + + </dependencies> +</ivy-module> \ No newline at end of file Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/Component.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/Component.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/Component.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,125 @@ +package org.smartfrog.services.groovy.install + +import org.smartfrog.services.groovy.install.download.ISource +import org.smartfrog.services.groovy.install.task.ITask +import java.rmi.RemoteException +import org.smartfrog.sfcore.common.SmartFrogCoreKeys +import org.smartfrog.sfcore.common.SmartFrogException +import org.smartfrog.sfcore.common.SmartFrogResolutionException +import org.smartfrog.sfcore.compound.CompoundImpl + +/** + * Base class for all Components + */ +class Component extends CompoundImpl implements IComponent { + + ComponentState state + + public Component() throws RemoteException { + super() + } + + @Override + public synchronized void sfDeploy() throws RemoteException, SmartFrogException { + super.sfDeploy() + sfLog().debug("Deployed " + this.getClass().getSimpleName()) + } + + @Override + public synchronized void sfStart() throws RemoteException, SmartFrogException { + super.sfStart() + sfLog().debug("Starting " + this.getClass().getSimpleName()) + init() + sfChildren().each { child -> + if (child instanceof ISource) { + child.retrieve() + } + } + while (state != ComponentState.READY) { + execute() + changeState() + } + } + + + private void init() { + sfLog().debug("Initialising ${sfCompleteName()}") + state = ComponentState.REMOVED + } + + private void execute() { + switch (state) { + case ComponentState.REMOVED: + run("install") + break + case ComponentState.INSTALLED: + run("preConfigure") + break + case ComponentState.PRECONFIGURED: + run("start") + break + case ComponentState.STARTED: + run("postConfigure") + break + default: + return + } + } + + private void run(String task) { + def taskObject = sfResolve(task) + if (taskObject instanceof ITask) { + taskObject.run() + } else { + throw new IllegalArgumentException("Value of attribute ${task} is not of class ITask") + } + } + + /** + * Return the expected next state of the software component during deployment. + */ + private ComponentState nextDeployState() { + switch (state) { + case ComponentState.REMOVED: + return ComponentState.INSTALLED + case ComponentState.INSTALLED: + return ComponentState.PRECONFIGURED + case ComponentState.PRECONFIGURED: + return ComponentState.STARTED + case ComponentState.STARTED: + return ComponentState.POSTCONFIGURED + case ComponentState.POSTCONFIGURED: + return ComponentState.READY + default: + throw new IllegalStateException("No next state for current state $state defined!") + } + } + + private void changeState() { + state = nextDeployState() + sfReplaceAttribute("state", state) + } + + /** + * Overrides sfResolve to allow for resolving attributes without having to know the path to them + * @param reference i.e.: port or webServer:port + * @return reference to local or remote attribute + * @throws SmartFrogResolutionException + * @throws RemoteException + */ + @Override + public Object sfResolve(String reference) throws SmartFrogResolutionException, RemoteException { + if (reference.contains(":")) { + sfLog().debug("Resolving reference $reference with parser") + def parts = reference.split(":") + def root = sfResolveWithParser(SmartFrogCoreKeys.SF_ROOT) + def ref = root.sfResolveWithParser("ATTRIB ${parts[0]}") + for (int i = 1; i < parts.size(); i++) { + ref = ref.sfResolve(parts[i]) + } + return ref + } else { + return super.sfResolve(reference) + } + } +} \ No newline at end of file Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/ComponentState.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/ComponentState.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/ComponentState.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,18 @@ +package org.smartfrog.services.groovy.install + +/** + * Software component states. The states are ordered: + * UNKNOWN // Component has been created in model, but state not yet determined. + * // A placeholder to allow a script to probe actual system to determine state. + * REMOVED // Component has been completely removed from system, or has not yet started installation. + * INSTALLED // Component has been installed, but not yet configured. + * PRECONFIGURED // Component has been configured, but not yet running. + * // This is the first stage of configuration - preconfiguration. + * STARTED // Component is running, but not yet available for use - + * // still needs to be postconfigured and subcomponents made ready. + * POSTCONFIGURED // Component has been postconfigured. This is the second stage of configuration. + * READY // Component is ready for use. + */ +enum ComponentState { + UNKNOWN, REMOVED, INSTALLED, PRECONFIGURED, STARTED, POSTCONFIGURED, READY +} Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/IComponent.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/IComponent.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/IComponent.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,14 @@ +package org.smartfrog.services.groovy.install + +import java.rmi.Remote +import org.smartfrog.sfcore.compound.Compound + +/** + * Interface for all components + */ +public interface IComponent extends Compound, Remote { + + // Defaults for installation + static final String TEMP_DIR = "/service" + +} Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/base.sf =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/base.sf (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/base.sf 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,38 @@ +#include "org/smartfrog/components.sf" +#include "org/smartfrog/sfcore/workflow/combinators/parallel.sf" + +Architecture extends Parallel { + asynchCreateChild true; // deploy all components in parallel + repository TBD; // define a repository which provides the component directory + // (such as ftp://installer-vif0.cell-ko.vms.sup.hpl.hp.com) + // we could also define a default repository here +} + +Component extends Compound { + sfClass "org.smartfrog.services.groovy.install.Component"; + + directory "/service"; + + install extends Task { + file "install.groovy"; + } + preConfigure extends Task { + file "preConfigure.groovy"; + } + start extends Task { + file "start.groovy"; + } + postConfigure extends Task { + file "postConfigure.groovy"; + } +} + +// at the moment only Groovy tasks are supported +Task extends Prim { + sfClass "org.smartfrog.services.groovy.install.task.GroovyTask"; +} + +// copy a file or directory +Source extends Prim { + sfClass "org.smartfrog.services.groovy.install.download.Source"; +} \ No newline at end of file Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/ISource.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/ISource.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/ISource.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,18 @@ +package org.smartfrog.services.groovy.install.download + +import java.rmi.Remote +import java.rmi.RemoteException +import org.smartfrog.sfcore.common.SmartFrogException +import org.smartfrog.sfcore.prim.Prim + +/** + * Interface for accessing a remote data source + */ +interface ISource extends Prim, Remote { + + /** + * Copy all files from remoteURL into local temp directory + * @return True if successful + */ + public boolean retrieve() throws RemoteException, SmartFrogException; +} Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/Source.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/Source.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/download/Source.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,38 @@ +package org.smartfrog.services.groovy.install.download + +import org.smartfrog.services.groovy.install.task.Helper +import java.rmi.RemoteException +import org.smartfrog.sfcore.common.SmartFrogException +import org.smartfrog.sfcore.prim.PrimImpl +import org.smartfrog.services.groovy.install.Component + +class Source extends PrimImpl implements ISource { + + private Helper helper + + public Source() throws RemoteException { + super() + } + + @Override + public synchronized void sfDeploy() throws RemoteException, SmartFrogException { + super.sfDeploy() + sfLog().debug("Deployed " + this.getClass().getSimpleName()) + } + + @Override + public synchronized void sfStart() throws RemoteException, SmartFrogException { + super.sfStart() + sfLog().debug("Starting " + this.getClass().getSimpleName()) + helper = new Helper((Component)sfParent()) + } + + @Override + public boolean retrieve() { + def source = sfResolve("source").toString() + def destination = sfParent().sfResolve("directory").toString() + sfLog().info("Copying $source to $destination") + helper.copy(source, destination) + return true; + } +} \ No newline at end of file Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/DelegatingScript.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/DelegatingScript.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/DelegatingScript.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,61 @@ +/* + * Adapted from: + * http://grepcode.com/file/repo1.maven.org/maven2/org.spockframework/spock-core/0.4-groovy-1.6/org/spockframework/builder/DelegatingScript.java + * + * this is Apache 2.0 Licensed. + * + */ + + +package org.smartfrog.services.groovy.install.task + +import org.smartfrog.services.groovy.install.Component +import org.codehaus.groovy.runtime.InvokerHelper +import org.smartfrog.sfcore.common.SmartFrogCoreKeys +import org.smartfrog.sfcore.common.SmartFrogExtractedException +import org.smartfrog.sfcore.logging.LogFactory +import org.smartfrog.sfcore.logging.LogSF + +public abstract class DelegatingScript extends Script { + + private LogSF sfLog = LogFactory.sfGetProcessLog() + + private Component component + private Helper helper + + public void setComponent(Component comp) { + if (comp) { + component = comp + try { + sfLog = LogFactory.getLog(component.sfResolve(SmartFrogCoreKeys.SF_APP_LOG_NAME, "DelegatingScript", true)) + } catch (Exception e) { + sfLog.error(e.message) + throw new SmartFrogExtractedException(SmartFrogExtractedException.convert(e)) + } + } + + // ScriptHelper needs component to bind it within task scripts + helper = new Helper(comp) + } + + @Override + public Object invokeMethod(String name, Object args) { + try { + if (component.metaClass.methods*.name.contains(name)) { + sfLog.debug("Delegating call to $name with $args to Component") + return InvokerHelper.invokeMethod(component, name, args) + } + if (helper.metaClass.methods*.name.contains(name)) { + sfLog.debug("Delegating call to $name with $args to Helper") + return InvokerHelper.invokeMethod(helper, name, args) + } + //if we get here, nothing was found + sfLog.error("Method $name not found, trying super class") + return super.invokeMethod(name, args); + + } catch (MissingMethodException e) { + sfLog.error("Method $name not found, trying super class: " +e, e) + return super.invokeMethod(name, args); + } + } +} \ No newline at end of file Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/GroovyTask.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/GroovyTask.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/GroovyTask.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,126 @@ +package org.smartfrog.services.groovy.install.task + +import java.rmi.RemoteException +import org.codehaus.groovy.control.CompilerConfiguration +import org.smartfrog.sfcore.common.SmartFrogException +import org.smartfrog.sfcore.common.SmartFrogExtractedException +import org.smartfrog.sfcore.prim.PrimImpl +import org.smartfrog.services.groovy.install.Component + +/** + * User: koenigbe + * Date: 02/02/11 + * Time: 11:07 + */ +class GroovyTask extends PrimImpl implements ITask { + + private static final String simplename = getClass().getSimpleName() + private Vector previousTasks + + private List<ITask> observers = new ArrayList<ITask>() + + private final Object lock = new Object() + + public GroovyTask() throws RemoteException { + super() + } + + @Override + public synchronized void sfDeploy() throws RemoteException, SmartFrogException { + super.sfDeploy() + sfLog().debug("Deployed " + simplename) + } + + @Override + public synchronized void sfStart() throws RemoteException, SmartFrogException { + super.sfStart() + sfLog().debug("Starting " + simplename) + } + + @Override + public void run() throws RemoteException, SmartFrogException { + if (!sfResolve("finished", false, false)) { + def file = sfResolve("file", "", false) + if (!file) return // no task file specified + def directory = sfParent().sfResolve("directory") + previousTasks = sfResolve("preconditions", new Vector(), false) + register() + waitForPreconditions() + execute(directory, file) + sfReplaceAttribute("finished", true) + notifyObservers() + } + } + + private void register() { + previousTasks.each { task -> + if (task instanceof ITask || task instanceof GroovyTask) { + task.addObserver(this) + } else { + throw new SmartFrogException("""Reference $task does not refer to an object of class ITask. + task is ${task.class.name}""") + } + } + } + + private void waitForPreconditions() { + def wait = false + while (true) { + wait = false + previousTasks.each { task -> + if (!task.sfResolve("finished", false, false)) { + wait = true + } + } + if (wait) lock() + else return + } + } + + private void lock() { + synchronized (lock) { + try { + sfLog().debug("Going to sleep") + lock.wait(); + } catch (InterruptedException ex) { + sfLog().debug("Thread interrupted"); + } + } + } + + private void unlock() { + synchronized (lock) { + lock.notifyAll(); + } + } + + private void execute(directory, file) { + sfLog().debug("Executing file $file in directory $directory") + def f = new File("$directory/$file") + def conf = new CompilerConfiguration() + conf.setScriptBaseClass("org.smartfrog.services.groovy.install.task.DelegatingScript") + DelegatingScript s + try { + s = new GroovyShell(conf).parse(f.getText()) + } catch (Exception e) { + sfLog().error(e.message) + throw new SmartFrogExtractedException(SmartFrogExtractedException.convert(e)) + } + s?.setComponent((Component)sfParent()) + s?.run() + } + + @Override + public void addObserver(ITask observer) throws RemoteException, SmartFrogException { + observers.add(observer) + } + + private void notifyObservers() { + observers.each { it.update() } + } + + @Override + public void update() throws RemoteException, SmartFrogException { + unlock() + } +} \ No newline at end of file Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/Helper.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/Helper.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/Helper.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,261 @@ +package org.smartfrog.services.groovy.install.task + +import groovy.text.GStringTemplateEngine +import org.smartfrog.services.groovy.install.Component +import org.apache.commons.vfs2.FileObject +import org.apache.commons.vfs2.FileSystemManager +import org.apache.commons.vfs2.FileSystemOptions +import org.apache.commons.vfs2.FileType +import org.apache.commons.vfs2.Selectors +import org.apache.commons.vfs2.VFS +import org.apache.commons.vfs2.provider.http.HttpFileSystemConfigBuilder +import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder +import org.smartfrog.sfcore.common.SmartFrogCoreKeys +import org.smartfrog.sfcore.common.SmartFrogExtractedException +import org.smartfrog.sfcore.logging.LogFactory +import org.smartfrog.sfcore.logging.LogSF +import sun.reflect.generics.reflectiveObjects.NotImplementedException + +/** + * Provides access to worker functions which may be used in Source components and in task files. + * + */ +class Helper { + + private LogSF sfLog = LogFactory.sfGetProcessLog() + + private FileSystemManager manager + private FileSystemOptions options + private FileObject root + + private Component component + + public Helper(Component comp) { + + if (comp) { + component = comp + try { + sfLog = LogFactory.getLog(component.sfResolve(SmartFrogCoreKeys.SF_APP_LOG_NAME, "Helper", true)) + } catch (Exception e) { + sfLog.error(e.message) + throw new SmartFrogExtractedException(SmartFrogExtractedException.convert(e)) + } + } + + options = new FileSystemOptions(); + // TODO define proxy in config file + HttpFileSystemConfigBuilder.getInstance().setProxyHost(options, "sup-prj-372301.sup.hpl.hp.com") + HttpFileSystemConfigBuilder.getInstance().setProxyPort(options, 3128) + + SftpFileSystemConfigBuilder.getInstance().setProxyHost(options, "sup-prj-372301.sup.hpl.hp.com") + SftpFileSystemConfigBuilder.getInstance().setProxyPort(options, 3128) + SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, false) + SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(options, "no") + + manager = VFS.getManager() + root = manager.resolveFile(component.sfResolve("directory").toString()) + } + + public Process command(String c) { + // all commands are executed in root directory by default + return command(c, root.getName().getPath()) + } + + public Process command(String c, String directory) { + sfLog.debug("Executing command $c in directory $directory") + try { + if (directory) { + return c.execute((String[])null, new File(directory)) + } else { + return c.execute() + } + } catch (Exception e) { + sfLog.error(e.message) + // We have to catch exceptions and throw our own. + // Otherwise we get an Unmarshallexception (Script1) + throw new SmartFrogExtractedException(SmartFrogExtractedException.convert(e)) + } + } + + public Process rpm(String file) { + // TODO users should not need to specify version + return command("rpm -i $file") + } + + /** + * Extract a compressed tar file in a directory. + * Although you can threat .tar files as directories and copy its contents using VFS + * it is faster to just copy the .tar file in one piece and then extract it on the host machine. + * Also, this avoids out of heap space errors! + * + * http://apache-commons.680414.n4.nabble.com/commons-vfs-copy-progress-aborting-copy-operation-td740573.html + * + * @param file + * @return + */ + public Process unpack(String file, String directory) { + sfLog.debug("Unpacking $file") + if (file.endsWith("gz")) return command("tar zxf $file", directory) + else if (file.endsWith("bz2")) return command("tar jxf $file", directory) + else throw new NotImplementedException("Unknown archive type") + } + + public Process unpack(String file) { + return unpack(file, root.getName().getPath()) + } + + private FileObject resolve(location) { + sfLog.debug("Resolving URL: $location") + if (location.contains("http://") || location.contains("sftp://")) { + assert !location.contains("***") + return manager.resolveFile(location, options) + } else { + // resolve relative paths against root + return manager.resolveFile(root, location) + } + } + + public boolean mkdir(directory) { + sfLog.debug("Creating $directory") + FileObject dir = resolve(directory) + if (dir.exists()) sfLog.error("A file or directory with same name already exists.") + dir.createFolder() + dir.close() + return true + } + + public boolean delete(fileOrDirectory) { + sfLog.debug("Deleting $fileOrDirectory") + FileObject src = resolve(fileOrDirectory) + if (!src.exists()) sfLog.warn("Cannot delete. The file or directory does not exist.") + def delete = src.delete(Selectors.SELECT_ALL) + src.close() + return delete!=0 + } + + public void copy(String source, String destination) { + sfLog.debug("Copying $source to $destination") + FileObject src = resolve(source); + if (!src.exists()) { + sfLog.error("Source URL does not exist!") + return + } + if (!src.isReadable()) { + sfLog.error("Source URL cannot be read!") + return + } + FileObject dest = resolve(destination); + if (src.getType() == FileType.FILE) { + if (dest.exists()) { + if (dest.getType() == FileType.FILE) { + sfLog.warn("Destination file does already exist and will be overwritten!") + dest.copyFrom(src, Selectors.SELECT_SELF) + } else if (dest.getType() == FileType.FOLDER) { + sfLog.info("Copying file $source into directory $destination") + dest = resolve("$destination/${src.getName().getBaseName()}") + dest.copyFrom(src, Selectors.SELECT_SELF) + } + } else { + sfLog.info("Copying file $source to $destination") + dest.copyFrom(src, Selectors.SELECT_SELF) + } + } else if (src.getType() == FileType.FOLDER) { + if (dest.exists()) { + if (dest.getType() == FileType.FILE) { + throw new IllegalArgumentException("Cannot copy directory $source into file $destination") + } else { + sfLog.info("Copying directory contents of $source into directory $destination") + dest.copyFrom(src, Selectors.EXCLUDE_SELF) + } + } else { + sfLog.info("Directory $destination does not exist and will be created") + dest.copyFrom(src, Selectors.EXCLUDE_SELF) + } + } + src.close() + dest.close() + } + + public void move(String source, String destination) { + sfLog.debug("Moving $source to $destination") + FileObject src = resolve(source); + if (!src.exists()) { + sfLog.error("Source URL does not exist!") + return + } + if (!src.isReadable()) { + sfLog.error("Source URL cannot be read!") + return + } + FileObject dest = resolve(destination); + if (src.getType() == FileType.FILE) { + if (dest.exists()) { + if (dest.getType() == FileType.FILE) { + sfLog.warn("Destination file does already exist and will be overwritten!") + src.moveTo(dest) + } else if (dest.getType() == FileType.FOLDER) { + sfLog.info("Moving file $source into directory $destination") + dest = resolve("$destination/${src.getName().getBaseName()}") + src.moveTo(dest) + } + } else { + sfLog.info("Moving file $source to $destination") + src.moveTo(dest) + } + } else if (src.getType() == FileType.FOLDER) { + if (dest.exists()) { + if (dest.getType() == FileType.FILE) { + throw new IllegalArgumentException("Cannot move directory $source into file $destination") + } else { + sfLog.info("Moving directory contents of $source into directory $destination") + src.getChildren().each { srcChild -> + FileObject destChild = resolve("$destination/${srcChild.getName().getBaseName()}") + srcChild.moveTo(destChild) + destChild.close() + } + } + } else { + sfLog.info("Directory $destination does not exist and will be created") + src.moveTo(dest) + } + } + src.close() + dest.close() + } + + /** + * Replaces Groovy code within a config file using GStringTemplateEngine. + * @param file - file + * @param binding - variables refered to in the file + */ + public void parse(String file, binding) { + def engine = new GStringTemplateEngine() + def input = new File(file); + if (!input.exists()) { + sfLog.error("File $file does not exist!") + return + } + try { + def template = engine.createTemplate(input.text).make(binding) + sfLog.debug("Created template") + def replacedText = template.toString() + sfLog.debug("Evaluated template as: $replacedText") + input.write(replacedText) + } catch (e) { + sfLog.error(e.message) + throw new SmartFrogExtractedException(SmartFrogExtractedException.convert(e)) + } + } + + /** + * Replaces Groovy code within a config file using GStringTemplateEngine. + * Makes component available inside the file as "comp". + * @see this.parse ( file , binding ) + */ + public void parse(file) { + def binding = [ + comp: component + ] + parse(file, binding) + } +} \ No newline at end of file Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/ITask.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/ITask.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/ITask.groovy 2011-06-07 16:23:22 UTC (rev 8594) @@ -0,0 +1,26 @@ +package org.smartfrog.services.groovy.install.task + +import java.rmi.Remote +import java.rmi.RemoteException +import org.smartfrog.sfcore.common.SmartFrogException +import org.smartfrog.sfcore.prim.Prim + +/** + * User: koenigbe + * Date: 02/02/11 + * Time: 11:23 + */ +public interface ITask extends Prim, Remote { + + public void run() throws RemoteException, SmartFrogException + + ; + + public void addObserver(ITask observer) throws RemoteException, SmartFrogException + + ; + + public void update() throws RemoteException, SmartFrogException + + ; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2011-06-09 17:34:34
|
Revision: 8615 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8615&view=rev Author: steve_l Date: 2011-06-09 17:34:25 +0000 (Thu, 09 Jun 2011) Log Message: ----------- SFOS-1569 Move up to JUnit 4.8.2 Modified Paths: -------------- trunk/core/components/junit/ivy.xml trunk/core/components/junit/src/org/Version.java trunk/core/components/junit/src/org/smartfrog/services/junit/example.sf trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/JUnit3TestSuiteImpl.java trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/TestCaseWithContext.java trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/Warning.java trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/components.sf trunk/core/components/junit/test/files/components.sf trunk/core/components/junit/test/files/junit-sysprops.sf trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedChainListenerTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedHtmlListenerTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedXMLListenerTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/SyspropsTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/TestRunnerTestBase.java trunk/core/components/libraries.properties trunk/core/components/xunit/build.xml trunk/core/components/xunit/src/org/smartfrog/services/sfunit/SFUnitTestSuite.java Added Paths: ----------- trunk/core/components/junit/test/log4j.properties trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FunnyCharactersTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/OutputTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/SuccessTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/SyspropsTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/SystemExitTestTarget.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ThrowingTestTarget.java Removed Paths: ------------- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FunnyCharactersTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/OutputTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/SuccessTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/SyspropsTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/SystemExitTest.java trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ThrowingTest.java Modified: trunk/core/components/junit/ivy.xml =================================================================== --- trunk/core/components/junit/ivy.xml 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/ivy.xml 2011-06-09 17:34:25 UTC (rev 8615) @@ -49,20 +49,30 @@ rev="latest.integration" conf="build->default"/> <dependency org="org.smartfrog" + name="sf-loggingservices" + changing="true" + rev="latest.integration" + conf="daemon,compile->default;runtime->runtime;redist->redist"/> + + <dependency org="org.smartfrog" name="sf-xml" changing="true" rev="latest.integration" - conf="compile->master;runtime->default"/> + conf="compile->master;runtime->master"/> + + <!--avoid asking for junit so that this component can play with different versions--> <dependency org="org.smartfrog" name="sf-testharness" changing="true" rev="latest.integration" - conf="test->default"/> + conf="test->master"> + </dependency> <dependency org="org.smartfrog" name="sf-xunit" changing="true" rev="latest.integration" - conf="compile->master;runtime->default"/> + conf="compile->master;runtime->master"/> <dependency org="junit" name="junit" - rev="${junit.version}" + rev="${junit4.version}" conf="compile->default;redist->default"/> + </dependencies> </ivy-module> \ No newline at end of file Modified: trunk/core/components/junit/src/org/Version.java =================================================================== --- trunk/core/components/junit/src/org/Version.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/src/org/Version.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -1,22 +1,22 @@ /** (C) Copyright 1998-2005 Hewlett-Packard Development Company, LP -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -For more information: www.smartfrog.org + For more information: www.smartfrog.org -*/ + */ package org; @@ -51,11 +51,11 @@ // Dont' change this. MODIFY version.sf in same package!!!!!!!!!!!!!!!!!!! - private static String name= "SmartFrog"; - private static String majorRelease="3"; - private static String minorRelease="4"; - private static String build= "17"; // odd numbers are development versions - private static String status= ""; //alpha, beta, stable + private static String name = "SmartFrog"; + private static String majorRelease = "3"; + private static String minorRelease = "4"; + private static String build = "17"; // odd numbers are development versions + private static String status = ""; //alpha, beta, stable private static String minCoreVersion = null; @@ -65,34 +65,35 @@ /** The copyright String for the SmartFrog system. */ private static String copyright = "(C) Copyright 1998-2005 HP Development Company, LP"; - private static boolean initialized=false; + private static boolean initialized = false; - private Version(){ + private Version() { init(); } - private synchronized void init() { + private synchronized void init() { if (initialized) return; try { //Check Class and read configuration...NOT including system.properties ComponentDescription classComponentDescription = ComponentDescriptionImpl. - getClassComponentDescription(this, false, null); + getClassComponentDescription(this, false, null); - name = classComponentDescription.sfResolve(ATR_NAME, name , false); - majorRelease = classComponentDescription.sfResolve(ATR_MAJOR_RELEASE, majorRelease , false); - minorRelease = classComponentDescription.sfResolve(ATR_MINOR_RELEASE, minorRelease , false); - build = classComponentDescription.sfResolve(ATR_BUILD, build , false); - status = classComponentDescription.sfResolve(ATR_STATUS, status , false); - copyright = classComponentDescription.sfResolve(COPYRIGHT, copyright , false); - minCoreVersion = classComponentDescription.sfResolve(ATR_MIN_CORE_VERSION, minCoreVersion , false); - maxCoreVersion = classComponentDescription.sfResolve(ATR_MAX_CORE_VERSION, maxCoreVersion , false); - initialized=true; + name = classComponentDescription.sfResolve(ATR_NAME, name, false); + majorRelease = classComponentDescription.sfResolve(ATR_MAJOR_RELEASE, majorRelease, false); + minorRelease = classComponentDescription.sfResolve(ATR_MINOR_RELEASE, minorRelease, false); + build = classComponentDescription.sfResolve(ATR_BUILD, build, false); + status = classComponentDescription.sfResolve(ATR_STATUS, status, false); + copyright = classComponentDescription.sfResolve(COPYRIGHT, copyright, false); + minCoreVersion = classComponentDescription.sfResolve(ATR_MIN_CORE_VERSION, minCoreVersion, false); + maxCoreVersion = classComponentDescription.sfResolve(ATR_MAX_CORE_VERSION, maxCoreVersion, false); + initialized = true; } catch (Exception ex) { - if (sfGetProcessLog().isWarnEnabled()) + if (sfGetProcessLog().isWarnEnabled()) { sfGetProcessLog().warn( - "Error during init of "+ this.getClass().toString()+"", - ex); + "Error during init of " + this.getClass().toString() + "", + ex); + } } } @@ -100,34 +101,38 @@ * * @return String Complete Version String */ - public static String versionString(){ + public static String versionString() { //init(); if (!initialized) new Version(); - String newStatus=null; - if (!status.trim().equals("")){ - newStatus="_"+status; - } else newStatus=""; - return name+" "+majorRelease+"."+minorRelease+"."+build+newStatus; + String newStatus = null; + if (!status.trim().equals("")) { + newStatus = "_" + status; + } else { + newStatus = ""; + } + return name + " " + majorRelease + "." + minorRelease + "." + build + newStatus; } /** * * @return String Complete Version String */ - public static String versionStringforrelease(){ + public static String versionStringforrelease() { //init(); if (!initialized) new Version(); - String newStatus=null; - if (!status.trim().equals("")){ - newStatus="_"+status; - } else newStatus=""; - return majorRelease+"."+minorRelease+"."+build+newStatus; + String newStatus = null; + if (!status.trim().equals("")) { + newStatus = "_" + status; + } else { + newStatus = ""; + } + return majorRelease + "." + minorRelease + "." + build + newStatus; } /** * Major release number. */ - public static String majorRelease(){ + public static String majorRelease() { if (!initialized) new Version(); return majorRelease; } @@ -135,14 +140,15 @@ /** *Minor release number. */ - public static String minorRelease(){ + public static String minorRelease() { if (!initialized) new Version(); return minorRelease; } + /** * Build number. */ - public static String build(){ + public static String build() { if (!initialized) new Version(); return build; } @@ -150,12 +156,12 @@ /** * Status [alpha, beta, (Empty when statable)]. */ - public static String status(){ + public static String status() { if (!initialized) new Version(); return status; } - public static String copyright(){ + public static String copyright() { //init(); if (!initialized) new Version(); return copyright; @@ -165,7 +171,7 @@ * Min Core compatible version * If null, it is considred compatible with all */ - public static String minCoreVersion(){ + public static String minCoreVersion() { if (!initialized) new Version(); return minCoreVersion; } @@ -175,7 +181,7 @@ * If null, it is considered compatible with all version numbers bigger * than ours */ - public static String maxCoreVersion(){ + public static String maxCoreVersion() { if (!initialized) new Version(); return maxCoreVersion; } @@ -186,13 +192,13 @@ * @param version String Version has to be of the form: MajorRelease.MinorRelease.Build_status. * @return boolean */ - public static boolean compatible(String version){ + public static boolean compatible(String version) { if (!initialized) new Version(); - String majorRelease = version.substring(0,version.indexOf('.')); + String majorRelease = version.substring(0, version.indexOf('.')); String cutVersion = version.substring(majorRelease.indexOf('.')); - String minorRelease = cutVersion.substring(0,cutVersion.indexOf('.')); + String minorRelease = cutVersion.substring(0, cutVersion.indexOf('.')); cutVersion = version.substring(majorRelease.indexOf('.')); - String build = cutVersion.substring(0,cutVersion.indexOf('_')); + String build = cutVersion.substring(0, cutVersion.indexOf('_')); boolean compatible = true; compatible = checkMaxVersion(majorRelease, minorRelease, build); @@ -202,14 +208,20 @@ //@todo review this matching method. - private static boolean checkMaxVersion (String majorReleaseN, String minorReleaseN, String buildN){ - if (majorRelease==null) return true; - if (!(Integer.parseInt(majorRelease) < (Integer.parseInt(majorReleaseN)))){return false;} - if (!(Integer.parseInt(majorRelease) == (Integer.parseInt(majorReleaseN)))){ - if (!(Integer.parseInt(minorRelease) < (Integer.parseInt(minorReleaseN)))){return false;} - if (!(Integer.parseInt(minorRelease) == (Integer.parseInt(minorReleaseN)))){ - if (!(Integer.parseInt(build) < (Integer.parseInt(buildN)))){return false;} - if (!(Integer.parseInt(build) == (Integer.parseInt(buildN)))){ + private static boolean checkMaxVersion(String majorReleaseN, String minorReleaseN, String buildN) { + if (majorRelease == null) return true; + if (!(Integer.parseInt(majorRelease) < (Integer.parseInt(majorReleaseN)))) { + return false; + } + if (!(Integer.parseInt(majorRelease) == (Integer.parseInt(majorReleaseN)))) { + if (!(Integer.parseInt(minorRelease) < (Integer.parseInt(minorReleaseN)))) { + return false; + } + if (!(Integer.parseInt(minorRelease) == (Integer.parseInt(minorReleaseN)))) { + if (!(Integer.parseInt(build) < (Integer.parseInt(buildN)))) { + return false; + } + if (!(Integer.parseInt(build) == (Integer.parseInt(buildN)))) { return true; // All numbers are equal :-) } } @@ -220,14 +232,20 @@ //@todo review this matching method. - private static boolean checkMinVersion (String majorReleaseN, String minorReleaseN, String buildN){ - if (majorRelease==null) return true; - if (!(Integer.parseInt(majorRelease) > (Integer.parseInt(majorReleaseN)))){return false;} - if (!(Integer.parseInt(majorRelease) == (Integer.parseInt(majorReleaseN)))){ - if (!(Integer.parseInt(minorRelease) > (Integer.parseInt(minorReleaseN)))){return false;} - if (!(Integer.parseInt(minorRelease) == (Integer.parseInt(minorReleaseN)))){ - if (!(Integer.parseInt(build) > (Integer.parseInt(buildN)))){return false;} - if (!(Integer.parseInt(build) == (Integer.parseInt(buildN)))){ + private static boolean checkMinVersion(String majorReleaseN, String minorReleaseN, String buildN) { + if (majorRelease == null) return true; + if (!(Integer.parseInt(majorRelease) > (Integer.parseInt(majorReleaseN)))) { + return false; + } + if (!(Integer.parseInt(majorRelease) == (Integer.parseInt(majorReleaseN)))) { + if (!(Integer.parseInt(minorRelease) > (Integer.parseInt(minorReleaseN)))) { + return false; + } + if (!(Integer.parseInt(minorRelease) == (Integer.parseInt(minorReleaseN)))) { + if (!(Integer.parseInt(build) > (Integer.parseInt(buildN)))) { + return false; + } + if (!(Integer.parseInt(build) == (Integer.parseInt(buildN)))) { return true; // All numbers are equal :-) } } @@ -241,8 +259,8 @@ * @return Logger implementing LogSF and Log */ private LogSF sfGetProcessLog() { - LogSF sflog = LogFactory.sfGetProcessLog(); - return sflog; + LogSF sflog = LogFactory.sfGetProcessLog(); + return sflog; } /** @@ -251,13 +269,14 @@ * @param args command line arguments. */ public static void main(String[] args) { - if ((args.length > 0) && (args[0].equals("-b"))) - System.out.print(versionStringforrelease()); - else if ((args.length > 0) && (args[0].equals("-min"))) - System.out.print(minCoreVersion()); - else if ((args.length > 0) && (args[0].equals("-max"))) - System.out.print(maxCoreVersion()); - else - System.out.print(versionString()); + if ((args.length > 0) && (args[0].equals("-b"))) { + System.out.print(versionStringforrelease()); + } else if ((args.length > 0) && (args[0].equals("-min"))) { + System.out.print(minCoreVersion()); + } else if ((args.length > 0) && (args[0].equals("-max"))) { + System.out.print(maxCoreVersion()); + } else { + System.out.print(versionString()); + } } } Modified: trunk/core/components/junit/src/org/smartfrog/services/junit/example.sf =================================================================== --- trunk/core/components/junit/src/org/smartfrog/services/junit/example.sf 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/src/org/smartfrog/services/junit/example.sf 2011-06-09 17:34:25 UTC (rev 8615) @@ -39,6 +39,9 @@ JUnitTestSuite extends JUnit3TestSuite { package "org.example"; - classes ["firstTest","secondTest"]; + classes [ + "firstTest", + "secondTest" + ]; } } \ No newline at end of file Modified: trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/JUnit3TestSuiteImpl.java =================================================================== --- trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/JUnit3TestSuiteImpl.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/JUnit3TestSuiteImpl.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -24,27 +24,28 @@ import junit.framework.TestCase; import junit.framework.TestResult; import junit.framework.TestSuite; +import org.smartfrog.services.testcontext.TestContextInjector; import org.smartfrog.services.xunit.base.AbstractTestSuite; -import org.smartfrog.services.xunit.base.TestContextInjector; import org.smartfrog.services.xunit.base.TestListener; +import org.smartfrog.services.xunit.log.TestListenerLog; +import org.smartfrog.services.xunit.serial.TestInfo; import org.smartfrog.services.xunit.utils.Utils; -import org.smartfrog.services.xunit.serial.TestInfo; -import org.smartfrog.services.xunit.log.TestListenerLog; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogInitException; import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.reference.Reference; import org.smartfrog.sfcore.utils.ListUtils; -import org.smartfrog.sfcore.reference.Reference; -import org.smartfrog.sfcore.componentdescription.ComponentDescription; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.rmi.RemoteException; import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Properties; -import java.util.Iterator; /** @@ -71,10 +72,10 @@ private String suitename; /** test class list we build up */ - private HashMap<String, String> testClasses; + private Map<String, String> testClasses; /** track the active tests; used to build up full statistics on what a test does. */ - private HashMap<String, Long> startedTests; + private Map<String, Long> startedTests; /** listener for tests; set at binding time */ private TestListener listener; @@ -105,6 +106,7 @@ * @throws SmartFrogException failure while starting * @throws RemoteException In case of network/rmi error */ + @Override public synchronized void sfStart() throws SmartFrogException, RemoteException { super.sfStart(); @@ -134,13 +136,13 @@ singleTest = sfResolve(ATTR_SINGLE_TEST, singleTest, false); //properties. extract the list, flatten it and bind to sysproperties - sysproperties = ListUtils.resolveProperties(this, new Reference(ATTR_SYSPROPS), true); + sysproperties = ListUtils.resolveProperties(this, new Reference(ATTR_SYSPROPS), true); //now pull in the propertySet - ComponentDescription propSet = null; + ComponentDescription propSet = null; propSet = sfResolve(ATTR_PROPERTY_SET, propSet, true); CDtoProperties(sysproperties, propSet); - + //package attribute names a package packageValue = sfResolve(ATTR_PACKAGE, packageValue, false); if (packageValue == null) { @@ -205,7 +207,7 @@ || singleTest.equals(fullname); if (add && testClasses.get(fullname) == null) { - sfLog().debug("adding test " + fullname); + log("adding test " + fullname); testClasses.put(fullname, fullname); } } @@ -220,11 +222,7 @@ return packageValue + classname; } - private void log(String message) { - sfLog().info(message); - } - /** * Evaluate the condition by delegating to the underlying condition, and pull in the if/unless values. * @@ -232,6 +230,7 @@ * @throws RemoteException for network problems * @throws SmartFrogException for any other problem */ + @Override public synchronized boolean evaluate() throws RemoteException, SmartFrogException { return super.evaluate() && ifValue && !unlessValue; } @@ -243,10 +242,11 @@ * @throws RemoteException for network problems * @throws SmartFrogException for any other problem */ + @Override public boolean runTests() throws RemoteException, SmartFrogException { - sfLog().info("Running junit3 test suite " + suitename); + log("Running junit3 test suite " + suitename); checkConfigured(); //bind to our listener TestListenerLog testLog = null; @@ -254,6 +254,7 @@ try { if (maybeSkipTestSuite()) { //exit early + sfLog().info("Skipping test suite " + suitename); listener.endTest(TestInfo.skipped(suitename)); return true; } @@ -344,7 +345,7 @@ * * @param classname test class to load and run * @param context name-object mapping context - * @return true if the test ran + * @return true if the tests were set up */ private boolean testSingleClass(String classname, HashMap<String, Object> context) { log("testing " + classname); @@ -352,17 +353,21 @@ TestResult result; result = new TestResult(); result.addListener(this); + boolean testsSetUp; try { Class clazz = loadTestClass(classname); tests = extractTest(clazz); injectTestContext(tests, context); + testsSetUp = true; } catch (Throwable e) { //couldn't set up the tests, so we catch the exception and create a failure //test that reports the outcome tests = new Warning(classname, e); + testsSetUp = false; } + //run the tests tests.run(result); - return true; + return testsSetUp; } @@ -401,8 +406,8 @@ + " in class " + clazz, e); } catch (InvocationTargetException e) { throw new SmartFrogInitException("Exception in " + SUITE_METHOD_NAME - + " in class " + clazz - + " : " + e.toString(), + + " in class " + clazz + + " : " + e.toString(), e.getCause()); } } @@ -447,7 +452,13 @@ return listener; } - /** An error occurred. */ + + /** + * Implement {@link junit.framework.TestListener#addError(Test, Throwable)} + * @param test test that errored + * @param throwable what went wrong + */ + @Override public void addError(Test test, Throwable throwable) { getStats().incErrors(); TestInfo info = onEnd(test, throwable); @@ -472,10 +483,11 @@ /** * A failure occurred. - * + * Implement JUnit's {@link junit.framework.TestListener#addFailure(Test, AssertionFailedError)} * @param test test * @param error error */ + @Override public void addFailure(Test test, AssertionFailedError error) { getStats().incFailures(); TestInfo info = onEnd(test, error); @@ -491,9 +503,10 @@ /** * A test ended. - * + * Implement JUnit's {@link junit.framework.TestListener#endTest(Test)} * @param test test */ + @Override public void endTest(Test test) { getStats().incTestsRun(); TestInfo info = onEnd(test, null); @@ -508,11 +521,13 @@ } /** - * A test started. Note that if a test throws an exception in {@link TestCase#setUp()} then this callback is + * A message from {@link junit.framework.TestListener#startTest(Test)} that a test started. + * Note that if a test throws an exception in {@link TestCase#setUp()} then this callback is * <i>not</i> invoked by Junit. We need to be aware of this fact. * * @param test test */ + @Override public void startTest(Test test) { TestInfo info = onStart(test); try { @@ -604,8 +619,7 @@ */ public static TestInfo createTestInfo(Test test, Throwable fault) { TestInfo testInfo = new TestInfo(fault); - String classname = test.getClass().getName(); - String testname = classname; + String testname = test.getClass().getName(); String text; if (test instanceof TestCase) { //TestCase information is extracted specially Modified: trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/TestCaseWithContext.java =================================================================== --- trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/TestCaseWithContext.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/TestCaseWithContext.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -20,7 +20,7 @@ package org.smartfrog.services.junit.junit3; import junit.framework.TestCase; -import org.smartfrog.services.xunit.base.TestContextInjector; +import org.smartfrog.services.testcontext.TestContextInjector; import java.util.HashMap; import java.util.Map; @@ -28,9 +28,9 @@ /** * This is a test case with context. - * + * * This design is intended to work inside SmartFrog or outside; it creates a stub context which can be overwritten - * by {@link TestContextInjector#setTestContext(HashMap)} when the SF test runner forces a context + * by {@link TestContextInjector#setTestContext(Map)} when the SF test runner forces a context */ public abstract class TestCaseWithContext extends TestCase implements TestContextInjector { @@ -63,7 +63,7 @@ this.testContext = testContext; contextSet = testContext != null; //set the properties, with a bit of contingency planning - if(contextSet) { + if (contextSet) { properties = (Properties) getContextEntry(TestContextInjector.ATTR_PROPERTIES); } if (properties == null) { Modified: trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/Warning.java =================================================================== --- trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/Warning.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/Warning.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -23,7 +23,7 @@ import junit.framework.TestCase; /** - * A variant on how JUnit3 reports problems. This pseudo-test case class throws whichever fault is passed in created + * A variant on how JUnit3 reports problems. This pseudo-test case class throws whichever fault is passed in during creation * 24-Oct-2006 13:38:22 */ @@ -74,6 +74,7 @@ * * @throws Throwable whatever we were constructed with */ + @SuppressWarnings({"ProhibitedExceptionThrown"}) public void testReportError() throws Throwable { if (thrown != null) { throw thrown; Modified: trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/components.sf =================================================================== --- trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/components.sf 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/src/org/smartfrog/services/junit/junit3/components.sf 2011-06-09 17:34:25 UTC (rev 8615) @@ -37,6 +37,7 @@ unless extends OptionalBoolean; } sfClass "org.smartfrog.services.junit.junit3.JUnit3TestSuiteImpl"; + sfShouldTerminate false; if true; unless false; } Modified: trunk/core/components/junit/test/files/components.sf =================================================================== --- trunk/core/components/junit/test/files/components.sf 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/files/components.sf 2011-06-09 17:34:25 UTC (rev 8615) @@ -21,7 +21,6 @@ #include "/org/smartfrog/services/junit/all.sf" #include "/org/smartfrog/services/filesystem/tempfile.sf" #include "/org/smartfrog/sfcore/workflow/conditional/conditions/components.sf" -//sfCodeBase PROPERTY org.smartfrog.codebase; /** @@ -87,9 +86,9 @@ SuccessTest:classes, SetupTearDownTests:classes, BadClassnameTest:classes, - "ThrowingTest", - "FunnyCharactersTest", - "OutputTest"]; + "ThrowingTestTarget", + "FunnyCharactersTestTarget", + "OutputTestTarget"]; } /** @@ -105,7 +104,7 @@ * system exit handling */ SystemExitTest extends NamedTest { - name "SystemExitTest"; + name "SystemExitTestTarget"; } @@ -113,7 +112,7 @@ * test failure */ FailureTest extends NamedTest { - name "FailureTest"; + name "FailureTestTarget"; } @@ -121,21 +120,21 @@ * test that arbitrary exceptions are processed */ ThrowingTest extends NamedTest { - name "ThrowingTest"; + name "ThrowingTestTarget"; } /** * test success */ SuccessTest extends NamedTest { - name "SuccessTest"; + name "SuccessTestTarget"; } /** * test success */ SyspropsTest extends NamedTest { - name "SyspropsTest"; + name "SyspropsTestTarget"; } /** @@ -143,8 +142,10 @@ */ SetupTearDownTests extends TestBase { name "SetupTearDownTests"; - classes ["ErrorInSetupTest", - "ErrorInTeardownTest"]; + classes [ + "ErrorInSetupTestTarget", + "ErrorInTeardownTestTarget" + ]; } @@ -153,7 +154,7 @@ * This is a classname that we dont know of */ BadClassnameTest extends NamedTest { - name "BadClassnameTest"; + name "BadClassnameTestTarget"; } Modified: trunk/core/components/junit/test/files/junit-sysprops.sf =================================================================== --- trunk/core/components/junit/test/files/junit-sysprops.sf 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/files/junit-sysprops.sf 2011-06-09 17:34:25 UTC (rev 8615) @@ -31,7 +31,7 @@ tests extends SyspropsTest { - properties [["one","1"],"two","2",[["three"],"3"]]; + properties [["one","1"],["two","2"],[["three"],"3"]]; } } Added: trunk/core/components/junit/test/log4j.properties =================================================================== --- trunk/core/components/junit/test/log4j.properties (rev 0) +++ trunk/core/components/junit/test/log4j.properties 2011-06-09 17:34:25 UTC (rev 8615) @@ -0,0 +1,10 @@ +#this file is here for testing, not production + +### direct log messages to stdout ### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{DATE} %-5p [%t] %c.%M() -- %m%n + +log4j.rootLogger=info, stdout + Modified: trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedChainListenerTest.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedChainListenerTest.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedChainListenerTest.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -43,7 +43,8 @@ true); boolean finished = spinTillFinished(runner, seconds); assertTrue("Test run timed out", finished); - + ping("test runner", runner); + ping("application", application); StatisticsTestListener statsListener = null; statsListener = (StatisticsTestListener) application.sfResolve( "statistics", Modified: trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedHtmlListenerTest.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedHtmlListenerTest.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedHtmlListenerTest.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -62,6 +62,8 @@ */ //now fetch from the tests + ping("test runner", runner); + ping("test application", application); Prim tests; tests = application.sfResolve(DeployedHtmlListenerTest.TEST_SUITE_COMPONENT_NAME, Modified: trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedXMLListenerTest.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedXMLListenerTest.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/DeployedXMLListenerTest.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -43,7 +43,7 @@ int seconds = getTimeout(); application = deployExpectingSuccess(url, "XmlTest"); - TestRunner runner = getTestRunner(); + TestRunner runner = getApplicationAsTestRunner(); XmlListenerFactory listenerFactory = null; listenerFactory = (XmlListenerFactory) application.sfResolve( @@ -52,7 +52,9 @@ true); boolean finished = spinTillFinished(runner, seconds); assertTrue("Test run timed out", finished); - + ping("test runner", runner); + ping("test application", application); + ping("listenerFactory", listenerFactory); String path = listenerFactory.lookupFilename(null, SUITENAME); assertNotNull("path of test suite " + SUITENAME, path); Modified: trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/SyspropsTest.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/SyspropsTest.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/SyspropsTest.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -39,26 +39,26 @@ int seconds = getTimeout(); application = deployExpectingSuccess(url, "localhostTest"); - TestRunner runner = getTestRunner(); + TestRunner runner = getApplicationAsTestRunner(); BufferingListener listener = null; listener = (BufferingListener) application.sfResolve(TestRunner.ATTR_LISTENER, listener, true); boolean finished = spinTillFinished(runner, seconds); - assertTrue("Test run timed out", finished); + ping("test runner", runner); + assertTrue("Test run timed out after " + seconds + " seconds", finished); assertEquals("session started", 1, listener.getSessionStartCount()); assertEquals("session ended", 1, listener.getSessionEndCount()); Statistics statistics = runner.getStatistics(); - System.out.println(statistics.toString()); + getLog().info(statistics.toString()); assertTrue("testsWereSuccessful() is false", listener.testsWereSuccessful()); assertEquals("statistics.errors!=0 -is " + statistics.getErrors(), 0, statistics.getErrors()); assertEquals("statistics.failures!=0", 0, statistics.getFailures()); - } } Modified: trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/TestRunnerTestBase.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/TestRunnerTestBase.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/system/TestRunnerTestBase.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -21,9 +21,13 @@ package org.smartfrog.services.junit.test.system; +import junit.framework.AssertionFailedError; import org.smartfrog.services.xunit.base.TestRunner; import org.smartfrog.services.xunit.listeners.BufferingListener; import org.smartfrog.services.xunit.serial.Statistics; +import org.smartfrog.sfcore.common.SmartFrogLifecycleException; +import org.smartfrog.sfcore.common.SmartFrogLivenessException; +import org.smartfrog.sfcore.prim.Liveness; import org.smartfrog.test.DeployingTestBase; import org.smartfrog.test.TestHelper; import org.w3c.dom.Document; @@ -59,25 +63,24 @@ * If the application is null: a JUnit exception is trown * @return the application as a test runner. */ - TestRunner getTestRunner() { + TestRunner getApplicationAsTestRunner() { TestRunner runner = (TestRunner) application; assertNotNull(runner); return runner; } - + /** * Spin till a component is finished * * @param runner * @param timeoutSeconds * @return whether it finished or false for timeout - * @throws InterruptedException - * @throws RemoteException + * @throws InterruptedException if interrupted + * @throws RemoteException on network problems */ protected boolean spinTillFinished(TestRunner runner, int timeoutSeconds) throws InterruptedException, RemoteException { - try { do { Thread.sleep(1000); @@ -127,15 +130,15 @@ } /** - * execute a test run to a buffer + * execute a test run to a buffer, and make assertions about the results * @param name the test to run (base-relative; no .sf extension needed) * @param run number of tests to run; -1 means no - * @param errors - * @param failures - * @throws Throwable + * @param errors number of errors expected + * @param failures number of failures expected + * @throws Throwable on any failure */ protected void executeBufferedTestRun(String name, int run, int errors, int failures) throws Throwable { - application = deployExpectingSuccess(BASE+name+".sf", name); + application = deployExpectingSuccess(BASE + name + ".sf", name); int seconds = getTimeout(); TestRunner runner = (TestRunner) application; assertTrue(runner != null); @@ -146,8 +149,11 @@ listener, true); boolean finished = spinTillFinished(runner, seconds); + ping("test runner", runner); + ping("BufferingListener", listener); + assertTrue("Test run timed out", finished); - if(run>=0) { + if (run >= 0) { assertTrue("expected tests to run", listener.getStartCount() == 1); assertTrue("session started", listener.getSessionStartCount() == 1); @@ -155,13 +161,23 @@ listener.getSessionEndCount() == 1); //assertTrue("all tests passed", listener.testsWereSuccessful()); Statistics statistics = runner.getStatistics(); - assertEquals("statistics.testRun"+run, run, statistics.getTestsRun()); + assertEquals("statistics.testRun" + run, run, statistics.getTestsRun()); assertEquals("statistics.errors", errors, statistics.getErrors()); - assertEquals("statistics.failures",failures, + assertEquals("statistics.failures", failures, statistics.getFailures()); } else { assertEquals("expected tests to be skipped and startcount==0", - 0,listener.getStartCount()); + 0, listener.getStartCount()); } } + + protected void ping(final String component, final Liveness runner) throws SmartFrogLivenessException, RemoteException { + try { + runner.sfPing(null); + } catch (NoSuchObjectException e) { + //if we get here then the test runner finished, but it isn't hanging around. This usually indicates some kind of + //deployment failure + throw new SmartFrogLivenessException("The "+ component +" is no longer live", e); + } + } } Deleted: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTest.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTest.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTest.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -1,44 +0,0 @@ -/** (C) Copyright 2006 Hewlett-Packard Development Company, LP - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - For more information: www.smartfrog.org - - */ -package org.smartfrog.services.junit.test.targets; - -import junit.framework.TestCase; - -/** - * created Nov 25, 2004 3:34:58 PM - */ - -public class ErrorInConstructorTest extends TestCase { - - - - - /** Constructs a test case with the given name. */ - public ErrorInConstructorTest(String name) { - super(name); - throw new IllegalArgumentException("fail in constructor"); - } - - public void testNothing() { - fail("We should never get here"); - } - - -} Copied: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTestTarget.java (from rev 8590, trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTest.java) =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTestTarget.java (rev 0) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInConstructorTestTarget.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -0,0 +1,45 @@ +/** (C) Copyright 2006 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.services.junit.test.targets; + +import junit.framework.TestCase; + +/** + * created Nov 25, 2004 3:34:58 PM + */ + +public class ErrorInConstructorTestTarget extends TestCase { + + + /** + * a test case designed to fail in the constructor + * @param name test name + */ + public ErrorInConstructorTestTarget(String name) { + super(name); + throw new IllegalArgumentException("fail in constructor"); + } + + public void testNothing() { + fail("We should never get here"); + } + + +} Deleted: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTest.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTest.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTest.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -1,50 +0,0 @@ -/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - For more information: www.smartfrog.org - - */ -package org.smartfrog.services.junit.test.targets; - -import junit.framework.TestCase; - -/** - * created Nov 25, 2004 3:34:58 PM - */ - -public class ErrorInSetupTest extends TestCase { - - - /** Constructs a test case with the given name. */ - public ErrorInSetupTest(String name) { - super(name); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() throws Exception { - super.setUp(); - throw new IllegalArgumentException("fail in setUp()"); - } - - public void testNothing() { - - } - - -} Copied: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTestTarget.java (from rev 8590, trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTest.java) =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTestTarget.java (rev 0) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTestTarget.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -0,0 +1,53 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.services.junit.test.targets; + +import junit.framework.TestCase; + +/** + * created Nov 25, 2004 3:34:58 PM + */ + +public class ErrorInSetupTestTarget extends TestCase { + + + /** + * a test case designed to fail in the setup + * @param name test name + */ + public ErrorInSetupTestTarget(String name) { + super(name); + } + + /** + * @throws IllegalArgumentException always + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + throw new IllegalArgumentException("fail in setUp()"); + } + + public void testNothing() { + + } + + +} Property changes on: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInSetupTestTarget.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTest.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTest.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTest.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -1,49 +0,0 @@ -/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - For more information: www.smartfrog.org - - */ -package org.smartfrog.services.junit.test.targets; - -import junit.framework.TestCase; - -/** - * See what happens when we fail at teardown - * created Nov 25, 2004 3:36:30 PM - */ - -public class ErrorInTeardownTest extends TestCase { - - - /** Constructs a test case with the given name. */ - public ErrorInTeardownTest(String name) { - super(name); - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() throws Exception { - super.tearDown(); - throw new IllegalArgumentException("tearDown()"); - } - - public void testNothing() { - - } -} Copied: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTestTarget.java (from rev 8590, trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTest.java) =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTestTarget.java (rev 0) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTestTarget.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -0,0 +1,51 @@ +/** (C) Copyright 1998-2004 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ +package org.smartfrog.services.junit.test.targets; + +import junit.framework.TestCase; + +/** + * See what happens when we fail at teardown + * created Nov 25, 2004 3:36:30 PM + */ + +public class ErrorInTeardownTestTarget extends TestCase { + + + /** Constructs a test case with the given name. + * @param name test name + * */ + public ErrorInTeardownTestTarget(String name) { + super(name); + } + + /** + * @throws IllegalArgumentException always + */ + @Override + protected void tearDown() throws Exception { + super.tearDown(); + throw new IllegalArgumentException("tearDown()"); + } + + public void testNothing() { + + } +} Property changes on: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/ErrorInTeardownTestTarget.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTest.java =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTest.java 2011-06-09 16:58:38 UTC (rev 8614) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTest.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -1,42 +0,0 @@ -/** (C) Copyright 2004 Hewlett-Packard Development Company, LP - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - For more information: www.smartfrog.org - - */ - - -package org.smartfrog.services.junit.test.targets; - -import junit.framework.TestCase; - -/** - * This test fails - * Date: 05-Jul-2004 - * Time: 22:08:54 - */ -public class FailureTest extends TestCase { - - public FailureTest(String s) { - super(s); - } - - public void testFailure() { - assertTrue("expected failure",false); - } - - -} Copied: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTestTarget.java (from rev 8590, trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTest.java) =================================================================== --- trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTestTarget.java (rev 0) +++ trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTestTarget.java 2011-06-09 17:34:25 UTC (rev 8615) @@ -0,0 +1,42 @@ +/** (C) Copyright 2004 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + */ + + +package org.smartfrog.services.junit.test.targets; + +import junit.framework.TestCase; + +/** + * This test fails + * Date: 05-Jul-2004 + * Time: 22:08:54 + */ +public class FailureTestTarget extends TestCase { + + public FailureTestTarget(String s) { + super(s); + } + + public void testFailure() { + assertTrue("expected failure", false); + } + + +} Property changes on: trunk/core/components/junit/test/org/smartfrog/services/junit/test/targets/FailureTestTarget.java ________________________________________... [truncated message content] |
From: <st...@us...> - 2011-06-26 18:23:22
|
Revision: 8666 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8666&view=rev Author: steve_l Date: 2011-06-26 18:23:15 +0000 (Sun, 26 Jun 2011) Log Message: ----------- SFOS-1598 Create grinstall Groovy Installer component Modified Paths: -------------- trunk/core/components/grinstall/build.xml trunk/core/components/grinstall/doc/README.txt trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/DelegatingScript.groovy trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/GroovyTask.groovy trunk/core/components/groovy/test/org/smartfrog/test/system/services/scripting/groovy/GroovyScriptEngineTest.java Added Paths: ----------- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/utils/ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/utils/ComponentUtils.groovy trunk/core/components/grinstall/test/log4j.properties Modified: trunk/core/components/grinstall/build.xml =================================================================== --- trunk/core/components/grinstall/build.xml 2011-06-26 18:22:25 UTC (rev 8665) +++ trunk/core/components/grinstall/build.xml 2011-06-26 18:23:15 UTC (rev 8666) @@ -24,7 +24,7 @@ <import file="${root.dir}/common.xml"/> <property name="is.component" value="true"/> - <property name="org.apache.commons.logging.diagnostics.dest" value="STDERR"/> +<!-- <property name="org.apache.commons.logging.diagnostics.dest" value="STDERR"/>--> <echo message="==================================================================="/> <echo message="= ${ant.project.name}"/> Modified: trunk/core/components/grinstall/doc/README.txt =================================================================== --- trunk/core/components/grinstall/doc/README.txt 2011-06-26 18:22:25 UTC (rev 8665) +++ trunk/core/components/grinstall/doc/README.txt 2011-06-26 18:23:15 UTC (rev 8666) @@ -1,22 +1,31 @@ Author: Benjamin Koenig -E-Mail: ben...@hp... State: Basically working, able to deploy Hadoop, no tests yet -This project provides a SmartFrog addon which enable users to deploy diverse applications (i.e. Hadoop, Ganglia). +This project provides a SmartFrog addon which enable users to deploy diverse applications (i.e. Hadoop, Ganglia) +without having to write Java code or create JAR files. Instead it uses Groovy scripts in the filesystem to +define actions, and SmartFrog .sf files to provide the configuration/control data. -HOW TO BUILD +Key Concepts + +* Targets Unix only; assumes the normal Linux toolchain is present. +* Originally written for post-instantiation deployment on virtual machines, it assumes + the user is running as root, at least for the example Hadoop files. + + + HOW TO BUILD ------------ ant clean -ant package // creates installer jar (dist/lib) +ant package // creates sf-grinstall.jar (dist/lib) ant ivy-retrieve // retrieves 3rdparty jars (build/ivy/lib/runtime) +ant publish // publishes the JAR and its dependency metadata to the local Ivy cache. Each VM has to have the installer jar and all its dependencies! You can set SFUSERHOME, SFUSERHOME1, etc., to set the classpath of the SmartFrog daemon. The following files have to be in the classpath: -- installer jar (all daemons) +- sf-grinstall.jar (all daemons) - 3rdparty jars (all daemons) - the .sf file of each component you use (only initial daemon) @@ -32,15 +41,18 @@ - The "directory" attribute defines a directory on the destination host for all source downloads and task files. -- a variable number of ISource subcomponents (see base.sf) which take care of downloading files before installation. -Currently, "installer.download.Source" is the only Java class implementing ISource. It wraps the Apache Commons VFS API -and you can use it to download the contents of a directory, tar or jar file, or files individually. +- a variable number of ISource subcomponents (see src/org/smartfrog/services/groovy/install/base.sf) which +takes care of downloading files before installation. + +Currently, "installer.download.Source" is the only Java class implementing ISource. + +It wraps the Apache Commons VFS API and you can use it to download the contents of a directory, tar or JAR file, or files individually. The following file systems are currently supported: * FTP * Local Files * HTTP and HTTPS - * SFTP + * SFTP (provided jsch is on the classpath, which comes from sf-ssh) * Temporary Files * Zip, Jar and Tar (uncompressed, tgz or tbz2) * gzip and bzip2 @@ -76,4 +88,8 @@ delete("$baseDir/example2.txt") -If you have any questions or suggestions for further development, please feel free to contact me. \ No newline at end of file +If you have any questions or suggestions for further development, please feel free to contact the smartfrog +mailing list. + +Using the components +==================== Modified: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/DelegatingScript.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/DelegatingScript.groovy 2011-06-26 18:22:25 UTC (rev 8665) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/DelegatingScript.groovy 2011-06-26 18:23:15 UTC (rev 8666) @@ -16,9 +16,9 @@ import org.smartfrog.sfcore.logging.LogFactory import org.smartfrog.sfcore.logging.LogSF -public abstract class DelegatingScript extends Script { +public class DelegatingScript extends Script { - private LogSF sfLog = LogFactory.sfGetProcessLog() + private LogSF sfLog = LogFactory.getLog(this.class) private Component component private GroovyComponentHelper helper @@ -27,10 +27,14 @@ if (comp) { component = comp try { - sfLog = LogFactory.getLog(component.sfResolve(SmartFrogCoreKeys.SF_APP_LOG_NAME, - "DelegatingScript", true)) + String logName = component.sfResolve(SmartFrogCoreKeys.SF_APP_LOG_NAME, + "", false) + if(logName) { + sfLog = LogFactory.getLog(logName) + } } catch (Exception e) { - sfLog.error(e.message) + //retrieval failed, so it retains the original + sfLog.error(e.toString()) throw new SmartFrogExtractedException(SmartFrogExtractedException.convert(e)) } } @@ -51,12 +55,20 @@ return InvokerHelper.invokeMethod(helper, name, args) } //if we get here, nothing was found - sfLog.error("Method $name not found, trying super class") + sfLog.warn("Method $name not found, trying super class") return super.invokeMethod(name, args); } catch (MissingMethodException e) { - sfLog.error("Method $name not found, trying super class: " + e, e) + sfLog.warn("Method $name not found, trying super class: " + e, e) return super.invokeMethod(name, args); } } + + @Override + Object run() { + sfLog.info("In the script runner of $this") + return null + } + + } \ No newline at end of file Modified: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/GroovyTask.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/GroovyTask.groovy 2011-06-26 18:22:25 UTC (rev 8665) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/task/GroovyTask.groovy 2011-06-26 18:23:15 UTC (rev 8666) @@ -6,6 +6,8 @@ import org.smartfrog.sfcore.common.SmartFrogExtractedException import org.smartfrog.sfcore.prim.PrimImpl import org.smartfrog.services.groovy.install.Component +import org.smartfrog.services.groovy.install.utils.ComponentUtils +import org.smartfrog.sfcore.common.SmartFrogDeploymentException /** * User: koenigbe @@ -14,7 +16,7 @@ */ class GroovyTask extends PrimImpl implements ITask { - private static final String simplename = getClass().getSimpleName() + private final String simplename = getClass().getSimpleName() private Vector previousTasks @@ -26,12 +28,21 @@ super() } + /** + * Implement {@link ITask#run() } + * @throws RemoteException + * @throws SmartFrogException + */ @Override public void run() throws RemoteException, SmartFrogException { if (!sfResolve(ATTR_FINISHED, false, false)) { def file = sfResolve(ATTR_FILE, "", false) - if (!file) return // no task file specified + if (!file) { + // no task file specified + sfLog().debug("No file specified") + return + } def directory = sfParent().sfResolve(ATTR_DIRECTORY) previousTasks = sfResolve(ATTR_PRECONDITIONS, new Vector(), false) register() @@ -78,6 +89,9 @@ } } + /** + * Notify everything that is waiting on the lock that they arefree to continue + */ private void unlock() { synchronized (lock) { lock.notifyAll(); @@ -86,18 +100,29 @@ private void execute(directory, file) { sfLog().debug("Executing file $file in directory $directory") - def f = new File("$directory/$file") + def filename = new File("$directory/$file") def conf = new CompilerConfiguration() - conf.setScriptBaseClass("org.smartfrog.services.groovy.install.task.DelegatingScript") - DelegatingScript s + conf.setScriptBaseClass(DelegatingScript.class.name) + Binding binding = new Binding() + DelegatingScript script try { - s = new GroovyShell(conf).parse(f.getText()) + GroovyShell shell = new GroovyShell(this.class.classLoader, binding, conf) + String text = filename.getText() + Script parsedScript = shell.parse(text) + ComponentUtils utils = new ComponentUtils() + if (!(parsedScript instanceof DelegatingScript)) { + def hierarchy = utils.extractClassHierarchy(parsedScript) + sfLog().warn(hierarchy) + throw new SmartFrogDeploymentException("Unable to convert the instance $parsedScript" + + " into a Delegating Script; class hierarchy is :\n$hierarchy"); + } + script = parsedScript + script.setComponent((Component)sfParent()) + script.run() } catch (Exception e) { - sfLog().error(e.toString(), e) + sfLog().error("When trying to parse $filename: $e", e) throw new SmartFrogExtractedException(SmartFrogExtractedException.convert(e)) } - s?.setComponent((Component)sfParent()) - s?.run() } @Override Added: trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/utils/ComponentUtils.groovy =================================================================== --- trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/utils/ComponentUtils.groovy (rev 0) +++ trunk/core/components/grinstall/src/org/smartfrog/services/groovy/install/utils/ComponentUtils.groovy 2011-06-26 18:23:15 UTC (rev 8666) @@ -0,0 +1,25 @@ +package org.smartfrog.services.groovy.install.utils + +/** + * Utils to aid working with Groovy components + */ +public class ComponentUtils { + + public String extractClassHierarchy(instance) { + StringBuilder builder = new StringBuilder() + builder << "Instance $instance : ${instance.class} \n" + listParents(builder, instance.class) + return builder.toString() + } + + def listParents(StringBuilder builder, Class clazz) { + builder << clazz << "\n" + def parent = clazz.getSuperclass() + if (parent != null) { + listParents(builder, parent) + } else { + builder << " -- \n " + } + } + +} Copied: trunk/core/components/grinstall/test/log4j.properties (from rev 8663, trunk/core/testharness/test/log4j.properties) =================================================================== --- trunk/core/components/grinstall/test/log4j.properties (rev 0) +++ trunk/core/components/grinstall/test/log4j.properties 2011-06-26 18:23:15 UTC (rev 8666) @@ -0,0 +1,13 @@ +# This is the log4j settings for the testharness + +# Set root category priority to INFO and its only appender to CONSOLE. +#log4j.rootCategory=INFO, CONSOLE + +log4j.logger.org.smartfrog=INFO + +# CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.Threshold=DEBUG +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%-4r %-5p %c %x - %m%n + Modified: trunk/core/components/groovy/test/org/smartfrog/test/system/services/scripting/groovy/GroovyScriptEngineTest.java =================================================================== --- trunk/core/components/groovy/test/org/smartfrog/test/system/services/scripting/groovy/GroovyScriptEngineTest.java 2011-06-26 18:22:25 UTC (rev 8665) +++ trunk/core/components/groovy/test/org/smartfrog/test/system/services/scripting/groovy/GroovyScriptEngineTest.java 2011-06-26 18:23:15 UTC (rev 8666) @@ -5,13 +5,16 @@ package org.smartfrog.test.system.services.scripting.groovy; import junit.framework.TestCase; +import org.smartfrog.test.SmartFrogTestBase; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; -@SuppressWarnings({"UseOfSystemOutOrSystemErr"}) -public class GroovyScriptEngineTest extends TestCase { +public class GroovyScriptEngineTest extends SmartFrogTestBase { + public GroovyScriptEngineTest(final String name) { + super(name); + } public void testScriptEngineLoadsGroovy() throws Throwable { ScriptEngineManager factory = new ScriptEngineManager(); @@ -19,7 +22,8 @@ assertNotNull("No groovy found", engine); engine.put("key", "value"); Object result = engine.eval("\"$key\""); - System.out.println(result); - assertEquals("value", result.toString()); + String resultText = result.toString(); + getLog().info(resultText); + assertEquals("value", resultText); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <st...@us...> - 2011-09-13 12:37:21
|
Revision: 8726 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=8726&view=rev Author: steve_l Date: 2011-09-13 12:37:09 +0000 (Tue, 13 Sep 2011) Log Message: ----------- SFOS-1648 Move to Ant 1.8.2 Modified Paths: -------------- trunk/core/components/ant/ivy.xml trunk/core/components/ant/project-template.pom trunk/core/components/libraries.properties Modified: trunk/core/components/ant/ivy.xml =================================================================== --- trunk/core/components/ant/ivy.xml 2011-09-13 12:34:07 UTC (rev 8725) +++ trunk/core/components/ant/ivy.xml 2011-09-13 12:37:09 UTC (rev 8726) @@ -44,10 +44,6 @@ <artifact name="sf-ant-documentation" conf="documentation" ext="zip"/> </publications> <dependencies> - <dependency org="org.apache.ant" - name="ant-nodeps" - rev="${apache.ant.version}" - conf="ant-optional->master"/> <dependency org="org.smartfrog" name="smartfrog" changing="true" @@ -69,7 +65,8 @@ <dependency org="org.apache.ant" name="ant-launcher" rev="${apache.ant.version}" - conf="redist->master"/> + conf="redist->master"/> + <!-- here are the optionals --> <dependency org="org.apache.ant" name="ant-antlr" Modified: trunk/core/components/ant/project-template.pom =================================================================== --- trunk/core/components/ant/project-template.pom 2011-09-13 12:34:07 UTC (rev 8725) +++ trunk/core/components/ant/project-template.pom 2011-09-13 12:37:09 UTC (rev 8726) @@ -32,12 +32,6 @@ <!--optional dependencies--> <dependency> <groupId>org.apache.ant</groupId> - <artifactId>ant-nodeps</artifactId> - <version>${apache.ant.version}</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.apache.ant</groupId> <artifactId>ant-antlr</artifactId> <version>${apache.ant.version}</version> <optional>true</optional> Modified: trunk/core/components/libraries.properties =================================================================== --- trunk/core/components/libraries.properties 2011-09-13 12:34:07 UTC (rev 8725) +++ trunk/core/components/libraries.properties 2011-09-13 12:37:09 UTC (rev 8726) @@ -5,7 +5,7 @@ #FOUND IN MAVEN activation.version=1.1 -apache.ant.version=1.8.1 +apache.ant.version=1.8.2 apache.httpcommons.core.version=4.1 apache.httpcommons.client.version=4.1 ant-testutil.version=${apache.ant.version} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |