cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mayank Thakore" <>
Subject ABR Communication Pattern
Date Sun, 13 Jan 2008 17:39:03 GMT

I was trying to achieve Asynchronous Batch Response (ABR) pattern with
CXF for JMS transport. ABR means user can send multiple responses to a
single request.

Please read this and let me know what you think.

Hazard info: I haven't finished the client for this yet, so don't know
wheather it is working. It does print the cxf logs correctly.

Below is my interceptor code. It attaches to the end of the
interceptor chain and executes the previous two interceptors which
invoke the service implementation and send the out message

package ws.v1.tmf854;

import java.util.ListIterator;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;

public class ABRInterceptor extends AbstractPhaseInterceptor<Message> {

	public ABRInterceptor() {

	public void handleMessage(Message message) throws Fault {
		System.out.println("ABRInterceptor invoked");
		if (ABRSession.isEnabled()) {

	private void executeReRuns(Message message) {
		ListIterator<Interceptor<? extends Message>> iterator =
		while (ABRSession.isEnabled()) {
			for (int i = 0; i < 2; i++) {
			for (int i = 0; i < 2; i++) {
				Interceptor currentInterceptor =;

	private ListIterator<Interceptor<? extends Message>> prepareReRunIterator(
			Message message) {
		ListIterator<Interceptor<? extends Message>> iterator = message
		while (iterator.hasNext()) {;
		return iterator;



Below is the session control device. It uses a thread local variable
to remember if ABR session is enabled or disabled.

package ws.v1.tmf854;

public class ABRSession {

	private static ThreadLocal<Boolean> status = new ThreadLocal<Boolean>() {
		protected synchronized Boolean initialValue() {
			return new Boolean(false);

	public static synchronized boolean isEnabled() {
		return status.get().booleanValue();

	public static synchronized void disable() {
		System.out.println("Disabling ABRSession");
		status.set(new Boolean(false));

	public static synchronized void enable() {
		System.out.println("Enabling ABRSession");
		status.set(new Boolean(true));



So, if user wants ABR mode, they just need to invoke
ABRSession.enable() inside the service implementation.

Here is the server main for completion:

package ws.v1.tmf854;


import org.apache.cxf.jaxws.EndpointImpl;

 * This class was generated by Apache CXF (incubator) 2.0.3-incubator Sat Jan 12
 * 11:10:39 IST 2008 Generated source version: 2.0.3-incubator

public class AlarmRetrieval_AlarmRetrievalJms_Server {

	protected AlarmRetrieval_AlarmRetrievalJms_Server() throws Exception {
		System.out.println("Starting Server");
		Object implementor = new AlarmRetrievalImpl();
		String address = "jms://";
		EndpointImpl ep = (EndpointImpl) Endpoint.publish(address, implementor);
				new ABRInterceptor());

	public static void main(String args[]) throws Exception {
		new AlarmRetrieval_AlarmRetrievalJms_Server();
		System.out.println("Server ready...");



So, what do you think?

Thanks for any and all comments. Feel free to be critical.


View raw message