public void createAsyncCallbackEndpoint(){
CompositeContext compositeContext = getCompositeContext();
FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class);
RuntimeAssemblyFactory assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class);
RuntimeEndpoint endpoint = (RuntimeEndpoint)assemblyFactory.createEndpoint();
endpoint.bind(compositeContext);
endpoint.setComponent(getComponent());
// Create pseudo-service
ComponentService service = assemblyFactory.createComponentService();
JavaInterfaceFactory javaInterfaceFactory =
(JavaInterfaceFactory)modelFactories.getFactory(JavaInterfaceFactory.class);
JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
try {
interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(AsyncResponseService.class));
} catch (InvalidInterfaceException e1) {
// Nothing to do here - will not happen
} // end try
service.setInterfaceContract(interfaceContract);
String serviceName = getReference().getName() + "_asyncCallback";
service.setName(serviceName);
service.getEndpoints().add(endpoint);
service.setForCallback(true);
endpoint.setService(service);
// Set pseudo-service onto the component
getComponent().getServices().add(service);
// if the reference has a WSDL contract reset the response endpoint to be WSDL also
InterfaceContract referenceInterfaceContract = getComponentTypeReferenceInterfaceContract();
if (referenceInterfaceContract instanceof WSDLInterfaceContract){
WSDLInterfaceContract wsdlInterfaceContract = (WSDLInterfaceContract)endpoint.getGeneratedWSDLContract(interfaceContract);
service.setInterfaceContract(wsdlInterfaceContract);
}
// Create a binding
// Mike had to go via the XML but I don't remember why
Binding binding = null;
try {
binding = (Binding)getBinding().clone();
} catch (Exception ex){
//
}
String callbackURI = "/" + component.getName() + "/" + service.getName();
binding.setURI(callbackURI);
BuilderExtensionPoint builders = registry.getExtensionPoint(BuilderExtensionPoint.class);
BindingBuilder builder = builders.getBindingBuilder(binding.getType());
if (builder != null) {
org.apache.tuscany.sca.assembly.builder.BuilderContext builderContext = new BuilderContext(registry);
builder.build(component, service, binding, builderContext, true);
} // end if
endpoint.setBinding(binding);
// Need to establish policies here (binding has some...)
endpoint.getRequiredIntents().addAll(getRequiredIntents());
endpoint.getPolicySets().addAll(getPolicySets());
String epURI = getComponent().getName() + "#service-binding(" + serviceName + "/" + serviceName + ")";
endpoint.setURI(epURI);
endpoint.setUnresolved(false);
setCallbackEndpoint(endpoint);
}