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
@Transactional
@Secured("ROLE_ADMIN")
public void createOrUpdate(User user) throws Exception
{
if (user.getCompany()== null) {
user.setCompany(companyDAO.get(1));
}
userDAO.createOrUpdate(user);
String password = user.getPassword();
Object salt = saltSource.getSalt(user);
user.setPassword(passwordEncoder.encodePassword(password,salt));
userDAO.merge(user);
}
import com.twoh.dto.User
import com.twoh.dto.Company
def u = new User()
def c = new Company()
// Set up the User.Company only the id is required
// when adding a user
c.id = 1
// Set up the new User mandatory fields
u.id = 0
u.username = "soapui"
u.password = "soapui"
u.company = c
// Update the parameters value
parameters['user'] = u
@Transactional(readOnly=true)
@Secured("ROLE_USER")
public User getByUsername(String username) {
return userDAO.findByUsername(username);
}
<flex.messaging.io.amf.ASObject serialization="custom">
<unserializable-parents/>
<map>
<default>
<loadFactor>0.75</loadFactor>
<threshold>12</threshold>
</default>
<int>16</int>
<int>9</int>
<string>id</string>
<int>122</int>
<string>username</string>
<string>soapui</string>
<string>forename</string>
<null/>
<string>email</string>
<null/>
<string>initials</string>
<null/>
<string>status</string>
<null/>
<string>company</string>
<flex.messaging.io.amf.ASObject serialization="custom">
<unserializable-parents/>
<map>
<default>
<loadFactor>0.75</loadFactor>
<threshold>12</threshold>
</default>
<int>16</int>
<int>2</int>
<string>id</string>
<int>1</int>
<string>name</string>
<string>2HXX</string>
</map>
<flex.messaging.io.amf.ASObject>
<default>
<inHashCode>false</inHashCode>
<inToString>false</inToString>
<namedType>com.twoh.dto.Company</namedType>
</default>
</flex.messaging.io.amf.ASObject>
</flex.messaging.io.amf.ASObject>
<string>surname</string>
<null/>
<string>password</string>
<string>be17beaf5bc5a796ab871a76ea78f02b51e4ab17</string>
</map>
<flex.messaging.io.amf.ASObject>
<default>
<inHashCode>false</inHashCode>
<inToString>false</inToString>
<namedType>com.twoh.dto.User</namedType>
</default>
</flex.messaging.io.amf.ASObject>
</flex.messaging.io.amf.ASObject>
@Transactional
@Secured("ROLE_USER")
public void deleteUser(User user) {
userDAO.delete(user);
}
import flex.messaging.io.amf.client.AMFConnection;
import com.twoh.dto.User;
AMFConnection.registerAlias("com.twoh.dto.User","com.twoh.dto.User");
<flex.messaging.io.amf.ASObject serialization="custom">
<unserializable-parents/>
<map>
<default>
<loadFactor>0.75</loadFactor>
<threshold>12</threshold>
</default>
<int>16</int>
<int>4</int>
<string>message</string>
<string>Cannot invoke method 'deleteUser'.</string>
<string>rootCause</string>
<flex.messaging.messages.ErrorMessage>
<messageId>B7B0248A-11F5-9CB9-B36F-95F0F6251F32</messageId>
<timestamp>1294863786289</timestamp>
<timeToLive>0</timeToLive>
<faultCode>Client.Message.Deserialize.InvalidType</faultCode>
<faultString>Cannot convert type java.lang.String with value '' to an instance of class com.twoh.dto.User</faultString>
</flex.messaging.messages.ErrorMessage>
<string>details</string>
<string>The expected argument types are (com.twoh.dto.User) but the supplied types were (java.lang.String) and converted to (null).</string>
<string>code</string>
<string>Server.ResourceUnavailable</string>
</map>
<flex.messaging.io.amf.ASObject>
<default>
<inHashCode>false</inHashCode>
<inToString>false</inToString>
</default>
</flex.messaging.io.amf.ASObject>
</flex.messaging.io.amf.ASObject>
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();
}