Skip to content

Instantly share code, notes, and snippets.

@rzymek
Created August 22, 2013 15:10
Show Gist options
  • Save rzymek/6308462 to your computer and use it in GitHub Desktop.
Save rzymek/6308462 to your computer and use it in GitHub Desktop.
native JBoss 7 client to redeploy a war.
/*
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.2.0.Final</version>
</dependency>
*/
public class ReDep {
public String reboot() throws Exception {
ModelControllerClient client = createClient(InetAddress.getByName("localhost"), 9999, user, pass, "management");
ModelNode operation = new ModelNode();
operation.get("operation").set("redeploy");
operation.get("address").add("deployment","okolab.war");
return client.execute(operation).toString();
}
static ModelControllerClient createClient(final InetAddress host, final int port, final String username, final String password,
final String securityRealmName) {
final CallbackHandler callbackHandler = new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback current : callbacks) {
if (current instanceof NameCallback) {
NameCallback ncb = (NameCallback) current;
ncb.setName(username);
} else if (current instanceof PasswordCallback) {
PasswordCallback pcb = (PasswordCallback) current;
pcb.setPassword(password.toCharArray());
} else if (current instanceof RealmCallback) {
RealmCallback rcb = (RealmCallback) current;
rcb.setText(rcb.getDefaultText());
} else {
throw new UnsupportedCallbackException(current);
}
}
}
};
return ModelControllerClient.Factory.create(host, port, callbackHandler);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment