Announcement Announcement Module
Collapse
No announcement yet.
Updating/creating destination dynamically from Flex throw NULL pointer exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Updating/creating destination dynamically from Flex throw NULL pointer exception

    I want to create destination from Flex dynamically in order to create chatroom on demand, but always meet NULL point exception, please help.

    This is what I did:

    1. Service-cionfig.xml
    <services-config>
    <services>
    <service-include file-path="messaging-config.xml" />
    </services>
    ....
    2. messaging-config.xml:
    <service id="message-service"
    class="flex.messaging.services.MessageService">
    ...
    3. in Spring
    <bean id="simpleChatService" class="org.springframework.samples.jpetstore.domai n.logic.SimpleChat">
    <flex:remoting-destination />
    </bean>

    4. simpleChat.java
    public String modifyDestination(String id)
    {
    System.out.print("Received request ");
    MessageBroker broker = MessageBroker.getMessageBroker(null);
    //Get the service
    System.out.print("gettting service ");
    MessageService service = (MessageService) broker.getService("message-service");
    System.out.print("gettting service failed ");

    5. in Flex:
    <fxeclarations>
    <s:RemoteObject id="srv"
    destination="simpleChatService"
    endpoint="http://localhost:8080/spring/amf"
    />
    </fxeclarations>
    <fx:Script>
    private function run():void {
    srv.modifyDestination(destToModify);
    ....
    </fx:script>

    Whenever I called the modifyDestination method on RemoteObject, the NullPointerException is thrown.

    I think something is wrong with thie line:
    MessageBroker broker = MessageBroker.getMessageBroker(null);
    the error is broker can not be created, it is always NULL

    What's wrong with my setting? Help please.

    Thanks

  • #2
    I googled the solution,
    changing MessageBroker to FlexContext, then it will work!
    Just don't understand why all the documents mentioned using MessageBroker instead of FlexContext?

    MessageBroker broker = FlexContext.getMessageBroker();

    Comment


    • #3
      First off, you shouldn't need messaging-config.xml at all, unless you're doing something in there that can't be configured via Spring.

      Secondly, since you are using Spring, you can completely avoid such static lookups and instead just inject the MessageBroker as a dependency into SimpleChat.

      Something like:
      Code:
      <bean id="simpleChatService" class="org.springframework.samples.jpetstore.domai n.logic.SimpleChat">
          <property name="messageBroker" ref="_messageBroker"/>
          <flex:remoting-destination />
      </bean>

      Comment


      • #4
        I appreciate your instruction to use DI to inject messageBroker. It works very well.
        Only that you mentioned I shouldn't use messaging-config.xml to config messaging channels. Unfortunately, I can not find any instruction on how to achieve the same effect as messaging-config config in spring code. can you show some tips?

        Comment


        • #5
          See:
          http://static.springsource.org/sprin...l/ch05s02.html

          One other point worth mentioning...so that you can avoid dependence on the id String of the MessageService, I'd suggest looking it up by type instead:

          Code:
          MessageService service = (MessageService) broker.getServiceByType(MessageService.class.getName());

          Comment


          • #6
            Great!
            Thanks for your suggestion!
            Now I have totally removed messaging-config.xml and only service-config.xml remain there.
            Spring really made flex-blazeDS extremely proficient. I hope it becomes dominant in RIA development.

            Comment

            Working...
            X