我无法弄清楚如何简单地通过BlazeDs(On Tomcat)向Flex客户端发送消息。我有它从客户端发送/接收消息,但我有一种情况,我需要发送一个源自Java的消息。我认为这会容易得多。
我尝试过的方法:
MessageService.pushMessageToClients(MSG);
ServiceAdapter.invoke(MSG);
异常:flex.messaging.MessageException:java.lang.NullPointerException:null
MessageBroker.routeMessageToService(MSG);
[BlazeDS] 14:03:35.898调用服务时出现异常:(无),带有消息:Flex Message(flex.messaging.messages.AsyncMessage)
的services.xml:
<channel-definition id="my-streaming-amf"
class="mx.messaging.channels.StreamingAMFChannel">
<endpoint url="http://192.168.2.43:8400/testdrive/messagebroker/streamingamf"
class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
</channel-definition>
MESSAGE-CONFIG.XML:
<?xml version="1.0" encoding="UTF-8"?>
<adapters>
<adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="false" />
<adapter-definition id="AMFMessageAdapter" class="services.AMFMessageAdapter" default="true" />
<!-- <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/> -->
</adapters>
<default-channels>
<channel ref="my-streaming-amf"/>
</default-channels>
<destination id="AMFMessageAdapterDestination">
<channels>
<channel ref="my-streaming-amf" />
</channels>
<adapter ref="AMFMessageAdapter" />
</destination>
AMFMessageAdapter
package services;
import flex.messaging.messages.AsyncMessage;
import flex.messaging.messages.Message;
import flex.messaging.services.MessageService;
import flex.messaging.services.ServiceAdapter;
/**
* Test service adapter. Great for testing when you want to JUST SEND AN OBJECT and nothing
* else. This class has to stay in the main codebase (instead of test) because, when it's used
* it needs to be deployed to Tomcat.
* @author Kevin G
*
*/
public class AMFMessageAdapter extends ServiceAdapter {
String testMessage = "TEST_MESSAGE";
@Override
public Object invoke(Message message) {
AsyncMessage newMessage = (AsyncMessage) message;
newMessage.setBody(testMessage);
MessageService msgService = (MessageService)getDestination().getService();
msgService.pushMessageToClients(newMessage, false);
return null;
}
}
任何想法的人?