16 Replies Latest reply on Jul 11, 2007 8:04 AM by Newsgroup_User

    Flex with JNDI

    taurivalor
      Hi Guys,

      I am working with Flex2.0. I have gone through the documentation, but I couldnt find how I could connect to a backend LDAP source (eg. Sunone, ActiveDirectory..) using ActionScript. Please help me understand how I could make LDAP calls using Actionscript.

      Thanks,
      Tauri.
        • 1. Re: Flex with JNDI
          JeffreyGong Level 1
          Hi taurivalor,

          You may use RemoteObject to call a Java method inside a Java Class (JavaBean), then let the Java method to connect to LDAP (JNDI).

          Hope it helps,

          Jeffrey
          • 2. Re: Flex with JNDI
            taurivalor Level 1
            Hi Jeffrey,

            Thanks for the reply.
            As you've said I will try to use RemoteObject to call a Java method inside a Java Class (JavaBean), then let the Java method to connect to LDAP (JNDI).

            But, I did not understand how the Actionscript calls the JavaBean..Pls help me understand this... :)

            Thanks,
            Tauri.
            • 3. Re: Flex with JNDI
              JeffreyGong Level 1
              Hi taurivalor,

              In ActionScript, it's like

              ro.javaMethod()

              in mxml, like

              <mx:RemoteObject id="ro" destination="testds" fault="faultHandler(event)">
              <mx:method name="javaMethod" result="resultHander(event)"/>
              </mx:RemoteObject>

              in remoting-config.xml, like

              <destination id="testds">
              <properties>
              <source>test.MyJavaBean</source>
              <scope>application</scope>
              </properties>
              </destination>

              Have fun!

              Jeffrey
              • 4. Re: Flex with JNDI
                taurivalor Level 1
                Hi Jeffrey,

                I have followed the steps that you've explained. Thanks for the solution.
                But I have a problem calling the java method in my action script.

                The following is my mxml file:

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application
                xmlns:mx=" http://www.adobe.com/2006/mxml"
                viewSourceURL="src/XMLDataByReference/index.html"
                >
                <mx:Script>
                <![CDATA[
                import mx.controls.Alert;
                import mx.rpc.events.ResultEvent;
                import mx.rpc.events.FaultEvent;
                private function gotName(event:ResultEvent):void
                {
                Alert.show("Server Message: " + event.result, "Success");
                }

                private function faultHandler(event:FaultEvent):void
                {
                Alert.show("Server Message: Error");
                }
                ]]>
                </mx:Script>
                <mx:Script>

                <![CDATA[

                private function getData():void
                {

                ro.getName();
                //Invoke the call
                }
                //todo............
                ]]>
                </mx:Script>

                <mx:RemoteObject id="ro" destination="testds" fault="faultHandler(event)">
                <mx:method name="getName" result="gotName(event)"/>
                </mx:RemoteObject>

                <mx:Button label="Get LDAP Data" click="getData()"/>
                </mx:Application>


                I have declared the Javaclass in remoting-config.xml the following way:

                <destination id="testds">
                <properties>
                <source>/WEB-INF/classes/Test3</source>
                <scope>application</scope>
                </properties>
                </destination>

                When I click on the button it returns an error message from faulthandler..

                What could be the probable reason ?

                Thanks,
                Tauri Valor
                • 5. Re: Flex with JNDI
                  taurivalor Level 1
                  Jeffrey,

                  Heres my JavaBean:

                  import javax.naming.Context;
                  import javax.naming.NameNotFoundException;
                  import javax.naming.NamingEnumeration;
                  import javax.naming.directory.Attribute;
                  import javax.naming.directory.InitialDirContext;
                  import javax.naming.directory.DirContext;
                  import javax.naming.directory.Attributes;
                  import javax.naming.directory.SearchControls;
                  import javax.naming.directory.SearchResult;
                  import javax.naming.NamingException;
                  import java.util.Hashtable;
                  import java.util.LinkedList;
                  import java.util.List;

                  public class Test3 {

                  public Object getName(){
                  Object name=null;
                  Hashtable env = new Hashtable();
                  env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                  // specify where the ldap server is running
                  env.put(Context.PROVIDER_URL, "ldap://localhost:2389/ou=People,dc=fiftyk,dc=com");
                  // use simple authenticate to authenticate the user
                  env.put(Context.SECURITY_AUTHENTICATION, "simple");
                  env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
                  env.put(Context.SECURITY_CREDENTIALS, "secret");

                  try {
                  // Create the initial directory context
                  DirContext ctx = new InitialDirContext(env);

                  Attributes attrs = ctx.getAttributes("uid=userid.1");

                  // Find the surname ("sn") attribute of this object and print it
                  System.out.println("Last Name: " + attrs.get("sn").get());
                  name=attrs.get("sn").get();

                  // Close the context
                  ctx.close();
                  } catch (NamingException e) {
                  System.err.println("Problem getting attribute: " + e);
                  }


                  return name;



                  }



                  }

                  • 6. Re: Flex with JNDI
                    JeffreyGong Level 1
                    Hi taurivaor,

                    Your remoting-config.xml should have the lines as follows,


                    <destination id="testds">
                    <properties>
                    <source>Test3</source>
                    <scope>application</scope>
                    </properties>
                    </destination>

                    Please note that "Test3" replaced "WEB-INF/classes/Test3" for the source line in your case.

                    Have a try again.

                    Jeffrey

                    • 7. Re: Flex with JNDI
                      taurivalor Level 1
                      Jeffrey

                      Hi again !! Thanks again for your reply..
                      Ive tried changing the "remoting-config.xml" but I hv the same problem...I think the Java class which I ve declared in remoting-cofng.xml is not being identified.

                      I placed my java class in web-inf/classes folder.

                      I also tried placing the class in the same location where my remoting-config.xml lies.

                      I have the same problem my error handler is being called every time I press click button...

                      Please let me know if theres any other problem.
                      (Im using Tomcat4.1.27 to run my mxml file)


                      Thanks,
                      Tauri Valor.



                      • 8. Re: Flex with JNDI
                        JeffreyGong Level 1
                        Hi taurivalor,

                        It might be a problem by using Tomcat4.1.27. One of the System requirements for FDS is Apache Tomcat 5.5.x based on Adobe. Can you run Adobe FDS examples such as http://localhost:8080/samples/sqladmin/sqladmin.mxml from you PC?

                        Jeffrey
                        • 9. Re: Flex with JNDI
                          taurivalor Level 1
                          Hi Jeffrey

                          Im used Tomcat5.5, but I still had the same error. I tried the example 'sqladmin' with database running, but I had the same problem, It gives the error "Faled to send".

                          Im unable to track the problem. I also used jdk1.5 . I think that my mxml file is not able to locate the java class which I placed in web-inf/classes folder.

                          Please let me understand this problem...thx for your patience :)

                          Thanks,
                          Tauri Valor
















                          • 10. Re: Flex with JNDI
                            taurivalor Level 1
                            Hi Jeffrey

                            I could finally access the RemoteObject, could retrieve the data from ldap backend.
                            Im now trying to build a form which queries the back end and displays the result.

                            I couldnt have done this without your help..

                            Thanks,
                            Tauri.

                            • 11. Re: Flex with JNDI
                              taurivalor Level 1
                              And by the way...I used Flex Test Drive Server to run my application...

                              Thanks,
                              Tauri
                              • 12. Re: Flex with JNDI
                                JeffreyGong Level 1
                                Hi taurivalor,

                                The following link wil be in good help

                                http://livedocs.adobe.com/flex/201/html/dataservices_intro_098_2.html

                                Jeffrey
                                • 13. Re: Flex with JNDI
                                  taurivalor Level 1
                                  Hi Jeffrey

                                  I have been able to access RemoteObject from mxml.

                                  Today I had a problem, when Im trying to call a RemoteObject which retrieves the list of results from LDAP backend.

                                  I wrote a java class in which Im using a Pojo to create an object, the following is the chunk of code in my getAllAttrs() method:

                                  valsList
                                  .add(new TPojo(attrs.get("cn").toString(), attrs.get( "givenName").toString(), attrs.get( "telephoneNumber").toString(), attrs.get( "userPassword").toString(), attrs.get ("objectClass").toString(), attrs.get("postalCode").toString(), attrs.get("employeeNumber").toString(), attrs.get("description").toString(), attrs.get("st").toString()));


                                  When Im starting the server and trying to run my mxml , it gives the following error :

                                  [RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: ' http://localhost:8600/messagebroker/amf'"
                                  at mx.rpc::AbstractInvoker/ http://www.adobe.com/2006/flex/mx/internal::faultHandler()
                                  at mx.rpc::Responder/fault()
                                  at mx.rpc::AsyncRequest/fault()
                                  at mx.messaging::ChannelSet/::faultPendingSends()
                                  at mx.messaging::ChannelSet/channelFaultHandler()
                                  at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
                                  at flash.events::EventDispatcher/dispatchEvent()
                                  at mx.messaging::Channel/mx.messaging:Channel::connectFailed()
                                  at mx.messaging.channels::PollingChannel/mx.messaging.channels:PollingChannel::connectFailed ()
                                  at mx.messaging.channels::AMFChannel/mx.messaging.channels:AMFChannel::statusHandler()


                                  I have gone through web, and somewhere I learnt that its because of the beta version of FDS.
                                  But I dont think thats true since other examples works fine.

                                  Please let me know if have any idea of the above problem :)

                                  Thanks,
                                  Tauri Valor.




                                  • 14. Re: Flex with JNDI
                                    taurivalor Level 1
                                    Hi

                                    Can I know how I could generate mxml from a java file ?
                                    My challenge has been to read xml file using java and generating a form in mxml .

                                    Please help.

                                    Thanks,
                                    Tauri
                                    • 15. Re: Flex with JNDI
                                      Mete Atamel Level 1
                                      There's no automatic way to generate mxml from a Java file.
                                      • 16. Re: Flex with JNDI
                                        Level 7
                                        LCDS 2.5 has a JSP tag library that can be used to dynamically create
                                        MXML which will be compiled into a Flex application as a SWF.

                                        See:

                                        http://livedocs.adobe.com/livecycle/es/sdkHelp/programmer/lcds/wwhelp/wwhimpl/common/html/ wwhelp.htm?context=LiveDocs_Parts&file=Part1_developer_1.html