RE: Returned object null;

"Jackson, Stephen" <[email protected]>
Newsgroups gmane.comp.java.openamf.user
Message-ID <3428D9627CC79A4ABF37A519431D981206A64771@nmr001oldmsx05.enterprisenet.org>
Not sure if you are doing this but add an appender as described in the
openamf download.  Set the log level to DEBUG. It may lead you in the
right direction.  The logging is pretty good and usually points you in
the right direction.

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of jake
Sent: Monday, May 09, 2005 4:27 AM
To: [email protected]
Subject: [Openamf-user] Returned object null;

I have a problem. 



THE PROBLEM

All of the code below works up to the point where the BMUser instance is
received back at the client in the login_Result method of UserDirectory.


 I know that a correctly instantiated BMUser instance is dispatched by
the server, but when it is received in the login_Result method of
UserDirectory all properties are undefined. Furthermore, I put a trace
method in the constructor of BMUser in AS, assuming it would be called
[I]before[/I] login_Result. It wasn't, which suggests that the client
(ie Flash) did not even try to instantiate BMUser.  


Any ideas ? I would be most grateful for some help


Jake




For the archives, here are the bits that work. I hope it well help a few
people get up and running a little faster than I did. 

My  user bean in  AS: 

NOTE: The property names (not the getter names) in the AS class must
match the  getter and setter names in the java class.

////////////////////////////////////////////////////////////////////////
////////
import mx.remoting.NetServices;
class BMUser {
	public var userName:String;
	public var pword:String;
	public var uid:Number;
	public var lastLogin:Number;
	function BMUser() {
		trace(userName+" "+pword+" "+uid+" "+lastLogin);
	}
	function getUserName():String {
		return userName;
	}
	function setUserName(in_s:String) {
		userName = in_s;
	}
	function getPword():String {
		return pword;
	}
	function setPword(in_s:String) {
		pword = in_s;
	}
	function getUid():Number {
		return uid;
	}
	function setUid(in_id:Number) {
		uid = in_id;
	}
	function getLastLogin():Number {
		return lastLogin;
	}
	function setLastLogin(in_l:Number) {
		lastLogin = in_l;
	}
}

----------------------------------------------------------

My communication class in AS:


////////////////////////////////////////////////////////////
import mx.remoting.NetServices;
class UserDirectory {
	
	private var gatewayPath:String = "";
	private var servicePath:String = "";
	private var serviceConnection:Object = new Object();
	private var serviceObject:Object = new Object();
	
	
	public static var _instance:UserDirectory




	public static function getInstance():UserDirectory
	{
		if(_instance == undefined)
		{
			_instance = new UserDirectory()
		}
		return _instance
	}
	
	private function UserDirectory() {
		this.gatewayPath = GLOBALS.gatewayPath;
		this.servicePath = "";
	
this.setServicePath("com.jakestone.bm.remoting.UserDirectory");
		this.setServiceObject();
	}
	function getGatewayPath():String {
		return gatewayPath;
	}
	function setGatewayPath(in_s:String) {
		gatewayPath = in_s;
	}
	function getServicePath():String {
		return servicePath;
	}
	function setServicePath(in_s:String) {
		servicePath = in_s;
	}
	function setServiceObject() {
		trace("UserDirectory settingserviceObject");
		NetServices.setDefaultGatewayUrl(this.gatewayPath);
		this.serviceConnection =
NetServices.createGatewayConnection();
		this.serviceObject =
this.serviceConnection.getService(this.servicePath,
this);
	}
	
	function login(user:BMUser) {
		try {
			trace("UserDirectory:login
username="+user.getUserName());
			trace("UserDirectory:login
username="+user.getPword());
			this.setServiceObject();
			this.serviceObject.login(user);
		} catch (errorObj:Error) {
			trace(errorObj.message);
		}
	}
	function login_Result(loginresult:BMUser) {
		try {
			trace("UserDirectory:login_result
loginresult.getLastLogin()="+loginresult.getLastLogin());
			if (undefined == loginresult.getLastLogin()) {
				trace(" Login Failed");
			} else {
				trace(" Login Succeeded");
			}
		} catch (errorObj:Error) {
			trace(errorObj.message);
		}
	}
}

------------------------------------------------------

This works fine.



SERVER SIDE:

openamf.config.xml

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

	<!--
	Configure behavior of outgoing AMF messages:
	forceLowerCaseKeys - if true, the hash maps used to return
custom classes
	will convert all keys to lower case; 
	set this to:
		true if you're using ActionScript 1.0 on the client,
		false if you're using ActionScript 2.0 (which is
case-sensitive)
	-->
	<amf-serializer>
	
<force-lower-case-keys>true</force-lower-case-keys>
	</amf-serializer>
       
	<!-- Required for DefaultGateway-->
	<invoker>
		<name>PageableRecordSet</name>
	
<class>org.openamf.invoker.PageableResultSetServiceInvoker</class>
	</invoker>
	<invoker>
		<name>SessionControl</name>
	
<class>org.openamf.invoker.SessionControlInvoker</class>
	</invoker>
	<invoker>
		<name>WebService</name>
		<class>org.openamf.invoker.WebServiceInvoker</class>
	</invoker>
	<invoker>
		<name>JMX</name>
		<class>org.openamf.invoker.JMXServiceInvoker</class>
	</invoker>
	
	<!-- Uncomment this to enable EJB invoker
	<invoker>
		<name>EJB</name>
		<class>org.openamf.invoker.EJBServiceInvoker</class>
	</invoker>
	-->
	
	<invoker>
		<name>Java</name>
	
<class>org.openamf.invoker.JavaServiceInvoker</class>
	</invoker>
	<pageable-recordset>
		<initial-data-row-count>20</initial-data-row-count>
	</pageable-recordset>
	<!-- 
	Example Custom Class to Java Class mapping
	
	When a class of type org.openamf.examples.Person is Serialized
	it will be registered to Person in flash 
	
	When a custom class of Person is Deserialized it
	will be translated to an org.openamf.examples.Person
	    -->
	<custom-class-mapping>
	
<java-class>com.jakestone.bm.datamodel.BMUser</java-class>
		<custom-class>BMUser</custom-class>
	</custom-class-mapping>

	<!-- Required  for AdvancedGateway -->
	<!-- 
		This allows you to declare infomation about your
services,
		instead of having the DefaultGateway guess 
	-->
	<service>
		<name>SessionControlService</name>
		<invoker-ref>SessionControl</invoker-ref>
		<method>
			<name>close</name>
			<parameter>
				<type>*</type>
			</parameter>
		</method>
	</service>
	<service>
		<name>OpenAMFPageableRecordSet</name>
		<invoker-ref>PageableRecordSet</invoker-ref>
		<method>
			<name>*</name>
			<parameter>
				<type>*</type>
			</parameter>
		</method>
	</service>
	<service>
		<name>Test</name>
	
<service-location>com.jakestone.bm.Test</service-location>
		<invoker-ref>Java</invoker-ref>
		<method>
			<!-- Operation's are matched by the name and
parameters -->
			<name>sayHello</name>
			<state-bean-ref>
				<name>Authentication</name>
			</state-bean-ref>
			<parameter>
				<!-- 
					type can be the the name of the
class, 
					a * for any types,
					or a ? any 1 type
				-->
				<type>*</type>
			</parameter>
		</method>

	</service>
    <service>
		<name>UserDirectory</name>
	
<service-location>com.jakestone.bm.remoting.UserDirectory</service-locat
ion>
		<invoker-ref>Java</invoker-ref>
		<method>
			<!-- Operation's are matched by the name and
parameters -->
			<name>login</name>
			<state-bean-ref>
				<name>Authentication</name>
			</state-bean-ref>
			<parameter>
				<!--
					type can be the the name of the
class,
					a * for any types,
					or a ? any 1 type
				-->
				<type>*</type>
			</parameter>
		</method>

	</service>
	<state-bean>
		<name>Authentication</name>
		<class>org.openamf.examples.Authentication</class>
		<scope>session</scope>
	</state-bean>
</config>

------------------------------------------------------------------------
-




My service class:
////////////////////////////////////////////////////////////////////////
//
package com.jakestone.bm.remoting;

import com.jakestone.bm.datamodel.BMUser;
import com.jakestone.bm.utils.BMLogManager;

import java.util.logging.Level;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: Jacob
 * Date: May 8, 2005
 * Time: 8:59:05 PM
 * To change this template use Options | File Templates.
 */
public class UserDirectory implements Serializable {
    public BMUser login(BMUser user)
    {
        try
        {

           
BMLogManager.getDefaultLogger().log(Level.INFO,"user
is "+user.toString());
            user.login();
            return user;
        }
        catch(Exception e)
        {
           
BMLogManager.getDefaultLogger().log(Level.WARNING,"EXCEPTION
IN DIRECTORY"+e.toString(),e);
        }
        return null;
    }
}

---------------------------------------------------------------


and my userbean which talks to a DAO:

//////////////////////////////////////////////////////////////////
package com.jakestone.bm.datamodel;

import com.jakestone.bm.BMException;
import com.jakestone.bm.ExceptionEncoder;
//import com.jakestone.bm.servlet.Constants;
//import com.jakestone.bm.servlet.XMLWrap; import
com.jakestone.bm.utils.BMLogManager;

import java.sql.Date;
import java.util.logging.Level;
import java.io.Serializable;


/**
 * Created by IntelliJ IDEA.
 * User: jake
 * Date: Jun 26, 2004
 * Time: 8:09:42 AM
 * To change this template use Options | File Templates.
 */
public class BMUser extends BMAbstractDataObject implements Serializable
{

    private String userName;
    private String pword;
    private long lastLogin;


    public long getUid()
    {
        return uid;
    }

    public void setUid(long in_id)
    {
        uid = in_id;
    }

    public BMException getBMException()
    {
        return exception;
    }

    public void setBMException(BMException
in_exception)
    {
        exception = in_exception;
    }

    public String getUserName()
    {
        return userName;
    }

    public String getPword()
    {
        return pword;
    }

    public long getLastLogin()
    {
        return lastLogin;
    }


    public void setUserName(String in_userName)
    {
        userName = in_userName;
    }

    public void setPword(String in_password)
    {
        pword = in_password;
    }

    public void setLastLogin(long in_lastLogin)
    {
        lastLogin = in_lastLogin;

    }

    public Date showLastLogin()
    {
        return new Date(lastLogin);
    }


    protected void doInsert() throws
BMDataModelException
    {
       
//BMLogManager.getDefaultLogger().log(Level.FINE,
"inserting ");
        BMUserMgr.getInstance().doInsert(this);
    }

    protected void doUpdate() throws
BMDataModelException
    {
        BMUserMgr.getInstance().doUpdate(this);
    }

    public void doPopulate() throws
BMDataModelException
    {
        BMUserMgr.getInstance().populate(this);
    }

    public void doDelete() throws BMDataModelException
    {
        BMUserMgr.getInstance().delete(this);
    }

    public void populate(String un, String pw) throws
BMDataModelException
    {
        this.userName = un;
        this.pword = pw;
        BMUserMgr.getInstance().populate(this);
    }

    protected void validate() throws BMException
    {
        if (null == pword || null == userName)
        {
           
BMLogManager.getDefaultLogger().log(Level.WARNING,
"Username or pword is blank");

            BMException exc = new
BMException("Username or pword is blank");
            exc.setHumanMessage("Username or pword is blank");

            throw  exc;
        }

        if (userName.length() > 16)
        {
           
BMLogManager.getDefaultLogger().log(Level.WARNING,
"User name longer than 16 characters");
            BMException exc = new BMException("User name longer than 16
characters");
            exc.setHumanMessage("User name longer than
16 characters");

            throw  exc;
        }
        else if (userName.length() > 16)
        {
           
BMLogManager.getDefaultLogger().log(Level.WARNING,
"Password longer than 16 characters");
            BMException exc = new
BMException("Password longer than 16 characters");
            exc.setHumanMessage("Password longer than
16 characters");

            throw  exc;
        }
    }

    public void login()
    {
        try
        {

                try
                {
                   
BMLogManager.getDefaultLogger().log(Level.FINE, "db is local");

                   
BMUserMgr.getInstance().login(this);


                }
                catch (Exception e)
                {
                   
BMLogManager.getDefaultLogger().log(Level.FINE,
e.getMessage());
                   
setBMException(ExceptionEncoder.encodeException(e));
                }


        }
        catch (Exception e)
        {

           
this.setBMException(ExceptionEncoder.encodeException(e));


           
BMLogManager.getDefaultLogger().log(Level.FINE,
"standard exception" + e.getMessage());
        }

    }

    public String toString()
    {
        return super.toString() + "\r\nuser=" + userName +
"\r\nlastlogin=" + lastLogin;
    }

}[/as]



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events,
4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Openamf-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openamf-user



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.