[Red5devs] Sending extended Objects from Red5to Flex

Roland Zagler laureen at laureen.at
Sun Jun 14 06:13:03 PDT 2009


Sorry, I forgot to mention the versions used:

Red5 0.8.0
Java JDK 1.6.0_13

Eclipse 3.4.2 M20090211-1700
Flex Builder 3 PlugIn 3.0.2.214193
Flex SDK 3.3.0.4852

Regards,
Roland

-----Original message-----

Hi everyone,

I encountered a problem when sending extended objects via RTMP to Flex.
Until now I was successfully able to send simple POJOs in both
directions (Flex->Red5 and Red5->Flex) if the classes were correctly
defined on both sides and the Flex class includes the

[RemoteClass(alias="<fq java class name>")]

tag, everything is fine.

Now I wanted to start send extended classes, for instance:

----- Attribute.java -----
package at.laureen.example.common;

import java.io.Serializable;

public class Attribute implements Serializable {

	private static final long serialVersionUID = 5328881684312717488L;

	private String key = null;
	private Object value = null;
	
	public Attribute(String key, Object value) {
		this.key = key;
		this.value = value;
	}
	
	public String getKey() {
		return key;
	}
	
	public void setKey(String key) {
		this.key = key;
	}
	
	public Object getValue() {
		return value;
	}
	
	public void setValue(Object value) {
		this.value = value;
	}
}

----- IAttributedObject.java -----
package at.laureen.example.api;

import java.util.Collection;
import java.util.Set;

import at.laureen.example.common.Attribute;

public interface IAttributedObject {

	public void setAttribute(String key, Object value);

	public void setAttributes(Set<Attribute> attributes);

	public Object getAttribute(String key);

	public Collection<Attribute> getAttributes();

	public String[] getAttributeNames();

	public int getAttributeCount();

	public void clearAttributes();

}

----- AttributedObject.java -----
package at.laureen.example.common;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import at.laureen.example.api.IAttributedObject;

public class AttributedObject implements Serializable, IAttributedObject {

	private static final long serialVersionUID = 3295226293181736603L;

	protected Set<Attribute> attributes =
Collections.synchronizedSet(new HashSet<Attribute>());
	
	public void setAttribute(String key, Object value) {
		attributes.add(new Attribute(key, value));
	}
	
	public void setAttributes(Set<Attribute> attributes) {
		attributes = Collections.synchronizedSet(attributes);
	}
	
	public Object getAttribute(String key) {
		synchronized (attributes) {
			for(Iterator<Attribute> iter =
attributes.iterator(); iter.hasNext();) {
				Attribute a = iter.next();
				if(a.getKey().equals(key)) {
					return a.getValue();
				}
			}
		}
		return null;
	}
	
	public Collection<Attribute> getAttributes() {
		return attributes;
	}
	
	public String[] getAttributeNames() {
		String[] aNames = new String[attributes.size()];
		synchronized (attributes) {
			int i = 0;
			for(Iterator<Attribute> iter =
attributes.iterator(); iter.hasNext();) {
				Attribute a = iter.next();
				aNames[i] = a.getKey();
				i++;
			}
		}
		return aNames;
	}
	
	public int getAttributeCount() {
		return attributes.size();
	}
	
	public void clearAttributes() {
		attributes.clear();
	}
}

----- User.java -----
package at.laureen.example.user;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.red5.annotations.DontSerialize;

import at.laureen.example.common.AttributedObject;

public class User extends AttributedObject implements Serializable {

	private static final long serialVersionUID = 8764345726170986162L;

	private int id = 0;
	private String username = null;
	@DontSerialize
	private String password = null;
	private boolean authenticated = false;
	private Set<Group> groups = Collections.synchronizedSet(new
HashSet<Group>());

	public User(String username, String password) {
		this.username = username;
		this.password = password;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public boolean isAuthenticated() {
		return authenticated;
	}

	public void setAuthenticated(boolean authenticated) {
		this.authenticated = authenticated;
	}

	public Set<Group> getGroups() {
		return groups;
	}
	
	public void setGroups(Set<Group> groups) {
		this.groups = groups;
	}
	
	public void addGroup(Group group) {
		this.groups.add(group);
	}
	
	public void removeGroup(Group group) {
		this.groups.remove(group);
	}
	
	public Group removeGroup(int id) {
		synchronized (groups) {
			Iterator<Group> iter = groups.iterator();
			while(iter.hasNext()) {
				Group g = iter.next();
				if(g.getId() == id) {
					iter.remove();
					return g;
				}
			}
		}
		return null;
	}
}

I have found no possibility to transfer an Object of class "User" to Flex,
it always ends up in an "Object" that is neither recognized by Flex as
"User" object
nor can be casted to the appropriate "User"-Object in Flex. The Flex class
"User"
is defined including

[RemoteClass(alias="at.laureen.example.user.User")]

tag, it contains all fields as public variables that are sent from Red5.

I have to mention that the definition of the "User" class is *NOT*
"optimized-out"
by the Flex compiler, so it is be available inside the application swf.

Maybe someone of the dev-gurus can help me or give me a hint what to try.

Thanks in advance,
Roland



_______________________________________________
Red5devs mailing list
Red5devs at osflash.org
http://osflash.org/mailman/listinfo/red5devs_osflash.org





More information about the Red5devs mailing list