Creating an Endpoint Reference

Prerequisites

Enable the SOAP binding that delivers the message to the Spring component for WS-Addressing to use reference parameters.
You must set an endpoint reference object before invoking a reference that is dynamically wired to a service.

Procedure

  1. Import context, endpoint reference, and URI class definitions:
    import org.osoa.sca.annotations.Context;
    import com.tibco.amf.platform.runtime.extension.context.ComponentContext;
    import com.tibco.amf.platform.runtime.extension.context.EndpointReference;
    import com.tibco.amf.platform.runtime.extension.context.MutableRequestContext;
    import com.tibco.amf.platform.runtime.extension.support.ElementEndpointReference;
    import com.tibco.amf.platform.runtime.extension.support.ElementWildcardExtension;
  2. Declare the component context:
    @Context
    public ComponentContext context;
  3. Create an endpoint reference:
    EndpointReference<Element> epr = new ElementEndpointReference(targetURI);
  4. Optionally create and set a list of parameters. For example:
    String property1= "<property1 " + "xmlns=\"" + WSQName + "\">value1</property1>";
    String property2= "<property2 " + "xmlns=\"" + WSQName + "\">value2</property2>";
    List<Element> elements = Arrays.asList(
        DOMUtils.getDOMNode(property1).getDocumentElement(), 
        DOMUtils.getDOMNode(property2).getDocumentElement());
        ElementWildcardExtension refParams = new ElementWildcardExtension(null, elements);
        epr.setReferenceParameters(refParams);
  5. Create a mutable request context object:
    MutableRequestContext mctxt = (MutableRequestContext)context.createMutableRequestContext();
  6. Set the endpoint reference of the mutable context object:
    mctxt.setEndpointReference(epr);
  7. Set the request context of the component context to the mutable request context:
    context.setRequestContext(mctxt);

Example

import org.osoa.sca.annotations.Context;
import com.tibco.amf.platform.runtime.extension.context.ComponentContext;
import com.tibco.amf.platform.runtime.extension.context.EndpointReference;
import com.tibco.amf.platform.runtime.extension.context.MutableRequestContext;
import com.tibco.amf.platform.runtime.extension.support.ElementEndpointReference;
import com.tibco.amf.platform.runtime.extension.support.ElementWildcardExtension;
import java.net.URI;
import java.util.List;
import java.util.Arrays;
@Context
public ComponentContext context;
public static final String WSQName = "com.ws.base";
private void setEPR(URI targetURI) {
		EndpointReference<Element> epr = new ElementEndpointReference(targetURI);

		String property1= "<property1 " + "xmlns=\"" + WSQName + "\">value1</property1>";
		String property2= "<property2 " + "xmlns=\"" + WSQName + "\">value2</property2>";
		List<Element> elements = Arrays.asList(
            DOMUtils.getDOMNode(property1).getDocumentElement(), 
            DOMUtils.getDOMNode(property2).getDocumentElement());
		ElementWildcardExtension refParams = new ElementWildcardExtension(null, elements);
		epr.setReferenceParameters(refParams);

		MutableRequestContext mctxt = (MutableRequestContext) context.createMutableRequestContext();
		mctxt.setEndpointReference(epr);
		context.setRequestContext(mctxt);		
	}