Forum Discussion
hairyone
15 years agoNew Contributor
OK,
I never got a response to this and gave up for a while. Yesterday I HAD to get something working, in the end I did not use the AMF functionality at all. Following a very handy example on thenet http://aredko.blogspot.com/2010/06/testing-blazeds-remote-objects-with_06.html I came up with this as a Groovy test step and to be honest I found it much easier.
I'm posting this as I have used SoapUI in the past for web service testing and found it to be great. Using the approach below I can now do what I want with AMF services.
I never got a response to this and gave up for a while. Yesterday I HAD to get something working, in the end I did not use the AMF functionality at all. Following a very handy example on thenet http://aredko.blogspot.com/2010/06/testing-blazeds-remote-objects-with_06.html I came up with this as a Groovy test step and to be honest I found it much easier.
I'm posting this as I have used SoapUI in the past for web service testing and found it to be great. Using the approach below I can now do what I want with AMF services.
import flex.messaging.io.amf.ASObject;
import flex.messaging.io.amf.client.AMFConnection;
import flex.messaging.messages.CommandMessage;
import flex.messaging.util.Base64.Encoder;
import flex.messaging.messages.Message;
def clientId = "soapUI." + UUID.randomUUID().toString();
def amfConnection = new AMFConnection();
amfConnection.instantiateTypes = false;
try {
amfConnection.connect(context.expand('${#Project#ServiceEndpoint}'));
amfConnection.addAmfHeader( Message.FLEX_CLIENT_ID_HEADER, clientId );
// First we need to authenticate
CommandMessage commandMessage = new CommandMessage();
String credentials = context.expand( '${#Project#AMFUsername}' ) + ":" + context.expand( '${#Project#AMFPassword}' );
Encoder encoder = new Encoder( credentials.length() );
encoder.encode( credentials.getBytes() );
commandMessage.setHeader( Message.FLEX_CLIENT_ID_HEADER, clientId );
commandMessage.setOperation( CommandMessage.LOGIN_OPERATION );
commandMessage.setBody( encoder.drain() );
commandMessage.setDestination( "auth" );
amfConnection.call( null, commandMessage );
// Try to update an existing user
def user = amfConnection.call("userService.getByUsername", "freddy");
log.info(user);
def result = amfConnection.call("lockService.create", "USER", user["id"]);
log.info(result);
user["surname"] = "XXX";
result = amfConnection.call("userService.createOrUpdate", user);
log.info(result);
result = amfConnection.call("lockService.delete", "USER", user["id"]);
log.info(result);
// Try to create a new user
def company = amfConnection.call("companyService.get", 1);
log.info(company);
def newUser = new ASObject("com.twoh.dto.User");
newUser["id"] = null;
newUser["username"] = "soapui";
newUser["company"] = company;
log.info(newUser);
result = amfConnection.call("userService.createOrUpdate", newUser);
log.info(result);
// username, oldPassword, newPassword
result = amfConnection.call("userService.setPassword", "soapui", "", "soappass");
log.info(result);
// Must remember to log out
commandMessage = new CommandMessage();
commandMessage.setHeader( Message.FLEX_CLIENT_ID_HEADER, clientId );
commandMessage.setOperation( CommandMessage.LOGOUT_OPERATION );
commandMessage.setDestination( "auth" );
amfConnection.call( null, commandMessage );
} finally {
amfConnection.close();
}