0 Replies Latest reply on Sep 11, 2010 4:09 PM by iwd2

    Flex + BlazeDS + Java (works only on localhost)

    iwd2

      Hi!

       

      I'm new in Flex so I have very incomplete knowledge in many issues. I usually use Java to write applications but now, I need to connect Java with Flex. I read some articles and tutorials about integration using BlazeDS but I still have problem. I made a simple web app and it works, but only on localhost. If I upload my app on server it works but I can't call Java methods.

       

      Applicaton copy text from TextInput to Label when user press Button.

      Below I add content of some files (remote-config.xml, services-config.xml, web.xml and flex main MXML file)


      remote-config.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <service id="remoting-service"
          class="flex.messaging.services.RemotingService">

       

          <adapters>
              <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
          </adapters>

       

          <default-channels>
              <channel ref="my-amf"/>
          </default-channels>

       

      </service>


      services-config.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <services-config>
          <services>
              <service-include file-path="remoting-config.xml" />      
          </services>

       

          <channels>
              <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
                  <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
              </channel-definition>
          </channels>

       

          <logging>
              <target class="flex.messaging.log.ConsoleTarget" level="Error">
                  <properties>
                      <prefix>[BlazeDS] </prefix>
                      <includeDate>false</includeDate>
                      <includeTime>false</includeTime>
                      <includeLevel>false</includeLevel>
                      <includeCategory>false</includeCategory>
                  </properties>
                  <filters>
                      <pattern>Endpoint.*</pattern>
                      <pattern>Service.*</pattern>
                      <pattern>Configuration</pattern>
                  </filters>
              </target>
          </logging>

       

          <system>
              <redeploy>
                  <enabled>false</enabled>
              </redeploy>
          </system>
      </services-config>

       

      flex-servlet.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:flex="http://www.springframework.org/schema/flex"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="
              http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/flex
              http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd">
              
          <flex:message-broker>
              <flex:remoting-service default-channels="my-amf"/>
          </flex:message-broker>
         
          <context:annotation-config />
          <context:component-scan base-package="blah" />
      </beans>

       

      web.xml

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">


      <web-app>

       

          <display-name>BlazeDS Spring Integration Application</display-name>


          <description>BlazeDS Spring Integration Application</description>

          <servlet>
              <servlet-name>flex</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
              <load-on-startup>1</load-on-startup>
          </servlet>

       

          <servlet>
              <servlet-name>RDSDispatchServlet</servlet-name>
              <display-name>RDSDispatchServlet</display-name>
              <servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
              <init-param>
                  <param-name>useAppserverSecurity</param-name>
                  <param-value>false</param-value>
              </init-param>
              <init-param>
                  <param-name>messageBrokerId</param-name>
                  <param-value>_messageBroker</param-value>
              </init-param>
              <load-on-startup>10</load-on-startup>
          </servlet>

       

          <servlet-mapping id="RDS_DISPATCH_MAPPING">
              <servlet-name>RDSDispatchServlet</servlet-name>
              <url-pattern>/CFIDE/main/ide.cfm</url-pattern>
          </servlet-mapping>

       

          <servlet-mapping>
              <servlet-name>flex</servlet-name>
              <url-pattern>/messagebroker/*</url-pattern>
           </servlet-mapping>

       

      </web-app>


      FooProject.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:services="services.*">
         
          <fx:Declarations>
              <s:CallResponder id="sayHelloResult"/>
              <services:FooService id="fooService">
                  <services:channelSet>
                      <s:ChannelSet>
                          <s:AMFChannel uri="http://mctg.yoyo.pl/WebContent/messagebroker/amf"/>
                      </s:ChannelSet>
                  </services:channelSet>
              </services:FooService>
          </fx:Declarations>
         
          <s:TextInput id="ti" x="10" y="13"/>
         
          <s:Label x="10" y="43" text="{sayHelloResult.lastResult}"/>
          <s:Button x="146" y="14" label="Send" click="sayHelloResult.token = fooService.sayHello(ti.text)"/>
      </s:Application>

       

       

      The problem is in my opinion in the line wchich is bold. If I change it to <s:AMFChannel uri="http://localhost:8080/WebContent/messagebroker/amf"/> and run on localhost everything is fine. If I upload app on server and call Java method I can only wait for response but I never will get it.

       

      I realize that similar threads are currently on this forum. I read a few o them but finally I haven't solved my problem yet. I would be grateful for any help.