My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
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
package org.integratedsemantics.flexspaces.control.delegate.webscript
{
import mx.messaging.ChannelSet;
import mx.messaging.channels.AMFChannel;
import mx.messaging.channels.HTTPChannel;
import mx.messaging.channels.SecureAMFChannel;
import mx.messaging.channels.SecureHTTPChannel;
import mx.rpc.AsyncToken;
import mx.rpc.Fault;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
import mx.utils.Base64Encoder;

import org.integratedsemantics.flexspaces.control.delegate.webscript.event.FailureEvent;
import org.integratedsemantics.flexspaces.control.delegate.webscript.event.SuccessEvent;
import org.integratedsemantics.flexspaces.control.error.ErrorMgr;
import org.integratedsemantics.flexspaces.control.error.WebScriptError;
import org.integratedsemantics.flexspaces.model.AppModelLocator;


public class WebScriptService extends HTTPService
{
public static const GET:String = "GET";
public static const POST:String = "POST";
public static const PUT:String = "PUT";
public static const DELETE:String = "DELETE";

// unique last part of webscript url
private var relativeUrl:String;

private var requestedMethod:String;
private var alwaysTunnelGetMethod:Boolean = true;
private var ticketRequired:Boolean = true;


public function WebScriptService(relativeUrl:String, method:String, onSuccess:Function=null, onFailure:Function=null, ticketRequired:Boolean=true, alwaysTunnelGetMethod:Boolean = true)
{
super();

this.relativeUrl = relativeUrl;
this.requestedMethod = method;
this.alwaysTunnelGetMethod = alwaysTunnelGetMethod;
this.ticketRequired = ticketRequired;

if (this.requestedMethod == GET && this.alwaysTunnelGetMethod == false)
{
this.method = GET;
}
else
{
this.method = POST;
}

var model:AppModelLocator = AppModelLocator.getInstance();
this.url = model.ecmServerConfig.urlPrefix + relativeUrl;

addEventListener(ResultEvent.RESULT, onResultEvent);
addEventListener(FaultEvent.FAULT, onFaultEvent);

if (onSuccess != null)
{
addEventListener(SuccessEvent.SUCCESS, onSuccess);
}
if (onFailure != null)
{
addEventListener(FailureEvent.FAILURE, onFailure);
}

// using e4x result format by default not object format
resultFormat = HTTPService.RESULT_FORMAT_E4X;
}

public function execute(parameters:Object=null):AsyncToken
{
var result:AsyncToken = null;

try
{
if (parameters == null)
{
parameters = new Object();
}

// livecycle
var model:AppModelLocator = AppModelLocator.getInstance();

if (model.ecmServerConfig.isLiveCycleContentServices == true)
{
/*
if (model.remotingChannelSet == null)
{
setupChannels();
}

this.useProxy = true;

//this.destination = "DefaultHTTP";

this.channelSet = model.remotingChannelSet;

// basic auth header
if ( (model.userInfo.loginUserName != null) && (model.userInfo.loginPassword != null) &&
(model.userInfo.loginUserName != "") && (model.userInfo.loginPassword != "") )
{
var headerList:Array = new Array();

var encoder:Base64Encoder = new Base64Encoder();
encoder.encode(model.userInfo.loginUserName + ":" + model.userInfo.loginPassword);
headerList["Authorization"] = "Basic " + encoder.toString();

// saml assertion ticket header
//headerList["ticket"] = model.userInfo.loginTicket;

this.headers = headerList;
}
*/
if (this.ticketRequired == true)
{
var ticket:String = model.userInfo.loginTicket;
if (ticket == null)
{
throw new Error("Unable to execute web script because required ticket is not available");
}

parameters.ticket = ticket;
}

if (this.method == POST && this.requestedMethod != POST)
{
parameters.alf_method = this.requestedMethod;
}
}
else
{
if (this.ticketRequired == true)
{
ticket = model.userInfo.loginTicket;
if (ticket == null)
{
throw new Error("Unable to execute web script because required ticket is not available");
}

parameters.alf_ticket = ticket;
}

if (this.method == POST && this.requestedMethod != POST)
{
parameters.alf_method = this.requestedMethod;
}

}


result = send(parameters);
}
catch (error:Error)
{
ErrorMgr.getInstance().raiseError(ErrorMgr.APPLICATION_ERROR, error);
}

return result;
}

public function onResultEvent(event:ResultEvent):void
{
var newEvent:SuccessEvent = new SuccessEvent(SuccessEvent.SUCCESS, event.bubbles, event.cancelable, event.result, event.token, event.message);
dispatchEvent(newEvent);
}

public function onFaultEvent(event:FaultEvent):void
{
var fault:Fault = event.fault;

if (hasEventListener(FailureEvent.FAILURE) == true)
{
var newEvent:FailureEvent = new FailureEvent(FailureEvent.FAILURE, false, true, fault);
dispatchEvent(newEvent);
}
else
{
var error:WebScriptError = new WebScriptError("Web script failed: " + this.requestedMethod + " " + this.url + " " + fault.faultString);
ErrorMgr.getInstance().raiseError(ErrorMgr.APPLICATION_ERROR, error);
}
}

private function setupChannels():void
{
var model:AppModelLocator = AppModelLocator.getInstance();

var channelSet:ChannelSet = new ChannelSet();

var baseUrl:String = model.ecmServerConfig.protocol + "://" + model.ecmServerConfig.domain + ":" + model.ecmServerConfig.port;

if (model.ecmServerConfig.protocol == "http")
{
// setup a channel for web scripts
var channelUrl:String = baseUrl + "/remoting/messagebroker/http";
var channelId:String = "remoting-http";
var channel:HTTPChannel = new HTTPChannel(channelId, channelUrl);
channelSet.addChannel(channel);

// setup a channel for remoting to LC for directory mgr service, etc.
var channelUrl2:String = baseUrl + "/remoting/messagebroker/amf";
var channelId2:String = "remoting-amf";
var channel2:AMFChannel = new AMFChannel(channelId2, channelUrl2);
channelSet.addChannel(channel2);
}
else if (model.ecmServerConfig.protocol == "https")
{
// setup a channel for web scripts
var channelUrl3:String = baseUrl + "/remoting/messagebroker/httpsecure";
var channelId3:String = "remoting-secure-http";
var channel3:SecureHTTPChannel = new SecureHTTPChannel(channelId3, channelUrl3);
channelSet.addChannel(channel3);

// setup a channel for remoting to LC for directory mgr service, etc.
var channelUrl4:String = baseUrl + "/remoting/messagebroker/amfsecure";
var channelId4:String = "remoting-secure-amf";
var channel4:SecureAMFChannel = new SecureAMFChannel(channelId4, channelUrl4);
channelSet.addChannel(channel4);
}
model.remotingChannelSet = channelSet;
}

}
}

Change log

r214 by steverei...@integratedsemantics.com on Mar 27, 2012   Diff
added flexspaces-lib library with all code
other than application class from original
FlexSpaces app project, other changes: DI
with spring actionscript of adv search and
tagscategories dialogs, added show busy
cursor on most dialogs and login, simpler
error dialog, use VideoPlayer with
controls, added play video on File menu,
added File/Exit menu, tags/categories,
suggest tags, dialogs now resizable,
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 8571 bytes, 227 lines
Powered by Google Project Hosting