We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More
This site is now read-only. You can still browse and search as usual. Learn More
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();
}