> -----Original Message----- > From: Simon Nash [mailto:[email protected]] > Sent: Sunday, November 20, 2011 10:15 PM > To: [email protected] > Subject: Re: Dynamic service references ? > [snip] > > The code to serialize a service reference to an XML string looks like > this: > > public static String serializeServiceReferenceXML(ServiceReference<?> > sr) throws IOException { > ServiceReferenceImpl<?> sri = (ServiceReferenceImpl<?>) sr; > return sri.toXMLString(); > } > > The code to deserialize a service reference from an XML string looks > like this: > > public static ServiceReference<?> deserializeServiceReferenceXML(String > serializedSR) throws Exception { > StringReader reader = new StringReader(serializedSR); > XMLStreamReader xmlReader = > XMLInputFactory.newInstance().createXMLStreamReader(reader); > ServiceReferenceImpl<?> sri = new ServiceReferenceImpl(xmlReader); > return (ServiceReference<?>) sri; > } > > Simon
Hello Simon, thank you for finding this out. There's a snag, however, in that serializing/deserializing a ServiceReference somehow prevents authentication from working. Example: On my reference I have put requires="sca:authentication" and have added a definitions.xml for the policy set just as shown in "Tuscany SCA in Action" (definitions.xml attached). Simply calling the injected reference in my SCA component works fine. Calling a copy of the reference derived by calling serializeServiceReferenceXML() followed by deserializeServiceReferenceXML() results in an authentication fault: - No credentials available for BASIC 'SAP NetWeaver Application Server [D01/100]'@bla:8000 - Unable to sendViaPost to url[foobaz] org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized [stacktrace snipped] Setting a breakpoint in BasicAuthenticationReferencePolicyInterceptor#invoke() demonstrates that this interceptor is not called when the copied reference is used. -- Sebastian 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 http://www.softwareag.com
<?xml version="1.0" encoding="ASCII"?> <definitions xmlns="http://www.osoa.org/xmlns/sca/1.0" targetNamespace="http://ps.softwareag.com/server-composite/" xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0" xmlns:ip="http://itest/policy" > <sca:policySet name="BasicAuthenticationPolicySet" provides="authentication" appliesTo="sca:reference/sca:binding.ws"> <tuscany:basicAuthentication> <tuscany:userName>BUTZ</tuscany:userName> <tuscany:password>develop</tuscany:password> </tuscany:basicAuthentication> </sca:policySet> </definitions>
