Update of /cvsroot/openamf/openamf/src/java/org/openamf
In directory sc8-pr-cvs1:/tmp/cvs-serv15188/src/java/org/openamf
Added Files:
RemotingTester.java
Log Message:
added initial test client
--- NEW FILE: RemotingTester.java ---
package org.openamf;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.openamf.io.AMFDeserializer;
import org.openamf.io.AMFSerializer;
public class RemotingTester {
public static AMFMessage sendMessage(
String gateway,
String target,
String response,
ArrayList 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());
}
}
}
-------------------------------------------------------
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/psa00100006ave/direct;at.asp_061203_01/01
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.