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.wsrf.impl;
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.security.ISecurityProperties;
52 import org.ogf.graap.wsag.api.security.SecurityConstants;
53 import org.ogf.graap.wsag.client.api.RemoteClient;
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 extends RemoteClient
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 final 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 Properties properties, ISecurityProperties securityProperties )
145 {
146 super( destination, properties, securityProperties );
147
148 if ( ( useDefaultSOAPClient ) && ( defaultSOAPClient != null ) )
149 {
150 soapClient = defaultSOAPClient;
151 }
152 else
153 {
154 soapClient = new Axis2SoapClient( properties, securityProperties );
155 }
156
157 client = new WsResourceClient( convertEndpoint( destination ), convertEndpoint( source ), soapClient );
158 }
159
160
161
162
163
164
165
166
167
168
169
170 public WsrfResourceClient( EndpointReferenceType destination, Properties properties,
171 ISecurityProperties securityProperties )
172 {
173 this( destination, ANONYMOUS_EPR, properties, securityProperties );
174 this.securityProperties = securityProperties;
175
176 X500Principal serverIdentity = extractServerIdentity( destination );
177 if ( serverIdentity != null )
178 {
179 this.securityProperties.getProperties().put( SecurityConstants.X500_SERVER_IDENTITY,
180 serverIdentity );
181 }
182 }
183
184 private X500Principal extractServerIdentity( EndpointReferenceType epr )
185 {
186 X500Principal principal = null;
187
188 if ( epr.isSetMetadata() )
189 {
190 XmlObject[] identity =
191 epr.getMetadata().selectChildren( ServerIdentityDocument.type.getDocumentElementName() );
192 if ( identity.length > 0 )
193 {
194 XmlString serverId = (XmlString) identity[0];
195 principal = new X500Principal( serverId.getStringValue() );
196 }
197 }
198
199 return principal;
200 }
201
202 private static EndpointReferenceType convertMuseEndpoint( EndpointReference epr )
203 {
204 try
205 {
206 EndpointReferenceDocument converted =
207 (EndpointReferenceDocument) XmlObject.Factory.parse( epr.toXML() );
208 return converted.getEndpointReference();
209 }
210 catch ( XmlException e )
211 {
212 String message = "Error while converting MUSE EPR to endpoint reference.";
213 throw new RuntimeException( message, e );
214 }
215 }
216
217 private static EndpointReference convertEndpoint( EndpointReferenceType epr )
218 {
219 try
220 {
221 EndpointReferenceDocument doc = EndpointReferenceDocument.Factory.newInstance();
222 doc.setEndpointReference( epr );
223 return new EndpointReference( (Element) doc.getDomNode().getFirstChild() );
224 }
225 catch ( SoapFault e )
226 {
227 String message = "Error while converting endpoint reference to MUSE EPR.";
228 throw new RuntimeException( message, e );
229 }
230 }
231
232
233
234
235 @Override
236 public Properties getProperties()
237 {
238 return soapClient.getProperties();
239 }
240
241
242
243
244
245 @Override
246 public void setProperties( Properties properties )
247 {
248 soapClient.setProperties( properties );
249 }
250
251
252
253
254 @Override
255 public ISecurityProperties getSecurityProperties()
256 {
257 return securityProperties;
258 }
259
260
261
262
263 public EndpointReferenceType getEndpoint()
264 {
265 return convertMuseEndpoint( client.getEndpointReference() );
266 }
267
268
269
270
271
272
273
274
275 public void deleteResourceProperty( QName qname ) throws SoapFault
276 {
277 client.deleteResourceProperty( qname );
278 }
279
280
281
282
283
284
285
286 public void destroy() throws SoapFault
287 {
288 client.destroy();
289 }
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304 public Element[] getMultipleResourceProperties( QName[] qnames ) throws SoapFault
305 {
306 return client.getMultipleResourceProperties( qnames );
307 }
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322 public Element[] getResourceProperty( QName qname ) throws SoapFault
323 {
324 return client.getResourceProperty( qname );
325 }
326
327
328
329
330
331
332
333
334
335
336
337 public Element getResourcePropertyDocument() throws SoapFault
338 {
339 return client.getResourcePropertyDocument();
340 }
341
342
343
344
345
346
347 @Override
348 public boolean isUsingTrace()
349 {
350 return client.isUsingTrace();
351 }
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370 public Node[] queryResourceProperties( String query, String dialect ) throws SoapFault
371 {
372 return client.queryResourceProperties( query, dialect );
373 }
374
375
376
377
378
379
380
381
382
383
384 public void setResourceProperties( SetRequest request ) throws SoapFault
385 {
386 client.setResourceProperties( request );
387 }
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402 public Date setTerminationTime( Date time ) throws SoapFault
403 {
404 return client.setTerminationTime( time );
405 }
406
407
408
409
410
411
412
413 @Override
414 public void setTrace( boolean trace )
415 {
416 client.setTrace( trace );
417 }
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432 public void updateResourceProperty( QName qname, Object[] values ) throws SoapFault
433 {
434 client.updateResourceProperty( qname, values );
435 }
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453 public Element invoke( String action, Element soapBody ) throws SoapFault
454 {
455 return client.invoke( action, soapBody );
456 }
457
458 }