Skip to content

Instantly share code, notes, and snippets.

@ge0ffrey
Created July 19, 2011 06:47
Show Gist options
  • Save ge0ffrey/1091512 to your computer and use it in GitHub Desktop.
Save ge0ffrey/1091512 to your computer and use it in GitHub Desktop.
public class ConfigurationServiceImplementation
extends RemoteServiceServlet // The GWT servlet with a public final void doPost(...) method
implements ConfigurationService {
...
// We want to use the DI way here
@Inject private Repository repository;
public String save(IFramePerspectiveConfiguration configuration) {
serviceSecurity.checkSecurityIsAdmin(); // we'll probably want to do that with interceptors?
// RulesRepository repository = getRepository(); // the old way
...
... repository.createPerspectivesConfiguration(...); // NPE
... repository.loadPerspectivesConfiguration(...);
repository.save();
...
}
...
// the old way in Seam 2. compile errors in Seam 3/Weld
protected RulesRepository getRepository() {
if (Contexts.isApplicationContextActive()) {
return (RulesRepository) Component.getInstance("repository");
} else {
try {
return new RulesRepository(TestEnvironmentSessionHelper.getSession(false));
} catch (Exception e) {
throw new IllegalStateException("Unable to get repo to run tests", e);
}
}
}
// Failed new attempt to tmp mimic the old way (but the DI way is better)
protected RulesRepository getRepository2() {
BeanManager beanManager = (BeanManager) getServletContext()
.getAttribute("org.jboss.weld.environment.servlet.javax.enterprise.inject.spi.BeanManager");
return (RulesRepository) beanManager.getBeans("repository").iterator().next();
}
// Failed new attempt to tmp mimic the old way (but the DI way is better)
protected RulesRepository getRepository3() {
BeanManagerLocator beanManagerLocator = new BeanManagerLocator();
if (beanManagerLocator.isBeanManagerAvailable()) {
return (RulesRepository) BeanManagerUtils.getInstance("repository");
} else {
try {
return new RulesRepository(TestEnvironmentSessionHelper.getSession(false));
} catch (Exception e) {
throw new IllegalStateException("Unable to get repo to run tests", e);
}
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment