flex.messaging.io.amf.client
Class AMFConnection

java.lang.Object
  extended by flex.messaging.io.amf.client.AMFConnection

public class AMFConnection
extends Object

A Java alternative to the native flash.net.NetConnection class for sending AMF formatted requests over HTTP or HTTPS based on AMFConnection in ActionScript. AMFConnection automatically handles cookies by looking for cookie headers and setting the cookies in subsequent request. AMF connection class is not thread safe.


Field Summary
static String COOKIE
           
static String COOKIE_NAMEVALUE_SEPERATOR
           
static String COOKIE_SEPERATOR
           
static String COOKIE2
           
static String SET_COOKIE
           
static String SET_COOKIE2
           
 
Constructor Summary
AMFConnection()
          Creates a default AMF connection instance.
 
Method Summary
 void addAmfHeader(String name, boolean mustUnderstand, Object data)
          Adds an AMF packet-level header which is sent with every request for the life of this AMF connection.
 void addAmfHeader(String name, Object data)
          Add an AMF packet-level header with mustUnderstand=false, which is sent with every request for the life of this AMF connection.
 void addHttpRequestHeader(String name, String value)
          Adds a Http request header to the underlying connection.
 Object call(String command, Object[] arguments)
          Makes an AMF request to the server.
 void close()
          Closes the underlying URL connection, sets the url to null, and clears the cookies.
 void connect(String url)
          Connects to the URL provided.
 AMFHeaderProcessor getAMFHeaderProcessor()
          Returns the AMF header processor associated with the AMF connection.
static int getDefaultObjectEncoding()
          The default object encoding for all AMFConnection instances.
 int getObjectEncoding()
          The object encoding for this AMF connection sets which AMF version to use during serialization.
 String getUrl()
          Returns the HTTP or HTTPS url for the AMF connection.
 boolean isInstantiateTypes()
          Returns instantiateTypes property.
static void registerAlias(String alias, String className)
          Registers a custom alias for a class name bidirectionally.
 void removeAllAmfHeaders()
          Removes all AMF headers.
 void removeAllHttpRequestHeaders()
          Removes all Http request headers.
 boolean removeAmfHeader(String name)
          Removes any AMF headers found with the name given.
 boolean removeHttpRequestHeader(String name)
          Removes the Http header found with the name given.
 void setAMFHeaderProcessor(AMFHeaderProcessor amfHeaderProcessor)
          Sets the AMF header processor associated with the AMF connection.
static void setDefaultObjectEncoding(int value)
          Sets the default object encoding of the AMF connection.
 void setInstantiateTypes(boolean instantiateTypes)
          Sets the instantiateTypes property.
 void setObjectEncoding(int objectEncoding)
          Sets the object encoding for the AMF connection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COOKIE

public static final String COOKIE
See Also:
Constant Field Values

COOKIE2

public static final String COOKIE2
See Also:
Constant Field Values

COOKIE_SEPERATOR

public static final String COOKIE_SEPERATOR
See Also:
Constant Field Values

COOKIE_NAMEVALUE_SEPERATOR

public static final String COOKIE_NAMEVALUE_SEPERATOR
See Also:
Constant Field Values

SET_COOKIE

public static final String SET_COOKIE
See Also:
Constant Field Values

SET_COOKIE2

public static final String SET_COOKIE2
See Also:
Constant Field Values
Constructor Detail

AMFConnection

public AMFConnection()
Creates a default AMF connection instance.

Method Detail

registerAlias

public static void registerAlias(String alias,
                                 String className)
Registers a custom alias for a class name bidirectionally.

Parameters:
alias - The alias for the class name.
className - The concrete class name.

getAMFHeaderProcessor

public AMFHeaderProcessor getAMFHeaderProcessor()
Returns the AMF header processor associated with the AMF connection. AMF header processor is same as NetConnection's client property. See flash.net.NetConnection#client.

Returns:
The AMF header processor associated with the AMF connection.

setAMFHeaderProcessor

public void setAMFHeaderProcessor(AMFHeaderProcessor amfHeaderProcessor)
Sets the AMF header processor associated with the AMF connection.

Parameters:
amfHeaderProcessor - The AMF header processor to set.

getDefaultObjectEncoding

public static int getDefaultObjectEncoding()
The default object encoding for all AMFConnection instances. This controls which version of AMF is used during serialization. The default is AMF 3. See flash.net.ObjectEncoding#DEFAULT

Returns:
The default object encoding of the AMF connection.

setDefaultObjectEncoding

public static void setDefaultObjectEncoding(int value)
Sets the default object encoding of the AMF connection.

Parameters:
value - The value to set the default object encoding to.

isInstantiateTypes

public boolean isInstantiateTypes()
Returns instantiateTypes property. InstantiateTypes property determines whether type information will be used to instantiate a new instance. If set to false, types will be deserialized as flex.messaging.io.ASObject instances with type information retained but not used to create an instance. Note that types in the flex.* package (and any subpackage) will always be instantiated. The default is true.

Returns:
The instantitateTypes property.

setInstantiateTypes

public void setInstantiateTypes(boolean instantiateTypes)
Sets the instantiateTypes property.

Parameters:
instantiateTypes - The value to set the instantiateTypes property to.

getObjectEncoding

public int getObjectEncoding()
The object encoding for this AMF connection sets which AMF version to use during serialization. If set, this version overrides the defaultObjectEncoding.

Returns:
The object encoding for the AMF connection.

setObjectEncoding

public void setObjectEncoding(int objectEncoding)
Sets the object encoding for the AMF connection.

Parameters:
objectEncoding - The value to set the object encoding to.

getUrl

public String getUrl()
Returns the HTTP or HTTPS url for the AMF connection.

Returns:
The HTTP or HTTPs url for the AMF connection.

addAmfHeader

public void addAmfHeader(String name,
                         boolean mustUnderstand,
                         Object data)
Adds an AMF packet-level header which is sent with every request for the life of this AMF connection.

Parameters:
name - The name of the header.
mustUnderstand - Whether the header must be processed or not.
data - The value of the header.

addAmfHeader

public void addAmfHeader(String name,
                         Object data)
Add an AMF packet-level header with mustUnderstand=false, which is sent with every request for the life of this AMF connection.

Parameters:
name - The name of the header.
data - The value of the header.

removeAmfHeader

public boolean removeAmfHeader(String name)
Removes any AMF headers found with the name given.

Parameters:
name - The name of the header(s) to remove.
Returns:
true if a header existed with the given name.

removeAllAmfHeaders

public void removeAllAmfHeaders()
Removes all AMF headers.


addHttpRequestHeader

public void addHttpRequestHeader(String name,
                                 String value)
Adds a Http request header to the underlying connection.

Parameters:
name - The name of the Http header.
value - The value of the Http header.

removeHttpRequestHeader

public boolean removeHttpRequestHeader(String name)
Removes the Http header found with the name given.

Parameters:
name - The name of the Http header.
Returns:
true if a header existed with the given name.

removeAllHttpRequestHeaders

public void removeAllHttpRequestHeaders()
Removes all Http request headers.


call

public Object call(String command,
                   Object[] arguments)
            throws ClientStatusException,
                   ServerStatusException
Makes an AMF request to the server. A connection must have been made prior to making a call.

Parameters:
command - The method to call on the server.
arguments - Arguments for the method.
Returns:
The result of the call.
Throws:
ClientStatusException - If there is a client side exception.
ServerStatusException - If there is a server side exception.

close

public void close()
Closes the underlying URL connection, sets the url to null, and clears the cookies.


connect

public void connect(String url)
             throws ClientStatusException
Connects to the URL provided. Any previous connections are closed.

Parameters:
url - The URL to connect to.
Throws:
ClientStatusException - If there is a client side exception.


Copyright © 2008 Adobe Systems Inc. All Rights Reserved.

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/blazeds/1/javadoc/flex/messaging/io/amf/client/AMFConnection.html