Home

Post

Feeds

RSS

Oct 14Remoting From Java To ColdFusion By Example

This week, I've gotten the chance to work on a pretty slick proof-of-concept for a client. It's always cool to have a little bit of R&D time to play with some ideas. One of the requirements was that we send data as compactly as possible in order to minimize the bandwidth used from client to server over a low-bandwidth connection. Well, if we're trying to be efficient, the most efficient protocol I know is AMF. A few months ago (July 2008), Adobe announced the Java AMF Client as a part of BlazeDS. What this nifty client does is allow you to make AMF remoting calls from Java to any AMF endpoint including, but not limited to: BlazeDS, LCDS, and ColdFusion. Since we were working with a Java client talking to ColdFusion, this seemed, to me, to be the best and most efficient solution for moving data over low-bandwidth connections. Tom Jordahl has blogged about this a little bit, but has not, as yet, posted a complete sample for talking to ColdFusion over AMF from Java. Here is such an implementation for your digestion:

package com.universalmind.util;
   import flex.messaging.io.amf.client.AMFConnection;
   import flex.messaging.io.amf.client.exceptions.ClientStatusException;
   import flex.messaging.io.amf.client.exceptions.ServerStatusException;
   import flex.messaging.messages.RemotingMessage;
   /**
    * @author Andrew Powell
    */
   public class ColdFusionAMFSender {
    /**
    *
    * @param args the arguments, in order required, to pass into the CFC method
    * @return the value returned from the CFC
    * @throws ClientStatusException
    * @throws ServerStatusException
    */
    public Object sendAMFMessage(Object[] args) throws ClientStatusException, ServerStatusException {
    // Create the AMF connection.
    AMFConnection amfConnection = new AMFConnection();
    // Connect to the remote url.
    String url = "http://{yourservername}:{yourport}/{yourcontextroot}/flex2gateway";
    try
    {
    amfConnection.connect(url);
    }
    catch (ClientStatusException cse)
    {
    System.out.println(cse);
    return null;
    }
    String sourceName = "full.path.to.your.CFC";
    RemotingMessage message = new RemotingMessage();
    message.setMessageId(flex.messaging.util.UUIDUtils.createUUID());
    message.setOperation("remoteMethodName");
    message.setBody(args);
    message.setSource(sourceName);
    message.setDestination("ColdFusion");
    return amfConnection.call(null, message);
    }

   }

Posted by: Andrew Powell

Categories: Java , ColdFusion , BlazeDS , Adobe , Universal Mind , MOM

Comments

Nice post! I have been playing with code like this in order to do CF -> CF communication as using web services is slow and painful.

David Beale David Beale
10/15/08 9:03 AM

Well, remember, if you're doing CF to CF comm, you need to install the latest and greatest version of BlazeDS to support this.

Andy Powell Andy Powell
10/22/08 3:28 PM

Write your comment



(it will not be displayed)







About Andrew Powell

More ...

Powered by Mango Blog: a ColdFusion blog engine