tuscany-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Millies, Sebastian" <Sebastian.Mill...@softwareag.com>
Subject Re: Dynamic service references ?
Date Wed, 16 Nov 2011 18:44:44 GMT
> From: Jon Giddy [mailto:jongiddy@gmail.com]
> Sent: Wednesday, November 16, 2011 5:44 PM
> On 16/11/11 13:29, Simon Nash wrote:
> > Millies, Sebastian wrote:
> >>
> >>
> >> can references in composite files somehow be made dynamic? In
> >> particular, can I define or override
> >>
> >> the endpoints in a web service reference at run time?
> >
> > It might be possible to use service references for this.  A service
> > reference can be serialized/deserialized to/from XML.  So you could
> > use runtime code to create the XML-equivalent form of the service
> > reference that you need, then deserialize the XML to create the
> > service reference.
> We tried something like this, but failed to get it to work fully.
> We then tried a solution where, as each service starts up, it creates a
> ServiceReference to itself, marshals that into Base64, and calls an
> endpoint on the client, passing in its ServiceReference, which is
> stored
> in an internal directory (basically a HashMap). The client is then able
> to retrieve the endpoints from its internal directory and use them.
> However, a service registering with a client is a little bizarre. We
> really wanted the service to register its ServiceReference with a
> directory service, and for the client to retrieve the
> ServiceReference(s) from the directory service. That is, replace the
> internal HashMap with an external service. This would be the classic
> Publish-Find-Bind model of Service Oriented Architecture.
> However, we couldn't get it to work. The client can get the Base64
> encoded ServiceReference, and perform the same actions as before, but
> we
> get a NullPointerException when attempting to use the reference.
> It would be great to know if anyone else succeeds at this, as we feel
> so
> close to achieving dynamic binding in Tuscany,...and yet so far.
> Jon.

My problem is similar but not identical. I would need to manipulate the
ServiceReference itself according to Simon's suggestion. Now, how would one
go about serializing and deserializing a ServiceReference to/from XML. I have
tried two approaches, neither of which will quite work:

private <T> ServiceReference<T> copy( ServiceReference<T> serviceRef, String
wsUri )
  throws IOException
// first approach
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ObjectOutputStream out = new ObjectOutputStream( baos );
  out.writeObject( serviceRef );
  // will not yield XML, but binary data, so is not easily manipulable
  String xml1 = baos.toString( "UTF-8" ) ;

// second approach
  ServiceReferenceImpl<T> sri = (ServiceReferenceImpl<T>) serviceRef;
  String xml2 = sri.toXMLString();
  // manipulate xml2 ...
  ComponentContextHelper cch = ComponentContextHelper.getCurrentComponentContextHelper();
  Component comp = cch.fromXML( xml2 );
  List<?> refs = comp.getReferences();
  // ClassCastException, because we'll get back a RuntimeComponentReferenceImpl
  ServiceReference<T> sr = (ServiceReference<T>) refs.get( 0 );

  return sr;


IDS Scheer Consulting GmbH
Geschäftsführer/Managing Directors: Kamyar Niroumand, Ivo Totev
Sitz/Registered office: Altenkesseler Straße 17, 66115 Saarbrücken, Germany - Registergericht/Commercial
register: Saarbrücken HRB 19681

View raw message