2 Replies Latest reply on Aug 20, 2007 3:28 AM by happyok

    one question about lcds2.5 link with java

    happyok
      when i am creating a custom Message Service adapter,found a question with rewriting invoke() method.
      java class :
      package test;

      import flex.messaging.services.ServiceAdapter;
      import flex.messaging.services.MessageService;
      import flex.messaging.messages.Message;

      public class TestAdapter extends ServiceAdapter {

      public Object invoke(Message message) {
      MessageService msgService = (MessageService)service;
      msgService.pushMessageToClients(message, true);
      msgService.sendPushMessageFromPeer(message, true);
      return null;
      }
      }

      error:
      service can not resolved about MessageService msgService = (MessageService)service;

      please tell me a method :how to write this TestAdapter class.

        • 1. Re: one question about lcds2.5 link with java
          Level 7
          In LCDS 2.5, we cleaned up some things across all of the components of the
          message broker to make them consistent in preparation for documentation and
          exposing their APIs for runtime configuration.

          ServiceAdapter implementations can now get hold of the Service through the
          destination (which better reflects the actual heirarchy that exists between
          these components. Services have destinations that each have a new instance
          of an adapter).

          public Object invoke(Message message)
          {
          MessageService msgService = (MessageService)getDestination().getService();
          ...
          }


          • 2. Re: one question about lcds2.5 link with java
            happyok Level 1
            ths, i can success.
            but one error occur when i send message from java class to lcds2.5 service.
            i tranfer this IMessageUtil interface's setMessage method,set param as "test",but no value in mxml file's mx:Consumer .
            my message-config.xml is correct.
            message-config.xml:
            <adapter-definition id="fdschathandler" class="test"/>

            <destination id="fdschat">

            <properties>
            <network>
            <session-timeout>0</session-timeout>
            </network>
            <server>
            <max-cache-size>1000</max-cache-size>
            <message-time-to-live>0</message-time-to-live>
            <durable>false</durable>
            </server>

            </properties>


            <channels>
            <channel ref="my-rtmp"/>
            </channels>

            <adapter ref="fdschathandler"/>
            </destination>

            java class:
            package test;

            import flex.messaging.MessageBroker;
            import flex.messaging.MessageException;
            import flex.messaging.messages.AsyncMessage;
            import flex.messaging.messages.Message;
            import flex.messaging.services.MessageService;
            import flex.messaging.services.ServiceAdapter;

            public class MessageUtil extends ServiceAdapter implements IMessageUtil {


            public Object invoke(Message message) {
            try{
            MessageBroker broker = MessageBroker.getMessageBroker(null);
            MessageService msgService = (MessageService) broker.getService("message-service");

            msgService.pushMessageToClients(message, true);
            msgService.sendPushMessageFromPeer(message, true);
            return null;
            }catch(MessageException ff){
            System.out.println("fff:="+ff.getErrorMessage());
            }
            catch(Exception e){
            e.printStackTrace();
            }
            return message;
            }

            public void setMessage(String mess) {
            try{
            AsyncMessage message=new AsyncMessage();
            message.setDestination("fdschat");
            message.setBody(mess);
            this.invoke(message);
            }catch(Exception e){
            e.printStackTrace();
            }

            }

            }


            mxml:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
            creationComplete="consumer.subscribe()">

            <mx:Script>
            <![CDATA[
            import mx.messaging.events.MessageEvent;

            import mx.messaging.messages.AsyncMessage;
            import mx.messaging.messages.IMessage;

            private function send():void
            {
            var message:AsyncMessage = new AsyncMessage();
            message.body = msg.text;
            producer.send(message);
            msg.text = "";
            }

            private function messageHandler(message:MessageEvent):void
            {
            var msg:AsyncMessage = AsyncMessage( message.message );
            log.text += msg.body + "\n";
            }

            ]]>
            </mx:Script>

            <mx:Producer id="producer" destination="fdschat"/>
            <mx:Consumer id="consumer" destination="fdschat" message="messageHandler(event)"/>

            <mx:Panel title="Chat" width="100%" height="100%">
            <mx:TextArea id="log" width="100%" height="100%"/>
            <mx:ControlBar>
            <mx:TextInput id="msg" width="100%" enter="send()"/>
            <mx:Button label="Send" click="send()"/>
            </mx:ControlBar>
            </mx:Panel>

            </mx:Application>