Skip to main content

Updating the Service Consumer

Availability-noteDeprecated

The consumer side configuration includes setting up a CXF client to send a request to the provider, and setting up a CXF endpoint which will receive callback messages back from the provider. The client may be set up using Spring-based configuration. RequestCallbackFeature must be added to the client to work properly. The following is an example of Client Spring configuration:

CXF client configuration on consumer side

<jaxws:client id="library" serviceName="library:LibraryProvider"
    endpointName="library:LibraryJmsPort"
    address="jms:jndi:dynamicQueues/library.queue?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp
;jndiConnectionFactoryName=ConnectionFactory&amp;jndiURL=tcp://localhost:61616"
    serviceClass="org.talend.services.demos.library._1_0.Library">
    <jaxws:features>
        <bean class="org.talend.esb.mep.requestcallback.feature.RequestCallbackFeature"/>
    </jaxws:features>
    <jaxws:properties>
            <entry key="org.talend.esb.mep.requestcallback.CallbackEndpoint">
                <ref bean="custTestServiceConsumerEndpoint"/>
            </entry>
    </jaxws:properties>
 </jaxws:client>

The setup of callback-receiving endpoint on the consumer side can be done via Spring configuration as well:

Callback-receiving endpoint Spring configuration

<jaxws:endpoint xmlns:library="http://services.talend.org/demos/Library/1.0"
    id="LibraryConsumerJMS"
    address="jms:jndi:dynamicQueues/libraryconsumer.queue?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory&jnd
iConnectionFactoryName=ConnectionFactory&jndiURL=tcp://localhost:61616"
    serviceName="library:LibraryConsumer" endpointName="library:LibraryConsumerPort"
    implementor="org.talend.services.demos.client.LibraryConsumerImpl">
    <jaxws:features>
        <bean class="org.talend.esb.mep.requestcallback.feature.RequestCallbackFeature"/>
        <bean class="org.apache.cxf.feature.LoggingFeature"/>
    </jaxws:features>
    <jaxws:properties>
        <entry key="jaxws.provider.interpretNullAsOneway" value="true"/>
    </jaxws:properties>
</jaxws:endpoint>

After both provider and consumer are set up, the request-callback message exchange can be done. The following is an example of sending a request:

Sending request from consumer to provider

public class LibraryTester {
    ...

    /** The Library proxy will be injected either by spring or by a direct call to the setter  */
    Library library;

   public void testRequestCallbackPositive() throws SeekBookError {

        // Create new request object and fill it with
        // some business data
        SearchInBasementFor request = new SearchInBasementFor();
        request.getAuthorLastName().add("Stripycat");

        // Add correlation info map to the request context
        Map<String, Object> rctx = ((BindingProvider) library).getRequestContext();
        Map<String, Object> correlationInfo = new HashMap<String, Object>();
        rctx.put(RequestCallbackFeature.CALL_INFO_PROPERTY_NAME, correlationInfo);

        // Send request to the provider
        library.seekBookInBasement(request);
   ...
}

CallContext object related to request-callback messages contains various information regarding a message. The following code snippet shows how to get the message information on the consumer side when callback message is received.

Receiving callback message

@WebServiceProvider
@Features(features = { "org.talend.esb.mep.requestcallback.feature.RequestCallbackFeature"})
public class LibraryConsumerImpl implements LibraryConsumer {
    @Resource
    private WebServiceContext wsContext;
    public void seekBookInBasementResponse(ListOfBooks body) {
      
        CallContext ctx = CallContext.getCallContext(wsContext.getMessageContext());
        System.out.println("Info from CallContext:");
        if (ctx == null) {
            System.out.println("- no CallContext");
        } else {
            System.out.println("- Call ID is " + ctx.getCallId());
            System.out.println("- Callback ID is " + ctx.getCallbackId());
        }
    }
    ... 
 }

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!