openamf/src/java/org/openamf AMFBody.java,1.17,1.18 AMFError.java,1.9,1.10 AMFHeader.java,1.7,1.8 AMFMessage.java,1.10,1.11 RemotingTester.java,1.6,1.7 ServiceRequest.java,1.8,1.9
[email protected] Sat, 16 Aug 2003 06:11:18 -0700
| Newsgroups | gmane.comp.java.openamf.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/openamf/openamf/src/java/org/openamf
In directory sc8-pr-cvs1:/tmp/cvs-serv26881/java/org/openamf
Modified Files:
AMFBody.java AMFError.java AMFHeader.java AMFMessage.java
RemotingTester.java ServiceRequest.java
Log Message:
Serializer/Deserializer cleanup
Index: AMFBody.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/AMFBody.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** AMFBody.java 15 Aug 2003 22:41:41 -0000 1.17
--- AMFBody.java 16 Aug 2003 13:11:16 -0000 1.18
***************
*** 8,11 ****
--- 8,13 ----
package org.openamf;
+ import java.io.Serializable;
+
/**
***************
*** 18,207 ****
* @version $Revision$, $Date$
*/
! public class AMFBody {
! protected String target;
! protected String serviceName;
! protected String serviceMethodName;
! protected String response;
! protected Object value;
! protected byte type;
! /**
* Unknow object type
*/
! public static final byte DATA_TYPE_UNKNOWN = -1;
/**
* Number object type
*/
! public static final byte DATA_TYPE_NUMBER = 0;
/**
* Boolean object type
*/
! public static final byte DATA_TYPE_BOOLEAN = 1;
/**
* String object type
*/
! public static final byte DATA_TYPE_STRING = 2;
/**
* Object object type
*/
! public static final byte DATA_TYPE_OBJECT = 3;
/**
! * NULL object type
*/
! public static final byte DATA_TYPE_NULL = 5;
/**
* NULL object type
*/
! public static final byte DATA_TYPE_NULL2 = 6;
/**
! * Flushed shared object type
*/
! public static final byte DATA_TYPE_FLUSHED_SHARED_OBJECT = 7;
/**
* Mixed Array Object type
*/
! public static final byte DATA_TYPE_MIXED_ARRAY = 8;
/**
* Array Object type
*/
! public static final byte DATA_TYPE_ARRAY = 10;
/**
* Date object type
*/
! public static final byte DATA_TYPE_DATE = 11;
/**
* Long String object type
*/
! public static final byte DATA_TYPE_STRING_LONG = 12;
/**
! *
*/
! public static final byte DATA_TYPE_AS_OBJECT = 13;
/**
* XML Document object type
*/
! public static final byte DATA_TYPE_XML = 15;
/**
* Custom class object type
*/
! public static final byte DATA_TYPE_CUSTOM_CLASS = 16;
!
! public AMFBody(String target, String response, Object value) {
! this(target, response, value, DATA_TYPE_UNKNOWN);
! }
!
! public AMFBody(String target, String response, Object value, byte type) {
! this.response = response;
! this.value = value;
! this.type = type;
! setTarget(target);
! }
! public String getTarget() {
! return target;
! }
! public void setTarget(String target) {
! this.target = target;
! int dotIndex = target.lastIndexOf('.');
! if (dotIndex > 0) {
! this.serviceName = target.substring(0, dotIndex);
! this.serviceMethodName = target.substring(dotIndex + 1);
! }
! }
! public String getServiceName() {
! return serviceName;
! }
! public String getServiceMethodName() {
! return serviceMethodName;
! }
! public String getResponse() {
! return response;
! }
! public void setResponse(String response) {
! this.response = response;
! }
! public Object getValue() {
! return value;
! }
! public void setValue(Object value) {
! this.value = value;
! }
! public byte getType() {
! return type;
! }
! public void setType(byte type) {
! this.type = type;
! }
! public String toString() {
! StringBuffer sb = new StringBuffer();
! sb.append("[AMFBody: {target=");
! sb.append(getTarget());
! sb.append(",serviceName=");
! sb.append(getServiceName());
! sb.append(",serviceMethodName=");
! sb.append(getServiceMethodName());
! sb.append(",response=");
! sb.append(getResponse());
! sb.append(",value=");
! sb.append(getValue());
! sb.append(",type=");
! switch (type) {
! case DATA_TYPE_UNKNOWN:
! sb.append("UNKNOWN");
! break;
! case DATA_TYPE_NUMBER:
! sb.append("NUMBER");
! break;
! case DATA_TYPE_BOOLEAN:
! sb.append("BOOLEAN");
! break;
! case DATA_TYPE_STRING:
! sb.append("STRING");
! break;
! case DATA_TYPE_STRING_LONG:
! sb.append("STRING_LONG");
! break;
! case DATA_TYPE_OBJECT:
! sb.append("OBJECT");
! break;
! case DATA_TYPE_NULL:
! sb.append("NULL");
! break;
! case DATA_TYPE_FLUSHED_SHARED_OBJECT:
! sb.append("FLUSHED_SHARED_OBJECT");
! break;
! case DATA_TYPE_MIXED_ARRAY:
! sb.append("MIXED_ARRAY");
! break;
! case DATA_TYPE_ARRAY:
! sb.append("ARRAY");
! break;
! case DATA_TYPE_DATE:
! sb.append("DATE");
! break;
! case DATA_TYPE_AS_OBJECT:
! sb.append("AS_OBJECT");
! break;
! case DATA_TYPE_XML:
! sb.append("XML");
! break;
! case DATA_TYPE_CUSTOM_CLASS:
! sb.append("CUSTOM_CLASS");
! break;
! default:
! sb.append(type);
! break;
! }
sb.append("}]");
! return sb.toString();
! }
}
--- 20,246 ----
* @version $Revision$, $Date$
*/
! public class AMFBody implements Serializable {
! protected String target;
! protected String serviceName;
! protected String serviceMethodName;
! protected String response;
! protected Object value;
! protected byte type;
! /**
* Unknow object type
*/
! public static final byte DATA_TYPE_UNKNOWN = -1;
/**
* Number object type
*/
! public static final byte DATA_TYPE_NUMBER = 0;
/**
* Boolean object type
*/
! public static final byte DATA_TYPE_BOOLEAN = 1;
/**
* String object type
*/
! public static final byte DATA_TYPE_STRING = 2;
/**
* Object object type
*/
! public static final byte DATA_TYPE_OBJECT = 3;
/**
! * Movie clip object type
*/
! public static final byte DATA_TYPE_MOVIE_CLIP = 4;
/**
* NULL object type
*/
! public static final byte DATA_TYPE_NULL = 5;
/**
! * Undefined object type
*/
! public static final byte DATA_TYPE_UNDEFINED = 6;
! /**
! * Reference object type
! */
! public static final byte DATA_TYPE_REFERENCE_OBJECT = 7;
/**
* Mixed Array Object type
*/
! public static final byte DATA_TYPE_MIXED_ARRAY = 8;
! /**
! * Object end type
! */
! public static final byte DATA_TYPE_OBJECT_END = 9;
/**
* Array Object type
*/
! public static final byte DATA_TYPE_ARRAY = 10;
/**
* Date object type
*/
! public static final byte DATA_TYPE_DATE = 11;
/**
* Long String object type
*/
! public static final byte DATA_TYPE_LONG_STRING = 12;
/**
! * General Object type
*/
! public static final byte DATA_TYPE_AS_OBJECT = 13;
! /**
! * RecordSet object type
! */
! public static final byte DATA_TYPE_RECORDSET = 14;
/**
* XML Document object type
*/
! public static final byte DATA_TYPE_XML = 15;
/**
* Custom class object type
*/
! public static final byte DATA_TYPE_CUSTOM_CLASS = 16;
! /**
! * AMF body with unknown type
! *
! * @param target
! * @param response
! * @param value
! */
! public AMFBody(String target, String response, Object value) {
! this(target, response, value, DATA_TYPE_UNKNOWN);
! }
! /**
! * AMF Body constructor
! *
! * @param target
! * @param response
! * @param value
! * @param type
! */
! public AMFBody(String target, String response, Object value, byte type) {
! this.response = response;
! this.value = value;
! this.type = type;
! setTarget(target);
! }
! public String getTarget() {
! return target;
! }
! public void setTarget(String target) {
! this.target = target;
! int dotIndex = target.lastIndexOf('.');
! if (dotIndex > 0) {
! this.serviceName = target.substring(0, dotIndex);
! this.serviceMethodName = target.substring(dotIndex + 1);
! }
! }
! public String getServiceName() {
! return serviceName;
! }
! public String getServiceMethodName() {
! return serviceMethodName;
! }
! public String getResponse() {
! return response;
! }
! public void setResponse(String response) {
! this.response = response;
! }
! public Object getValue() {
! return value;
! }
! public void setValue(Object value) {
! this.value = value;
! }
! /**
! * Returns object type
! *
! * @return
! */
! public byte getType() {
! return type;
! }
! /**
! * Sets object type
! *
! * @param type
! */
! public void setType(byte type) {
! this.type = type;
! }
! /**
! * Returns String description of object type
! *
! * @param type object type
! * @return
! */
! public static String getObjectTypeDescription(byte type) {
! switch (type) {
! case DATA_TYPE_UNKNOWN:
! return "UNKNOWN";
! case DATA_TYPE_NUMBER:
! return "NUMBER";
! case DATA_TYPE_BOOLEAN:
! return "BOOLEAN";
! case DATA_TYPE_STRING:
! return "STRING";
! case DATA_TYPE_OBJECT:
! return "OBJECT";
! case DATA_TYPE_MOVIE_CLIP:
! return "MOVIECLIP";
! case DATA_TYPE_NULL:
! return "NULL";
! case DATA_TYPE_UNDEFINED:
! return "UNDEFINED";
! case DATA_TYPE_REFERENCE_OBJECT:
! return "REFERENCE";
! case DATA_TYPE_MIXED_ARRAY:
! return "MIXED_ARRAY";
! case DATA_TYPE_OBJECT_END:
! return "OBJECT_END";
! case DATA_TYPE_ARRAY:
! return "ARRAY";
! case DATA_TYPE_DATE:
! return "DATE";
! case DATA_TYPE_LONG_STRING:
! return "LONG_STRING";
! case DATA_TYPE_AS_OBJECT:
! return "AS_OBJECT";
! case DATA_TYPE_RECORDSET:
! return "RECORDSET";
! case DATA_TYPE_XML:
! return "XML";
! case DATA_TYPE_CUSTOM_CLASS:
! return "CUSTOM_CLASS";
! default:
! return "UNKNOWN: 0x" + Integer.toBinaryString(type);
! }
! }
! public String toString() {
! StringBuffer sb = new StringBuffer();
! sb.append("[AMFBody: {target=");
! sb.append(getTarget());
! sb.append(", serviceName=");
! sb.append(getServiceName());
! sb.append(", serviceMethodName=");
! sb.append(getServiceMethodName());
! sb.append(", response=");
! sb.append(getResponse());
! sb.append(", type=");
! sb.append(getObjectTypeDescription(type));
! sb.append(", value=");
! sb.append(getValue());
sb.append("}]");
! return sb.toString();
! }
}
Index: AMFError.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/AMFError.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** AMFError.java 15 Aug 2003 22:09:19 -0000 1.9
--- AMFError.java 16 Aug 2003 13:11:16 -0000 1.10
***************
*** 8,73 ****
package org.openamf;
/**
* @author Jason Calabrese <[email protected]>
* @version $Revision$, $Date$
*/
! public class AMFError {
! private String code;
! private String type;
! private String level;
! private String details;
! private String description;
!
! public String getCode() {
! return code;
! }
!
! public void setCode(String code) {
! this.code = code;
! }
!
! public String getType() {
! return type;
! }
!
! public void setType(String type) {
! this.type = type;
! }
! public String getLevel() {
! return level;
! }
! public void setLevel(String level) {
! this.level = level;
! }
! public String getDetails() {
! return details;
! }
! public void setDetails(String details) {
! this.details = details;
! }
! public String getDescription() {
! return description;
! }
- public void setDescription(String description) {
- this.description = description;
- }
public String toString() {
StringBuffer sb = new StringBuffer();
! sb.append("[AMFError: {code=");
! sb.append(code);
! sb.append(", type=");
! sb.append(type);
! sb.append(", level=");
! sb.append(level);
! sb.append(", description=");
! sb.append(description);
! sb.append(", details=");
! sb.append(details);
sb.append("}]");
return sb.toString();
--- 8,60 ----
package org.openamf;
+ import java.io.Serializable;
+
/**
+ * AMF Error object
+ *
* @author Jason Calabrese <[email protected]>
* @version $Revision$, $Date$
*/
! public class AMFError extends ASObject implements Serializable {
! public static final String CODE = "code";
! public static final String LEVEL = "level";
! public static final String DESCRIPTION = "description";
! public static final String DETAILS = "details";
! public static final String TYPE = "type";
! public static final String LEVEL_ERROR = "error";
! public static final String LEVEL_STATUS = "status";
! public static final String LEVEL_WARNING = "warning";
! public static final String SERVER_PROCESSING = "SERVER.PROCESSING";
! public static final String SERVER_RESOURCE_NOTFOUND = "SERVER.RESOURCE_NOT_FOUND";
! public static final String SERVER_RESOURCE_UNAVAILABLE = "SERVER.RESOURCE_UNAVAILABLE";
! /**
! * Returns code
! * @return
! */
! public String getCode() {
! return (String) get(CODE);
! }
! public void setCode(String code) {
! put(CODE, code);
! }
! public void setLevel(String level) {
! put(LEVEL, level);
! }
! public void setDetails(String details) {
! put(DETAILS, details);
! }
! public void setDescription(String description) {
! put(DESCRIPTION, description);
! }
public String toString() {
StringBuffer sb = new StringBuffer();
! sb.append("[AMFError: {");
! sb.append(super.toString());
sb.append("}]");
return sb.toString();
Index: AMFHeader.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/AMFHeader.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** AMFHeader.java 15 Aug 2003 22:09:19 -0000 1.7
--- AMFHeader.java 16 Aug 2003 13:11:16 -0000 1.8
***************
*** 8,11 ****
--- 8,13 ----
package org.openamf;
+ import java.io.Serializable;
+
/**
* AMF Header
***************
*** 17,21 ****
* @version $Revision$, $Date$
*/
! public class AMFHeader {
protected String key;
protected boolean required;
--- 19,23 ----
* @version $Revision$, $Date$
*/
! public class AMFHeader implements Serializable {
protected String key;
protected boolean required;
Index: AMFMessage.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/AMFMessage.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** AMFMessage.java 15 Aug 2003 22:09:19 -0000 1.10
--- AMFMessage.java 16 Aug 2003 13:11:16 -0000 1.11
***************
*** 11,14 ****
--- 11,15 ----
import java.util.Iterator;
import java.util.List;
+ import java.io.Serializable;
/**
***************
*** 21,25 ****
* @version $Revision$, $Date$
*/
! public class AMFMessage {
private static final int CURRENT_VERSION = 0;
--- 22,26 ----
* @version $Revision$, $Date$
*/
! public class AMFMessage implements Serializable {
private static final int CURRENT_VERSION = 0;
***************
*** 105,109 ****
sb.append(amfBody);
}
- sb.append(bodies);
sb.append("}}]");
return sb.toString();
--- 106,109 ----
Index: RemotingTester.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/RemotingTester.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** RemotingTester.java 15 Aug 2003 22:09:19 -0000 1.6
--- RemotingTester.java 16 Aug 2003 13:11:16 -0000 1.7
***************
*** 14,17 ****
--- 14,18 ----
import java.io.IOException;
import java.util.List;
+ import java.util.HashMap;
import org.apache.commons.httpclient.HttpClient;
***************
*** 27,89 ****
public class RemotingTester {
! public static AMFMessage sendMessage(
! String gateway,
! String target,
! String response,
! List parameters)
! throws IOException, HttpException {
!
! AMFMessage requestMessage = new AMFMessage();
! AMFBody requestBody = new AMFBody(target, response, parameters);
! requestMessage.addBody(requestBody);
!
! ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
! DataOutputStream outputStream = new DataOutputStream(baOutputStream);
! AMFSerializer serializer = new AMFSerializer(outputStream);
! serializer.serializeMessage(requestMessage);
!
! PostMethod post = new PostMethod(gateway);
! post.setRequestBody(new ByteArrayInputStream(baOutputStream.toByteArray()));
! post.setRequestContentLength(baOutputStream.size());
! post.setRequestHeader("Content-type", "application/x-amf");
!
! HttpClient httpclient = new HttpClient();
! int result = httpclient.executeMethod(post);
!
! DataInputStream inputStream =
! new DataInputStream(new ByteArrayInputStream(post.getResponseBody()));
!
! AMFDeserializer deserializer = new AMFDeserializer(inputStream);
! AMFMessage resposeMessage = deserializer.getAMFMessage();
!
! // Release current connection to the connection pool once you are done
! post.releaseConnection();
!
! return resposeMessage;
! }
! public static void printMessage(AMFMessage resposeMessage) {
! int headerCount = resposeMessage.getHeaderCount();
! for (int i = 0; i < headerCount; i++) {
! AMFHeader header = resposeMessage.getHeader(i);
! System.out.println(header.getKey() + " = " + header.getValue());
! }
!
! int bodyCount = resposeMessage.getBodyCount();
! for (int i = 0; i < bodyCount; i++) {
! AMFBody body = resposeMessage.getBody(i);
! System.out.println("Body " + i);
! System.out.println("target = " + body.getTarget());
! System.out.println("response = " + body.getResponse());
! if (body.getValue() != null) {
! System.out.println(
! "value class = " + body.getValue().getClass());
! }
! System.out.println("value = " + body.getValue());
! }
! }
! public static void main(String[] args) {
}
}
--- 28,98 ----
public class RemotingTester {
! public static AMFMessage sendMessage(
! String gateway,
! String target,
! String response,
! List parameters)
! throws IOException, HttpException {
! AMFMessage requestMessage = new AMFMessage();
! AMFBody requestBody = new AMFBody(target, response, parameters);
! requestMessage.addBody(requestBody);
! return sendMessage(gateway, requestMessage);
}
+ public static AMFMessage sendMessage(String gateway, AMFMessage requestMessage)
+ throws IOException, HttpException {
+
+ ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
+ DataOutputStream outputStream = new DataOutputStream(baOutputStream);
+ AMFSerializer serializer = new AMFSerializer(outputStream);
+ serializer.serializeMessage(requestMessage);
+
+ PostMethod post = new PostMethod(gateway);
+ post.setRequestBody(new ByteArrayInputStream(baOutputStream.toByteArray()));
+ post.setRequestContentLength(baOutputStream.size());
+ post.setRequestHeader("Content-type", "application/x-amf");
+
+ HttpClient httpclient = new HttpClient();
+ int result = httpclient.executeMethod(post);
+
+ DataInputStream inputStream =
+ new DataInputStream(new ByteArrayInputStream(post.getResponseBody()));
+
+ AMFDeserializer deserializer = new AMFDeserializer(inputStream);
+ AMFMessage resposeMessage = deserializer.getAMFMessage();
+
+ // Release current connection to the connection pool once you are done
+ post.releaseConnection();
+
+ return resposeMessage;
+ }
+ public static void main(String[] args) throws IOException {
+ AMFMessage msg1 = createMessage1();
+ System.out.println("msg1 = " + msg1);
+ AMFMessage msg2 = sendMessage("http://localhost:8080/openamf/gateway", msg1);
+ System.out.println("msg2 = " + msg2);
+ }
+ private static AMFMessage createMessage1() {
+ /**
+ * msg1 = [AMFMessage: {version=0, headers={[AMFHeader: {key=amf_server_debug, required=true,
+ * value={amfheaders=false, httpheaders=false, coldfusion=true, m_debug=true, recordset=true, trace=true,
+ * amf=false, error=true}}]}, bodies={[AMFBody: {target=org.openamf.test.Test3.getNumber,
+ * serviceName=org.openamf.test.Test3,serviceMethodName=getNumber,response=/1,value=3.14,type=NUMBER}]}}]
+ */
+ AMFMessage message = new AMFMessage();
+ HashMap keys1 = new HashMap();
+ keys1.put("amf", Boolean.FALSE);
+ keys1.put("error", Boolean.TRUE);
+ keys1.put("trace", Boolean.TRUE);
+ keys1.put("coldfusion", Boolean.TRUE);
+ keys1.put("m_debug", Boolean.TRUE);
+ keys1.put("httpheaders", Boolean.FALSE);
+ keys1.put("amfheaders", Boolean.FALSE);
+ keys1.put("recordset", Boolean.TRUE);
+ message.addHeader("amf_server_debug", true, keys1);
+ message.addBody("org.openamf.test.Test3.getNumber","/1", new Double(3.14), AMFBody.DATA_TYPE_NUMBER);
+ return message;
+ }
}
Index: ServiceRequest.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/ServiceRequest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ServiceRequest.java 9 Aug 2003 16:59:22 -0000 1.8
--- ServiceRequest.java 16 Aug 2003 13:11:16 -0000 1.9
***************
*** 8,15 ****
package org.openamf;
- import java.util.List;
-
import org.openamf.config.ServiceConfig;
import org.openamf.config.ServiceMethodConfig;
/**
--- 8,15 ----
package org.openamf;
import org.openamf.config.ServiceConfig;
import org.openamf.config.ServiceMethodConfig;
+
+ import java.util.List;
/**
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01