summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-1.2.1/samples/calculator-implementation-policies/README
blob: b69c6873a6a7701b14259c85cc67aa3a8306b5b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Calculator Implementation Policies Sample
=========================================
This sample builds over simple calculator sample to demonstrate how Implementation Policies can 
be use in Tuscany SCA Java.

The README in the samples directory (the directory above this) provides 
general instructions about building and running samples. Take a look there 
first. 

If you just want to run the sample  to see what happens open a command prompt, navigate
to this sample directory and do:

ant run

OR if you don't have ant, on Windows do

java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator.jar calculator.CalculatorClient

and on *nix do

java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator.jar calculator.CalculatorClient


Sample Overview
---------------
The sample provides the calculator service with a default SCA (java) binding.  The 'logging' policy
which is handled by the Tuscany SCA java policy-logging module is used in this calculator 
composite to specify the need for 'logging'.  The MultiplyService Component specifies for 'jassAuthentication'
which is one way of implemention login authentication, using the Java Authentication and Authorization Service.

The logging intent and policyset that is to be used by this calculator application must be 
defined in the definitions.xml file.  Here we use the policyset structure already defined in
Tuscany for logging under the policy-logging and hence there is no need to specify the policyset processors 
and policy handler classes as part of this application.  

Similarly the jaasAuthentication intent and policyset also is defined in the definitions.xml file 
of this sample.  This sample uses the calculator.security.JaasLoginModule class for handling the 
authentication functions.  Right now there is a simply matching of userid and passwords that happens in this
class.  Applications could implement their own sophisticated authentication mechanisms.  For more information
on how to do this please look up Java Authentication and Authorization Service documentation.  The sample
also use the calculator.security.CalculatorCallbackHandler to fetch the userid and password to be use for the
login authentication.  This handler presently uses hardcoded userids and passwords.  Applications could
typically use this handler to prompt for userid and passwords.

There are two components that provide the calculator service namely 'CalculatorServiceComponent'
and 'AnotherCalculatorServiceComponent'.  The logging intent is specified for the 'subtract' and 'divide' 
operations of the 'CalculatorServiceCompnent' implementation, and on the entire implementation 
(i.e. all operations) for the AddServiceComponent and AnotherCalculatorServiceComponent.

The CalculatorClient first exercises the CalculatorServiceComponent calling add, 
subtract, multiply and divide operations.  This results in logging messages appearing on the 
console for 'add', 'subtract' and 'divide' operations.  The CalculatorClient then exercises the 
AnotherCalculatorServiceComponent calling all the service methods.  This will result in logging messages
printed on the console for all the operations.  For the 'add' operation there will be two sets of messages
printed - one that has resulted from specifying the 'logging' intent on the implementation element of the
'AnotherCalculatorServiceComponent' and another from specifying the 'logging' intent on the 
'AddServiceComponent'

The jaasAuthentication intent is specified for the 'MultiplyServiceComponent'.  So everytime this component
is invoke an authentication is attempted and only if it succeeds, is the multiply function is invoked.  The
console prints messages that denote if the authentication has succeeded or failed.

Thus this sample demonstrates how intents could be applied to either implementations as a whole or to some
selective operations on an implementation.


calculator/
  src/
    main/
      java/
        calculator/
          CalculatorService.java                - the first component, calls +-/* as 
                                                appropriate
          CalculatorServiceImpl.java
          AddService.java                       - adds two numbers
          AddServiceImpl.java
          SubtractService.java                  - subtracts one number from another
          SubtractServiceImpl.java
          MultiplyService.java                  - multiplies two numbers
          MultiplyServiceImpl.java
          DivideService.java                    - divides one number by another
          DivideServiceImpl.java
          CalculatorClient.java                 - starts the SCA Runtime and 
                                                deploys the Calculator.composite. 
                                                It then calls the deployed Calculator 
                                                Components services
       calculator/security		
       	  JaasLoginModule.java					JaasLoginModule implementation for this sample
       	  CalculatorCallbackHandler.java		JAAS callbackhandler for fetching userid and password
			
		                                                
      resources/
        Calculator.composite                    - the SCA assembly for this sample
        definitions.xml                         - sca definitions file that defines the 'logging' intent 
                                                and policyset
                                                used by this application
        CalculatorLogMessages.properties        - A resource bundle contain the log messages to be 
                                                used.
        CalculatorJaas.config					- JAAS Login Configuration file
        
    test/
      java/
        calculator/
          CalculatorTestCase.java - JUnit test case 
  calculator.png                  - a pictorial representation of the sample 
                                    .composite file
  build.xml                       - the Ant build file
  pom.xml                         - the Maven build file        



Building And Running The Sample Using Ant
-----------------------------------------
With the binary distribution the sample can be built and run using Ant as 
follows

cd calculator-implementation-policies
ant compile
ant run

You should see the following output from the run target.

run:
        [java] Calling CalculatorServiceComponent configured with 'logging' policy for subtract and divide operations...
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Invoking operation - add
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Returned from operation - add
        [java] 3 + 2=5.0
        [java] 3 - 2=1.0
        [java] 3 * 2=6.0
        [java] 3 / 2=1.5
        [java] Calling CalculatorServiceComponent configured with 'logging' for all operations in the implementation...
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Invoking operation - subtract
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Returned from operation - subtract
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Invoking operation - divide
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Returned from operation - divide
        [java] Nov 23, 2007 1:06:10 PM
        [java] 3 + 2=5.0
        [java] 3 - 2=1.0
        [java] 3 * 2=6.0
        [java] INFO:  Invoking operation - add
        [java] 3 / 2=1.5
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Invoking operation - add
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Returned from operation - add
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Returned from operation - add
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Invoking operation - subtract
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Returned from operation - subtract
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Invoking operation - multiply
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Returned from operation - multiply
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Invoking operation - divide
        [java] Nov 23, 2007 1:06:10 PM
        [java] INFO:  Returned from operation - divide

Building And Running The Sample Using Maven 
-------------------------------------------
With either the binary or source distributions the sample can be built and run 
using Maven as follows. 

cd calculator
mvn

You should see the following output from the test phase. Notice the log messages.

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running calculator.CalculatorTestCase
Dec 18, 2007 12:05:06 PM org.apache.tuscany.sca.contribution.processor.ValidatingXMLStreamReader$1 error
WARNING: XMLSchema validation problem in: file:/F:/LatestTrunk/sca/samples/calculator-implementation-policies/target/
classes/Calculator.composite, line: 28, column: 4
cvc-complex-type.2.4.a: Invalid content was found starting with element 'operation'. One of '{WC[##other:"http://www.
osoa.org/xmlns/sca/1.0"]}' is expected.
Dec 18, 2007 12:05:06 PM
INFO:  Invoking operation - add
Dec 18, 2007 12:05:06 PM
FINER: Inovoking operation add with arguments 3.0, 2.0,
Dec 18, 2007 12:05:06 PM
INFO:  Returned from operation - add
Dec 18, 2007 12:05:06 PM
FINER: Returning from operation add with return value 5
Dec 18, 2007 12:05:06 PM
INFO:  Invoking operation - subtract
Dec 18, 2007 12:05:06 PM
FINER: Inovoking operation subtract with arguments 3.0, 2.0,
Dec 18, 2007 12:05:06 PM
INFO:  Returned from operation - subtract
Dec 18, 2007 12:05:06 PM
FINER: Returning from operation subtract with return value 1
Successfully AUTHENTICATED!!
Dec 18, 2007 12:05:06 PM
INFO:  Invoking operation - divide
Dec 18, 2007 12:05:06 PM
FINER: Inovoking operation divide with arguments 3.0, 2.0,
Dec 18, 2007 12:05:06 PM
INFO:  Returned from operation - divide
Dec 18, 2007 12:05:06 PM
FINER: Returning from operation divide with return value 1.5
Dec 18, 2007 12:05:06 PM org.apache.tuscany.sca.contribution.processor.ValidatingXMLStreamReader$1 error
WARNING: XMLSchema validation problem in: file:/F:/LatestTrunk/sca/samples/calculator-implementation-policies/target/
classes/Calculator.composite, line: 28, column: 4
cvc-complex-type.2.4.a: Invalid content was found starting with element 'operation'. One of '{WC[##other:"http://www.
osoa.org/xmlns/sca/1.0"]}' is expected.
Dec 18, 2007 12:05:06 PM
INFO:  Invoking operation - add
Dec 18, 2007 12:05:06 PM
FINER: Inovoking operation add with arguments 3.0, 2.0,
Dec 18, 2007 12:05:06 PM
INFO:  Invoking operation - add
Dec 18, 2007 12:05:06 PM
FINER: Inovoking operation add with arguments 3.0, 2.0,
Dec 18, 2007 12:05:06 PM
INFO:  Returned from operation - add
Dec 18, 2007 12:05:06 PM
FINER: Returning from operation add with return value 5
Dec 18, 2007 12:05:06 PM
INFO:  Returned from operation - add
Dec 18, 2007 12:05:06 PM
FINER: Returning from operation add with return value 5
Dec 18, 2007 12:05:06 PM
INFO:  Invoking operation - subtract
Dec 18, 2007 12:05:06 PM
FINER: Inovoking operation subtract with arguments 3.0, 2.0,
Dec 18, 2007 12:05:06 PM
INFO:  Returned from operation - subtract
Dec 18, 2007 12:05:06 PM
FINER: Returning from operation subtract with return value 1
Dec 18, 2007 12:05:06 PM
INFO:  Invoking operation - multiply
Dec 18, 2007 12:05:06 PM
FINER: Inovoking operation multiply with arguments 3.0, 2.0,
Successfully AUTHENTICATED!!
Dec 18, 2007 12:05:06 PM
INFO:  Returned from operation - multiply
Dec 18, 2007 12:05:06 PM
FINER: Returning from operation multiply with return value 6
Dec 18, 2007 12:05:06 PM
INFO:  Invoking operation - divide
Dec 18, 2007 12:05:06 PM
FINER: Inovoking operation divide with arguments 3.0, 2.0,
Dec 18, 2007 12:05:06 PM
INFO:  Returned from operation - divide
Dec 18, 2007 12:05:06 PM
FINER: Returning from operation divide with return value 1.5
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.823 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
This shows that the Junit test cases have run successfully.