0 Replies Latest reply on Dec 15, 2011 3:35 PM by Anshul108

    Flex Integration with J2EE Communication Problem

    Anshul108 Level 1

      Hi,

          I have written a simple program to accept Name using Flex SDK 3.2 HttpService in Flex builder 3. Using LiveCycle DS ES 3.0 to communicate with struts 1.2 on Web

      Server(Tomcat 6.0) in MyEclipse. My flex code runs and Struts code runs independently. The problem is when trying to send data from client to Server, it does not work.

      Below given are my client and Server side code. Copy of services-config.xml & proxy-config.xml is same on both client side and server side. Both LifeCycle DS ES 3.0

      and WebServer Tomcat 6.0 are running on same machine.I have imported fds.swc file in Flex Builder lib folder.Please help me to run this code.

      LiveCycle DS ES 3.0  uses port no - 8400
      WebServer Tomcat 6.0 uses port no - 8000

      Client Side
      ========

       

      hello.mxml
      -----------------

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[
        public function hello1():void{
         HelloCall.send();
        }
      ]]>
      </mx:Script>

      <mx:HTTPService id= "HelloCall" destination= "myHello">
          <mx:request xmlns= " ">
                  <name>  {nameInput.text}</name>
          </mx:request>
      </mx:HTTPService>


      <mx:Label x= "312" y= "47" text= "Enter Name" fontSize= "20" />
      <mx:TextInput id= "nameInput" x="260" y= "104" fontSize= "20" />
      <mx:Button x= "301" y= "186" label= "Submit" fontSize= "20" click= "hello1();" />
      <mx:Label x= "312" y= "285" text= "{HelloCall.lastResult.jlc.message}" fontSize= "20" />
      </mx:Application>

       

      services-config.xml
      -------------------

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

          <services>
              <service-include file-path="remoting-config.xml" />
              <service-include file-path="proxy-config.xml" />
              <service-include file-path="messaging-config.xml" />
              <service-include file-path="data-management-config.xml" />
              <service class="fiber.data.services.ModelDeploymentService" id="model-deploy-service" />
             
              <!--
           Application level default channels. Application level default channels are
           necessary when a dynamic destination is being used by a service component
           and no ChannelSet has been defined for the service component. In that case,
           application level default channels will be used to contact the destination.
              -->  
              <default-channels>
                 <channel ref="my-rtmp"/>
              </default-channels>

          </services>

          <security>
        <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>       
              <!-- Uncomment the correct app server
              <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>
              <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
              <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>
              -->
              <security-constraint id="basic-read-access">
                  <auth-method>Basic</auth-method>
                  <roles>
                      <role>guests</role>
                      <role>accountants</role>
                      <role>employees</role>
                      <role>managers</role>
                  </roles>
              </security-constraint>
          </security>

          <!-- Socket servers that NIO endpoints all share -->
          <servers>
              <server id="my-nio-server" class="flex.messaging.socketserver.SocketServer">
              </server>
              <!--
              <server id="secure-nio-server" class="flex.messaging.socketserver.SocketServer">
                  <properties>
                      <keystore-file>{context.root}/WEB-INF/flex/localhost.keystore</keystore-file>
                      <keystore-password>changeit</keystore-password>
                  </properties>
              </server>
              -->
          </servers>

          <channels>

              <!-- Servlet Based endpoints -->
              <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
                  <endpoint url="http://localhost:8400/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
                  <properties>
                      <polling-enabled>false</polling-enabled>
                  </properties>
              </channel-definition>

              <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
                  <endpoint url="http://localhost:8400/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
                  <properties>
                      <polling-enabled>true</polling-enabled>
                      <polling-interval-seconds>8</polling-interval-seconds>
                  </properties>
              </channel-definition>

              <channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel">
                  <endpoint url="http://localhost:8400/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
              </channel-definition>

              <!-- Secure Servlet-based endpoints -->
              <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
                  <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
                  <properties>
                      <!--HTTPS requests on some browsers do not work when pragma "no-cache" are set-->
                      <add-no-cache-headers>false</add-no-cache-headers>
                  </properties>
              </channel-definition>

              <channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
                  <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
                  <properties>
                   <!--HTTPS requests on some browsers do not work when pragma "no-cache" are set-->
                      <add-no-cache-headers>false</add-no-cache-headers>
                  </properties>
              </channel-definition>

              <!-- NIO based endpoints -->
              <channel-definition id="my-rtmp" class="mx.messaging.channels.RTMPChannel">
                  <endpoint url="rtmp://localhost:2048" class="flex.messaging.endpoints.RTMPEndpoint"/>
                  <properties>
                      <idle-timeout-minutes>20</idle-timeout-minutes>
                      <!-- for deployment on WebSphere, must be mapped to a WorkManager available in the web application's jndi context.
                      <websphere-workmanager-jndi-name>java:comp/env/wm/MessagingWorkManager</websphere-workman ager-jndi-name>
                      -->
                  </properties>
              </channel-definition>

              <channel-definition id="my-nio-amf" class="mx.messaging.channels.AMFChannel">
                  <endpoint url="http://localhost:2888/nioamf" class="flex.messaging.endpoints.NIOAMFEndpoint"/>
                  <server ref="my-nio-server"/>
                  <properties>
                      <polling-enabled>false</polling-enabled>
                  </properties>
              </channel-definition>

              <channel-definition id="my-nio-amf-poll" class="mx.messaging.channels.AMFChannel">
                  <endpoint url="http://localhost:2888/nioamfpoll" class="flex.messaging.endpoints.NIOAMFEndpoint"/>
                  <server ref="my-nio-server"/>
                  <properties>
                      <polling-enabled>true</polling-enabled>
                      <polling-interval-millis>3000</polling-interval-millis>
                  </properties>
              </channel-definition>

              <channel-definition id="my-nio-http" class="mx.messaging.channels.HTTPChannel">
                  <endpoint url="http://localhost:2888/niohttp" class="flex.messaging.endpoints.NIOHTTPEndpoint"/>
                  <server ref="my-nio-server"/>
                  <properties>
                      <polling-enabled>false</polling-enabled>
                  </properties>
              </channel-definition>

              <!-- Secure NIO based endpoints -->
              <!--
              <channel-definition id="secure-nio-amf" class="mx.messaging.channels.SecureAMFChannel">
                  <endpoint url="https://{server.name}:2443/securenioamf" class="flex.messaging.endpoints.SecureNIOAMFEndpoint"/>
                  <server ref="secure-nio-server"/>
                  <properties>
                      <polling-enabled>false</polling-enabled>
                  </properties>
              </channel-definition>

              <channel-definition id="secure-nio-http" class="mx.messaging.channels.SecureHTTPChannel">
                  <endpoint url="https://{server.name}:2443/secureniohttp" class="flex.messaging.endpoints.SecureNIOHTTPEndpoint"/>
                  <server ref="secure-nio-server"/>
                  <properties>
                      <polling-enabled>false</polling-enabled>
                  </properties>
              </channel-definition>
              -->
          </channels>

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

          <system>
              <redeploy>
                  <enabled>true</enabled>
                  <watch-interval>20</watch-interval>
                  <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
                  <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
                  <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
                  <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>
                  <watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file>
                  <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
              </redeploy>
          </system>

      </services-config>


      proxy-config.xml
      -----------------
      <?xml version="1.0" encoding="UTF-8"?>
      <service id="proxy-service"
          class="flex.messaging.services.HTTPProxyService">

          <properties>
              <connection-manager>
                  <max-total-connections>100</max-total-connections>
                  <default-max-connections-per-host>2</default-max-connections-per-host>
              </connection-manager>
              <allow-lax-ssl>true</allow-lax-ssl>
          </properties>

          <adapters>
              <adapter-definition id="http-proxy" class="flex.messaging.services.http.HTTPProxyAdapter" default="true"/>
              <adapter-definition id="soap-proxy" class="flex.messaging.services.http.SOAPProxyAdapter"/>
          </adapters>

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

          <destination id="myHello">
          <properties>
      <url>http://localhost:8000/{context.root}/hello.do</url>
      </properties>
          </destination>

      </service>


      Server-Side
      ============

       

      struts-config.xml
      ------------------

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

      <struts-config> 

        <form-beans>

             <form-bean name= "helloForm" type= "org.apache.struts.action.DynaActionForm">
                    <form-property name= "name" type="java.lang.String" />
             </form-bean>
         </form-beans>


        <global-forwards>
        <forward name= "success" path= "/index.jsp" />
        </global-forwards>
       

      <action-mappings>
          <action path= "/hello" name= "helloForm" type="com.jlcindia.struts.HelloAction" input= "/hello.html" />

      </action-mappings>


        <message-resources parameter="com.jlcindia.struts.ApplicationResources" />
      </struts-config>

       


      web.xml
      --------

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"

      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

         <!-- MessageBroker Servlet -->
         <!-- Http Flex Session attribute and binding listener support -->
        
          <listener>
              <listener-class>flex.messaging.HttpFlexSession</listener-class>
          </listener>

        
       
        <servlet>
          <servlet-name>action</servlet-name>
          <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

          <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
          </init-param>

         <init-param>
            <param-name>debug</param-name>
            <param-value>3</param-value>
         </init-param>

         <init-param>
            <param-name>detail</param-name>
            <param-value>3</param-value>
          </init-param>

          <load-on-startup>1</load-on-startup>
        </servlet>
       
       
         <servlet>
        <servlet-name>MessageBrokerServlet</servlet-name>
        <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
       
         <init-param>
          <param-name>services.configuration.file</param-name>
          <param-value>/WEB-INF/flex/services-config.xml</param-value>
         </init-param>
        <load-on-startup>1</load-on-startup>
          </servlet>
       
       
        <servlet-mapping>
          <servlet-name>action</servlet-name>
          <url-pattern>*.do</url-pattern>
        </servlet-mapping>
       
        <servlet-mapping>
          <servlet-name>MessageBrokerServlet</servlet-name>
          <url-pattern>/messagebroker/*</url-pattern>
        </servlet-mapping>
       
        
        <welcome-file-list>
          <welcome-file>hello.html</welcome-file>
        </welcome-file-list>
      </web-app>

       


      HelloAction.java
      ------------------

      package com.jlcindia.struts;

      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import org.apache.struts.action.*;
      import org.apache.struts.action.ActionForm;
      import org.apache.struts.action.ActionForward;
      import org.apache.struts.action.ActionMapping;
      import org.apache.struts.action.DynaActionForm;

      import java.io.PrintWriter;

      public class HelloAction extends Action{

       

      public ActionForward execute(ActionMapping am,ActionForm af,HttpServletRequest req,HttpServletResponse res) throws Exception {

       

          System.out.println("Hi am here");
          DynaActionForm daf= (DynaActionForm)af;
          String name= daf.get("name").toString();
          String msg= "Hello!"+ name + "Welcome to JLC FLex LCDS with HttpService";
          res.setContentType("text/html");
          PrintWriter out= res.getWriter();
          out.println("<message>" + msg + "</message>");
          out.close();
          return am.findForward("success");
      }
      }

       

      I have Installed Flex Debugger and it gives follwoing error message :-

      [RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url:

      'http://localhost:8400/JLCAPP/messagebroker/amf'"]
      at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.2.0

      \frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:220]
      at mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder .as:53]
      at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:103]
      at mx.messaging::ChannelSet/faultPendingSends()[C:\autobuild\3.2.0\frameworks\projects\rpc\s rc\mx\messaging\ChannelSet.as:1482]
      at mx.messaging::ChannelSet/channelFaultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc \src\mx\messaging\ChannelSet.as:975]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.messaging::Channel/connectFailed()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\m essaging\Channel.as:997]
      at mx.messaging.channels::PollingChannel/connectFailed()[C:\autobuild\3.2.0\frameworks\proje cts\rpc\src\mx\messaging\channels\PollingChannel.as:354]
      at mx.messaging.channels::AMFChannel/statusHandler()[C:\autobuild\3.2.0\frameworks\projects\ rpc\src\mx\messaging\channels\AMFChannel.as:390]

       

      Any Help will be appriciated.