@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final ApplicationClientMetaData appClientData = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_META_DATA);
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
final DeploymentClassIndex classIndex = deploymentUnit.getAttachment(Attachments.CLASS_INDEX);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
Boolean activate = deploymentUnit.getAttachment(AppClientAttachments.START_APP_CLIENT);
if (activate == null || !activate) {
return;
}
final Class<?> mainClass = deploymentUnit.getAttachment(AppClientAttachments.MAIN_CLASS);
if (mainClass == null) {
throw MESSAGES.cannotStartAppClient(deploymentUnit.getName());
}
final ApplicationClientComponentDescription component = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_COMPONENT);
ClassReflectionIndex<?> index = deploymentReflectionIndex.getClassIndex(mainClass);
Method method = index.getMethod(void.class, "main", String[].class);
if (method == null) {
throw MESSAGES.cannotStartAppClient(deploymentUnit.getName(), mainClass);
}
//setup the callback handler
final CallbackHandler callbackHandler;
if (appClientData != null && appClientData.getCallbackHandler() != null && !appClientData.getCallbackHandler().isEmpty()) {
try {
final Class<?> callbackClass = classIndex.classIndex(appClientData.getCallbackHandler()).getModuleClass();
callbackHandler = new RealmCallbackWrapper((CallbackHandler) callbackClass.newInstance());
} catch (ClassNotFoundException e) {
throw AppClientMessages.MESSAGES.couldNotLoadCallbackClass(appClientData.getCallbackHandler());
} catch (Exception e) {
throw AppClientMessages.MESSAGES.couldNotCreateCallbackHandler(appClientData.getCallbackHandler());
}
} else {
callbackHandler = new DefaultApplicationClientCallbackHandler();
}