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 package org.ogf.graap.wsag.client.remote;
36
37 import java.util.Date;
38 import java.util.Properties;
39
40 import javax.security.auth.x500.X500Principal;
41 import javax.xml.namespace.QName;
42
43 import org.apache.muse.ws.addressing.EndpointReference;
44 import org.apache.muse.ws.addressing.WsaConstants;
45 import org.apache.muse.ws.addressing.soap.SoapFault;
46 import org.apache.muse.ws.resource.properties.set.SetRequest;
47 import org.apache.muse.ws.resource.remote.WsResourceClient;
48 import org.apache.xmlbeans.XmlException;
49 import org.apache.xmlbeans.XmlObject;
50 import org.apache.xmlbeans.XmlString;
51 import org.ogf.graap.wsag.api.client.WsClient;
52 import org.ogf.graap.wsag.api.security.ISecurityProperties;
53 import org.ogf.graap.wsag.security.core.SecurityConstants;
54 import org.ogf.graap.wsag4j.types.engine.ServerIdentityDocument;
55 import org.w3.x2005.x08.addressing.EndpointReferenceDocument;
56 import org.w3.x2005.x08.addressing.EndpointReferenceType;
57 import org.w3c.dom.Element;
58 import org.w3c.dom.Node;
59
60
61
62
63
64
65
66 public class WsrfResourceClient implements WsClient
67 {
68
69
70
71
72 public static final EndpointReferenceType ANONYMOUS_EPR =
73 convertMuseEndpoint( WsaConstants.ANONYMOUS_EPR );
74
75
76
77
78 @Deprecated
79 public static final String EXTRA_HEADERS = "http://de.fraunhofer.scai.wsag4j/extra-headers";
80
81
82
83
84 private WsResourceClient client;
85
86
87
88
89 private Axis2SoapClient soapClient;
90
91
92
93
94 private ISecurityProperties securityProperties;
95
96
97
98
99 private static Axis2SoapClient defaultSOAPClient = null;
100
101
102
103
104 public static Axis2SoapClient getDefaultSOAPClient()
105 {
106 return defaultSOAPClient;
107 }
108
109
110
111
112
113 public static void setDefaultSOAPClient( Axis2SoapClient defaultSOAPClient )
114 {
115 WsrfResourceClient.defaultSOAPClient = defaultSOAPClient;
116 }
117
118
119
120
121 private static boolean useDefaultSOAPClient = false;
122
123
124
125
126 public static boolean isUseDefaultSOAPClient()
127 {
128 return useDefaultSOAPClient;
129 }
130
131
132
133
134
135 public static void setUseDefaultSOAPClient( boolean useDefaultSOAPClient )
136 {
137 WsrfResourceClient.useDefaultSOAPClient = useDefaultSOAPClient;
138 }
139
140
141
142
143 private WsrfResourceClient( EndpointReferenceType destination, EndpointReferenceType source,
144 ISecurityProperties securityProperties )
145 {
146 if ( ( useDefaultSOAPClient ) && ( defaultSOAPClient != null ) )
147 {
148 soapClient = defaultSOAPClient;
149 }
150 else
151 {
152 soapClient = new Axis2SoapClient( securityProperties );
153 }
154
155 client = new WsResourceClient( convertEndpoint( destination ), convertEndpoint( source ), soapClient );
156 }
157
158
159
160
161
162
163
164
165
166
167
168 public WsrfResourceClient( EndpointReferenceType destination, ISecurityProperties securityProperties )
169 {
170 this( destination, ANONYMOUS_EPR, securityProperties );
171 this.securityProperties = securityProperties;
172
173 X500Principal serverIdentity = extractServerIdentity( destination );
174 if ( serverIdentity != null )
175 {
176 this.securityProperties.getProperties().put( SecurityConstants.X500_SERVER_IDENTITY,
177 serverIdentity );
178 }
179 }
180
181 private X500Principal extractServerIdentity( EndpointReferenceType epr )
182 {
183 X500Principal principal = null;
184
185 if ( epr.isSetMetadata() )
186 {
187 XmlObject[] identity =
188 epr.getMetadata().selectChildren( ServerIdentityDocument.type.getDocumentElementName() );
189 if ( identity.length > 0 )
190 {
191 XmlString serverId = (XmlString) identity[0];
192 principal = new X500Principal( serverId.getStringValue() );
193 }
194 }
195
196 return principal;
197 }
198
199 private static EndpointReferenceType convertMuseEndpoint( EndpointReference epr )
200 {
201 try
202 {
203 EndpointReferenceDocument converted =
204 (EndpointReferenceDocument) XmlObject.Factory.parse( epr.toXML() );
205 return converted.getEndpointReference();
206 }
207 catch ( XmlException e )
208 {
209 String message = "Error while converting MUSE EPR to endpoint reference.";
210 throw new RuntimeException( message, e );
211 }
212 }
213
214 private static EndpointReference convertEndpoint( EndpointReferenceType epr )
215 {
216 try
217 {
218 EndpointReferenceDocument doc = EndpointReferenceDocument.Factory.newInstance();
219 doc.setEndpointReference( epr );
220 return new EndpointReference( (Element) doc.getDomNode().getFirstChild() );
221 }
222 catch ( SoapFault e )
223 {
224 String message = "Error while converting endpoint reference to MUSE EPR.";
225 throw new RuntimeException( message, e );
226 }
227 }
228
229
230
231
232 public Properties getProperties()
233 {
234 return soapClient.getProperties();
235 }
236
237
238
239
240
241 public void setProperties( Properties properties )
242 {
243 soapClient.setProperties( properties );
244 }
245
246
247
248
249 public ISecurityProperties getSecurityProperties()
250 {
251 return securityProperties;
252 }
253
254
255
256
257 public EndpointReferenceType getEndpoint()
258 {
259 return convertMuseEndpoint( client.getEndpointReference() );
260 }
261
262
263
264
265
266
267
268
269 public void deleteResourceProperty( QName qname ) throws SoapFault
270 {
271 client.deleteResourceProperty( qname );
272 }
273
274
275
276
277
278
279
280 public void destroy() throws SoapFault
281 {
282 client.destroy();
283 }
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298 public Element[] getMultipleResourceProperties( QName[] qnames ) throws SoapFault
299 {
300 return client.getMultipleResourceProperties( qnames );
301 }
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316 public Element[] getResourceProperty( QName qname ) throws SoapFault
317 {
318 return client.getResourceProperty( qname );
319 }
320
321
322
323
324
325
326
327
328
329
330
331 public Element getResourcePropertyDocument() throws SoapFault
332 {
333 return client.getResourcePropertyDocument();
334 }
335
336
337
338
339
340
341 public boolean isUsingTrace()
342 {
343 return client.isUsingTrace();
344 }
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363 public Node[] queryResourceProperties( String query, String dialect ) throws SoapFault
364 {
365 return client.queryResourceProperties( query, dialect );
366 }
367
368
369
370
371
372
373
374
375
376
377 public void setResourceProperties( SetRequest request ) throws SoapFault
378 {
379 client.setResourceProperties( request );
380 }
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395 public Date setTerminationTime( Date time ) throws SoapFault
396 {
397 return client.setTerminationTime( time );
398 }
399
400
401
402
403
404
405
406 public void setTrace( boolean trace )
407 {
408 client.setTrace( trace );
409 }
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424 public void updateResourceProperty( QName qname, Object[] values ) throws SoapFault
425 {
426 client.updateResourceProperty( qname, values );
427 }
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445 public Element invoke( String action, Element soapBody ) throws SoapFault
446 {
447 return client.invoke( action, soapBody );
448 }
449
450 }