use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class OutputGeneratedDescriptors method writeEjbJar.
private void writeEjbJar(final EjbModule ejbModule) {
try {
final EjbJar ejbJar = ejbModule.getEjbJar();
final File tempFile = tempFile("ejb-jar-", ejbModule.getModuleId() + ".xml");
final OutputStream out = IO.write(tempFile);
try {
EjbJarXml.marshal(ejbJar, out);
logger.info("Dumping Generated ejb-jar.xml to: " + tempFile.getAbsolutePath());
} catch (final JAXBException e) {
// no-op
} finally {
IO.close(out);
}
} catch (final Exception e) {
// no-op
}
}
use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class RemoveWebServices method deploy.
public AppModule deploy(final AppModule appModule) throws OpenEJBException {
for (final EjbModule ejbModule : appModule.getEjbModules()) {
final EjbJar ejbJar = ejbModule.getEjbJar();
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final Map<String, EjbDeployment> deployments = openejbJar.getDeploymentsByEjbName();
for (final EnterpriseBean bean : ejbJar.getEnterpriseBeans()) {
final String ejbName = bean.getEjbName();
final EjbDeployment ejbDeployment = deployments.get(ejbName);
// Clear any <service-ref> references from ejbs
bean.getServiceRef().clear();
if (!(bean instanceof SessionBean)) {
continue;
}
final SessionBean sessionBean = (SessionBean) bean;
if (sessionBean.getServiceEndpoint() == null) {
continue;
}
sessionBean.setServiceEndpoint(null);
// if not, then we should just delete it
if (sessionBean.getHome() != null) {
continue;
}
if (sessionBean.getLocalHome() != null) {
continue;
}
if (sessionBean.getBusinessLocal().size() > 0) {
continue;
}
if (sessionBean.getBusinessRemote().size() > 0) {
continue;
}
// Ok, delete away...
ejbJar.removeEnterpriseBean(ejbName);
openejbJar.removeEjbDeployment(ejbDeployment);
// As well, let's get rid of any transaction or security attributes
// associated with the bean we just deleted.
final AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
if (assemblyDescriptor != null) {
for (final MethodPermission permission : copy(assemblyDescriptor.getMethodPermission())) {
for (final Method method : copy(permission.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
permission.getMethod().remove(method);
}
}
if (permission.getMethod().size() == 0) {
assemblyDescriptor.getMethodPermission().remove(permission);
}
}
for (final ContainerTransaction transaction : copy(assemblyDescriptor.getContainerTransaction())) {
for (final Method method : copy(transaction.getMethod())) {
if (method.getEjbName().equals(ejbName)) {
transaction.getMethod().remove(method);
}
}
if (transaction.getMethod().size() == 0) {
assemblyDescriptor.getContainerTransaction().remove(transaction);
}
}
for (final InterceptorBinding binding : copy(assemblyDescriptor.getInterceptorBinding())) {
if (binding.getEjbName().equals(ejbName)) {
assemblyDescriptor.getInterceptorBinding().remove(binding);
}
}
}
}
// Clear any <service-ref> references from interceptors
for (final Interceptor interceptor : ejbJar.getInterceptors()) {
interceptor.getServiceRef().clear();
}
}
return appModule;
}
use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class BusinessInterfacesTest method setUp.
@Override
protected void setUp() throws Exception {
final Assembler assembler = new Assembler();
config = new ConfigurationFactory();
ejbModule = new EjbModule(new EjbJar());
ejbModule.setOpenejbJar(new OpenejbJar());
ejbJar = ejbModule.getEjbJar();
strict(false);
}
use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class ConfigurationFactoryTest method testConfigureApplicationEjbJar.
@Test
public void testConfigureApplicationEjbJar() throws OpenEJBException {
// Just to find out whether the validationDisabled message shows up
SystemInstance.get().setProperty(ConfigurationFactory.VALIDATION_SKIP_PROPERTY, "true");
final boolean offline = true;
final ConfigurationFactory factory = new ConfigurationFactory(offline);
final String id = "testConfigureApplicationEjbJar";
final EjbJar ejbJar = new EjbJar(id);
// no real classes engaged so disable metadata (annotation) processing
ejbJar.setMetadataComplete(true);
final EjbJarInfo info = factory.configureApplication(ejbJar);
// not much to assert
assertEquals(id, info.moduleName);
}
use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class AutoConfigResourceRefsTest method testCaseInsensitive.
public void testCaseInsensitive() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("DeFAultDataSource", "DataSource", null), ResourceInfo.class));
assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("YeLLowDataSource", "DataSource", null), ResourceInfo.class));
assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("PurpLEDataSource", "DataSource", null), ResourceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
final Map<String, ResourceReferenceInfo> refs = new HashMap<>();
for (final ResourceReferenceInfo ref : beanInfo.jndiEnc.resourceRefs) {
refs.put(ref.referenceName.replaceAll(".*/", ""), ref);
}
ResourceReferenceInfo info;
info = refs.get("yellowDataSource");
assertNotNull(info);
assertEquals("YeLLowDataSource", info.resourceID);
info = refs.get("orangeDataSource");
assertNotNull(info);
assertEquals("DeFAultDataSource", info.resourceID);
info = refs.get("purpleDataSource");
assertNotNull(info);
assertEquals("PurpLEDataSource", info.resourceID);
}
Aggregations