From 580265475dca3952d6e243b1edeb5243df998c23 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 16 Nov 2009 06:44:01 +0000 Subject: Cleaning up SVN structure, moving tag under sca-cpp/tags. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@880623 13f79535-47bb-0310-9956-ffa450edef68 --- .../CustomerRestClient.py | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 sca-cpp/tags/native-sca-1.0.incubating-M3/samples/RestCustomer/sample.customer.restclient/CustomerRestClient.py (limited to 'sca-cpp/tags/native-sca-1.0.incubating-M3/samples/RestCustomer/sample.customer.restclient/CustomerRestClient.py') diff --git a/sca-cpp/tags/native-sca-1.0.incubating-M3/samples/RestCustomer/sample.customer.restclient/CustomerRestClient.py b/sca-cpp/tags/native-sca-1.0.incubating-M3/samples/RestCustomer/sample.customer.restclient/CustomerRestClient.py new file mode 100644 index 0000000000..340da8700d --- /dev/null +++ b/sca-cpp/tags/native-sca-1.0.incubating-M3/samples/RestCustomer/sample.customer.restclient/CustomerRestClient.py @@ -0,0 +1,85 @@ +# 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 Python code is a simple sample that provides a Python +# client for the REST Customer sample + + +from xml.etree import ElementTree as et +import sca + +# Locate the customer resource service +customerResource = sca.locateservice("CustomerResource") + +# Show how to invoke CRUD operations on the customer resource +# The CRUD operations translate to HTTP POST, GET, PUT and DELETE +# according to the REST pattern + +customer = customerResource.retrieve("2345") +print "Rest - Retrieved customer " + et.tostring(customer) + +customer = et.fromstring("""1234JaneDoe""") +url = customerResource.create(customer) +print "Rest - Created customer " + url + +customer = customerResource.retrieve("1234") +print "Rest - Retrieved customer " + et.tostring(customer) + +customer = customerResource.retrieve(url) +print "Rest - Retrieved by url " + et.tostring(customer) + +customer.find("{http://sample.customer}lastName").text="Smith" +customerResource.update("1234", customer) +print "Rest - Updated customer 1234" + +customer = customerResource.retrieve("1234") +print "Rest - Retrieved customer " + et.tostring(customer) + +customerResource.delete("1234") +print "Rest - Deleted customer 1234" + +# Also show how to use REST binding to invoke remote commands +# using HTTP GET and XML over HTTP POST, the REST binding +# uses that command pattern when you don't declare a REST interface +# on your SCA reference + +# Locate the customer command service +customerCommand = sca.locateservice("CustomerCommand") + +# Invoke operations on the customer command service +customer = customerCommand.retrieve("2345") +print "Command - Retrieved customer " + et.tostring(customer) + +customer = et.fromstring("""1234JaneDoe""") +url = customerCommand.create(customer) +print "Command - Created customer " + url + +customer = customerCommand.retrieve("1234") +print "Command - Retrieved customer " + et.tostring(customer) + +customer.find("{http://sample.customer}lastName").text="Smith" +customerCommand.update("1234", customer) +print "Command - Updated customer 1234" + +customer = customerCommand.retrieve("1234") +print "Command - Retrieved customer " + et.tostring(customer) + +customerCommand.delete("1234") +print "Command - Deleted customer 1234" -- cgit v1.2.3