incubator-stonehenge-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shan...@apache.org
Subject svn commit: r720797 [1/9] - in /incubator/stonehenge/contrib/stocktrader/ruby: ./ order_processor/ order_processor/keys/ order_processor/policies/ trader_client/ trader_client/app/ trader_client/app/controllers/ trader_client/app/helpers/ trader_client...
Date Wed, 26 Nov 2008 10:52:44 GMT
Author: shankar
Date: Wed Nov 26 02:52:40 2008
New Revision: 720797

URL: http://svn.apache.org/viewvc?rev=720797&view=rev
Log:
adding Ruby Stock Trader

Added:
    incubator/stonehenge/contrib/stocktrader/ruby/
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/data_access_layer.rb
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/database_config.xml
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_cert.cert
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_key.pem
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_cert.cert
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_key.pem
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor.rb
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_client.rb
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_controller.rb
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_msec_controller.rb
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/policies/
    incubator/stonehenge/contrib/stocktrader/ruby/order_processor/policies/order_processor_policy.xml
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/README
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/Rakefile
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/application.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/trade_controller.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/trade_logic.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/trade_utils.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/helpers/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/helpers/application_helper.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/helpers/trade_helper.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/models/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/layouts/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/layouts/default.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/account.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/config.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/confirmation.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/glossary.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/home.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/index.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/login.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/portfolio.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/quotes.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/views/trade/register.html.erb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/boot.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/database.yml
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/database.yml.bk
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/environment.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/environments/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/environments/development.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/environments/production.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/environments/test.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/initializers/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/initializers/inflections.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/initializers/mime_types.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/initializers/new_rails_defaults.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/config/routes.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/db/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/doc/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/doc/README_FOR_APP
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/lib/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/lib/tasks/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/log/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/log/development.log
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/log/production.log
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/log/server.log
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/log/test.log
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/404.html
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/422.html
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/500.html
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/dispatch.cgi
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/dispatch.fcgi
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/dispatch.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/favicon.ico
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/Thumbs.db   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/bg.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/button-bg.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/footer-bg.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/green-arrow.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/header-bg.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/header-link-bg-hover.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/header-link-bg.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/header-links-bg.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/logo.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/middle-bg.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/powered-by-logo.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/rails.png   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/images/red-arrow.gif   (with props)
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/index.html
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/javascripts/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/javascripts/application.js
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/javascripts/controls.js
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/javascripts/dragdrop.js
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/javascripts/effects.js
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/javascripts/prototype.js
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/robots.txt
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/stylesheets/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/stylesheets/style.css
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/wsdl/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/wsdl/TradeServiceWcf.svc.wsdl
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/wsdl/TradeServiceWcf.svc.wsdl0
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/wsdl/TradeServiceWcf.svc.xsd0
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/wsdl/TradeServiceWcf.svc.xsd1
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/wsdl/config_svc.wsdl
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/public/wsdl/noimports.wsdl
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/about
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/console
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/dbconsole
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/destroy
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/generate
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/performance/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/performance/benchmarker
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/performance/profiler
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/performance/request
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/plugin
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/process/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/process/inspector
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/process/reaper
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/process/spawner
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/runner
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/script/server
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/test/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/test/fixtures/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/test/functional/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/test/functional/trade_controller_test.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/test/integration/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/test/test_helper.rb
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/test/unit/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/tmp/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/tmp/cache/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/tmp/pids/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/tmp/sessions/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/tmp/sockets/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/vendor/
    incubator/stonehenge/contrib/stocktrader/ruby/trader_client/vendor/plugins/

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/data_access_layer.rb
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/data_access_layer.rb?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/data_access_layer.rb (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/data_access_layer.rb Wed Nov 26 02:52:40 2008
@@ -0,0 +1,96 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+
+# This class encapsulates information regarding the establishment
+# of database connection.
+class ConnectionInfo
+	attr_accessor :server, :user, :password, :database
+end
+
+# The method retrieves information for the database connection
+# from a configuration file. The name of the config file should
+# be, database_config.xml, and it should be in the same directory
+# as this file.
+# @return non NULL value (ConnectionInfo object), upon successfull 
+# execution, and NULL if some information regarding the 
+# connection is not available.
+def GetConnectionInfo()
+	input = File.new('./app/controllers/database_config.xml')
+	unless input.nil?
+		doc = REXML::Document.new(input)
+     	unless doc.nil?
+       		root_element = doc.root
+	   		connectionInfo = ConnectionInfo.new();
+			server = REXML::XPath.match(root_element, "/config/server")
+			if(server)
+				connectionInfo.server = server[0].get_text.to_s;
+			end
+			user = REXML::XPath.match(root_element, "/config/user")
+			if(user)
+				connectionInfo.user = user[0].get_text.to_s;
+			end
+			password = REXML::XPath.match(root_element, "/config/password")
+			if(password)
+				connectionInfo.password = password[0].get_text.to_s;
+			end
+			database = REXML::XPath.match(root_element, "/config/database")
+			if(database)
+				connectionInfo.database = database[0].get_text.to_s;
+			end
+     	end
+   	end
+
+   if((connectionInfo) && (connectionInfo.server != "") && (connectionInfo.user != "") && 
+	  (connectionInfo.password != "") && (connectionInfo.database != ""))
+	   	return connectionInfo;
+   elsif
+	   	puts "Cannot get database configuration details \n"
+	   	return nil
+   end
+end
+
+# This method establishes a connection to the database. 
+# @return dbhandle, upon successfull execution a non null
+# handle to the database connection is returned. Else it 
+# will be null.
+def ConnectToDatabase()
+	require 'dbi'
+	connInfo = GetConnectionInfo()
+	connStr = 'DBI:ADO:Provider=SQLNCLI;Data Source="' + connInfo.server + '";Initial Catalog="' + connInfo.database + '";User ID="' + connInfo.user + '";password="' + connInfo.password + '"'
+	if(connInfo)
+		dbConn = DBI.connect(connStr)
+	end
+	return dbConn
+end
+
+# This method executes a query that it receives.
+# @param dbConn db connection
+# @param query the query to execute
+# @return non-NULL upon success and NULL otherwise.
+def ExecuteQuery(dbConn, query)
+	if(dbConn)
+		return dbConn.execute(query)
+	end
+end
+
+# This method close the connection that is established to the
+# database.
+# @param dbhandle handle to the database
+def CloseDatabase(dbConn)
+	dbConn.disconnect()
+end
+

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/database_config.xml
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/database_config.xml?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/database_config.xml (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/database_config.xml Wed Nov 26 02:52:40 2008
@@ -0,0 +1,6 @@
+<config>
+	<server>127.0.0.1,1433</server>
+	<user>trade</user>
+	<password>trade</password>
+	<database>StockTraderDB</database>
+</config>

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_cert.cert
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_cert.cert?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_cert.cert (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_cert.cert Wed Nov 26 02:52:40 2008
@@ -0,0 +1,19 @@
+-----BEGIN CERTIFICATE-----
+MIIDDDCCAfSgAwIBAgIQM6YEf7FVYx/tZyEXgVComTANBgkqhkiG9w0BAQUFADAw
+MQ4wDAYDVQQKDAVPQVNJUzEeMBwGA1UEAwwVT0FTSVMgSW50ZXJvcCBUZXN0IENB
+MB4XDTA1MDMxOTAwMDAwMFoXDTE4MDMxOTIzNTk1OVowQjEOMAwGA1UECgwFT0FT
+SVMxIDAeBgNVBAsMF09BU0lTIEludGVyb3AgVGVzdCBDZXJ0MQ4wDAYDVQQDDAVB
+bGljZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAoqi99By1VYo0aHrkKCNT
+4DkIgPL/SgahbeKdGhrbu3K2XG7arfD9tqIBIKMfrX4Gp90NJa85AV1yiNsEyvq+
+mUnMpNcKnLXLOjkTmMCqDYbbkehJlXPnaWLzve+mW0pJdPxtf3rbD4PS/cBQIvtp
+jmrDAU8VsZKT8DN5Kyz+EZsCAwEAAaOBkzCBkDAJBgNVHRMEAjAAMDMGA1UdHwQs
+MCowKKImhiRodHRwOi8vaW50ZXJvcC5iYnRlc3QubmV0L2NybC9jYS5jcmwwDgYD
+VR0PAQH/BAQDAgSwMB0GA1UdDgQWBBQK4l0TUHZ1QV3V2QtlLNDm+PoxiDAfBgNV
+HSMEGDAWgBTAnSj8wes1oR3WqqqgHBpNwkkPDzANBgkqhkiG9w0BAQUFAAOCAQEA
+BTqpOpvW+6yrLXyUlP2xJbEkohXHI5OWwKWleOb9hlkhWntUalfcFOJAgUyH30TT
+pHldzx1+vK2LPzhoUFKYHE1IyQvokBN2JjFO64BQukCKnZhldLRPxGhfkTdxQgdf
+5rCK/wh3xVsZCNTfuMNmlAM6lOAg8QduDah3WFZpEA0s2nwQaCNQTNMjJC8tav1C
+Br6+E5FAmwPXP7pJxn9Fw9OXRyqbRA4v2y7YpbGkG2GI9UvOHw6SGvf4FRSthMMO
+35YbpikGsLix3vAsXWWi4rwfVOYzQK0OFPNi9RMCUdSH06m9uLWckiCxjos0FQOD
+ZE9l4ATGy9s9hNVwryOJTw==
+-----END CERTIFICATE-----

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_key.pem
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_key.pem?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_key.pem (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/alice_key.pem Wed Nov 26 02:52:40 2008
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQCiqL30HLVVijRoeuQoI1PgOQiA8v9KBqFt4p0aGtu7crZcbtqt
+8P22ogEgox+tfgan3Q0lrzkBXXKI2wTK+r6ZScyk1wqctcs6OROYwKoNhtuR6EmV
+c+dpYvO976ZbSkl0/G1/etsPg9L9wFAi+2mOasMBTxWxkpPwM3krLP4RmwIDAQAB
+AoGAY+fazB357rE1YVrh2hlgwh6lr3YRASmzaye+MLOAdNCPW5Sm8iFL5Cn7IU2v
+/kKi2eW21oeaLtFzsMU9W2LJP6h33caPcMr/1F3wsiHRCBSZiRLgroYnryJ2pWRq
+B8r6/j1mCKzNkoxwspUS1tPFIT0yJB4L/bQGMIvnoM4v5aECQQDX2hBKRbsQYSgL
+xZmqx/KJG7+rcpjYXBcztcO09sAsJ+tJe7FPKoKB1CG/KWqj8KQn69blXxhKRDTp
+rPZLiU7RAkEAwOnfR+dwLbnNGTuafvvbWE1d0CCa3YGooCrrCq4Af7D5jv9TZXDx
+yOIZsHzQH5U47e9ht2JvYllbTlMhirKsqwJBAKbyAadwRz5j5pU0P6XW/78LtzLj
+b1Pn5goYi0VrkzaTqWcsQ/b26fmAGJnBbrldZZl6zrqY0jCekE4reFLz4AECQA7Y
+MEFFMuGh4YFmj73jvX4u/eANEj2nQ4WHp+x7dTheMuXpCc7NgR13IIjvIci8X9QX
+Toqg/Xcw7xC43uTgWN8CQF2p4WulNa6U64sxyK1gBWOr6kwx6PWU29Ay6MPDPAJP
+O84lDgb5dlC1SGE+xHUzPPN6E4YFI/ECawOHNrADEsE=
+-----END RSA PRIVATE KEY-----

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_cert.cert
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_cert.cert?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_cert.cert (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_cert.cert Wed Nov 26 02:52:40 2008
@@ -0,0 +1,19 @@
+-----BEGIN CERTIFICATE-----
+MIIDCjCCAfKgAwIBAgIQYDju2/6sm77InYfTq65x+DANBgkqhkiG9w0BAQUFADAw
+MQ4wDAYDVQQKDAVPQVNJUzEeMBwGA1UEAwwVT0FTSVMgSW50ZXJvcCBUZXN0IENB
+MB4XDTA1MDMxOTAwMDAwMFoXDTE4MDMxOTIzNTk1OVowQDEOMAwGA1UECgwFT0FT
+SVMxIDAeBgNVBAsMF09BU0lTIEludGVyb3AgVGVzdCBDZXJ0MQwwCgYDVQQDDANC
+b2IwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMCquMva4lFDrv3fXQnKK8Ck
+SU7HvVZ0USyJtlL/yhmHH/FQXHyYY+fTcSyWYItWJYiTZ99PAbD+6EKBGbdfuJNU
+JCGaTWc5ZDUISqM/SGtacYe/PD/4+g3swNPzTUQAIBLRY1pkr2cm3s5Ch/f+mYVN
+BR41HnBeIxybw25kkoM7AgMBAAGjgZMwgZAwCQYDVR0TBAIwADAzBgNVHR8ELDAq
+MCiiJoYkaHR0cDovL2ludGVyb3AuYmJ0ZXN0Lm5ldC9jcmwvY2EuY3JsMA4GA1Ud
+DwEB/wQEAwIEsDAdBgNVHQ4EFgQUXeg55vRyK3ZhAEhEf+YT0z986L0wHwYDVR0j
+BBgwFoAUwJ0o/MHrNaEd1qqqoBwaTcJJDw8wDQYJKoZIhvcNAQEFBQADggEBAIiV
+Gv2lGLhRvmMAHSlY7rKLVkv+zEUtSyg08FBT8z/RepUbtUQShcIqwWsemDU8JVts
+ucQLc+g6GCQXgkCkMiC8qhcLAt3BXzFmLxuCEAQeeFe8IATr4wACmEQE37TEqAuW
+EIanPYIplbxYgwP0OBWBSjcRpKRAxjEzuwObYjbll6vKdFHYIweWhhWPrefquFp7
+TefTkF4D3rcctTfWJ76I5NrEVld+7PBnnJNpdDEuGsoaiJrwTW3Ixm40RXvG3fYS
+4hIAPeTCUk3RkYfUkqlaaLQnUrF2hZSgiBNLPe8gGkYORccRIlZCGQDEpcWl1Uf9
+OHw6fC+3hkqolFd5CVI=
+-----END CERTIFICATE-----

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_key.pem
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_key.pem?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_key.pem (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/keys/bob_key.pem Wed Nov 26 02:52:40 2008
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXgIBAAKBgQDAqrjL2uJRQ679310JyivApElOx71WdFEsibZS/8oZhx/xUFx8
+mGPn03EslmCLViWIk2ffTwGw/uhCgRm3X7iTVCQhmk1nOWQ1CEqjP0hrWnGHvzw/
++PoN7MDT801EACAS0WNaZK9nJt7OQof3/pmFTQUeNR5wXiMcm8NuZJKDOwIDAQAB
+AoGBAL9MxBAlVXG68pXAonCF/MtaVC+Uw7qD49WFJzNiJxkRwfWpBSvxY8FbgJP0
+/Addkgb51bk0iUlk0Ni3twEMWga0j9jOJLkDDoXfpHmH5HGTvNa9m241PGQ+kzAU
+dFvFzR0qUTDlBjk4pYoeqoJBTgNZGu3b3BHEbz7O7PAJUQEBAkEA8Rwrf7/pSiPH
+2pfU5StQ77+1Uva5VHpDoKLC5mgAgiPvQm2yBBSXkwPwXHEeRYEOfHydtCrudQY3
+6fVP4Oy1GQJBAMyQsI6CIjEwZzS1KXLb+ulpFBjcK99PydBGKxRue/o0ZpD69siA
+AL4YqyXl4Ai4hEHHe7FxeJe4Wzp6F0A6kXMCQQCpC8QfzHEHTzDnPP7CMm2LupCp
++1wTM6nIrXUS0CZTGFi+7WQbYkinheJ3HcRInOSIOWLkmBkaKWL4gMshezS5AkB8
+1G5pCBBFY/wWtdYtOP/MH0scQH6lLtNAPRFczm7pJ8DPB9ZAU5wgZH1MCxLDP5W1
+bj2U8mFcdCt3a7l0gEjxAkEAwoWqq6i7ZfFg4LUcKElZhjMeF8tKs1fWHhunO80t
+6hQUhBHahc4+AAgoXOMe+KAxa+F6uftjM9eg8rAAZ+6q3g==
+-----END RSA PRIVATE KEY-----

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor.rb
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor.rb?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor.rb (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor.rb Wed Nov 26 02:52:40 2008
@@ -0,0 +1,427 @@
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+ORDER_TYPE_BUY = "buy"
+ORDER_TYPE_SELL = "sell"
+ORDER_STATUS_CLOSED = "closed"
+STATUS_SUCCESS = 1
+STATUS_FAILURE = 0
+INVALID_ID = -1
+
+require "data_access_layer.rb"
+
+# This class encapsulates information regarding the order
+class Order
+	attr_accessor :orderID, :orderType, :orderStatus, :quantity, :price, :orderFee, :symbol
+end
+
+# This class encapsulate information regarding a particular quote. The
+# quote information related to a particular symbol, have to be analyzed 
+# in order to process an order.
+class Quote
+	attr_accessor :low, :open1, :volume, :price, :high, :symbol, :change1
+end
+
+# This class encapsulates information regarding a particular holding.
+# Each buy order creates a holding object and stores an entry in the
+# holding table.
+class Holding
+	attr_accessor :purchasePrice, :holdingID, :quantity, :purchaseDate, :accountID, :quoteSymbol
+end
+
+# This is the primary function which corresponds to the SubmitOrder 
+# operation. 
+def ProcessOrder(order)
+	status = STATUS_SUCCESS
+	dbhandle = ConnectToDatabase()
+
+	#This method with "BEGIN TRAN" initialize a transaction; which privides 
+	#control so that later we can cancel a the transaction, if something 
+	#goes wrong.
+	commitStatus = dbhandle['AutoCommit']
+	dbhandle['AutoCommit'] = false
+	quote = GetQuoteForUpdate(dbhandle, order.symbol)
+	if (quote)
+		order.price = quote.price
+
+=begin
+		Buy or sell orders either first creates a holding or sell a 
+		holding. The return value is the holdingID upon success. If NULL
+		is returned, then the tranaction can not be completed. This is due
+		to either problem of accessing the database or if there is no 
+		maching holding.
+
+		upon success, total price should be deducted from account's balance. 
+		In case of sell, balance should increase. So, in sell case, total price will be
+		negative value 
+=end
+
+		if (order.orderType == ORDER_TYPE_BUY)
+			holdingID = CreateHolding(dbhandle, order)
+			if (holdingID != INVALID_ID)
+				totalPrice = order.quantity * order.price + order.orderFee
+			end
+		end
+			
+		if (order.orderType == ORDER_TYPE_SELL)
+			holdingID = SellHolding(dbhandle, order)
+			if (holdingID != INVALID_ID)
+				totalPrice = -1 * order.quantity * order.price + order.orderFee
+			end
+		end
+
+		if (holdingID != INVALID_ID)
+			status = UpdateSystemStatus(dbhandle, order, quote, holdingID, totalPrice)
+		else
+			puts "Holding id for order with order id " + order.orderID.to_s + " is not valid\n"
+			status = STATUS_FAILURE
+		end
+	else
+		puts "Cannot get quote with symbol " + order.symbol + "\n"
+		status = STATUS_FAILURE
+	end
+
+	if (status == STATUS_SUCCESS)
+		#Transaction is successfull, we can safely commit the transaction
+		#into the database.
+		dbhandle.commit
+	else
+		#Transaction is not successfull, we can safely rollback the 
+		#transaction without commiting to the database.
+		dbhandle.rollback
+	end
+	dbhandle['AutoCommit'] = commitStatus
+	CloseDatabase(dbhandle)
+end
+
+# This method, retrieves all the information related to a particular symbol
+# from the QUOTE table.
+# @param symbol is the symbol we are looking for
+# @return quote object filled with symbol information upons success and else 
+# NULL is returned.
+def GetQuoteForUpdate(dbhandle, symbol)
+	quote = nil
+	query = "Set NOCOUNT ON; SELECT SYMBOL, COMPANYNAME, VOLUME, PRICE, " +
+		"OPEN1, LOW, HIGH, CHANGE1 FROM QUOTE WITH (NOLOCK) WHERE SYMBOL " +
+		"= '" + symbol +"'"
+
+	result =  ExecuteQuery(dbhandle, query)
+	if (result)
+		row = result.fetch
+		if(row)
+			quote = Quote.new()
+			quote.symbol =  row[0] #Get the symbol.
+			quote.price = row[3].to_f #Get the price.
+			quote.low = row[5].to_f #Get the low value.
+			quote.high =  row[6].to_f #Get the high value.
+		end
+		result.finish
+	end
+	return quote
+end
+
+# This method updates all the system information relates to a particular
+# buy or sell operation.
+# @param order order object
+# @param quote  quote object
+# @param holdingID holdingID of the holding which relates to the current order
+# @param totalPrice the price change  (amount of money the flows in/out of a
+# user's account).
+# @return STATUS_SUCCESS upon success and STATUS_FAILURE otherwise.
+def UpdateSystemStatus(dbhandle, order, quote, holdingID, totalPrice)
+	status = STATUS_SUCCESS
+	accountID = GetAccountIDFromOrder(dbhandle, order)
+	if (accountID != INVALID_ID)
+		if(UpdateAccountBalance(dbhandle, accountID, totalPrice) == STATUS_SUCCESS)
+			if(UpdateStockPriceVolume(dbhandle, order.quantity, quote) == STATUS_SUCCESS)
+				if(CloseOrder(dbhandle, order, holdingID) == STATUS_FAILURE)
+					puts "Cannot close order for order id " + order.orderID.to_s + " \n"
+					status = STATUS_FAILURE
+				end
+			else
+				puts "Cannot update stock price volume for symbol " + quote.symbol + "\n"
+				status = STATUS_FAILURE
+			end
+		else
+			puts "Cannot update account balace for account id " + accountID.to_s + "\n"
+			status = STATUS_FAILURE
+		end
+	else
+		puts "Account id for order id " + order.orderID.to_s + " is not valid \n"
+		status = STATUS_FAILURE
+	end
+	return status
+end
+
+# This function corresponds to a sell operation. It matches a particular
+# holding related to a particular order (symbol) and then do the transaction
+# @param order order object
+# @return a valid holdingID upon success and INVALID_ID otherwise.
+def SellHolding(dbhandle, order)
+	holding = GetHoldingForUpdate(dbhandle, order)
+	if (holding)
+		accountID = holding.accountID
+		quantity = order.quantity
+		holdingQuantity = holding.quantity
+
+		if (order.quantity < holding.quantity)
+			if(UpdateHolding(dbhandle, holding, order.quantity) == STATUS_FAILURE)
+				puts "Cannot update holding with holding id " +  holding.holdingID.to_s + " \n"
+				holding.holdingID = INVALID_ID
+			end
+		elsif (order.quantity == holding.quantity)
+			if(DeleteHolding(dbhandle, holding) == STATUS_FAILURE)
+				puts "Cannot delete holding with holding id " + holding.holdingID.to_s + " \n"
+				holding.holdingID = INVALID_ID
+			end
+		else
+			if(DeleteHolding(dbhandle, holding) == STATUS_FAILURE)
+				puts "Cannot delete holding with holding id " + holding.holdingID.to_s + " \n"
+				holding.holdingID = INVALID_ID
+			else
+				order.quantity = holding.quantity
+				if(UpdateOrder(dbhandle, order) == STATUS_FAILURE)
+					puts "Cannot update order with order id " + order.orderID.to_s + " \n"
+					holding.holdingID = INVALID_ID
+				end
+			end
+		end
+	else
+		puts "Holding for order id " + order.orderID.to_s + " is not valid \n"
+		holding.holdingID = INVALID_ID
+	end
+	return holding.holdingID
+end
+
+# This method updates the status of an order as a result of a buy or sell
+# operation.
+# @param order order object
+# @return a Holding object upon success and NULL otherwise.
+def UpdateOrder(dbhandle, order)
+	query = "UPDATE ORDERS WITH (ROWLOCK) SET QUANTITY='" + order.quantity.to_s + "' WHERE" + 
+		" ORDERID='" + order.orderID.to_s + "'"
+	result = ExecuteQuery(dbhandle, query)
+	if(result)
+		status = STATUS_SUCCESS
+		result.finish
+	else
+		status = STATUS_FAILURE
+	end
+	return status
+end
+
+# This method updates a particular Holing entry in the HOLDING table.
+# @param holding is the holding object.
+# @param quantity is the amount of buy or sell.
+# @return a Holding object upon success and NULL otherwise.
+def UpdateHolding(dbhandle, holding, quantity)
+	query = "UPDATE HOLDING WITH (ROWLOCK) SET QUANTITY=QUANTITY-'" + quantity.to_s + "'" +
+		" WHERE HOLDINGID='" + holding.holdingID.to_s + "'"
+	result = ExecuteQuery(dbhandle, query)
+	if(result)
+		status = STATUS_SUCCESS
+		result.finish
+	else
+		status = STATUS_FAILURE
+	end
+	return status
+end
+
+# Removes an entry from the HOLDING table when a matching order is received.
+# @param holding is a holding object.
+# @return STATUS_SUCCESS value on success and STATUS_FAILURE otherwise.
+def DeleteHolding(dbhandle, holding)
+	query = "DELETE FROM HOLDING WITH (ROWLOCK) WHERE HOLDINGID='" + holding.holdingID.to_s + "'"
+	result = ExecuteQuery(dbhandle, query)
+	if(result)
+		status = STATUS_SUCCESS
+		result.finish
+	else
+		status = STATUS_FAILURE
+	end
+	return status
+end
+
+# This method returns a quote object which matches to the particular sell 
+# order. 
+# @param order the order object.
+# @return a Holding object upon success and NULL otherwise.
+def GetHoldingForUpdate(dbhandle, order)
+	holding = nil
+	query = "Set NOCOUNT ON; SELECT HOLDING.HOLDINGID, HOLDING.ACCOUNT_ACCOUNTID,"+
+		" HOLDING.QUANTITY, HOLDING.PURCHASEPRICE, HOLDING.PURCHASEDATE,"+
+		" HOLDING.QUOTE_SYMBOL FROM HOLDING WITH (ROWLOCK) INNER JOIN ORDERS"+
+		" ON HOLDING.HOLDINGID = ORDERS.HOLDING_HOLDINGID WHERE "+
+		"(ORDERS.ORDERID = '" + order.orderID.to_s + "')"
+
+	#Get the machining tuple from HOLDING table, that corresponds to the 
+	#current sell operation.
+	result = ExecuteQuery(dbhandle, query)
+	if (result)
+		row = result.fetch
+		if(row)
+			holding = Holding.new()
+			holding.holdingID = row[0] #Get the holdingID.
+			holding.accountID = row[1] #Get the accountID.
+			holding.quantity = row[2] #Get the quantity.
+			holding.purchasePrice = row[3] #Get the price.
+			holding.purchaseDate = row[4] #Get the date.
+			holding.quoteSymbol = row[5] #Get the symbol.
+		else
+			puts "Cannot obtain holding for order id " + order.orderID.to_s + "\n"
+		end
+		result.finish
+	else
+		puts "Cannot obtain holding for order id " + order.orderID.to_s + "\n"
+	end
+	return holding
+end
+
+# This method updates the order status, with newest settings on completion
+# of processing an order.
+# @param order order object.
+# @param holdingID holdingID of the particular holding.
+# @return STATUS_SUCCESS on success and STATUS_FAILURE on failure.
+def CloseOrder(dbhandle, order, holdingID)
+	order.orderStatus = ORDER_STATUS_CLOSED
+	if (order.orderType == ORDER_TYPE_SELL)
+		holdingID = 0
+	end
+	query = "UPDATE ORDERS WITH (ROWLOCK) SET " + 
+		"ORDERSTATUS='" + ORDER_STATUS_CLOSED + "'," + 
+		" COMPLETIONDATE=GetDate(), HOLDING_HOLDINGID='" + holdingID.to_s + "'," + 
+		" PRICE='" + order.price.to_s + "' WHERE ORDERID='" + order.orderID.to_s + "'"
+	result = ExecuteQuery(dbhandle, query)
+	if(result)
+		status = STATUS_SUCCESS
+		result.finish
+	else
+		status = STATUS_FAILURE
+	end
+end
+
+# Create an entry in the HOLDING table to represent a particular buy order.
+# @param order order object filled with order information.
+# @return the holdingID of the created holding upon success and else it 
+# returns INVALID_ID
+def CreateHolding(dbhandle, order)
+	accountID = GetAccountIDFromOrder(dbhandle, order)
+	if (accountID != INVALID_ID)
+		query = "INSERT INTO HOLDING (PURCHASEPRICE, QUANTITY, PURCHASEDATE," +
+			" ACCOUNT_ACCOUNTID, QUOTE_SYMBOL) VALUES ('" + order.price.to_s + "','" +
+			order.quantity.to_s + "', GetDate(), '" + accountID.to_s + "', '" + order.symbol + "');" + 
+			" SELECT ID=@@IDENTITY"
+		result = ExecuteQuery(dbhandle, query)
+		if(result)
+			row = result.fetch
+			if (row)
+				holdingID = row[0]
+			else
+				puts "Cannot create holding for order id " + order.orderID + "\n"
+				holdingID = INVALID_ID
+			end
+			result.finish
+		else
+			puts "Cannot create holding for order id " + order.orderID + "\n"
+			holdingID = INVALID_ID
+		end
+	else
+		puts "Account id for order with order id "+ order.orderID + " is not valid\n"
+		holdingID = INVALID_ID
+	end
+	return holdingID
+end
+
+# This method retrieves the acccountID from a given order.
+# @param order the order object.
+# @return NON-NULL accountID upon success and NULL otherwise. 
+def GetAccountIDFromOrder(dbhandle, order)
+	query = "Set NOCOUNT ON; SELECT ACCOUNT_ACCOUNTID FROM ORDERS WITH " + 
+		"(NOLOCK) WHERE ORDERID='" + order.orderID.to_s + "'"
+
+	#Get a tuple including accountID for a particular order
+	result = ExecuteQuery(dbhandle, query)
+	if(result)
+		row = result.fetch
+		if (row)
+			accountID = row[0] #Get accountID.
+		else
+			puts "Cannot obtain account id for order with order id " + order.orderID.to_s + "\n"
+			accountID = INVALID_ID
+		end
+		result.finish
+	else
+		puts "Cannot obtain account id for order with order id " + order.orderID.to_s + "\n"
+		accountID = INVALID_ID
+	end
+  	return accountID 
+end
+
+# This method updates the account balance of the user who buy or sell some
+# sybmol.
+# @param accountID is the account to be updated.
+# @param amount the amount of money by which the account is updated.
+# @return STATUS_SUCCESS upon success and STATUS_FAILURE on failure.
+def UpdateAccountBalance(dbhandle, accountID, amount)
+	status = STATUS_FAILURE
+	query = "UPDATE ACCOUNT WITH (ROWLOCK) SET BALANCE=(BALANCE - '" + amount.to_s + 
+		"') WHERE ACCOUNTID = '" + accountID.to_s + "'"
+	result = ExecuteQuery(dbhandle, query)
+	if(result)
+		status = STATUS_SUCCESS
+		result.finish
+	end
+	return status
+end
+
+# This method updates the QUOTE table with the new price values. In here, a
+# random value is generated which is between 0.1 and 2, and then the quote
+# price is changed by multiplying it with the generted random value.
+# @param quantity the quantity of a particular symbol the client buy or sell.
+# @return STATUS_SUCCESS upon success and STATUS_FAILURE upon failure.
+def UpdateStockPriceVolume(dbhandle, quantity, quote)
+	status = STATUS_FAILURE
+	if (quote)
+		randomfloat = rand()
+		randomint = rand(2)
+		priceChangeFactor = randomint + randomfloat
+		quote.price = quote.price * priceChangeFactor
+
+		if(quote.price < 0.05 || quote.price > 1000)
+			quote.price = 100
+		end
+
+		if (quote.price < quote.low)
+			quote.low = quote.price
+		end
+
+		if (quote.price > quote.high)
+			quote.high = quote.price
+		end
+
+		query = "UPDATE QUOTE WITH (ROWLOCK) SET PRICE='" + quote.price.to_s + 
+			"', LOW='" + quote.low.to_s + "', HIGH='" + quote.high.to_s + "', CHANGE1='" + quote.price.to_s + 
+			"' - OPEN1, VOLUME=VOLUME+'" + quantity.to_s + "' WHERE SYMBOL='" + quote.symbol + "'"
+
+		result = ExecuteQuery(dbhandle, query)
+		if(result)
+			status = STATUS_SUCCESS
+			result.finish
+		end
+	end
+	return status
+end

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_client.rb
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_client.rb?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_client.rb (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_client.rb Wed Nov 26 02:52:40 2008
@@ -0,0 +1,95 @@
+#!/usr/bin/env ruby
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require 'wsf'
+
+include WSO2::WSF
+
+req_payload_string = <<XML
+<ns1:SubmitOrder xmlns:ns1="http://Trade.TraderOrderHost" xmlns:ns2="http://trade.samples.websphere.ibm.com">
+         <ns1:order>
+            <ns2:orderID>100000097</ns2:orderID>
+            <ns2:orderType>buy</ns2:orderType>
+            <ns2:orderStatus>open</ns2:orderStatus>
+            <ns2:quantity>1</ns2:quantity>
+            <ns2:price>1</ns2:price>
+            <ns2:orderFee>15.95</ns2:orderFee>
+            <ns2:symbol>s:0</ns2:symbol>
+         </ns1:order>
+      </ns1:SubmitOrder>
+XML
+
+begin
+
+=begin
+	randomfloat = rand()
+		randomint = rand(2)
+		priceChangeFactor = randomint + randomfloat
+		puts priceChangeFactor
+=end
+  LOG_FILE_NAME = "ruby_echo_client_addr.log"
+  END_POINT = "http://localhost:3001/order_processor"
+  #ACTION = "http://ruby.wsf.wso2/samples/echoString"
+  ACTION = "SubmitOrderOnePhase"
+
+  client = WSClient.new({"use_wsa" => "TRUE"},
+                        LOG_FILE_NAME)
+
+  req_message = WSMessage.new(req_payload_string,
+                              nil,
+                              {"to" => END_POINT,
+                               "action" => ACTION})
+
+  puts "Sending OM : " << "\n" << req_payload_string << "\n" 
+
+  res_message = client.send(req_message)
+
+  #ACTION = "http://ruby.wsf.wso2/samples/echoString"
+  ACTION1 = "isOnline"
+
+  req_message = WSMessage.new(req_payload_string,
+                              nil,
+                              {"to" => END_POINT,
+                               "action" => ACTION1})
+
+  puts "Sending OM : " << "\n" << req_payload_string << "\n" 
+
+  res_message = client.send(req_message)
+
+  if not res_message.nil? then
+    puts "Received OM : "<< "\n" << res_message.payload_to_s << "\n\n"
+    puts "Client invocation SUCCESSFUL !!!"
+  else
+    puts "Client invocation FAILED !!!"
+  end
+rescue WSFault => wsfault
+  puts "Client invocation FAILED !!!\n"
+  puts "WSFault : "
+  puts wsfault.xml
+  puts "----------"
+  puts wsfault.code
+  puts "----------"
+  puts wsfault.reason
+  puts "----------"
+  puts wsfault.role
+  puts "----------"
+  puts wsfault.detail
+  puts "----------"
+rescue => exception
+  puts "Client invocation FAILED !!!\n"
+  puts "Exception : " << exception
+end

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_controller.rb
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_controller.rb?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_controller.rb (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_controller.rb Wed Nov 26 02:52:40 2008
@@ -0,0 +1,207 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+require "order_processor.rb"
+
+# This method corresponds to the primary operation of the service.It processes
+# an incomming order object.
+# @param input, the order object, filled with data correspond to an order
+# @return accept upon success.
+def SubmitOrderOnePhase(input) 
+	inputStr = input.payload_to_s()
+	order = nil
+	doc = REXML::Document.new(inputStr)
+	unless doc.nil?
+		root_element = doc.root
+	end
+	if(root_element)
+		orderType = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:orderType", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+		if(orderType != nil)
+			if((orderType[0].get_text == ORDER_TYPE_BUY) ||
+			   (orderType[0].get_text == ORDER_TYPE_SELL))
+				order = Order.new()
+
+				#filling values to order object
+				order.orderType = orderType[0].get_text.to_s;
+				orderID = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:orderID", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderID)
+					order.orderID = orderID[0].get_text.to_s.to_i;
+				end
+
+				orderStatus = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:orderStatus", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderStatus)
+					order.orderStatus = orderStatus[0].get_text.to_s;
+				end
+
+				quantity = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:quantity", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(quantity)
+					order.quantity = quantity[0].get_text.to_s.to_f;
+				end
+
+				price = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:price", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(price)
+					order.price = price[0].get_text.to_s.to_f;
+				end
+
+				orderFee = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:orderFee", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderFee)
+					order.orderFee = orderFee[0].get_text.to_s.to_f;
+				end
+
+				symbol = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:symbol", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(symbol)
+					order.symbol = symbol[0].get_text.to_s;
+				end
+
+				Thread.new do
+					# This will obtains some additional time and let the business service
+					# to store information regarding an order. Then the OrderProcessor can
+					# continue processing the order request that was just stored in the 
+					# database.
+					sleep(2)
+					ProcessOrder(order)
+				end
+			elsif
+				puts "Unknown order type given \n"
+			end
+		elsif
+			puts "Order type is not valid \n"
+		end
+	elsif
+		puts "Order object given for processing is not valid \n"
+	end
+end
+
+def SubmitOrderTransactedQueue(input) 
+	inputStr = input.payload_to_s()
+	order = nil
+	doc = REXML::Document.new(inputStr)
+	unless doc.nil?
+		root_element = doc.root
+	end
+	if(root_element)
+		orderType = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:orderType", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+		if(orderType != nil)
+			if((orderType[0].get_text == ORDER_TYPE_BUY) ||
+			   (orderType[0].get_text == ORDER_TYPE_SELL))
+				order = Order.new()
+
+				#filling values to order object
+				order.orderType = orderType[0].get_text.to_s;
+				orderID = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:orderID", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderID)
+					order.orderID = orderID[0].get_text.to_s.to_i;
+				end
+
+				orderStatus = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:orderStatus", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderStatus)
+					order.orderStatus = orderStatus[0].get_text.to_s;
+				end
+
+				quantity = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:quantity", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(quantity)
+					order.quantity = quantity[0].get_text.to_s.to_f;
+				end
+
+				price = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:price", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(price)
+					order.price = price[0].get_text.to_s.to_f;
+				end
+
+				orderFee = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:orderFee", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderFee)
+					order.orderFee = orderFee[0].get_text.to_s.to_f;
+				end
+
+				symbol = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:symbol", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(symbol)
+					order.symbol = symbol[0].get_text.to_s;
+				end
+
+				Thread.new do
+					# This will obtains some additional time and let the business service
+					# to store information regarding an order. Then the OrderProcessor can
+					# continue processing the order request that was just stored in the 
+					# database.
+					sleep(2)
+					ProcessOrder(order)
+				end
+			elsif
+				puts "Unknown order type given \n"
+			end
+		elsif
+			puts "Order type is not valid \n"
+		end
+	elsif
+		puts "Order object given for processing is not valid \n"
+	end
+end
+# This function corresponds to the isOnline operation. This is used by the
+# Configuration service to make sure that the OrderProcessor service is 
+# online.
+# @return just a return is expected to make sure the service is online.
+def isOnline(input) 
+end
+
+class OrderProcessorController < ApplicationController
+
+  require "wsf"
+  skip_before_filter :verify_authenticity_token
+  
+  def index
+      #operation to ruby function map
+      operations = {"isOnline" => "isOnline", "SubmitOrderOnePhase" => "SubmitOrderOnePhase", "SubmitOrderTransactedQueue" => "SubmitOrderTransactedQueue"}
+
+	  #action to operation map
+	  actions = {"isOnline" => "isOnline", "SubmitOrderOnePhase" => "SubmitOrderOnePhase", "SubmitOrder" => "SubmitOrderTransactedQueue"}
+	  
+
+      wss = WSO2::WSF::WSService.new({"operations" => operations, 
+									 	"actions" => actions})
+
+      res = wss.reply(request, response);
+      render :text => res, :status => 202
+  end
+  
+end

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_msec_controller.rb
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_msec_controller.rb?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_msec_controller.rb (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/order_processor_msec_controller.rb Wed Nov 26 02:52:40 2008
@@ -0,0 +1,230 @@
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require "order_processor.rb"
+
+# This method corresponds to the primary operation of the service.It processes
+# an incomming order object.
+# @param input, the order object, filled with data correspond to an order
+# @return accept upon success.
+def SubmitOrderOnePhase(input) 
+	inputStr = input.payload_to_s()
+	order = nil
+	doc = REXML::Document.new(inputStr)
+	unless doc.nil?
+		root_element = doc.root
+	end
+	if(root_element)
+		orderType = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:orderType", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+		if(orderType)
+			if((orderType[0].get_text == ORDER_TYPE_BUY) ||
+			   (orderType[0].get_text == ORDER_TYPE_SELL))
+				order = Order.new()
+
+				#filling values to order object
+				order.orderType = orderType[0].get_text.to_s;
+				orderID = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:orderID", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderID)
+					order.orderID = orderID[0].get_text.to_s.to_i;
+				end
+
+				orderStatus = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:orderStatus", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderStatus)
+					order.orderStatus = orderStatus[0].get_text.to_s;
+				end
+
+				quantity = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:quantity", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(quantity)
+					order.quantity = quantity[0].get_text.to_s.to_f;
+				end
+
+				price = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:price", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(price)
+					order.price = price[0].get_text.to_s.to_f;
+				end
+
+				orderFee = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:orderFee", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderFee)
+					order.orderFee = orderFee[0].get_text.to_s.to_f;
+				end
+
+				symbol = REXML::XPath.match(root_element, "/ns1:SubmitOrder/ns1:order/ns2:symbol", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(symbol)
+					order.symbol = symbol[0].get_text.to_s;
+				end
+
+				Thread.new do
+					# This will obtains some additional time and let the business service
+					# to store information regarding an order. Then the OrderProcessor can
+					# continue processing the order request that was just stored in the 
+					# database.
+					sleep(2)
+					ProcessOrder(order)
+				end
+			elsif
+				puts "Unknown order type given \n"
+			end
+		elsif
+			puts "Order type is not valid \n"
+		end
+	elsif
+		puts "Order object given for processing is not valid \n"
+	end
+end
+
+def SubmitOrderTransactedQueue(input) 
+	inputStr = input.payload_to_s()
+	order = nil
+	doc = REXML::Document.new(inputStr)
+	unless doc.nil?
+		root_element = doc.root
+	end
+	if(root_element)
+		orderType = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:orderType", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+		if(orderType != nil)
+			if((orderType[0].get_text == ORDER_TYPE_BUY) ||
+			   (orderType[0].get_text == ORDER_TYPE_SELL))
+				order = Order.new()
+
+				#filling values to order object
+				order.orderType = orderType[0].get_text.to_s;
+				orderID = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:orderID", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderID)
+					order.orderID = orderID[0].get_text.to_s.to_i;
+				end
+
+				orderStatus = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:orderStatus", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderStatus)
+					order.orderStatus = orderStatus[0].get_text.to_s;
+				end
+
+				quantity = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:quantity", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(quantity)
+					order.quantity = quantity[0].get_text.to_s.to_f;
+				end
+
+				price = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:price", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(price)
+					order.price = price[0].get_text.to_s.to_f;
+				end
+
+				orderFee = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:orderFee", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(orderFee)
+					order.orderFee = orderFee[0].get_text.to_s.to_f;
+				end
+
+				symbol = REXML::XPath.match(root_element, "/ns1:SubmitOrderTransactedQueue/ns1:order/ns2:symbol", 
+									   {"ns1" => "http://Trade.TraderOrderHost", 
+										"ns2" => "http://trade.samples.websphere.ibm.com"})
+				if(symbol)
+					order.symbol = symbol[0].get_text.to_s;
+				end
+
+				Thread.new do
+					# This will obtains some additional time and let the business service
+					# to store information regarding an order. Then the OrderProcessor can
+					# continue processing the order request that was just stored in the 
+					# database.
+					sleep(2)
+					ProcessOrder(order)
+				end
+			elsif
+				puts "Unknown order type given \n"
+			end
+		elsif
+			puts "Order type is not valid \n"
+		end
+	elsif
+		puts "Order object given for processing is not valid \n"
+	end
+end
+
+
+# This function corresponds to the isOnline operation. This is used by the
+# Configuration service to make sure that the OrderProcessor service is 
+# online.
+# @return just a return is expected to make sure the service is online.
+def isOnline(input) 
+end
+
+def load_policy_from_file(filename)
+	return nil unless filename.kind_of? String
+	input = File.new(filename)
+	unless input.nil?
+	 	doc = REXML::Document.new(input)
+		unless doc.nil?
+	   		root_element = doc.root
+	   		return root_element
+	 	end
+	end
+	return nil
+end
+
+class OrderProcessorMsecController < ApplicationController
+
+	require "wsf"
+  	skip_before_filter :verify_authenticity_token
+  
+  	def index
+ 	    operations = {"isOnline" => "isOnline", "SubmitOrderOnePhase" => "SubmitOrderOnePhase", "SubmitOrderTransactedQueue" => "SubmitOrderTransactedQueue"}
+	  	actions = {"isOnline" => "isOnline", "SubmitOrderOnePhase" => "SubmitOrderOnePhase", "SubmitOrder" => "SubmitOrderTransactedQueue"}
+
+	  	#security specific configurations
+	  	#cert = WSO2::Util::WSUtil::ws_get_cert_from_file("./app/controllers/keys/bob_cert.cert");
+		pvt_key = WSO2::Util::WSUtil::ws_get_key_from_file("./app/controllers/keys/bob_key.pem");
+		#pub_key = WSO2::Util::WSUtil::ws_get_cert_from_file("./app/controllers/keys/alice_cert.cert");
+		policy_content = load_policy_from_file("./app/controllers/policies/order_processor_policy.xml")
+		policy = WSO2::WSF::WSPolicy.new(policy_content)
+
+		sec_token = WSO2::WSF::WSSecurityToken.new({"private_key" => pvt_key})
+								#"certificate" => cert,
+								#"receiver_certificate" =>pub_key})
+
+     	wss = WSO2::WSF::WSService.new({"operations" => operations, 
+									 	"actions" => actions,
+										"policy" => policy,
+										"security_token" => sec_token})
+
+      	res = wss.reply(request, response);
+      	render :text => res, :status => 202
+ 	 end
+end

Added: incubator/stonehenge/contrib/stocktrader/ruby/order_processor/policies/order_processor_policy.xml
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/order_processor/policies/order_processor_policy.xml?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/order_processor/policies/order_processor_policy.xml (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/order_processor/policies/order_processor_policy.xml Wed Nov 26 02:52:40 2008
@@ -0,0 +1,43 @@
+<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+    <wsp:ExactlyOne>
+        <wsp:All>
+            <sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                <wsp:Policy>
+                    <sp:ProtectionToken>
+                        <wsp:Policy>
+                            <sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
+                                <wsp:Policy>
+                                    <sp:WssX509V3Token10/>
+                                </wsp:Policy>
+                            </sp:X509Token>
+                        </wsp:Policy>
+                    </sp:ProtectionToken>
+                    <sp:AlgorithmSuite>
+                        <wsp:Policy>
+                            <sp:Basic256/>
+                        </wsp:Policy>
+                    </sp:AlgorithmSuite>
+                    <sp:Layout>
+                        <wsp:Policy>
+                            <sp:Strict/>
+                        </wsp:Policy>
+                    </sp:Layout>
+                    <sp:IncludeTimestamp/>
+                </wsp:Policy>
+            </sp:SymmetricBinding>
+            <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                <wsp:Policy>
+                    <sp:MustSupportRefKeyIdentifier/>
+                    <sp:MustSupportRefEmbeddedToken/>
+                    <sp:MustSupportRefIssuerSerial/>
+                </wsp:Policy>
+            </sp:Wss10>
+            <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                <sp:Body/>
+            </sp:SignedParts>
+            <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
+                <sp:Body/>
+            </sp:EncryptedParts>
+        </wsp:All>
+    </wsp:ExactlyOne>
+</wsp:Policy>

Added: incubator/stonehenge/contrib/stocktrader/ruby/trader_client/README
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/trader_client/README?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/trader_client/README (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/trader_client/README Wed Nov 26 02:52:40 2008
@@ -0,0 +1,256 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create 
+database-backed web applications according to the Model-View-Control pattern. 
+
+This pattern splits the view (also called the presentation) into "dumb" templates
+that are primarily responsible for inserting pre-built data in between HTML tags.
+The model contains the "smart" domain objects (such as Account, Product, Person,
+Post) that holds all the business logic and knows how to persist themselves to
+a database. The controller handles the incoming requests (such as Save New Account,
+Update Product, Show Post) by manipulating the model and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails.  You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
+   and your application name. Ex: rails myapp
+2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
+3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
+4. Follow the guidelines to start developing your application
+
+
+== Web Servers
+
+By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
+Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
+Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
+that you can always get up and running quickly.
+
+Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
+suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
+getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
+More info at: http://mongrel.rubyforge.org
+
+If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
+Mongrel and WEBrick and also suited for production use, but requires additional
+installation and currently only works well on OS X/Unix (Windows users are encouraged
+to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
+http://www.lighttpd.net.
+
+And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
+web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
+for production.
+
+But of course its also possible to run Rails on any platform that supports FCGI.
+Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
+please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
+
+
+== Apache .htaccess example
+
+# General Apache options
+AddHandler fastcgi-script .fcgi
+AddHandler cgi-script .cgi
+Options +FollowSymLinks +ExecCGI
+
+# If you don't want Rails to look in certain directories,
+# use the following rewrite rules so that Apache won't rewrite certain requests
+# 
+# Example:
+#   RewriteCond %{REQUEST_URI} ^/notrails.*
+#   RewriteRule .* - [L]
+
+# Redirect all requests not available on the filesystem to Rails
+# By default the cgi dispatcher is used which is very slow
+# 
+# For better performance replace the dispatcher with the fastcgi one
+#
+# Example:
+#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
+RewriteEngine On
+
+# If your Rails application is accessed via an Alias directive,
+# then you MUST also set the RewriteBase in this htaccess file.
+#
+# Example:
+#   Alias /myrailsapp /path/to/myrailsapp/public
+#   RewriteBase /myrailsapp
+
+RewriteRule ^$ index.html [QSA]
+RewriteRule ^([^.]+)$ $1.html [QSA]
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
+
+# In case Rails experiences terminal errors
+# Instead of displaying this message you can supply a file here which will be rendered instead
+# 
+# Example:
+#   ErrorDocument 500 /500.html
+
+ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
+
+
+== Debugging Rails
+
+Sometimes your application goes wrong.  Fortunately there are a lot of tools that
+will help you debug it and get it back on the rails.
+
+First area to check is the application log files.  Have "tail -f" commands running
+on the server.log and development.log. Rails will automatically display debugging
+and runtime information to these files. Debugging info will also be shown in the
+browser on requests from 127.0.0.1.
+
+You can also log your own messages directly into the log file from your code using
+the Ruby logger class from inside your controllers. Example:
+
+  class WeblogController < ActionController::Base
+    def destroy
+      @weblog = Weblog.find(params[:id])
+      @weblog.destroy
+      logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
+    end
+  end
+
+The result will be a message in your log file along the lines of:
+
+  Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
+
+More information on how to use the logger is at http://www.ruby-doc.org/core/
+
+Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
+
+* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
+* Learn to Program: http://pine.fm/LearnToProgram/  (a beginners guide)
+
+These two online (and free) books will bring you up to speed on the Ruby language
+and also on programming in general.
+
+
+== Debugger
+
+Debugger support is available through the debugger command when you start your Mongrel or
+Webrick server with --debugger. This means that you can break out of execution at any point
+in the code, investigate and change the model, AND then resume execution! 
+You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
+Example:
+
+  class WeblogController < ActionController::Base
+    def index
+      @posts = Post.find(:all)
+      debugger
+    end
+  end
+
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the server window. Here you can do things like:
+
+  >> @posts.inspect
+  => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
+       #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
+  >> @posts.first.title = "hello from a debugger"
+  => "hello from a debugger"
+
+...and even better is that you can examine how your runtime objects actually work:
+
+  >> f = @posts.first
+  => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
+  >> f.
+  Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you enter "cont"
+
+
+== Console
+
+You can interact with the domain model by starting the console through <tt>script/console</tt>.
+Here you'll have all parts of the application configured, just like it is when the
+application is running. You can inspect domain models, change values, and save to the
+database. Starting the script without arguments will launch it in the development environment.
+Passing an argument will specify a different environment, like <tt>script/console production</tt>.
+
+To reload your controllers and models after launching the console run <tt>reload!</tt>
+
+== dbconsole
+
+You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
+You would be connected to the database with the credentials defined in database.yml.
+Starting the script without arguments will connect you to the development database. Passing an
+argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
+Currently works for mysql, postgresql and sqlite.
+
+== Description of Contents
+
+app
+  Holds all the code that's specific to this particular application.
+
+app/controllers
+  Holds controllers that should be named like weblogs_controller.rb for
+  automated URL mapping. All controllers should descend from ApplicationController
+  which itself descends from ActionController::Base.
+
+app/models
+  Holds models that should be named like post.rb.
+  Most models will descend from ActiveRecord::Base.
+
+app/views
+  Holds the template files for the view that should be named like
+  weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
+  syntax.
+
+app/views/layouts
+  Holds the template files for layouts to be used with views. This models the common
+  header/footer method of wrapping views. In your views, define a layout using the
+  <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
+  call <% yield %> to render the view using this layout.
+
+app/helpers
+  Holds view helpers that should be named like weblogs_helper.rb. These are generated
+  for you automatically when using script/generate for controllers. Helpers can be used to
+  wrap functionality for your views into methods.
+
+config
+  Configuration files for the Rails environment, the routing map, the database, and other dependencies.
+
+db
+  Contains the database schema in schema.rb.  db/migrate contains all
+  the sequence of Migrations for your schema.
+
+doc
+  This directory is where your application documentation will be stored when generated
+  using <tt>rake doc:app</tt>
+
+lib
+  Application specific libraries. Basically, any kind of custom code that doesn't
+  belong under controllers, models, or helpers. This directory is in the load path.
+
+public
+  The directory available for the web server. Contains subdirectories for images, stylesheets,
+  and javascripts. Also contains the dispatchers and the default HTML files. This should be
+  set as the DOCUMENT_ROOT of your web server.
+
+script
+  Helper scripts for automation and generation.
+
+test
+  Unit and functional tests along with fixtures. When using the script/generate scripts, template
+  test files will be generated for you and placed in this directory.
+
+vendor
+  External libraries that the application depends on. Also includes the plugins subdirectory.
+  If the app has frozen rails, those gems also go here, under vendor/rails/.
+  This directory is in the load path.

Added: incubator/stonehenge/contrib/stocktrader/ruby/trader_client/Rakefile
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/trader_client/Rakefile?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/trader_client/Rakefile (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/trader_client/Rakefile Wed Nov 26 02:52:40 2008
@@ -0,0 +1,10 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'

Added: incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/application.rb
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/application.rb?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/application.rb (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/application.rb Wed Nov 26 02:52:40 2008
@@ -0,0 +1,31 @@
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+  helper :all # include all helpers, all the time
+
+  # See ActionController::RequestForgeryProtection for details
+  # Uncomment the :secret if you're not using the cookie session store
+  protect_from_forgery # :secret => '82596297efe03131186d1f272ff82ba6'
+  
+  # See ActionController::Base for details 
+  # Uncomment this to filter the contents of submitted sensitive data parameters
+  # from your application log (in this case, all fields with names like "password"). 
+  # filter_parameter_logging :password
+end

Added: incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/trade_controller.rb
URL: http://svn.apache.org/viewvc/incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/trade_controller.rb?rev=720797&view=auto
==============================================================================
--- incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/trade_controller.rb (added)
+++ incubator/stonehenge/contrib/stocktrader/ruby/trader_client/app/controllers/trade_controller.rb Wed Nov 26 02:52:40 2008
@@ -0,0 +1,249 @@
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+require "trade_logic.rb"
+
+class TradeController < ApplicationController
+  #protect_from_forgery :only => []
+  skip_before_filter :verify_authenticity_token
+  layout "default"
+
+  def account
+    if(!IsLoggedIn())
+      redirect_to(request.protocol + request.host_with_port + "/trade/login")
+      return
+    else
+      updateProfile = request.parameters["UPDATEUSERPROFILE"]
+      if(updateProfile)
+        userId = GetUserFromCookie()
+        password = request.parameters["PASSWORD"]
+        fullName = request.parameters["FULLNAME"]
+        address = request.parameters["ADDRESS"]
+        email = request.parameters["EMAIL"]
+        creditCard = request.parameters["CREDITCARD"]
+
+        UpdateAccountProfile(userId, fullName, email, address, creditCard, password)
+      end
+    end
+
+    @ordersReturn = GetOrders(GetUserFromCookie())
+    @accountSummary = nil
+    if(@ordersReturn)
+      @accountSummary = GetUserAccountSummary(@ordersReturn)
+    end
+    @userAccountDataReturn = GetAccountData(GetUserFromCookie())
+    @userAccountProfileDataReturn = GetAccountProfileData(GetUserFromCookie())
+    @closedOrders = GetClosedOrders(GetUserFromCookie())
+    @userId = GetUserFromCookie()
+  end
+
+  def config
+  end
+
+  def confirmation
+    if(!IsLoggedIn())
+      redirect_to(request.protocol + request.host_with_port + "/trade/login")
+      return
+    end
+    @message = ""
+    if (request.parameters['SELL'])
+      @isSell = request.parameters['SELL']
+      @holdingID = request.parameters['HOLDINGID']
+      @quantity = request.parameters['QUANTITY']
+      @symbol = request.parameters['SYMBOL']
+    elsif (request.parameters['BUY'])
+      @quantity = request.parameters['QUANTITY']
+      @symbol = request.parameters['SYMBOL']
+      @price = request.parameters['PRICE']
+      @isBuy = request.parameters['BUY']
+    else
+      @message = "This is not buy or sell."
+    end
+  end
+
+  def glossary
+  end
+
+  def index
+  end
+
+  def login
+    @message = ""
+    if(IsLoggedIn())
+      user = GetUserFromCookie()
+      LogoutUser(user)
+      @message = "You are just log out as " + user
+    end
+    if(request.post?)
+      if(request.parameters["LOGINREQUEST"] != nil && request.parameters["USERNAME"] != nil && 
+        request.parameters["PASSWORD"] && request.parameters["USERNAME"] != "" && request.parameters["PASSWORD"] != "")
+        username = request.parameters['USERNAME']
+        password = request.parameters['PASSWORD']
+        response = Login(username, password)
+        @message = response
+        if(Login(username, password))
+          # login request received, log in  the user with given username and password
+          WriteUsername(username)
+          redirect_to(request.protocol + request.host_with_port + "/trade/account")
+          @message = username + " logged in." 
+        end
+      else
+        @message = "Login failed! Username or Password missing or invalid!" 
+      end
+    end
+  end
+
+  
+  def config
+    setendpoint = request.parameters["SETENDPOINT"]
+    endpoint = request.parameters["ENDPOINT"]
+    if(endpoint != nil && endpoint != "")
+      if(WriteEndpoint(endpoint))
+        @message = "<script type=\"text/javascript\">window.location='/trade/login'</script>"
+      else
+        redirect_to(request.protocol + request.host_with_port + "/trade/login")
+      end
+    end
+  end
+
+  def quotes
+    if(!IsLoggedIn())
+      redirect_to(request.protocol + request.host_with_port + "/trade/login")
+      return
+    elsif(request.parameters['GETQUOTE'] != nil)
+      # This is a request to get quote information for a particular symbol
+      symbol = request.parameters['SYMBOLS']
+      if (symbol)
+        @quotesReturn = GetQuote(symbol)
+      end
+    elsif (request.parameters['BUY'] != nil || request.parameters['SELL'] != nil)
+      # This is a buy or sell request
+      quantity = request.parameters['QUANTITY']
+      userID = GetUserFromCookie();
+      isBuy = false
+      isSell = false 
+
+      if (request.parameters['BUY'])
+        mode = 0;
+        @isBuy = true
+        symbol = request.parameters['SYMBOL']
+        @buyReturn = Buy(userID, symbol, quantity, mode)
+        if (@buyReturn && @buyReturn["orderID"])
+          @isReply = true
+        else
+          @response = nil
+        end
+      elsif(request.parameters['SELL'])
+        @isSell = true
+        holdingID = request.parameters['HOLDINGID']
+        @sellEnhancedReturn = SellEnhanced(userID, holdingID, quantity)
+        @message = obj_to_s(@shellEnhancedReturn)
+        if (@sellEnhancedReturn && @sellEnhancedReturn["orderID"])
+          @isReply = true
+        else
+          @response = nil
+        end
+      end
+    else
+      @quotesInitialPage = TRUE
+    end
+    
+    @closedOrders = GetClosedOrders(GetUserFromCookie())
+
+  end
+
+  def portfolio
+    if(!IsLoggedIn())
+      redirect_to(request.protocol + request.host_with_port + "/trade/login")
+      return
+    end
+    @holdingsReturn = GetHoldings(GetUserFromCookie())
+    @quoteInfo = {}
+    index = 0
+    while ((bean=@holdingsReturn["HoldingDataBean"][index]) != nil)
+      if (!@quoteInfo[bean["quoteID"]])
+        quotesReturn = GetQuote(bean["quoteID"])
+        @quoteInfo[bean["quoteID"]] = quotesReturn["price"]
+      end
+      index = index + 1
+    end
+    @closedOrders = nil
+    @closedOrders = GetClosedOrders(GetUserFromCookie())
+  end
+
+  def register
+    if (request.parameters['REGISTERUSER'])
+      # New user registration
+      userID = request.parameters['REQUESTEDID']
+      openBalance = request.parameters['OPENBALANCE']
+      fullname = request.parameters['FULLNAME']
+      email = request.parameters['EMAIL']
+      address = request.parameters['ADDRESS']
+      password = request.parameters['PASSWORD']
+      creditcard = request.parameters['CREDITCARD']
+      confpassword = request.parameters['CONFIRMATIONPASSWORD']
+
+      @invalidInformation = false
+      @successfulRegistration = false
+      @invalidInformation = false
+  
+
+
+      if (userID == nil || password != confpassword)
+        @invalidInformation = true
+      else
+        response = RegisterUser(userID, password, fullname, 
+          address, email, creditcard, openBalance)
+        #@message = obj_to_s(response)
+        if (response)
+          @successfulRegistration = true
+        else
+          @invalidInformation = true
+        end
+      end
+    end
+  end
+
+  def home
+    if(!IsLoggedIn())
+      redirect_to(request.protocol + request.host_with_port + "/trade/login")
+      return
+    end
+    
+    # Market data summary.
+    @getMarketSummaryReturn= GetMarketSummary()
+  
+    @tsia = @getMarketSummaryReturn["TSIA"]
+    @gain = @getMarketSummaryReturn["TSIA"].to_f - @getMarketSummaryReturn["openTSIA"].to_f
+    @volume = @getMarketSummaryReturn["volume"]
+    @topGainers = @getMarketSummaryReturn["topGainers"]
+    @topLosers = @getMarketSummaryReturn["topLosers"]
+
+    # Account information for the user.
+    @accountDataReturn = GetAccountData(GetUserFromCookie());
+    #@accountDataReturn = @accountData->getAccountDataReturn;
+
+    # Holding information for a particular user
+    @holdings = GetHoldings(GetUserFromCookie())
+    @holdingInfo = GetHoldingInformation(@holdings);
+    @noOfHoldings = @totalHoldings = 0
+    @noOfHoldings = @holdingInfo["noOfHoldings"]
+    @totalHoldings = @holdingInfo["totalHoldings"]
+
+    @userId = GetUserFromCookie()
+  end
+end



Mime
View raw message