repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
---|---|---|---|---|---|---|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/multiple/view/InjectingBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.multiple.view;
import jakarta.ejb.EJB;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@LocalBean
@Stateless
public class InjectingBean {
@EJB
private NoInterfaceAndWebServiceViewBean otherBean;
public boolean isBeanInjected() {
return this.otherBean != null;
}
public void invokeInjectedBean() {
this.otherBean.doNothing();
}
}
| 1,494 | 30.808511 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejb/Bean1.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejb;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless(name="bean")
public class Bean1 implements BeanInterface {
@Override
public String name() {
return "Bean1";
}
}
| 1,282 | 34.638889 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejb/BeanSuperInterface.java
|
package org.jboss.as.test.integration.ejb.injection.ejb;
/**
* @author Stuart Douglas
*/
public interface BeanSuperInterface {
String name();
}
| 151 | 15.888889 | 56 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejb/InjectingBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejb;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author Stuart Douglas
*/
@Stateless
@EJB(name = "jndiEjb",beanName = "../b1.jar#bean", beanInterface = BeanInterface.class)
public class InjectingBean {
@EJB(beanName = "../b1.jar#bean")
public BeanInterface bean1;
@EJB(beanName = "../b2.jar#bean")
public BeanInterface bean2;
public String getBean1Name() {
return bean1.name();
}
public String getBean2Name() {
return bean2.name();
}
public String getJndiEjbName() throws NamingException {
return ((BeanInterface)new InitialContext().lookup("java:comp/env/jndiEjb")).name();
}
}
| 1,811 | 31.945455 | 92 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejb/Bean2.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejb;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless(name = "bean")
public class Bean2 implements BeanInterface {
@Override
public String name() {
return "Bean2";
}
}
| 1,284 | 34.694444 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejb/BeanInterface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejb;
import jakarta.ejb.Local;
/**
* @author Stuart Douglas
*/
@Local
public interface BeanInterface {
String name();
}
| 1,198 | 33.257143 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejb/EjbInjectionSameEjbNameTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejb;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Tests that @Ejb injection works when two beans have the same name in different modules.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class EjbInjectionSameEjbNameTestCase {
@Deployment
public static Archive<?> deploy() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class,"testinject.ear");
final JavaArchive lib = ShrinkWrap.create(JavaArchive.class,"lib.jar");
lib.addClass(BeanInterface.class);
ear.addAsLibraries(lib);
final JavaArchive b1 = ShrinkWrap.create(JavaArchive.class,"b1.jar");
b1.addClass(Bean1.class);
ear.addAsModule(b1);
final JavaArchive b2 = ShrinkWrap.create(JavaArchive.class,"b2.jar");
b2.addClass(Bean2.class);
ear.addAsModule(b2);
final WebArchive main = ShrinkWrap.create(WebArchive.class, "main.war");
main.addClasses(EjbInjectionSameEjbNameTestCase.class, InjectingBean.class);
ear.addAsModule(main);
return ear;
}
@Test
public void testCorrectEjbInjected() throws NamingException {
InitialContext ctx = new InitialContext();
InjectingBean bean = (InjectingBean)ctx.lookup("java:module/" + InjectingBean.class.getSimpleName());
Assert.assertEquals("Bean1", bean.getBean1Name());
Assert.assertEquals("Bean2", bean.getBean2Name());
}
@Test
public void testEjbAnnotationOnClass() throws NamingException {
InitialContext ctx = new InitialContext();
InjectingBean bean = (InjectingBean)ctx.lookup("java:module/" + InjectingBean.class.getSimpleName());
Assert.assertEquals("Bean1", bean.getJndiEjbName());
}
}
| 3,270 | 37.940476 | 109 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbs/Bean1.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbs;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless(name="bean")
public class Bean1 implements BeanInterface {
@Override
public String name() {
return "Bean1";
}
}
| 1,283 | 34.666667 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbs/InjectingBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbs;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBs;
import jakarta.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author Stuart Douglas
*/
@Stateless
@EJBs({@EJB(name = "bean1", beanName = "../b1.jar#bean", beanInterface = BeanInterface.class), @EJB(name = "bean2", beanName = "../b2.jar#bean", beanInterface = BeanInterface.class)})
public class InjectingBean {
public String getBean1Name() {
try {
return ((BeanInterface) new InitialContext().lookup("java:comp/env/bean1")).name();
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
public String getBean2Name() {
try {
return ((BeanInterface) new InitialContext().lookup("java:comp/env/bean2")).name();
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
}
| 1,976 | 34.945455 | 183 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbs/EjbsInjectionTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbs;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that @EJBs() injection works as expected
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class EjbsInjectionTestCase {
@Deployment
public static Archive<?> deploy() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class,"testinject.ear");
final JavaArchive lib = ShrinkWrap.create(JavaArchive.class,"lib.jar");
lib.addClass(BeanInterface.class);
ear.addAsLibraries(lib);
final JavaArchive b1 = ShrinkWrap.create(JavaArchive.class,"b1.jar");
b1.addClass(Bean1.class);
ear.addAsModule(b1);
final JavaArchive b2 = ShrinkWrap.create(JavaArchive.class,"b2.jar");
b2.addClass(Bean2.class);
ear.addAsModule(b2);
final WebArchive main = ShrinkWrap.create(WebArchive.class, "main.war");
main.addClasses(EjbsInjectionTestCase.class, InjectingBean.class);
ear.addAsModule(main);
return ear;
}
@Test
public void testCorrectEjbInjected() throws NamingException {
InitialContext ctx = new InitialContext();
InjectingBean bean = (InjectingBean)ctx.lookup("java:module/" + InjectingBean.class.getSimpleName());
Assert.assertEquals("Bean1", bean.getBean1Name());
Assert.assertEquals("Bean2", bean.getBean2Name());
}
}
| 2,904 | 36.24359 | 109 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbs/Bean2.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbs;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless(name = "bean")
public class Bean2 implements BeanInterface {
@Override
public String name() {
return "Bean2";
}
}
| 1,285 | 34.722222 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbs/BeanInterface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbs;
import jakarta.ejb.Local;
/**
* @author Stuart Douglas
*/
@Local
public interface BeanInterface {
String name();
}
| 1,199 | 33.285714 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/compenvbindings/Bean1.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.compenvbindings;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless(name="bean")
public class Bean1 {
public String name() {
return "Bean1";
}
}
| 1,255 | 34.885714 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/compenvbindings/InjectingBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.compenvbindings;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author Stuart Douglas
*/
@Stateless
public class InjectingBean {
@EJB
public Bean1 bean1;
public Bean1 getBean() {
return bean1;
}
public Bean1 getBeanViaDirectLookup() throws NamingException {
return (Bean1)new InitialContext().lookup("java:comp/env/" + InjectingBean.class.getName() + "/bean1" );
}
}
| 1,569 | 33.130435 | 112 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/compenvbindings/EjbJavaCompBindingTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.compenvbindings;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Tests that EJB's resource injections in an ear correctly bind to the EJB's java:comp namespace
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class EjbJavaCompBindingTestCase {
@Deployment
public static Archive<?> deploy() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class,"testinject.ear");
final JavaArchive b1 = ShrinkWrap.create(JavaArchive.class,"b1.jar");
b1.addPackage(EjbJavaCompBindingTestCase.class.getPackage());
ear.addAsModule(b1);
return ear;
}
@Test
public void testCorrectEjbInjected() throws NamingException {
InitialContext ctx = new InitialContext();
InjectingBean bean = (InjectingBean)ctx.lookup("java:module/" + InjectingBean.class.getSimpleName());
Assert.assertNotNull(bean.getBean());
Assert.assertNotNull(bean.getBeanViaDirectLookup());
}
}
| 2,460 | 35.191176 | 109 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/duplicate/Bean1.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.duplicate;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless(name="bean")
public class Bean1 {
public String name() {
return "Bean1";
}
}
| 1,249 | 34.714286 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/duplicate/EjbDuplicateBindingTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.duplicate;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that the same EJB can be bound twice to the same java:global namespace with an env entry
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class EjbDuplicateBindingTestCase {
@Deployment
public static Archive<?> deploy() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class,"testglobal.ear");
final JavaArchive b1 = ShrinkWrap.create(JavaArchive.class,"b1.jar");
b1.addPackage(EjbDuplicateBindingTestCase.class.getPackage());
ear.addAsModule(b1);
return ear;
}
@Test
public void testCorrectEjbInjected() throws NamingException {
InitialContext ctx = new InitialContext();
InjectingBean bean = (InjectingBean)ctx.lookup("java:module/" + InjectingBean.class.getSimpleName());
Assert.assertNotNull(bean.getBean());
Assert.assertNotNull(bean.lookupGlobalBean());
InjectingBean2 bean2 = (InjectingBean2)ctx.lookup("java:module/" + InjectingBean2.class.getSimpleName());
Assert.assertNotNull(bean2.getBean());
Assert.assertNotNull(bean2.lookupGlobalBean());
}
}
| 2,667 | 36.577465 | 113 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/duplicate/InjectingBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.duplicate;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author Stuart Douglas
*/
@Stateless
public class InjectingBean {
@EJB(name = "java:global/a")
public Bean1 bean1;
public Bean1 getBean() {
return bean1;
}
public Bean1 lookupGlobalBean() throws NamingException {
return (Bean1)new InitialContext().lookup("java:global/a" );
}
}
| 1,537 | 32.434783 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/duplicate/InjectingBean2.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.duplicate;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author Stuart Douglas
*/
@Stateless
public class InjectingBean2 {
@EJB(name = "java:global/a")
public Bean1 bean1;
public Bean1 getBean() {
return bean1;
}
public Bean1 lookupGlobalBean() throws NamingException {
return (Bean1)new InitialContext().lookup("java:global/a" );
}
}
| 1,538 | 32.456522 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/LookupBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
import jakarta.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* @author Stuart Douglas
*/
@Stateless
public class LookupBean {
public HomeInterface doLookupRemote() {
try {
return (HomeInterface) new InitialContext().lookup("java:comp/env/ejb/remote");
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
public LocalHomeInterface doLookupLocal() {
try {
return (LocalHomeInterface) new InitialContext().lookup("java:comp/env/ejb/local");
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
}
| 1,759 | 33.509804 | 95 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/CtxInjectionTester.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
//@Remote
public interface CtxInjectionTester {
void checkInjection() throws FailedException;
@SuppressWarnings("serial")
class FailedException extends Exception {
}
}
| 1,352 | 35.567568 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/LocalInterface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
/**
* @author Stuart Douglas
*/
public interface LocalInterface {
String hello();
}
| 1,168 | 36.709677 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/HomeInterface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
import java.rmi.RemoteException;
import jakarta.ejb.EJBHome;
/**
* @author Stuart Douglas
*/
public interface HomeInterface extends EJBHome {
RemoteInterface create() throws RemoteException;
}
| 1,277 | 37.727273 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/EjbRefTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that lifecycle methods defined on classes in a different module to the component class
* are called.
*/
@RunWith(Arquillian.class)
public class EjbRefTestCase {
private static final String ARCHIVE_NAME = "ejbreftest.jar";
@ArquillianResource
private InitialContext iniCtx;
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME);
jar.addPackage(EjbRefTestCase.class.getPackage());
jar.addAsManifestResource(EjbRefTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
return jar;
}
@Test
public void testEjbRefLookup() throws Exception {
final LookupBean bean = (LookupBean) iniCtx.lookup("java:module/LookupBean");
HomeInterface home = bean.doLookupRemote();
RemoteInterface remote = home.create();
Assert.assertEquals("hello", remote.hello());
}
@Test
public void testEjbRefLocalLookup() throws Exception {
final LookupBean bean = (LookupBean) iniCtx.lookup("java:module/LookupBean");
LocalHomeInterface home = bean.doLookupLocal();
LocalInterface remote = home.create();
Assert.assertEquals("hello", remote.hello());
}
@Test
public void testInjection() throws Exception {
CtxInjectionTester session = (CtxInjectionTester) iniCtx.lookup("java:module/CtxInjectionTesterBean");
try {
session.checkInjection();
} catch (CtxInjectionTester.FailedException e) {
Assert.fail("SessionContext not injected");
}
}
}
| 3,113 | 34.793103 | 110 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/CtxInjectionTesterBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
import jakarta.ejb.SessionContext;
/**
* Checks whether injection via ejb-jar.xml of a SessionContext works.
*
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
//@Stateless
public class CtxInjectionTesterBean implements CtxInjectionTester {
// injected from ejb-jar.xml
private SessionContext ctx;
public void checkInjection() throws FailedException {
if (ctx == null) { throw new FailedException(); }
}
}
| 1,546 | 37.675 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/SimpleBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
/**
* @author Stuart Douglas
*/
public class SimpleBean {
public String hello() {
return "hello";
}
}
| 1,199 | 34.294118 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/LocalHomeInterface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
/**
* @author Stuart Douglas
*/
public interface LocalHomeInterface {
LocalInterface create();
}
| 1,180 | 38.366667 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/RemoteInterface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref;
import java.rmi.RemoteException;
import jakarta.ejb.EJBObject;
/**
* @author Stuart Douglas
*/
public interface RemoteInterface extends EJBObject {
String hello() throws RemoteException;
}
| 1,274 | 36.5 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/lookup/RemoteInterfaceBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref.lookup;
import jakarta.ejb.Stateless;
@Stateless
public class RemoteInterfaceBean implements RemoteInterface {
@Override
public String ping() {
return "1";
}
}
| 1,040 | 34.896552 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/lookup/SecondRestService.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref.lookup;
import jakarta.ejb.EJB;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
@Path("/second")
public class SecondRestService {
@EJB(lookup = "ejb:ejb-test-ear/ejb//RemoteInterfaceBean!org.jboss.as.test.integration.ejb.injection.ejbref.lookup.RemoteInterface")
RemoteInterface remoteBean;
@GET
@Path("/text")
@Produces
public String getResultXML() {
return String.valueOf(remoteBean.ping());
}
}
| 1,332 | 34.078947 | 136 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/lookup/SecondTestServlet.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref.lookup;
import java.io.IOException;
import jakarta.ejb.EJB;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = "/test2")
public class SecondTestServlet extends HttpServlet {
@EJB(lookup = "ejb:ejb-test-ear/ejb/RemoteInterfaceBean!org.jboss.as.test.integration.ejb.injection.ejbref.lookup.RemoteInterface")
RemoteInterface remoteBean;
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
write(response, String.valueOf(remoteBean.ping()));
}
private static void write(HttpServletResponse writer, String message) {
try {
writer.getWriter().write(message);
} catch (IOException e) {
e.printStackTrace();
}
}
}
| 1,737 | 37.622222 | 135 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/lookup/FirstTestServlet.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref.lookup;
import java.io.IOException;
import jakarta.ejb.EJB;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = "/test1")
public class FirstTestServlet extends HttpServlet {
@EJB(lookup = "java:comp/env/RemoteInterfaceBean")
RemoteInterface remoteBean;
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
write(response, String.valueOf(remoteBean.ping()));
}
private static void write(HttpServletResponse writer, String message) {
try {
writer.getWriter().write(message);
} catch (IOException e) {
e.printStackTrace();
}
}
}
| 1,655 | 35.8 | 84 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/lookup/RemoteInterface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref.lookup;
import jakarta.ejb.Remote;
@Remote
public interface RemoteInterface {
String ping();
}
| 960 | 34.592593 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/lookup/EjbRefLookupTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref.lookup;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Tomas Remes
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EjbRefLookupTestCase {
private static final String EAR_DEPLOYMENT = "ejb-test-ear";
private static final String WAR_DEPLOYMENT = "webapp-test";
@ArquillianResource
@OperateOnDeployment(WAR_DEPLOYMENT)
private URL warUrl;
@Deployment(order = 0, name = EAR_DEPLOYMENT)
public static Archive<?> deployEar() {
EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_DEPLOYMENT + ".ear");
JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb.jar").addClasses(RemoteInterface.class, RemoteInterfaceBean.class);
ear.addAsModule(ejbJar);
return ear;
}
@Deployment(order = 1, name = WAR_DEPLOYMENT)
public static Archive<?> deployWar() {
WebArchive war = ShrinkWrap.create(WebArchive.class);
war.addClasses(FirstRestService.class, FirstTestServlet.class, SecondRestService.class, SecondTestServlet.class);
war.addAsManifestResource(new StringAsset("Dependencies: deployment.ejb-test-ear.ear.ejb.jar\n"), "MANIFEST.MF");
war.addAsWebInfResource(EjbRefLookupTestCase.class.getPackage(), "web.xml", "web.xml");
war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}
private String doGetReq(String urlPattern) throws Exception {
return HttpRequest.get(warUrl + urlPattern, 4, TimeUnit.SECONDS);
}
@Test
public void testEjbRefInServlet() throws Exception {
Assert.assertEquals("1", doGetReq("test1"));
}
@Test
public void testJBossEjbRefInServlet() throws Exception {
Assert.assertEquals("1", doGetReq("test2"));
}
@Test
public void testEjbRefInRest() throws Exception {
Assert.assertEquals("1", doGetReq("rest/first/text"));
}
@Test
public void testJBossEjbRefInRest() throws Exception {
Assert.assertEquals("1", doGetReq("rest/second/text"));
}
}
| 3,687 | 37.821053 | 138 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/injection/ejbref/lookup/FirstRestService.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2016, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.injection.ejbref.lookup;
import jakarta.ejb.EJB;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
@Path("/first")
public class FirstRestService {
@EJB(lookup = "java:comp/env/RemoteInterfaceBean")
RemoteInterface remoteBean;
@GET
@Path("/text")
@Produces
public String getResultXML() {
return String.valueOf(remoteBean.ping());
}
}
| 1,248 | 31.868421 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mapbased/StatefulBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mapbased;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.ejb.EJBContext;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* @author Jan Martiska / [email protected]
*/
@Stateful
@Remote(StatefulIface.class)
@SecurityDomain("other")
@PermitAll
public class StatefulBean implements StatefulIface {
@Resource
private EJBContext ejbContext;
@Override
public String getCallerPrincipalName() {
return ejbContext.getCallerPrincipal().getName();
}
}
| 1,649 | 31.352941 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mapbased/StatefulIface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mapbased;
/**
* @author Jan Martiska / [email protected]
*/
public interface StatefulIface {
String getCallerPrincipalName();
}
| 1,198 | 35.333333 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mapbased/StatelessBean.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mapbased;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import jakarta.ejb.EJBContext;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.SecurityDomain;
/**
* @author Jan Martiska / [email protected]
*/
@Stateless
@Remote(StatelessIface.class)
@SecurityDomain("other")
@PermitAll
public class StatelessBean implements StatelessIface {
@Resource
private EJBContext ejbContext;
@Override
public String getCallerPrincipalName() {
return ejbContext.getCallerPrincipal().getName();
}
}
| 1,654 | 31.45098 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mapbased/StatelessIface.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mapbased;
/**
* @author Jan Martiska / [email protected]
*/
public interface StatelessIface {
String getCallerPrincipalName();
}
| 1,199 | 35.363636 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mapbased/MapBasedInitialContextEjbClientTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mapbased;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests for EJBCLIENT-34: properties-based JNDI InitialContext for EJB clients.
*
* @author Jan Martiska / [email protected]
*/
@RunWith(Arquillian.class)
@RunAsClient
public class MapBasedInitialContextEjbClientTestCase {
private static final String ARCHIVE_NAME = "map-based-client-1";
@Deployment
public static Archive<?> getDeployment() {
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME);
archive.addPackage(StatelessBean.class.getPackage());
return archive;
}
/**
* Tests that invocations on a scoped EJB client context use the correct receiver(s)
*
* @throws Exception
*/
@Test
public void testScopedEJBClientContexts() throws Exception {
InitialContext ctx = new InitialContext(getEjbClientProperties(System.getProperty("node0", "127.0.0.1"), 8080));
try {
String lookupName = "ejb:/" + ARCHIVE_NAME + "/" + StatelessBean.class.getSimpleName() + "!" + StatelessIface.class.getCanonicalName();
StatelessIface beanStateless = (StatelessIface) ctx.lookup(lookupName);
Assert.assertEquals("Unexpected EJB client context used for invoking stateless bean", CustomCallbackHandler.USER_NAME, beanStateless.getCallerPrincipalName());
lookupName = "ejb:/" + ARCHIVE_NAME + "/" + StatefulBean.class.getSimpleName() + "!" + StatefulIface.class.getCanonicalName() + "?stateful";
StatefulIface beanStateful = (StatefulIface) ctx.lookup(lookupName);
Assert.assertEquals("Unexpected EJB client context used for invoking stateful bean", CustomCallbackHandler.USER_NAME, beanStateful.getCallerPrincipalName());
ctx.close();
} finally {
ctx.close();
}
}
private Properties getEjbClientProperties(String node, int port) {
Properties props = new Properties();
props.put("org.jboss.ejb.client.scoped.context", true);
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
props.put("endpoint.name", "client");
props.put("remote.connections", "main");
props.put("remote.connection.main.host", node);
props.put("remote.connection.main.port", Integer.toString(port));
props.put("remote.connection.main.callback.handler.class", CustomCallbackHandler.class.getName());
props.put("remote.connection.main.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
props.put("remote.connection.main.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "true");
props.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
return props;
}
}
| 4,274 | 43.53125 | 171 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mapbased/CustomCallbackHandler.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mapbased;
import java.io.IOException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.sasl.RealmCallback;
/**
* A custom {@link CallbackHandler} which is used in {@link MapBasedInitialContextEjbClientTestCase} and sets the {@link NameCallback}
* to user name {@link #USER_NAME}
*
* @author Jaikiran Pai
*/
public class CustomCallbackHandler implements CallbackHandler {
static final String USER_NAME = "$local";
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (final Callback current : callbacks) {
if (current instanceof NameCallback) {
((NameCallback) current).setName(USER_NAME);
} else if (current instanceof RealmCallback) {
((RealmCallback) current).setText(((RealmCallback) current).getDefaultText());
}
}
}
}
| 2,139 | 39.377358 | 134 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/lifecycle/PooledEJBLifecycleTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.pool.lifecycle;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.PropertyPermission;
import jakarta.ejb.EJB;
import jakarta.jms.Connection;
import jakarta.jms.Destination;
import jakarta.jms.Message;
import jakarta.jms.MessageProducer;
import jakarta.jms.Queue;
import jakarta.jms.QueueConnection;
import jakarta.jms.QueueConnectionFactory;
import jakarta.jms.QueueReceiver;
import jakarta.jms.QueueSession;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.spec.se.manifest.ManifestDescriptor;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests instance lifecycle of EJB components which can potentially be pooled. Note that this testcase does *not* mandate that the components being tested be pooled. It's completely upto the container
* to decide if they want to pool these components by default or not.
*
* @author baranowb
* @author Jaikiran Pai - Updates related to https://issues.jboss.org/browse/WFLY-1506
*/
@RunWith(Arquillian.class)
@ServerSetup(PooledEJBLifecycleTestCase.CreateQueueForPooledEJBLifecycleTestCase.class)
public class PooledEJBLifecycleTestCase {
private static final String MDB_DEPLOYMENT_NAME = "mdb-pool-ejb-callbacks"; // module
private static final String SLSB_DEPLOYMENT_NAME = "slsb-pool-ejb-callbacks"; // module
private static final String DEPLOYMENT_NAME_SINGLETON = "pool-ejb-callbacks-singleton"; // module
private static final String SINGLETON_JAR = DEPLOYMENT_NAME_SINGLETON + ".jar"; // jar name
private static final String DEPLOYED_SINGLETON_MODULE = "deployment." + SINGLETON_JAR; // singleton deployed module name
private static final String SLSB_JNDI_NAME = "java:global/" + SLSB_DEPLOYMENT_NAME
+ "/PointLessMathBean!org.jboss.as.test.integration.ejb.pool.lifecycle.PointlesMathInterface";
private static final Logger log = Logger.getLogger(PooledEJBLifecycleTestCase.class.getName());
@ArquillianResource
public Deployer deployer;
@EJB(mappedName = "java:global/pool-ejb-callbacks-singleton/LifecycleTrackerBean!org.jboss.as.test.integration.ejb.pool.lifecycle.LifecycleTracker")
private LifecycleTracker lifecycleTracker;
// ----------------- DEPLOYMENTS ------------
// deploy Singleton bean. this will be deployed/managed by Arquillian outside of the test methods
@Deployment
public static JavaArchive createDeployment() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, SINGLETON_JAR);
// this includes test case class, since package name is the same.
archive.addClass(LifecycleTracker.class);
archive.addClass(LifecycleTrackerBean.class);
archive.addClass(TimeoutUtil.class);
archive.addClass(PointlesMathInterface.class);
archive.addClass(Constants.class);
archive.addAsManifestResource(createPermissionsXmlAsset(new PropertyPermission("ts.timeout.factor", "read")), "jboss-permissions.xml");
return archive;
}
// this will be deployed manually in the individual test methods
@Deployment(name = MDB_DEPLOYMENT_NAME, managed = false, testable = false)
public static JavaArchive getMDBTestArchive() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, MDB_DEPLOYMENT_NAME);
archive.addClass(LifecycleCounterMDB.class);
archive.addClass(LifecycleTracker.class);
archive.addClass(Constants.class);
archive.setManifest(new StringAsset(
Descriptors.create(ManifestDescriptor.class)
.attribute("Dependencies", DEPLOYED_SINGLETON_MODULE + ", org.apache.activemq.artemis.ra")
.exportAsString()));
return archive;
}
// this will be deployed manually in the individual test methods
@Deployment(name = SLSB_DEPLOYMENT_NAME, managed = false, testable = false)
public static JavaArchive getSLSBTestArchive() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, SLSB_DEPLOYMENT_NAME);
archive.addClass(PointLessMathBean.class);
archive.addClass(LifecycleTracker.class);
archive.setManifest(new StringAsset(
Descriptors.create(ManifestDescriptor.class)
.attribute("Dependencies", DEPLOYED_SINGLETON_MODULE + ", org.apache.activemq.artemis.ra")
.exportAsString()));
return archive;
}
@Before
public void beforeTest() {
log.trace("Clearing state of the singleton lifecycle tracker bean");
lifecycleTracker.clearState();
}
// ------------------- TEST METHODS ---------------------
@SuppressWarnings("static-access")
@Test
public void testMDB() throws Exception {
boolean requiresUndeploy = false;
try {
// do the deployment of the MDB
log.trace("About to deploy MDB archive " + MDB_DEPLOYMENT_NAME);
deployer.deploy(MDB_DEPLOYMENT_NAME);
// we keep track of this to make sure we undeploy before leaving this method
requiresUndeploy = true;
log.trace("deployed " + MDB_DEPLOYMENT_NAME);
// now send a messag to the queue on which the MDB is listening
log.trace("Sending a message to the queue on which the MDB " + " is listening");
triggerRequestResponseCycleOnQueue();
assertTrue("@PostConstruct wasn't invoked on MDB", lifecycleTracker.wasPostConstructInvokedOn(this.getClass().getPackage().getName() + ".LifecycleCounterMDB"));
// undeploy
log.trace("About to undeploy MDB archive " + MDB_DEPLOYMENT_NAME);
deployer.undeploy(MDB_DEPLOYMENT_NAME);
// we have undeployed successfully, there's no need anymore to trigger an undeployment before returning from this method
requiresUndeploy = false;
assertTrue("@PreDestroy wasn't invoked on MDB", lifecycleTracker.wasPreDestroyInvokedOn(this.getClass().getPackage().getName() + ".LifecycleCounterMDB"));
} finally {
if (requiresUndeploy) {
try {
deployer.undeploy(MDB_DEPLOYMENT_NAME);
} catch (Throwable t) {
// log and return since we don't want to corrupt any original exceptions that might have caused the test to fail
log.trace("Ignoring the undeployment failure of " + MDB_DEPLOYMENT_NAME, t);
}
}
}
}
@SuppressWarnings("static-access")
@Test
public void testSLSB() throws Exception {
boolean requiresUndeploy = false;
try {
// deploy the SLSB
log.trace("About to deploy SLSB archive " + SLSB_DEPLOYMENT_NAME);
deployer.deploy(SLSB_DEPLOYMENT_NAME);
requiresUndeploy = true;
log.trace("deployed " + SLSB_DEPLOYMENT_NAME);
// invoke on bean
final PointlesMathInterface mathBean = (PointlesMathInterface) new InitialContext().lookup(SLSB_JNDI_NAME);
mathBean.pointlesMathOperation(4, 5, 6);
assertTrue("@PostConstruct wasn't invoked on SLSB", lifecycleTracker.wasPostConstructInvokedOn(this.getClass().getPackage().getName() + ".PointLessMathBean"));
log.trace("About to undeploy SLSB archive " + SLSB_DEPLOYMENT_NAME);
deployer.undeploy(SLSB_DEPLOYMENT_NAME);
requiresUndeploy = false;
assertTrue("@PreDestroy wasn't invoked on SLSB", lifecycleTracker.wasPreDestroyInvokedOn(this.getClass().getPackage().getName() + ".PointLessMathBean"));
} finally {
if (requiresUndeploy) {
try {
deployer.undeploy(SLSB_DEPLOYMENT_NAME);
} catch (Throwable t) {
// log and return since we don't want to corrupt any original exceptions that might have caused the test to fail
log.trace("Ignoring the undeployment failure of " + SLSB_DEPLOYMENT_NAME, t);
}
}
}
}
// ------------------ HELPER METHODS -------------------
private void triggerRequestResponseCycleOnQueue() throws Exception {
final InitialContext ctx = new InitialContext();
final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
final QueueConnection connection = factory.createQueueConnection();
try {
connection.start();
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue replyDestination = session.createTemporaryQueue();
final String requestMessage = "test";
final Message message = session.createTextMessage(requestMessage);
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) ctx.lookup(Constants.QUEUE_JNDI_NAME);
final MessageProducer producer = session.createProducer(destination);
// create receiver
final QueueReceiver receiver = session.createReceiver(replyDestination);
producer.send(message);
producer.close();
//wait for reply
final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
assertNotNull("Did not receive a reply on the reply queue. Perhaps the original (request) message didn't make it to the MDB?", reply);
final String result = ((TextMessage) reply).getText();
assertEquals("Unexpected reply messsage", Constants.REPLY_MESSAGE_PREFIX + requestMessage, result);
} finally {
if (connection != null) {
// just closing the connection will close the session and other related resources (@see jakarta.jms.Connection)
safeClose(connection);
}
}
}
/**
* Responsible for creating and removing the queue required by this testcase
*/
static class CreateQueueForPooledEJBLifecycleTestCase implements ServerSetupTask {
private static final String QUEUE_NAME = "Queue-for-" + PooledEJBLifecycleTestCase.class.getName();
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
// create the JMS queue
final JMSOperations jmsOperations = JMSOperationsProvider.getInstance(managementClient);
jmsOperations.createJmsQueue(QUEUE_NAME, Constants.QUEUE_JNDI_NAME);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
// destroy the JMS queue
final JMSOperations jmsOperations = JMSOperationsProvider.getInstance(managementClient);
jmsOperations.removeJmsQueue(QUEUE_NAME);
}
}
private static void safeClose(final Connection connection) {
if (connection == null) {
return;
}
try {
connection.close();
} catch (Throwable t) {
// just log
log.trace("Ignoring a problem which occurred while closing: " + connection, t);
}
}
}
| 13,144 | 46.284173 | 200 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/lifecycle/Constants.java
|
package org.jboss.as.test.integration.ejb.pool.lifecycle;
/**
* @author: Jaikiran Pai
*/
interface Constants {
String QUEUE_JNDI_NAME = "queue/org.jboss.as.test.integration.ejb.pool.lifecycle.PooledEJBLifecycleTestCase-queue";
String REPLY_MESSAGE_PREFIX = "org.jboss.as.test.integration.ejb.pool.lifecycle.PooledEJBLifecycleTestCase-queue-reply-prefix";
}
| 369 | 32.636364 | 131 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/lifecycle/LifecycleTracker.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.lifecycle;
/**
* @author baranowb
*
*/
public interface LifecycleTracker {
void trackPostConstructOn(final String beanImplementationClassName);
void trackPreDestroyOn(final String beanImplementationClassName);
void clearState();
boolean wasPostConstructInvokedOn(final String beanImplClassName);
boolean wasPreDestroyInvokedOn(final String beanImplClassName);
}
| 1,437 | 38.944444 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/lifecycle/PointlesMathInterface.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.lifecycle;
/**
* @author baranowb
*
*/
public interface PointlesMathInterface {
double pointlesMathOperation(double a, double b, double c);
}
| 1,221 | 37.1875 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/lifecycle/LifecycleCounterMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.lifecycle;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.EJB;
import jakarta.ejb.MessageDriven;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.JMSContext;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import jakarta.jms.TextMessage;
import org.jboss.logging.Logger;
/**
* @author baranowb
* @author Jaikiran Pai - Updates related to https://issues.jboss.org/browse/WFLY-1506
*/
@MessageDriven(activationConfig = {@ActivationConfigProperty(propertyName = "destination", propertyValue = Constants.QUEUE_JNDI_NAME)})
public class LifecycleCounterMDB implements MessageListener {
private static final Logger log = Logger.getLogger(LifecycleCounterMDB.class.getName());
@Resource(lookup = "java:/JmsXA")
private ConnectionFactory factory;
@EJB(lookup = "java:global/pool-ejb-callbacks-singleton/LifecycleTrackerBean!org.jboss.as.test.integration.ejb.pool.lifecycle.LifecycleTracker")
private LifecycleTracker lifeCycleTracker;
@Override
public void onMessage(Message message) {
try {
log.trace(this + " received message " + message);
final Destination replyTo = message.getJMSReplyTo();
// ignore messages that need no reply
if (replyTo == null) {
log.trace(this + " noticed that no reply-to replyTo has been set. Just returning");
return;
}
try (
JMSContext context = factory.createContext()
) {
String reply = Constants.REPLY_MESSAGE_PREFIX + ((TextMessage) message).getText();
context.createProducer()
.setJMSCorrelationID(message.getJMSMessageID())
.send(replyTo, reply);
}
} catch (JMSException e) {
throw new RuntimeException(e);
}
}
@PreDestroy
protected void preDestroy() {
log.trace("@PreDestroy on " + this);
lifeCycleTracker.trackPreDestroyOn(this.getClass().getName());
}
@PostConstruct
protected void postConstruct() {
lifeCycleTracker.trackPostConstructOn(this.getClass().getName());
log.trace(this + " MDB @PostConstructed");
}
}
| 3,507 | 36.72043 | 148 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/lifecycle/PointLessMathBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.lifecycle;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import jakarta.jms.JMSException;
import javax.naming.NamingException;
import org.jboss.logging.Logger;
/**
* @author baranowb
*/
@Stateless
public class PointLessMathBean implements PointlesMathInterface {
private static final Logger log = Logger.getLogger(PointLessMathBean.class);
@EJB(lookup = "java:global/pool-ejb-callbacks-singleton/LifecycleTrackerBean!org.jboss.as.test.integration.ejb.pool.lifecycle.LifecycleTracker")
private LifecycleTracker lifeCycleTracker;
@Override
public double pointlesMathOperation(double a, double b, double c) {
return b * b - 4 * a * c;
}
@PostConstruct
private void postConstruct() throws JMSException, NamingException {
this.lifeCycleTracker.trackPostConstructOn(this.getClass().getName());
log.trace("@PostConstruct invoked on " + this);
}
@PreDestroy
private void preDestroy() {
lifeCycleTracker.trackPreDestroyOn(this.getClass().getName());
log.trace("@PreDestroy invoked on " + this);
}
}
| 2,250 | 35.306452 | 148 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/lifecycle/LifecycleTrackerBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.lifecycle;
import java.util.ArrayList;
import java.util.List;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
import jakarta.ejb.Startup;
import org.jboss.logging.Logger;
/**
* Lifecycle tracking singleton bean
*
* @author baranowb
* @author Jaikiran Pai - Updates related to https://issues.jboss.org/browse/WFLY-1506
*/
@Singleton
@Startup
@Remote(LifecycleTracker.class)
public class LifecycleTrackerBean implements LifecycleTracker {
private static final Logger logger = Logger.getLogger(LifecycleTrackerBean.class);
private List<String> postConstructedBeans;
private List<String> preDestroyedBeans;
@PostConstruct
private void initialize() {
postConstructedBeans = new ArrayList<>();
preDestroyedBeans = new ArrayList<>();
}
@Override
public void trackPostConstructOn(String beanImplementationClassName) {
if (beanImplementationClassName == null) {
return;
}
this.postConstructedBeans.add(beanImplementationClassName);
}
@Override
public void trackPreDestroyOn(String beanImplementationClassName) {
if (beanImplementationClassName == null) {
return;
}
this.preDestroyedBeans.add(beanImplementationClassName);
}
@Override
public void clearState() {
logger.trace("Clearing state on " + this);
this.postConstructedBeans.clear();
this.preDestroyedBeans.clear();
}
@Override
public boolean wasPostConstructInvokedOn(String beanImplClassName) {
return this.postConstructedBeans.contains(beanImplClassName);
}
@Override
public boolean wasPreDestroyInvokedOn(String beanImplClassName) {
return this.preDestroyedBeans.contains(beanImplClassName);
}
@PreDestroy
private void destroy() {
this.clearState();
}
}
| 3,015 | 29.77551 | 86 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/override/PoolAnnotatedAndSetInDDBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.override;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.Pool;
/**
* @author Jaikiran Pai
*/
@Stateless
@LocalBean
@Pool(value = "non-existent-pool-name-overriden-in-jboss-ejb3-xml")
public class PoolAnnotatedAndSetInDDBean extends AbstractSlowBean {
public static final String POOL_NAME = "C";
}
| 1,424 | 34.625 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/override/AbstractSlowBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.override;
import org.jboss.logging.Logger;
/**
* @author Jaikiran Pai
*/
public abstract class AbstractSlowBean {
private static final Logger logger = Logger.getLogger(AbstractSlowBean.class);
public void delay(final long delayInMilliSec) {
try {
logger.trace("Sleeping for " + delayInMilliSec + " milliseconds");
Thread.sleep(delayInMilliSec);
logger.trace("Woke up after " + delayInMilliSec + " milliseconds");
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
| 1,645 | 37.27907 | 82 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/override/PoolAnnotatedEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.override;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.Pool;
/**
* @author Jaikiran Pai
*/
@Stateless
@LocalBean
@Pool(value = PoolAnnotatedEJB.POOL_NAME)
public class PoolAnnotatedEJB extends AbstractSlowBean {
public static final String POOL_NAME = "A";
}
| 1,387 | 33.7 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/override/PoolSetInDDBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.override;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@LocalBean
public class PoolSetInDDBean extends AbstractSlowBean {
public static final String POOL_NAME_IN_DD = "B";
}
| 1,310 | 34.432432 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/override/PoolAnnotatedWithExpressionEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.override;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import org.jboss.ejb3.annotation.Pool;
/**
* @author Jaikiran Pai
*/
@Stateless
@LocalBean
@Pool(value = "${something:${poolprefix}123}pool")
public class PoolAnnotatedWithExpressionEJB extends AbstractSlowBean {
public static final String POOL_NAME = "awesome123pool";
}
| 1,423 | 34.6 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/pool/override/PoolOverrideTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.pool.override;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.EJBException;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.helpers.ClientConstants;
import org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests {@link org.jboss.ejb3.annotation.Pool} annotation usage and the <pool>
* element usage in jboss-ejb3.xml for EJBs.
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@ServerSetup({PoolOverrideTestCase.PoolOverrideTestCaseSetup.class,
PoolOverrideTestCase.AllowPropertyReplacementSetup.class})
public class PoolOverrideTestCase {
private static final Logger logger = Logger.getLogger(PoolOverrideTestCase.class);
static class PoolOverrideTestCaseSetup implements ServerSetupTask {
@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
EJBManagementUtil.createStrictMaxPool(managementClient.getControllerClient(), PoolAnnotatedEJB.POOL_NAME, 1, 10, TimeUnit.MILLISECONDS);
EJBManagementUtil.createStrictMaxPool(managementClient.getControllerClient(), PoolSetInDDBean.POOL_NAME_IN_DD, 1, 10, TimeUnit.MILLISECONDS);
EJBManagementUtil.createStrictMaxPool(managementClient.getControllerClient(), PoolAnnotatedAndSetInDDBean.POOL_NAME, 1, 10, TimeUnit.MILLISECONDS);
EJBManagementUtil.createStrictMaxPool(managementClient.getControllerClient(), PoolAnnotatedWithExpressionEJB.POOL_NAME, 1, 10, TimeUnit.MILLISECONDS);
}
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
EJBManagementUtil.removeStrictMaxPool(managementClient.getControllerClient(), PoolAnnotatedEJB.POOL_NAME);
EJBManagementUtil.removeStrictMaxPool(managementClient.getControllerClient(), PoolSetInDDBean.POOL_NAME_IN_DD);
EJBManagementUtil.removeStrictMaxPool(managementClient.getControllerClient(), PoolAnnotatedAndSetInDDBean.POOL_NAME);
EJBManagementUtil.removeStrictMaxPool(managementClient.getControllerClient(), PoolAnnotatedWithExpressionEJB.POOL_NAME);
}
}
static class AllowPropertyReplacementSetup implements ServerSetupTask {
@Override
public void setup(ManagementClient managementClient, String s) throws Exception {
final ModelNode enableSubstitutionOp = new ModelNode();
enableSubstitutionOp.get(ClientConstants.OP_ADDR).set(ClientConstants.SUBSYSTEM, "ee");
enableSubstitutionOp.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION);
enableSubstitutionOp.get(ClientConstants.NAME).set("annotation-property-replacement");
enableSubstitutionOp.get(ClientConstants.VALUE).set(true);
try {
applyUpdate(managementClient, enableSubstitutionOp);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void tearDown(ManagementClient managementClient, String s) throws Exception {
final ModelNode disableSubstitution = new ModelNode();
disableSubstitution.get(ClientConstants.OP_ADDR).set(ClientConstants.SUBSYSTEM, "ee");
disableSubstitution.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION);
disableSubstitution.get(ClientConstants.NAME).set("annotation-property-replacement");
disableSubstitution.get(ClientConstants.VALUE).set(false);
try {
applyUpdate(managementClient, disableSubstitution);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void applyUpdate(final ManagementClient managementClient, final ModelNode update)
throws Exception {
ModelNode result = managementClient.getControllerClient().execute(update);
if (result.hasDefined(ClientConstants.OUTCOME)
&& ClientConstants.SUCCESS.equals(result.get(ClientConstants.OUTCOME).asString())) {
} else if (result.hasDefined(ClientConstants.FAILURE_DESCRIPTION)) {
final String failureDesc = result.get(ClientConstants.FAILURE_DESCRIPTION).toString();
throw new RuntimeException(failureDesc);
} else {
throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
}
}
}
@Deployment
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ejb-pool-override-test.jar");
jar.addPackage(PoolAnnotatedEJB.class.getPackage());
jar.addAsManifestResource(PoolOverrideTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
jar.addAsManifestResource(PoolOverrideTestCase.class.getPackage(), "jboss.properties",
"jboss.properties");
jar.addAsResource(createPermissionsXmlAsset(new RuntimePermission("modifyThread")),
"META-INF/jboss-permissions.xml");
return jar;
}
/**
* Test that a stateless bean configured with the {@link org.jboss.ejb3.annotation.Pool} annotation
* is processed correctly and the correct pool is used by the bean
*
* @throws Exception
*/
@Test
public void testSLSBWithPoolAnnotation() throws Exception {
final PoolAnnotatedEJB bean = InitialContext.doLookup("java:module/" + PoolAnnotatedEJB.class.getSimpleName());
this.testSimulatenousInvocationOnEJBsWithSingleInstanceInPool(bean);
}
@Test
public void testSLSBWithPoolAnnotationWithExpression() throws Exception {
final PoolAnnotatedWithExpressionEJB bean = InitialContext.doLookup("java:module/" + PoolAnnotatedWithExpressionEJB.class.getSimpleName());
this.testSimulatenousInvocationOnEJBsWithSingleInstanceInPool(bean);
}
/**
* Test that a stateless bean configured with a pool reference in the jboss-ejb3.xml is processed correctly
* and the correct pool is used by the bean
*
* @throws Exception
*/
@Test
public void testSLSBWithPoolReferenceInDD() throws Exception {
final PoolSetInDDBean bean = InitialContext.doLookup("java:module/" + PoolSetInDDBean.class.getSimpleName());
this.testSimulatenousInvocationOnEJBsWithSingleInstanceInPool(bean);
}
/**
* Test that a stateless bean which has been annotated with a {@link org.jboss.ejb3.annotation.Pool} annotation
* and also has a jboss-ejb3.xml with a bean instance pool reference, is processed correctly and the deployment
* descriptor value overrides the annotation value. To make sure that the annotation value is overriden by the
* deployment descriptor value, the {@link PoolAnnotatedAndSetInDDBean} is annotated with {@link org.jboss.ejb3.annotation.Pool}
* whose value points to a non-existent pool name
*
* @throws Exception
*/
@Test
public void testPoolConfigInDDOverridesAnnotation() throws Exception {
final PoolAnnotatedAndSetInDDBean bean = InitialContext.doLookup("java:module/" + PoolAnnotatedAndSetInDDBean.class.getSimpleName());
this.testSimulatenousInvocationOnEJBsWithSingleInstanceInPool(bean);
}
/**
* Submits 2 {@link Callable}s to a {@link java.util.concurrent.Executor} to invoke on the {@link AbstractSlowBean bean}
* simulatenously. The bean is backed by a pool with <code>maxPoolSize</code> of 1 and the bean method "sleeps"
* for 1 second. So the second invocation waits for the first to complete. The pool for these beans is configured
* such that the instance acquisition timeout on the pool is (very) low compared to the time the bean method processing/sleep
* time. As a result, the second invocation is expected to fail. This method just validates that the correct pool is being used
* by the bean and not the default pool whose instance acquisition timeout is greater and these custom pools.
*
* @param bean The bean to invoke on
* @throws Exception
*/
private void testSimulatenousInvocationOnEJBsWithSingleInstanceInPool(final AbstractSlowBean bean) throws Exception {
final ExecutorService executorService = Executors.newFixedThreadPool(2);
Future<Void> firstBeanInvocationResult = null;
Future<Void> secondBeanInvocationResult = null;
try {
final PooledBeanInvoker firstBeanInvoker = new PooledBeanInvoker(bean, 1000);
firstBeanInvocationResult = executorService.submit(firstBeanInvoker);
final PooledBeanInvoker secondBeanInvoker = new PooledBeanInvoker(bean, 1000);
secondBeanInvocationResult = executorService.submit(secondBeanInvoker);
} finally {
executorService.shutdown();
}
boolean firstInvocationFailed = false;
boolean secondInvocationFailed = false;
try {
firstBeanInvocationResult.get(5, TimeUnit.SECONDS);
} catch (ExecutionException ee) {
if (ee.getCause() instanceof EJBException) {
logger.trace("Got EJBException for first invocation ", ee.getCause());
firstInvocationFailed = true;
} else {
throw ee;
}
}
try {
secondBeanInvocationResult.get(5, TimeUnit.SECONDS);
} catch (ExecutionException ee) {
if (ee.getCause() instanceof EJBException) {
logger.trace("Got EJBException for second invocation ", ee.getCause());
secondInvocationFailed = true;
} else {
throw ee;
}
}
// if both failed, then it's an error
if (firstInvocationFailed && secondInvocationFailed) {
Assert.fail("Both first and second invocations to EJB failed. Only one was expected to fail");
}
// if none failed, then it's an error too
if (!firstInvocationFailed && !secondInvocationFailed) {
Assert.fail("Both first and second invocations to EJB passed. Only one was expected to pass");
}
}
/**
* Invokes the {@link AbstractSlowBean#delay(long)} bean method
*/
private class PooledBeanInvoker implements Callable<Void> {
private AbstractSlowBean bean;
private long beanProcessingTime;
PooledBeanInvoker(final AbstractSlowBean bean, final long beanProcessingTime) {
this.bean = bean;
this.beanProcessingTime = beanProcessingTime;
}
@Override
public Void call() throws Exception {
this.bean.delay(this.beanProcessingTime);
return null;
}
}
}
| 12,802 | 47.680608 | 162 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/ReplyingMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb;
import jakarta.annotation.Resource;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.JMSContext;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import jakarta.jms.TextMessage;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/myAwesomeQueue")
})
public class ReplyingMDB implements MessageListener {
@Resource(lookup = "java:/JmsXA")
private ConnectionFactory factory;
@Override
public void onMessage(Message message) {
try {
final Destination replyTo = message.getJMSReplyTo();
// ignore messages that need no reply
if (replyTo == null)
return;
try (
JMSContext context = factory.createContext()
) {
context.createProducer()
.setJMSCorrelationID(message.getJMSMessageID())
.send(replyTo, "replying " + ((TextMessage) message).getText());
}
} catch (JMSException e) {
throw new RuntimeException(e);
}
}
}
| 2,413 | 36.71875 | 103 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/AnnoBasedMDB.java
|
package org.jboss.as.test.integration.ejb.mdb;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.EJB;
import jakarta.ejb.MessageDriven;
import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import org.jboss.ejb3.annotation.ResourceAdapter;
import org.jboss.logging.Logger;
@MessageDriven(name = "AnnoBasedBean", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "${destination}") })
@ResourceAdapter("${resource.adapter}")
public class AnnoBasedMDB implements MessageListener {
@EJB
private JMSMessagingUtil jmsMessagingUtil;
private static final Logger logger = Logger.getLogger(DDBasedMDB.class);
@Override
public void onMessage(Message message) {
logger.trace("Received message " + message + " in MDB " + this.getClass().getName());
try {
final Destination replyTo = message.getJMSReplyTo();
if (replyTo == null) {
return;
}
logger.trace("Sending a reply to destination " + replyTo);
jmsMessagingUtil.reply(message);
} catch (JMSException e) {
throw new RuntimeException(e);
} finally {
}
}
}
| 1,401 | 32.380952 | 105 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/BMTSLSB.java
|
package org.jboss.as.test.integration.ejb.mdb;
import jakarta.annotation.Resource;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionManagement;
import jakarta.ejb.TransactionManagementType;
import jakarta.transaction.UserTransaction;
import org.jboss.logging.Logger;
/**
* @author: Jaikiran Pai
*/
@Stateless
@TransactionManagement(value = TransactionManagementType.BEAN)
@LocalBean
public class BMTSLSB {
private static final Logger logger = Logger.getLogger(BMTSLSB.class);
@Resource
private UserTransaction userTransaction;
public void doSomethingWithUserTransaction() {
logger.trace("Beginning UserTransaction");
boolean utStarted = false;
try {
userTransaction.begin();
utStarted = true;
logger.trace("UserTransaction started");
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
if (utStarted) {
userTransaction.commit();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
| 1,185 | 24.782609 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/MDBTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.jms.Message;
import jakarta.jms.Queue;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.dmr.ModelNode;
import org.jboss.remoting3.security.RemotingPermission;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.io.FilePermission;
import java.io.IOException;
import java.util.PropertyPermission;
import org.jboss.as.controller.client.helpers.Operations;
/**
* Tests MDB deployments
*
* User: Jaikiran Pai
*/
@RunWith(Arquillian.class)
@ServerSetup({MDBTestCase.JmsQueueSetup.class})
public class MDBTestCase {
@EJB (mappedName = "java:module/JMSMessagingUtil")
private JMSMessagingUtil jmsUtil;
@Resource (mappedName = "java:jboss/mdbtest/queue")
private Queue queue;
@Resource (mappedName = "java:jboss/mdbtest/replyQueue")
private Queue replyQueue;
@Resource (mappedName = "java:jboss/mdbtest/annoQueue")
private Queue annoQueue;
@Resource (mappedName = "java:jboss/mdbtest/annoReplyQueue")
private Queue annoReplyQueue;
@ArquillianResource
private ManagementClient managementClient;
static class JmsQueueSetup implements ServerSetupTask {
private JMSOperations jmsAdminOperations;
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient.getControllerClient());
jmsAdminOperations.createJmsQueue("mdbtest/queue", "java:jboss/mdbtest/queue");
jmsAdminOperations.createJmsQueue("mdbtest/replyQueue", "java:jboss/mdbtest/replyQueue");
jmsAdminOperations.createJmsQueue("mdbtest/annoQueue", "java:jboss/mdbtest/annoQueue");
jmsAdminOperations.createJmsQueue("mdbtest/annoReplyQueue", "java:jboss/mdbtest/annoReplyQueue");
jmsAdminOperations.setSystemProperties("jboss/mdbtest/annoQueue", "activemq-ra.rar");
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
if (jmsAdminOperations != null) {
jmsAdminOperations.removeJmsQueue("mdbtest/queue");
jmsAdminOperations.removeJmsQueue("mdbtest/replyQueue");
jmsAdminOperations.removeJmsQueue("mdbtest/annoQueue");
jmsAdminOperations.removeJmsQueue("mdbtest/annoReplyQueue");
jmsAdminOperations.removeSystemProperties();
jmsAdminOperations.close();
}
}
}
@Deployment
public static Archive getDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "MDBTestCase.jar");
ejbJar.addClasses(DDBasedMDB.class, BMTSLSB.class, JMSMessagingUtil.class, AnnoBasedMDB.class, TimeoutUtil.class);
ejbJar.addPackage(JMSOperations.class.getPackage());
ejbJar.addClass(JmsQueueSetup.class);
ejbJar.addAsManifestResource(MDBTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
ejbJar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr, org.jboss.remoting\n"), "MANIFEST.MF");
ejbJar.addAsManifestResource(createPermissionsXmlAsset(
new RemotingPermission("createEndpoint"),
new RemotingPermission("connect"),
new FilePermission(System.getProperty("jboss.inst") + "/standalone/tmp/auth/*", "read"),
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")
), "permissions.xml");
return ejbJar;
}
/**
* Test a deployment descriptor based MDB
* @throws Exception
*/
@Test
public void testDDBasedMDB() throws Exception {
this.jmsUtil.sendTextMessage("Say hello to " + DDBasedMDB.class.getName(), this.queue, this.replyQueue);
final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
Assert.assertNotNull("Reply message was null on reply queue: " + this.replyQueue, reply);
}
/**
* Test an annotation based MDB with properties substitution
* @throws Exception
*/
@Test
public void testAnnoBasedMDB() throws Exception {
this.jmsUtil.sendTextMessage("Say Nihao to " + AnnoBasedMDB.class.getName(), this.annoQueue, this.annoReplyQueue);
final Message reply = this.jmsUtil.receiveMessage(annoReplyQueue, 5000);
Assert.assertNotNull("Reply message was null on reply queue: " + this.annoReplyQueue, reply);
}
/**
* Test a deployment descriptor based MDB
* @throws Exception
*/
@Test
public void testSuspendResumeWithMDB() throws Exception {
//Won't work with a remote broker
if(isRemote()) {
return;
}
boolean resumed = false;
ModelNode op = new ModelNode();
try {
//suspend the server
op.get(ModelDescriptionConstants.OP).set("suspend");
managementClient.getControllerClient().execute(op);
this.jmsUtil.sendTextMessage("Say hello to " + DDBasedMDB.class.getName(), this.queue, this.replyQueue);
Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
Assert.assertNull("Reply message was not null on reply queue: " + this.replyQueue, reply);
resumed = true;
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("resume");
managementClient.getControllerClient().execute(op);
reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
Assert.assertNotNull("Reply message was null on reply queue: " + this.replyQueue, reply);
} finally {
if(!resumed) {
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("resume");
managementClient.getControllerClient().execute(op);
}
}
}
private boolean isRemote() throws IOException {
ModelNode address = new ModelNode();
address.add("socket-binding-group", "standard-sockets");
address.add("remote-destination-outbound-socket-binding", "messaging-activemq");
ModelNode op = Operations.createReadResourceOperation(address, false);
ModelNode response = managementClient.getControllerClient().execute(op);
final String outcome = response.require("outcome").asString();
return "success".equalsIgnoreCase(outcome);
}
}
| 8,454 | 40.446078 | 154 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/JMSMessagingUtil.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb;
import org.jboss.as.test.shared.TimeoutUtil;
import java.io.Serializable;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import jakarta.ejb.Stateless;
import jakarta.jms.Connection;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.ObjectMessage;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
/**
* User: jpai
*/
@Stateless
public class JMSMessagingUtil {
private ConnectionFactory connectionFactory;
private Connection connection;
private Session session;
@PreDestroy
protected void preDestroy() throws JMSException {
session.close();
connection.close();
}
@PostConstruct
protected void postConstruct() throws JMSException {
connection = this.connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
@Resource(mappedName = "java:/ConnectionFactory")
public void setConnectionFactory(final ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
public void sendTextMessage(final String msg, final Destination destination, final Destination replyDestination) throws JMSException {
final TextMessage message = session.createTextMessage(msg);
this.sendMessage(message, destination, replyDestination);
}
public void sendObjectMessage(final Serializable msg, final Destination destination, final Destination replyDestination) throws JMSException {
final ObjectMessage message = session.createObjectMessage();
message.setObject(msg);
this.sendMessage(message, destination, replyDestination);
}
public void reply(final Message message) throws JMSException {
final Destination destination = message.getJMSReplyTo();
// ignore messages that need no reply
if (destination == null) {
return;
}
String text = (message instanceof TextMessage) ? ((TextMessage)message).getText() : message.toString();
final Message replyMsg = session.createTextMessage(text);
replyMsg.setJMSCorrelationID(message.getJMSMessageID());
this.sendMessage(replyMsg, destination, null);
}
public Message receiveMessage(final Destination destination, final int waitInMillis) throws JMSException {
MessageConsumer consumer = this.session.createConsumer(destination);
try {
return consumer.receive(TimeoutUtil.adjust(waitInMillis));
} finally {
consumer.close();
}
}
private void sendMessage(final Message message, final Destination destination, final Destination replyDestination) throws JMSException {
if (replyDestination != null) {
message.setJMSReplyTo(replyDestination);
}
final MessageProducer messageProducer = session.createProducer(destination);
messageProducer.send(message);
messageProducer.close();
}
}
| 4,279 | 36.217391 | 146 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/JMSMessageDrivenBeanTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageProducer;
import jakarta.jms.Queue;
import jakarta.jms.QueueConnection;
import jakarta.jms.QueueConnectionFactory;
import jakarta.jms.QueueReceiver;
import jakarta.jms.QueueSession;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.jms.auxiliary.CreateQueueSetupTask;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.PropertyPermission;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@RunWith(Arquillian.class)
@ServerSetup(CreateQueueSetupTask.class)
public class JMSMessageDrivenBeanTestCase {
@Deployment
public static Archive<?> deployment() {
final Archive<?> deployment = ShrinkWrap.create(JavaArchive.class, "JMSMessageDrivenBeanTestCase.jar")
.addClasses(ReplyingMDB.class,JMSMessagingUtil.class)
.addClass(CreateQueueSetupTask.class)
.addClass(TimeoutUtil.class)
.addAsResource(createPermissionsXmlAsset(new PropertyPermission("ts.timeout.factor", "read")), "META-INF/jboss-permissions.xml");
return deployment;
}
@Test
public void testSendMessage() throws JMSException, NamingException {
final InitialContext ctx = new InitialContext();
final QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
final QueueConnection connection = factory.createQueueConnection();
connection.start();
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue replyDestination = session.createTemporaryQueue();
final QueueReceiver receiver = session.createReceiver(replyDestination);
final Message message = session.createTextMessage("Test");
message.setJMSReplyTo(replyDestination);
final Destination destination = (Destination) ctx.lookup("queue/myAwesomeQueue");
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
final Message reply = receiver.receive(TimeoutUtil.adjust(5000));
assertNotNull(reply);
final String result = ((TextMessage) reply).getText();
assertEquals("replying Test", result);
} finally {
connection.close();
}
}
}
| 4,192 | 42.226804 | 145 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/DDBasedMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import javax.sql.DataSource;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
public class DDBasedMDB implements MessageListener {
@EJB
private JMSMessagingUtil jmsMessagingUtil;
@EJB
private BMTSLSB bmtslsb;
@Resource(lookup = "java:jboss/datasources/ExampleDS")
private DataSource dataSource;
private static final Logger logger = Logger.getLogger(DDBasedMDB.class);
static {
// @see https://issues.jboss.org/browse/WFLY-3989
// do an activity that depends on TCCL being the right one (== the application classloader)
final String className = DDBasedMDB.class.getName();
try {
loadClassThroughTCCL(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not load " + className + " through TCCL " + Thread.currentThread().getContextClassLoader() + " in the static block of MDB");
}
}
public DDBasedMDB() {
// @see https://issues.jboss.org/browse/WFLY-3989
// do an activity that depends on TCCL being the right one (== the application classloader)
final String className = this.getClass().getName();
try {
loadClassThroughTCCL(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not load " + className + " through TCCL " + Thread.currentThread().getContextClassLoader() + " in the constructor of MDB");
}
}
@Override
public void onMessage(Message message) {
logger.trace("Received message " + message + " in MDB " + this.getClass().getName());
Connection conn = null;
try {
final Destination replyTo = message.getJMSReplyTo();
if (replyTo == null) {
return;
}
logger.trace("Doing a DB operation using a DataSource");
try {
conn = dataSource.getConnection();
final PreparedStatement preparedStatement = conn.prepareStatement("select upper('foo')");
preparedStatement.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
logger.trace("Done invoking DB operation. Holding on to connection till this method completes");
logger.trace("Invoking a BMT SLSB which will use UserTransaction");
bmtslsb.doSomethingWithUserTransaction();
logger.trace("Sending a reply to destination " + replyTo);
jmsMessagingUtil.reply(message);
} catch (JMSException e) {
throw new RuntimeException(e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
private static void loadClassThroughTCCL(String className) throws ClassNotFoundException {
Thread.currentThread().getContextClassLoader().loadClass(className);
}
}
| 4,417 | 37.417391 | 170 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/DeploymentPackagedRATestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that a resource adapter packaged in a .ear can be used by a MDB as its resource adapter
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
public class DeploymentPackagedRATestCase {
private static final String EAR_NAME = "ear-containing-rar";
private static final String RAR_NAME = "rar-within-a-ear";
private static final String EJB_JAR_NAME = "ejb-jar";
@Deployment
public static Archive createDeplyoment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_NAME + ".ear");
final JavaArchive rar = ShrinkWrap.create(JavaArchive.class, RAR_NAME + ".rar");
rar.addAsManifestResource(DeploymentPackagedRATestCase.class.getPackage(), "ra.xml", "ra.xml");
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, EJB_JAR_NAME + ".jar");
ejbJar.addClasses(NonJMSMDB.class, DeploymentPackagedRATestCase.class);
final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, "common-lib.jar");
libJar.addClasses(SimpleActivationSpec.class, SimpleResourceAdapter.class, SimpleMessageListener.class, ResourceAdapterDeploymentTracker.class);
ear.addAsModule(rar);
ear.addAsModule(ejbJar);
ear.addAsLibrary(libJar);
return ear;
}
/**
* Tests that a RA deployed within the .ear is deployed and started successfully and it's endpoint
* activation is invoked
*
* @throws Exception
*/
@Test
public void testRADeployment() throws Exception {
Assert.assertTrue("Resource adapter deployed in the .ear was not started", ResourceAdapterDeploymentTracker.INSTANCE.wasEndpointStartCalled());
Assert.assertTrue("Resource adapter's endpoint was not activated", ResourceAdapterDeploymentTracker.INSTANCE.wasEndpointActivationCalled());
}
}
| 3,318 | 39.975309 | 152 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/SimpleActivationSpec.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ActivationSpec;
import jakarta.resource.spi.InvalidPropertyException;
import jakarta.resource.spi.ResourceAdapter;
import java.io.Serializable;
/**
* @author Jaikiran Pai
*/
public class SimpleActivationSpec implements ActivationSpec, Serializable {
private ResourceAdapter ra;
private String someProp;
public ResourceAdapter getResourceAdapter() {
return this.ra;
}
public void setResourceAdapter(ResourceAdapter ra) throws ResourceException {
this.ra = ra;
}
public void validate() throws InvalidPropertyException {
}
public String getSomeProp() {
return this.someProp;
}
public void setSomeProp(String prop) {
this.someProp = prop;
}
}
| 1,888 | 31.016949 | 81 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/SimpleMessageListener.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
/**
* @author Jaikiran Pai
*/
public interface SimpleMessageListener {
void onMessage(String msg);
}
| 1,196 | 36.40625 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/ConfiguredResourceAdapterNameMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.EJB;
import jakarta.ejb.MessageDriven;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.ejb3.annotation.ResourceAdapter;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@MessageDriven(
name="ConfiguredResourceAdapterNameMDB",
activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = ConfiguredResourceAdapterNameTestCase.QUEUE_JNDI_NAME)
})
@ResourceAdapter(value = "RARNameOverridenInJBossEJB3Xml.rar")
public class ConfiguredResourceAdapterNameMDB implements MessageListener {
private static final Logger logger = Logger.getLogger(ConfiguredResourceAdapterNameMDB.class);
public static final String REPLY = "Successful message delivery!";
@EJB
private JMSMessagingUtil jmsMessagingUtil;
@Override
public void onMessage(Message message) {
logger.trace("Received message " + message);
try {
if (message.getJMSReplyTo() != null) {
logger.trace("Replying to " + message.getJMSReplyTo());
// send a reply
this.jmsMessagingUtil.sendTextMessage(REPLY, message.getJMSReplyTo(), null);
}
} catch (JMSException jmse) {
throw new RuntimeException(jmse);
}
}
}
| 2,557 | 36.072464 | 142 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/ConfiguredResourceAdapterNameTestCase.java
|
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.jms.Message;
import jakarta.jms.Queue;
import jakarta.jms.TextMessage;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.PropertyPermission;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
@RunWith(Arquillian.class)
@ServerSetup({ConfiguredResourceAdapterNameTestCase.JmsQueueSetup.class})
public class ConfiguredResourceAdapterNameTestCase {
private static final String REPLY_QUEUE_JNDI_NAME = "java:jboss/override-resource-adapter-name-test/replyQueue";
public static final String QUEUE_JNDI_NAME = "java:jboss/override-resource-adapter-name-test/queue";
@EJB(mappedName = "java:module/JMSMessagingUtil")
private JMSMessagingUtil jmsUtil;
@Resource(mappedName = REPLY_QUEUE_JNDI_NAME)
private Queue replyQueue;
@Resource(mappedName = QUEUE_JNDI_NAME)
private Queue queue;
static class JmsQueueSetup implements ServerSetupTask {
private JMSOperations jmsAdminOperations;
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient.getControllerClient());
jmsAdminOperations.createJmsQueue("override-resource-adapter-name-test/queue", QUEUE_JNDI_NAME);
jmsAdminOperations.createJmsQueue("override-resource-adapter-name-test/reply-queue", REPLY_QUEUE_JNDI_NAME);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
if (jmsAdminOperations != null) {
jmsAdminOperations.removeJmsQueue("override-resource-adapter-name-test/queue");
jmsAdminOperations.removeJmsQueue("override-resource-adapter-name-test/reply-queue");
jmsAdminOperations.close();
}
}
}
@Deployment
public static Archive<JavaArchive> getDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "configured-resource-adapter-name-mdb-test.jar")
.addClasses(ConfiguredResourceAdapterNameMDB.class, JMSMessagingUtil.class, ConfiguredResourceAdapterNameTestCase.class,
JmsQueueSetup.class, TimeoutUtil.class)
.addPackage(JMSOperations.class.getPackage())
.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr \n"), "MANIFEST.MF")
.addAsManifestResource(ConfiguredResourceAdapterNameTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml")
.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml");
return ejbJar;
}
@Test
public void testMDBWithOverriddenResourceAdapterName() throws Exception {
final String goodMorning = "Hello World";
// send as TextMessage
this.jmsUtil.sendTextMessage(goodMorning, this.queue, this.replyQueue);
// wait for an reply
final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
// test the reply
final TextMessage textMessage = (TextMessage) reply;
Assert.assertNotNull(textMessage);
Assert.assertEquals("Unexpected reply message on reply queue: " + this.replyQueue, ConfiguredResourceAdapterNameMDB.REPLY, textMessage.getText());
}
}
| 4,346 | 45.244681 | 154 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/NonJMSMDBRelativePathWithDeploymentDescriptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
/**
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
*/
@MessageDriven(messageListenerInterface = SimpleMessageListener.class, activationConfig = {
@ActivationConfigProperty(propertyName = "someProp", propertyValue = "hello world")})
public class NonJMSMDBRelativePathWithDeploymentDescriptor implements SimpleMessageListener {
@Override
public void onMessage(String msg) {
}
}
| 1,587 | 38.7 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/OverriddenResourceAdapterNameMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.EJB;
import jakarta.ejb.MessageDriven;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = ResourceAdapterNameTestCase.QUEUE_JNDI_NAME)
})
public class OverriddenResourceAdapterNameMDB implements MessageListener {
private static final Logger logger = Logger.getLogger(OverriddenResourceAdapterNameMDB.class);
public static final String REPLY = "Successful message delivery!";
@EJB
private JMSMessagingUtil jmsMessagingUtil;
@Override
public void onMessage(Message message) {
logger.trace("Received message " + message);
try {
if (message.getJMSReplyTo() != null) {
logger.trace("Replying to " + message.getJMSReplyTo());
// send a reply
this.jmsMessagingUtil.sendTextMessage(REPLY, message.getJMSReplyTo(), null);
}
} catch (JMSException jmse) {
throw new RuntimeException(jmse);
}
}
}
| 2,369 | 34.909091 | 124 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/NonJMSMDBRelativePath.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
import org.jboss.ejb3.annotation.ResourceAdapter;
/**
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
*/
@MessageDriven(messageListenerInterface = SimpleMessageListener.class, activationConfig = {
@ActivationConfigProperty(propertyName = "someProp", propertyValue = "hello world")})
@ResourceAdapter(value = "#rar-within-a-ear.rar")
public class NonJMSMDBRelativePath implements SimpleMessageListener {
@Override
public void onMessage(String msg) {
}
}
| 1,664 | 37.72093 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/DeploymentPackagedRARelativePathTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.OperateOnDeployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that a resource adapter packaged in a .ear can be used by a MDB as its resource adapter. Resource name is specified
* relative to ear.
*
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
* @author <a href="mailto:[email protected]">Jan Martiska</a>
*/
@RunWith(Arquillian.class)
public class DeploymentPackagedRARelativePathTestCase {
private static final String EAR_NAME = "ear-containing-rar";
private static final String RAR_NAME = "rar-within-a-ear";
private static final String EJB_JAR_NAME = "ejb-jar";
private static final String DEPLOYMENT_ANNOTATED = "annotated";
private static final String DEPLOYMENT_WITH_DEPLOYMENT_DESCRIPTOR = "deployment-descriptor";
@Deployment(name = DEPLOYMENT_ANNOTATED)
public static Archive createDeplyomentAnnotated() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_NAME + ".ear");
final JavaArchive rar = ShrinkWrap.create(JavaArchive.class, RAR_NAME + ".rar");
rar.addAsManifestResource(DeploymentPackagedRARelativePathTestCase.class.getPackage(), "ra.xml", "ra.xml");
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, EJB_JAR_NAME + ".jar");
ejbJar.addClasses(NonJMSMDBRelativePath.class, DeploymentPackagedRARelativePathTestCase.class);
final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, "common-lib.jar");
libJar.addClasses(SimpleActivationSpec.class, SimpleResourceAdapter.class, SimpleMessageListener.class, ResourceAdapterDeploymentTracker.class);
ear.addAsModule(rar);
ear.addAsModule(ejbJar);
ear.addAsLibrary(libJar);
return ear;
}
@Deployment(name = DEPLOYMENT_WITH_DEPLOYMENT_DESCRIPTOR)
public static Archive createDeplyomentWithDeploymentDescriptor() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, EAR_NAME + "-deployment-descriptor.ear");
final JavaArchive rar = ShrinkWrap.create(JavaArchive.class, RAR_NAME + ".rar");
rar.addAsManifestResource(DeploymentPackagedRARelativePathTestCase.class.getPackage(), "ra.xml", "ra.xml");
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, EJB_JAR_NAME + ".jar");
ejbJar.addClasses(NonJMSMDBRelativePathWithDeploymentDescriptor.class, DeploymentPackagedRARelativePathTestCase.class);
ejbJar.addAsManifestResource(DeploymentPackagedRARelativePathTestCase.class.getPackage(),
"jboss-ejb3-relative-path.xml", "jboss-ejb3.xml");
final JavaArchive libJar = ShrinkWrap.create(JavaArchive.class, "common-lib.jar");
libJar.addClasses(SimpleActivationSpec.class, SimpleResourceAdapter.class, SimpleMessageListener.class, ResourceAdapterDeploymentTracker.class);
ear.addAsModule(rar);
ear.addAsModule(ejbJar);
ear.addAsLibrary(libJar);
return ear;
}
/**
* Tests that a RA deployed within the .ear is deployed and started successfully and it's endpoint
* activation is invoked
*
* @throws Exception
*/
@Test
@OperateOnDeployment(DEPLOYMENT_ANNOTATED)
public void testRADeploymentAnnotated() throws Exception {
Assert.assertTrue("Resource adapter deployed in the .ear was not started", ResourceAdapterDeploymentTracker.INSTANCE.wasEndpointStartCalled());
Assert.assertTrue("Resource adapter's endpoint was not activated", ResourceAdapterDeploymentTracker.INSTANCE.wasEndpointActivationCalled());
}
/**
* The same as testRADeploymentAnnotated, except we use a deployment descriptor rather than annotations.
*/
@Test
@OperateOnDeployment(DEPLOYMENT_WITH_DEPLOYMENT_DESCRIPTOR)
public void testRADeploymentWithDeploymentDescriptor() throws Exception {
Assert.assertTrue("Resource adapter deployed in the .ear was not started", ResourceAdapterDeploymentTracker.INSTANCE.wasEndpointStartCalled());
Assert.assertTrue("Resource adapter's endpoint was not activated", ResourceAdapterDeploymentTracker.INSTANCE.wasEndpointActivationCalled());
}
}
| 5,659 | 45.77686 | 152 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/SimpleResourceAdapter.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import javax.naming.NamingException;
import javax.naming.Reference;
import jakarta.resource.Referenceable;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ActivationSpec;
import jakarta.resource.spi.BootstrapContext;
import jakarta.resource.spi.ResourceAdapter;
import jakarta.resource.spi.ResourceAdapterInternalException;
import jakarta.resource.spi.endpoint.MessageEndpointFactory;
import javax.transaction.xa.XAResource;
import java.io.Serializable;
import org.jboss.logging.Logger;
/**
* @author Jaikiran Pai
*/
public class SimpleResourceAdapter implements ResourceAdapter, Referenceable, Serializable {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(SimpleResourceAdapter.class);
public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec)
throws ResourceException {
logger.trace("endpoint activation invoked for endpoint factory " + endpointFactory + " and activation spec " + spec);
ResourceAdapterDeploymentTracker.INSTANCE.endpointActivationCalled();
}
public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) {
logger.trace("endpoint de-activation invoked for endpoint factory " + endpointFactory + " and activation spec " + spec);
ResourceAdapterDeploymentTracker.INSTANCE.endpointDeactivationCalled();
}
public XAResource[] getXAResources(ActivationSpec[] specs) throws ResourceException {
return null;
}
public void start(BootstrapContext ctx) throws ResourceAdapterInternalException {
logger.trace("resource adapter start invoked");
try {
/*
* This is a small delay to emulate startup time of an RA.
* I understand that according to the spec, this step of RA should not perform any
* heavy task, and app server could throw WorkRejectedException if it takes too long.
* However, this small delay should be good rough approximation of the total time the RA
* could take to bootstrap itself more so, to reliably repoduce the issue, as otherwise,
* the failure is reproducible only indeterministically.
*/
Thread.sleep(500L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
ResourceAdapterDeploymentTracker.INSTANCE.endpointStartCalled();
}
public void stop() {
logger.trace("resource adapter stop invoked");
ResourceAdapterDeploymentTracker.INSTANCE.endpointStopCalled();
}
public Reference getReference() throws NamingException {
return null;
}
public void setReference(Reference reference) {
}
public boolean equals(Object o) {
return super.equals(o);
}
public int hashCode() {
return super.hashCode();
}
}
| 4,032 | 38.539216 | 128 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/ResourceAdapterDeploymentTracker.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
/**
* @author Jaikiran Pai
*/
public class ResourceAdapterDeploymentTracker {
public static final ResourceAdapterDeploymentTracker INSTANCE = new ResourceAdapterDeploymentTracker();
private boolean endpointActivationCalled;
private boolean endpointDeactivationCalled;
private boolean endpointStartCalled;
private boolean endpointStopCalled;
private ResourceAdapterDeploymentTracker() {
}
void endpointActivationCalled() {
this.endpointActivationCalled = true;
}
public boolean wasEndpointActivationCalled() {
return this.endpointActivationCalled;
}
void endpointDeactivationCalled() {
this.endpointDeactivationCalled = true;
}
public boolean wasEndpointDeactivationCalled() {
return this.endpointDeactivationCalled;
}
void endpointStartCalled() {
this.endpointStartCalled = true;
}
public boolean wasEndpointStartCalled() {
return this.endpointStartCalled;
}
void endpointStopCalled() {
this.endpointStopCalled = true;
}
public boolean wasEndpointStopCalled() {
return this.endpointStopCalled;
}
}
| 2,256 | 29.917808 | 107 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/ResourceAdapterNameTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.jms.Message;
import jakarta.jms.Queue;
import jakarta.jms.TextMessage;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.PropertyPermission;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* User: jpai
*/
@RunWith(Arquillian.class)
@ServerSetup({ResourceAdapterNameTestCase.JmsQueueSetup.class})
public class ResourceAdapterNameTestCase {
private static final String REPLY_QUEUE_JNDI_NAME = "java:jboss/resource-adapter-name-test/replyQueue";
public static final String QUEUE_JNDI_NAME = "java:jboss/jms/queue/resource-adapater-name-queue";
@EJB(mappedName = "java:module/JMSMessagingUtil")
private JMSMessagingUtil jmsUtil;
@Resource(mappedName = ResourceAdapterNameTestCase.REPLY_QUEUE_JNDI_NAME)
private Queue replyQueue;
@Resource(mappedName = QUEUE_JNDI_NAME)
private Queue queue;
static class JmsQueueSetup implements ServerSetupTask {
private JMSOperations jmsAdminOperations;
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient.getControllerClient());
jmsAdminOperations.createJmsQueue("resource-adapter-name-test/queue", QUEUE_JNDI_NAME);
jmsAdminOperations.createJmsQueue("resource-adapter-name-test/reply-queue", REPLY_QUEUE_JNDI_NAME);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
if (jmsAdminOperations != null) {
jmsAdminOperations.removeJmsQueue("resource-adapter-name-test/queue");
jmsAdminOperations.removeJmsQueue("resource-adapter-name-test/reply-queue");
jmsAdminOperations.close();
}
}
}
@Deployment
public static Archive getDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "resource-adapter-name-mdb-test.jar");
ejbJar.addClasses(OverriddenResourceAdapterNameMDB.class, JMSMessagingUtil.class, ResourceAdapterNameTestCase.class,
JmsQueueSetup.class, TimeoutUtil.class);
ejbJar.addPackage(JMSOperations.class.getPackage());
ejbJar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr \n"), "MANIFEST.MF");
ejbJar.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml");
return ejbJar;
}
@Test
public void testMDBWithOverriddenResourceAdapterName() throws Exception {
final String goodMorning = "Good morning";
// send as ObjectMessage
this.jmsUtil.sendTextMessage(goodMorning, this.queue, this.replyQueue);
// wait for an reply
final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
// test the reply
final TextMessage textMessage = (TextMessage) reply;
Assert.assertNotNull(textMessage);
Assert.assertEquals("Unexpected reply message on reply queue: " + this.replyQueue, OverriddenResourceAdapterNameMDB.REPLY, textMessage.getText());
}
}
| 5,173 | 42.478992 | 154 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/resourceadapter/NonJMSMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.resourceadapter;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
import org.jboss.ejb3.annotation.ResourceAdapter;
/**
* @author Jaikiran Pai
*/
@MessageDriven(messageListenerInterface = SimpleMessageListener.class, activationConfig = {
@ActivationConfigProperty(propertyName = "someProp", propertyValue = "hello world")})
@ResourceAdapter(value = "ear-containing-rar.ear#rar-within-a-ear.rar")
public class NonJMSMDB implements SimpleMessageListener {
@Override
public void onMessage(String msg) {
}
}
| 1,631 | 36.953488 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/DynamicMessageListenerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2013, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.ejb.mdb.dynamic.adapter.TelnetResourceAdapter;
import org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener;
import org.jboss.as.test.integration.ejb.mdb.dynamic.application.MyMdb;
import org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetInputStream;
import org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetPrintStream;
import org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.net.SocketPermission;
import java.util.PropertyPermission;
import static org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TtyCodes.TTY_Bright;
import static org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TtyCodes.TTY_Reset;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
import static org.junit.Assert.assertEquals;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class DynamicMessageListenerTestCase {
@ContainerResource
private ManagementClient managementClient;
private static void assertEmptyLine(final DataInputStream in) throws IOException {
assertEquals("", in.readLine());
}
private static void assertReply(final String expected, final String actual) {
assertEquals(TTY_Reset + TTY_Bright + "pronto> " + TTY_Reset + expected, actual);
}
@Deployment
public static Archive createDeplyoment() {
final EnterpriseArchive ear = create(EnterpriseArchive.class, "ear-with-rar.ear")
.addAsModule(create(JavaArchive.class, "telnet-ra.rar")
.addAsManifestResource(TelnetResourceAdapter.class.getPackage(), "ra.xml", "ra.xml")
.addPackages(true, TelnetResourceAdapter.class.getPackage(), TelnetListener.class.getPackage(), TelnetServer.class.getPackage()))
.addAsModule(create(JavaArchive.class, "mdb.jar")
.addClasses(MyMdb.class));
ear.addAsManifestResource(createPermissionsXmlAsset(
// Cmd (TelnetServer package) uses PropertyEditorManager#registerEditor during static initialization
new PropertyPermission("*", "read,write"),
// TelnetServer binds socket and accepts connections
new SocketPermission("*", "accept,listen")),
"permissions.xml");
return ear;
}
@Test
public void test1() throws Exception {
final Socket socket = new Socket(managementClient.getWebUri().getHost(), 2020);
final OutputStream sockOut = socket.getOutputStream();
final DataInputStream in = new DataInputStream(new TelnetInputStream(socket.getInputStream(), sockOut));
final PrintStream out = new TelnetPrintStream(sockOut);
assertEmptyLine(in);
assertEquals("type 'help' for a list of commands", in.readLine());
out.println("set a b");
out.flush();
assertReply("set a to b", in.readLine());
assertEmptyLine(in);
out.println("get a");
out.flush();
assertReply("b", in.readLine());
assertEmptyLine(in);
out.println("list");
out.flush();
assertReply("a = b", in.readLine());
assertEmptyLine(in);
}
}
| 5,071 | 41.983051 | 153 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/application/MyMdb.java
|
/*
* Copyright 2012 David Blevins
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.application;
import org.jboss.as.test.integration.ejb.mdb.dynamic.api.Command;
import org.jboss.as.test.integration.ejb.mdb.dynamic.api.Option;
import org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener;
import org.jboss.ejb3.annotation.ResourceAdapter;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "beanClass", propertyValue = "org.jboss.as.test.integration.ejb.mdb.dynamic.application.MyMdb"),
@ActivationConfigProperty(propertyName = "prompt", propertyValue = "pronto>")
})
@ResourceAdapter("ear-with-rar.ear#telnet-ra.rar")
public class MyMdb implements TelnetListener {
private final Properties properties = new Properties();
@Command("get")
public String doGet(@Option("key") String key) {
return properties.getProperty(key);
}
@Command("set")
public String doSet(@Option("key") String key, @Option("value") String value) {
final Object old = properties.setProperty(key, value);
final StringBuilder sb = new StringBuilder();
sb.append("set ").append(key).append(" to ").append(value);
sb.append("\n");
if (old != null) {
sb.append("old value: ").append(old);
sb.append("\n");
}
return sb.toString();
}
@Command("list")
public String doList(@Option("pattern") Pattern pattern) {
if (pattern == null) pattern = Pattern.compile(".*");
final StringBuilder sb = new StringBuilder();
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
final String key = entry.getKey().toString();
if (pattern.matcher(key).matches()) {
sb.append(key).append(" = ").append(entry.getValue()).append("\n");
}
}
return sb.toString();
}
}
| 2,640 | 36.728571 | 145 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/api/Command.java
|
/* =====================================================================
*
* Copyright (c) 2011 David Blevins. All rights reserved.
*
* =====================================================================
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
String value() default "";
String description() default "";
}
| 600 | 30.631579 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/api/TelnetListener.java
|
/*
* Copyright 2012 David Blevins
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.api;
public interface TelnetListener {
}
| 701 | 34.1 | 76 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/api/Option.java
|
/* =====================================================================
*
* Copyright (c) 2011 David Blevins. All rights reserved.
*
* =====================================================================
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface Option {
String value() default "";
String description() default "";
}
| 602 | 30.736842 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/api/Prompt.java
|
/* =====================================================================
*
* Copyright (c) 2011 David Blevins. All rights reserved.
*
* =====================================================================
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Prompt {
String value() default "telnet>";
String description() default "";
}
| 604 | 30.842105 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/adapter/TelnetActivationSpec.java
|
/*
* Copyright 2012 David Blevins
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.adapter;
import org.jboss.as.test.integration.ejb.mdb.dynamic.api.Command;
import org.jboss.as.test.integration.ejb.mdb.dynamic.api.Prompt;
import org.jboss.as.test.integration.ejb.mdb.dynamic.impl.Cmd;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ActivationSpec;
import jakarta.resource.spi.InvalidPropertyException;
import jakarta.resource.spi.ResourceAdapter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class TelnetActivationSpec implements ActivationSpec {
private ResourceAdapter resourceAdapter;
private final List<Cmd> cmds = new ArrayList<Cmd>();
private String prompt;
// JCA 1.6 doesn't allow Class as a valid property type
private String beanClassName;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
* @return the bean class
* @throws InvalidPropertyException
*/
private Class<?> beanClass() throws InvalidPropertyException {
// Carlo: this is different as opposed to the original proposal
try {
// we can only hope for the best here
return Class.forName(beanClassName);
} catch (ClassNotFoundException e) {
throw new InvalidPropertyException(e);
}
}
public String getPrompt() {
return prompt;
}
public void setPrompt(String prompt) {
this.prompt = prompt;
}
public String getBeanClass() {
return beanClassName;
}
public void setBeanClass(final String beanClassName) {
this.beanClassName = beanClassName;
}
public List<Cmd> getCmds() {
return cmds;
}
@Override
public void validate() throws InvalidPropertyException {
if (beanClassName == null)
throw new InvalidPropertyException("beanClass is null");
final Class<?> beanClass = beanClass();
// Set Prompt
final Prompt prompt = beanClass.getAnnotation(Prompt.class);
if (prompt != null) {
this.prompt = prompt.value();
}
// Get Commands
final Method[] methods = beanClass.getMethods();
for (Method method : methods) {
if (method.isAnnotationPresent(Command.class)) {
final Command command = method.getAnnotation(Command.class);
cmds.add(new Cmd(command.value(), method));
}
}
// Validate
if (this.prompt == null || this.prompt.length() == 0) {
this.prompt = "prompt>";
}
if (this.cmds.size() == 0) {
throw new InvalidPropertyException("No @Command methods");
}
}
@Override
public ResourceAdapter getResourceAdapter() {
return resourceAdapter;
}
@Override
public void setResourceAdapter(ResourceAdapter ra) throws ResourceException {
this.resourceAdapter = ra;
}
}
| 3,571 | 30.610619 | 81 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/adapter/TelnetResourceAdapter.java
|
/*
* Copyright 2012 David Blevins
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.adapter;
import org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener;
import org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer;
import jakarta.resource.ResourceException;
import jakarta.resource.spi.ActivationSpec;
import jakarta.resource.spi.BootstrapContext;
import jakarta.resource.spi.ResourceAdapterInternalException;
import jakarta.resource.spi.endpoint.MessageEndpoint;
import jakarta.resource.spi.endpoint.MessageEndpointFactory;
import jakarta.resource.spi.work.Work;
import jakarta.resource.spi.work.WorkManager;
import javax.transaction.xa.XAResource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* @version $Revision$ $Date$
*/
public class TelnetResourceAdapter implements jakarta.resource.spi.ResourceAdapter {
private final Map<Integer, TelnetServer> activated = new HashMap<Integer, TelnetServer>();
private WorkManager workManager;
/**
* Corresponds to the ra.xml <config-property>
*/
private int port;
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
@Override
public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
this.workManager = bootstrapContext.getWorkManager();
}
@Override
public void stop() {
}
@Override
public void endpointActivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) throws ResourceException {
final TelnetActivationSpec telnetActivationSpec = (TelnetActivationSpec) activationSpec;
final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null);
// This messageEndpoint instance is also castable to the ejbClass of the MDB
final TelnetListener telnetListener = (TelnetListener) messageEndpoint;
try {
final TelnetServer telnetServer = new TelnetServer(telnetActivationSpec, telnetListener, port);
workManager.scheduleWork(new Work() {
@Override
public void release() {
}
@Override
public void run() {
try {
telnetServer.activate();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}, 0, null, null);
activated.put(port, telnetServer);
} catch (IOException e) {
throw new ResourceException(e);
}
}
@Override
public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) {
final TelnetActivationSpec telnetActivationSpec = (TelnetActivationSpec) activationSpec;
final TelnetServer telnetServer = activated.remove(port);
try {
telnetServer.deactivate();
} catch (IOException e) {
e.printStackTrace();
}
final MessageEndpoint endpoint = (MessageEndpoint) telnetServer.getListener();
endpoint.release();
}
@Override
public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException {
return new XAResource[0];
}
@Override
public int hashCode() {
return port;
}
@Override
public boolean equals(final Object obj) {
return (obj instanceof TelnetResourceAdapter) && ((TelnetResourceAdapter) obj).port == this.port;
}
}
| 4,196 | 31.789063 | 139 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/impl/TelnetServer.java
|
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.impl;
import org.jboss.as.test.integration.ejb.mdb.dynamic.adapter.TelnetActivationSpec;
import org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener;
import org.jboss.logging.Logger;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
public class TelnetServer implements TtyCodes {
private static final Logger logger = Logger.getLogger(TelnetServer.class.getName());
private final TelnetListener listener;
private final TelnetActivationSpec spec;
private final int port;
private final Map<String, Cmd> cmds = new TreeMap<String, Cmd>();
private final AtomicBoolean running = new AtomicBoolean();
private final ServerSocket serverSocket;
public TelnetServer(TelnetActivationSpec spec, TelnetListener listener, int port) throws IOException {
this.port = port;
this.spec = spec;
this.listener = listener;
// make sure the socket is open right away
this.serverSocket = new ServerSocket(port);
logger.trace("Listening on " + serverSocket.getLocalPort());
for (Cmd cmd : spec.getCmds()) {
this.cmds.put(cmd.getName(), cmd);
}
try {
cmds.put("help", new BuiltInCmd("help", this.getClass().getMethod("help", String.class)));
cmds.put("exit", new BuiltInCmd("exit", this.getClass().getMethod("exit")));
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
public TelnetListener getListener() {
return listener;
}
public void activate() throws IOException {
if (running.compareAndSet(false, true)) {
while (running.get()) {
final Socket accept = serverSocket.accept();
final Thread thread = new Thread() {
@Override
public void run() {
try {
session(accept);
} catch (IOException e) {
e.printStackTrace();
}
}
};
thread.start();
}
}
}
public void deactivate() throws IOException {
if (running.compareAndSet(true, false)) {
try {
serverSocket.close();
} catch (IOException e) {
}
}
}
public void session(Socket socket) throws IOException {
InputStream telnetIn = null;
PrintStream telnetOut = null;
try {
final InputStream in = socket.getInputStream();
final OutputStream out = socket.getOutputStream();
telnetIn = new TelnetInputStream(in, out);
telnetOut = new TelnetPrintStream(out);
telnetOut.println("");
telnetOut.println("type \'help\' for a list of commands");
final DataInputStream dataInputStream = new DataInputStream(telnetIn);
while (running.get()) {
prompt(dataInputStream, telnetOut);
}
} catch (StopException s) {
// exit normally
} catch (Throwable t) {
t.printStackTrace();
} finally {
close(telnetIn);
close(telnetOut);
if (socket != null) socket.close();
}
}
private static void close(Closeable closeable) {
if (closeable == null) return;
try {
closeable.close();
} catch (IOException e) {
e.printStackTrace();
}
}
protected void prompt(DataInputStream in, PrintStream out) throws StopException {
try {
out.print(TTY_Reset + TTY_Bright + spec.getPrompt() + " " + TTY_Reset);
out.flush();
final String commandline = in.readLine().trim();
if (commandline.length() < 1) return;
final List<String> list = new ArrayList<String>();
Collections.addAll(list, commandline.split(" +"));
final String command = list.remove(0);
final String[] args = list.toArray(new String[list.size()]);
final Cmd cmd = cmds.get(command);
if (cmd == null) {
out.print(command);
out.println(": command not found");
} else {
try {
cmd.exec(listener, args, out);
} catch (StopException stop) {
throw stop;
} catch (Throwable throwable) {
throwable.printStackTrace(out);
}
}
} catch (StopException stop) {
throw stop;
} catch (UnsupportedOperationException e) {
throw new StopException(e);
} catch (Throwable e) {
e.printStackTrace(new PrintStream(out));
throw new StopException(e);
}
}
public class BuiltInCmd extends Cmd {
public BuiltInCmd(String name, Method method) {
super(name, method);
}
@Override
public void exec(Object impl, String[] args, PrintStream out) throws Throwable {
super.exec(TelnetServer.this, args, out);
}
}
public String help(String arg) {
final StringBuilder sb = new StringBuilder();
if (arg == null) {
for (String s : cmds.keySet()) {
sb.append(s).append("\n");
}
} else {
final Cmd cmd = cmds.get(arg);
if (cmd == null) {
sb.append("Unknown command: ").append(arg);
} else {
final Method method = cmd.getMethod();
sb.append(cmd.getName()).append(" ");
final Class<?>[] types = method.getParameterTypes();
for (Class<?> type : types) {
sb.append("<").append(type.getSimpleName().toLowerCase()).append(">").append(" ");
}
if (types.length == 0) {
sb.append("[no options]");
}
}
}
return sb.toString();
}
public void exit() throws StopException {
throw new StopException();
}
public static class StopException extends Exception {
public StopException() {
}
public StopException(Throwable cause) {
super(cause);
}
}
}
| 7,661 | 28.697674 | 106 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/impl/TelnetInputStream.java
|
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.impl;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class TelnetInputStream extends FilterInputStream implements TelnetCodes {
private TelnetOption[] options = new TelnetOption[256];
private OutputStream out = null;
public TelnetInputStream(InputStream in, OutputStream out) throws IOException {
super(in);
this.out = out;
negotiateOption(DONT, 1);
negotiateOption(DONT, 6);
negotiateOption(DONT, 24);
negotiateOption(DONT, 33);
negotiateOption(DONT, 34);
}
public int read() throws IOException {
int b = super.read();
if (b == IAC) {
processCommand();
b = this.read();
}
return b;
}
private void processCommand() throws IOException {
print("C: IAC ");
int command = super.read();
switch (command) {
case WILL:
senderWillEnableOption(super.read());
break;
case DO:
pleaseDoEnableOption(super.read());
break;
case WONT:
senderWontEnableOption(super.read());
break;
case DONT:
pleaseDontEnableOption(super.read());
break;
default:
unimplementedCommand(command);
break;
}
}
private void unimplementedCommand(int command) {
println(command + ": command not found");
}
private void senderWillEnableOption(int optionID) throws IOException {
println("WILL " + optionID);
TelnetOption option = getOption(optionID);
if (option.hasBeenNegotiated()) return;
if (option.isInNegotiation()) {
option.enable();
} else if (!option.isInNegotiation() && option.isSupported()) {
negotiateOption(DO, optionID);
option.enable();
} else if (!option.isInNegotiation() && !option.isSupported()) {
negotiateOption(DONT, optionID);
option.disable();
}
}
private void pleaseDoEnableOption(int optionID) throws IOException {
println("DO " + optionID);
TelnetOption option = getOption(optionID);
if (option.hasBeenNegotiated()) return;
if (option.isInNegotiation()) {
option.enable();
} else if (!option.isInNegotiation() && option.isSupported()) {
negotiateOption(WILL, optionID);
option.enable();
} else if (!option.isInNegotiation() && !option.isSupported()) {
negotiateOption(WONT, optionID);
option.disable();
}
}
private void senderWontEnableOption(int optionID) throws IOException {
println("WONT " + optionID);
TelnetOption option = getOption(optionID);
if (option.hasBeenNegotiated()) return;
if (!option.isInNegotiation()) {
negotiateOption(DONT, optionID);
}
option.disable();
}
private void pleaseDontEnableOption(int optionID) throws IOException {
println("DONT " + optionID);
TelnetOption option = getOption(optionID);
if (option.hasBeenNegotiated()) return;
if (!option.isInNegotiation()) {
negotiateOption(WONT, optionID);
}
option.disable();
}
private void println(String s) {
}
private void print(String s) {
}
private void negotiateOption(int negotiate, int optionID)
throws IOException {
TelnetOption option = getOption(optionID);
option.inNegotiation = true;
String n = null;
switch (negotiate) {
case WILL:
n = "WILL ";
break;
case DO:
n = "DO ";
break;
case WONT:
n = "WONT ";
break;
case DONT:
n = "DONT ";
break;
}
println("S: IAC " + n + optionID);
synchronized (out) {
out.write(IAC);
out.write(negotiate);
out.write(optionID);
}
}
private TelnetOption getOption(int optionID) {
TelnetOption opt = options[optionID];
if (opt == null) {
opt = new TelnetOption(optionID);
options[optionID] = opt;
}
return opt;
}
}
| 5,362 | 26.787565 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/impl/TelnetPrintStream.java
|
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.impl;
import java.io.OutputStream;
import java.io.PrintStream;
public class TelnetPrintStream extends PrintStream {
private final byte[] CRLF = new byte[]{(byte) '\r', (byte) '\n'};
public TelnetPrintStream(OutputStream out) {
super(out);
}
public void println() {
newLine();
}
public void println(String x) {
synchronized (this) {
print(x);
newLine();
}
}
public void println(long x) {
synchronized (this) {
print(x);
newLine();
}
}
public void println(char x) {
synchronized (this) {
print(x);
newLine();
}
}
public void println(boolean x) {
synchronized (this) {
print(x);
newLine();
}
}
public void println(float x) {
synchronized (this) {
print(x);
newLine();
}
}
public void println(double x) {
synchronized (this) {
print(x);
newLine();
}
}
public void println(int x) {
synchronized (this) {
print(x);
newLine();
}
}
public void println(char[] x) {
synchronized (this) {
print(x);
newLine();
}
}
private void newLine() {
try {
this.write(CRLF);
} catch (Exception e) {
}
}
}
| 2,317 | 22.896907 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/impl/Cmd.java
|
/*
* Copyright 2012 David Blevins
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.impl;
import jakarta.resource.spi.endpoint.MessageEndpoint;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.io.PrintStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.regex.Pattern;
/**
* @version $Revision$ $Date$
*/
public class Cmd {
private final String name;
private final Method method;
public Cmd(String name, Method method) {
this.name = name;
this.method = method;
}
public String getName() {
return name;
}
public void exec(Object impl, String[] args, PrintStream out) throws Throwable {
try {
if (impl instanceof MessageEndpoint) {
MessageEndpoint endpoint = (MessageEndpoint) impl;
endpoint.beforeDelivery(method);
}
final Object result = method.invoke(impl, toParams(args));
if (result != null) {
final String text = result.toString().replaceAll("\n*$", "");
out.println(text);
out.println();
}
} catch (InvocationTargetException e) {
throw e.getTargetException();
} finally {
if (impl instanceof MessageEndpoint) {
MessageEndpoint endpoint = (MessageEndpoint) impl;
endpoint.afterDelivery();
}
}
}
private Object[] toParams(String[] args) {
final Class<?>[] expected = method.getParameterTypes();
final Object[] converted = new Object[expected.length];
for (int i = 0; i < expected.length; i++) {
if (args.length <= i) {
converted[i] = null;
} else {
converted[i] = convert(expected[i], args[i]);
}
}
return converted;
}
private static Object convert(Class<?> type, String text) {
final PropertyEditor editor = PropertyEditorManager.findEditor(type);
if (editor != null) {
editor.setAsText(text);
return editor.getValue();
} else {
try {
final Constructor<?> constructor = type.getConstructor(String.class);
return constructor.newInstance(text);
} catch (NoSuchMethodException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
public Method getMethod() {
return method;
}
static {
PropertyEditorManager.registerEditor(Pattern.class, PatternEditor.class);
}
public static class PatternEditor extends java.beans.PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(Pattern.compile(text));
}
}
}
| 3,556 | 29.144068 | 85 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/impl/TtyCodes.java
|
/*
* Copyright 2012 David Blevins
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.impl;
/**
* @version $Revision$ $Date$
*/
public interface TtyCodes {
char ESC = (char) 27;
String TTY_Reset = ESC + "[0m";
String TTY_Bright = ESC + "[1m";
String TTY_Dim = ESC + "[2m";
String TTY_Underscore = ESC + "[4m";
String TTY_Blink = ESC + "[5m";
String TTY_Reverse = ESC + "[7m";
String TTY_Hidden = ESC + "[8m";
/* Foreground Colors */
String TTY_FG_Black = ESC + "[30m";
String TTY_FG_Red = ESC + "[31m";
String TTY_FG_Green = ESC + "[32m";
String TTY_FG_Yellow = ESC + "[33m";
String TTY_FG_Blue = ESC + "[34m";
String TTY_FG_Magenta = ESC + "[35m";
String TTY_FG_Cyan = ESC + "[36m";
String TTY_FG_White = ESC + "[37m";
/* Background Colors */
String TTY_BG_Black = ESC + "[40m";
String TTY_BG_Red = ESC + "[41m";
String TTY_BG_Green = ESC + "[42m";
String TTY_BG_Yellow = ESC + "[43m";
String TTY_BG_Blue = ESC + "[44m";
String TTY_BG_Magenta = ESC + "[45m";
String TTY_BG_Cyan = ESC + "[46m";
String TTY_BG_White = ESC + "[47m";
}
| 1,740 | 21.907895 | 76 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/impl/TelnetOption.java
|
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.impl;
class TelnetOption {
protected int optionCode;
protected boolean supported;
protected boolean enabled;
protected boolean negotiated;
protected boolean inNegotiation;
TelnetOption(int optionCode) {
this.optionCode = optionCode;
}
public int getOptionId() {
return optionCode;
}
public boolean isEnabled() {
return enabled;
}
public void enable() {
enabled = true;
negotiated = true;
}
public void disable() {
enabled = false;
negotiated = true;
}
public boolean isSupported() {
return supported;
}
public boolean hasBeenNegotiated() {
return negotiated;
}
public boolean isInNegotiation() {
return inNegotiation;
}
public void hasBeenNegotiated(boolean negotiated) {
this.negotiated = negotiated;
this.inNegotiation = false;
}
}
| 1,794 | 24.642857 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/dynamic/impl/TelnetCodes.java
|
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.ejb.mdb.dynamic.impl;
public interface TelnetCodes {
int SE = 240;
int NOP = 241;
int Data_Mark = 242;
int Break = 243;
int Interrupt_Process = 244;
int Abort_output = 245;
int Are_You_There = 246;
int Erase_character = 247;
int Erase_Line = 248;
int Go_ahead = 249;
int SB = 250;
int WILL = 251;
int WONT = 252;
int DO = 253;
int DONT = 254;
int IAC = 255;
}
| 1,283 | 22.777778 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/timerservice/AnnotationTimerServiceMDB.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.timerservice;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
import jakarta.ejb.Timeout;
import jakarta.ejb.TimerService;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
/**
* @author Stuart Douglas
*/
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/myAwesomeTopic")
})
public class AnnotationTimerServiceMDB implements MessageListener {
private static final CountDownLatch latch = new CountDownLatch(1);
private static boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
@Timeout
public void timeout() {
timerServiceCalled = true;
latch.countDown();
}
public static boolean awaitTimerCall() {
try {
latch.await(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
@Override
public void onMessage(final Message message) {
timerService.createTimer(100, null);
}
}
| 2,301 | 31.422535 | 103 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/timerservice/SimpleTimerMDBTestCase.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.timerservice;
import jakarta.jms.Destination;
import jakarta.jms.Message;
import jakarta.jms.MessageProducer;
import jakarta.jms.Session;
import jakarta.jms.TopicConnection;
import jakarta.jms.TopicConnectionFactory;
import jakarta.jms.TopicSession;
import javax.naming.InitialContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.test.jms.auxiliary.CreateTopicSetupTask;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that an @Timout method is called when a timer is created programatically.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
@ServerSetup(CreateTopicSetupTask.class)
public class SimpleTimerMDBTestCase {
@Deployment
public static Archive<?> deploy() {
final WebArchive war = ShrinkWrap.create(WebArchive.class, "testTimerServiceSimple.war");
war.addPackage(SimpleTimerMDBTestCase.class.getPackage());
war.addClass(CreateTopicSetupTask.class);
return war;
}
@Test
public void testAnnotationTimeoutMethod() throws Exception {
InitialContext ctx = new InitialContext();
sendMessage();
Assert.assertTrue(AnnotationTimerServiceMDB.awaitTimerCall());
}
@Test
public void testTimedObjectTimeoutMethod() throws Exception {
InitialContext ctx = new InitialContext();
sendMessage();
Assert.assertTrue(TimedObjectTimerServiceMDB.awaitTimerCall());
}
//the timer is created when the
public void sendMessage() throws Exception {
final InitialContext ctx = new InitialContext();
final TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("java:/JmsXA");
final TopicConnection connection = factory.createTopicConnection();
connection.start();
try {
final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
final Message message = session.createTextMessage("Test");
final Destination destination = (Destination) ctx.lookup("topic/myAwesomeTopic");
final MessageProducer producer = session.createProducer(destination);
producer.send(message);
producer.close();
} finally {
connection.close();
}
}
}
| 3,611 | 36.625 | 104 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/timerservice/TimedObjectTimerServiceMDB.java
|
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.timerservice;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import jakarta.annotation.Resource;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
import jakarta.ejb.TimedObject;
import jakarta.ejb.Timer;
import jakarta.ejb.TimerService;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
/**
* @author Stuart Douglas
*/
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/myAwesomeTopic")
})
public class TimedObjectTimerServiceMDB implements TimedObject , MessageListener {
private static final CountDownLatch latch = new CountDownLatch(1);
private static boolean timerServiceCalled = false;
@Resource
private TimerService timerService;
public void createTimer() {
timerService.createTimer(100, null);
}
public static boolean awaitTimerCall() {
try {
latch.await(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return timerServiceCalled;
}
@Override
public void ejbTimeout(final Timer timer) {
timerServiceCalled = true;
latch.countDown();
}
@Override
public void onMessage(final Message message) {
timerService.createTimer(100, null);
}
}
| 2,450 | 31.68 | 103 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/messagedrivencontext/SimpleMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.messagedrivencontext;
import jakarta.annotation.Resource;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.EJBException;
import jakarta.ejb.MessageDriven;
import jakarta.ejb.MessageDrivenBean;
import jakarta.ejb.MessageDrivenContext;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.JMSContext;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import org.jboss.logging.Logger;
/**
* @author Jaikiran Pai
*/
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/queue/set-message-context")
})
public class SimpleMDB implements MessageDrivenBean, MessageListener {
private static final Logger logger = Logger.getLogger(SimpleMDB.class);
public static final String SUCCESS_REPLY = "setMessageDrivenContext() method was invoked";
public static final String FAILURE_REPLY = "setMessageDrivenContext() method was *not* invoked";
@Resource(lookup = "java:/JmsXA")
private ConnectionFactory factory;
private MessageDrivenContext messageDrivenContext;
@Override
public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException {
this.messageDrivenContext = ctx;
}
@Override
public void ejbRemove() throws EJBException {
}
@Override
public void onMessage(Message message) {
logger.trace("Received message: " + message);
try {
final Destination replyTo = message.getJMSReplyTo();
if (replyTo != null) {
logger.trace("Replying to " + replyTo);
try (
JMSContext context = factory.createContext()
) {
String reply = (messageDrivenContext != null) ? SUCCESS_REPLY : FAILURE_REPLY;
context.createProducer()
.setJMSCorrelationID(message.getJMSMessageID())
.send(replyTo, reply);
}
}
} catch (JMSException jmse) {
throw new RuntimeException(jmse);
}
}
}
| 3,246 | 35.077778 | 119 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/messagedrivencontext/SetMessageDrivenContextInvocationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.messagedrivencontext;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.jms.Message;
import jakarta.jms.Queue;
import jakarta.jms.TextMessage;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.PropertyPermission;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Tests that the {@link jakarta.ejb.MessageDrivenBean#setMessageDrivenContext(jakarta.ejb.MessageDrivenContext)}
* method is invoked on MDBs which implement the {@link jakarta.ejb.MessageDrivenBean} interface
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@ServerSetup({SetMessageDrivenContextInvocationTestCase.JmsQueueSetup.class})
public class SetMessageDrivenContextInvocationTestCase {
private static final String QUEUE_JNDI_NAME = "java:jboss/queue/set-message-context";
private static final String REPLY_QUEUE_JNDI_NAME = "java:jboss/queue/set-message-context-reply-queue";
static class JmsQueueSetup implements ServerSetupTask {
private JMSOperations jmsAdminOperations;
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient);
jmsAdminOperations.createJmsQueue("setMessageDrivenContext/queue", QUEUE_JNDI_NAME);
jmsAdminOperations.createJmsQueue("setMessageDrivenContext/replyQueue", REPLY_QUEUE_JNDI_NAME);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
if (jmsAdminOperations != null) {
jmsAdminOperations.removeJmsQueue("setMessageDrivenContext/queue");
jmsAdminOperations.removeJmsQueue("setMessageDrivenContext/replyQueue");
jmsAdminOperations.close();
}
}
}
@EJB(mappedName = "java:module/JMSMessagingUtil")
private JMSMessagingUtil jmsUtil;
@Resource(mappedName = QUEUE_JNDI_NAME)
private Queue queue;
@Resource(mappedName = REPLY_QUEUE_JNDI_NAME)
private Queue replyQueue;
@Deployment
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "set-message-driven-context-invocation-test.jar");
jar.addClasses(SimpleMDB.class, JMSMessagingUtil.class, JmsQueueSetup.class, TimeoutUtil.class);
jar.addPackage(JMSOperations.class.getPackage());
jar.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml");
return jar;
}
/**
* Test that the {@link jakarta.ejb.MessageDrivenBean#setMessageDrivenContext(jakarta.ejb.MessageDrivenContext)}
* was invoked
*
* @throws Exception
*/
@Test
public void testSetMessageDrivenContext() throws Exception {
this.jmsUtil.sendTextMessage("hello world", this.queue, this.replyQueue);
final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
Assert.assertNotNull("Reply message was null on reply queue: " + this.replyQueue, reply);
final TextMessage textMessage = (TextMessage) reply;
Assert.assertEquals("setMessageDrivenContext method was *not* invoked on MDB", SimpleMDB.SUCCESS_REPLY, textMessage.getText());
}
}
| 5,162 | 42.025 | 135 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/messagedestination/ReplyingMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.messagedestination;
import jakarta.annotation.Resource;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.MessageDriven;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.JMSContext;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import jakarta.jms.TextMessage;
/**
* @author <a href="mailto:[email protected]">Carlo de Wolf</a>
*/
@MessageDriven(activationConfig = {
// queue does not exist but it will be corrected by jboss-ejb3.xml
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/mdbtest/notExistingQueue")
})
public class ReplyingMDB implements MessageListener {
@Resource(lookup = "java:/JmsXA")
private ConnectionFactory factory;
@Override
public void onMessage(Message message) {
try {
//System.out.println("Message " + message);
final Destination replyTo = message.getJMSReplyTo();
// ignore messages that need no reply
if (replyTo == null)
return;
try (
JMSContext context = factory.createContext()
) {
context.createProducer()
.setJMSCorrelationID(message.getJMSMessageID())
.send(replyTo, "replying " + ((TextMessage) message).getText());
}
} catch (JMSException e) {
throw new RuntimeException(e);
}
}
}
| 2,590 | 38.257576 | 118 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/messagedestination/MessagingEjb.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.messagedestination;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import jakarta.ejb.Stateless;
import jakarta.jms.Connection;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Queue;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
/**
* User: jpai
*/
@Stateless
public class MessagingEjb {
private ConnectionFactory connectionFactory;
private Connection connection;
private Session session;
@Resource(name = "myQueue")
private Queue queue;
@Resource(name = "myReplyQueue")
private Queue replyQueue;
@PreDestroy
protected void preDestroy() throws JMSException {
session.close();
connection.close();
}
@PostConstruct
protected void postConstruct() throws JMSException {
connection = this.connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
@Resource(mappedName = "java:/ConnectionFactory")
public void setConnectionFactory(final ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
public void sendTextMessage(final String msg) throws JMSException {
final TextMessage message = session.createTextMessage(msg);
this.sendMessage(message, queue, replyQueue);
}
public void reply(final Message message) throws JMSException {
final Destination destination = message.getJMSReplyTo();
// ignore messages that need no reply
if (destination == null) {
return;
}
final Message replyMsg = session.createTextMessage("replying to message: " + message.toString());
replyMsg.setJMSCorrelationID(message.getJMSMessageID());
this.sendMessage(replyMsg, destination, null);
}
public Message receiveMessage(final long waitInMillis) throws JMSException {
MessageConsumer consumer = this.session.createConsumer(replyQueue);
return consumer.receive(waitInMillis);
}
private void sendMessage(final Message message, final Destination destination, final Destination replyDestination) throws JMSException {
if (replyDestination != null) {
message.setJMSReplyTo(replyDestination);
}
final MessageProducer messageProducer = session.createProducer(destination);
messageProducer.send(message);
messageProducer.close();
}
}
| 3,737 | 33.611111 | 140 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/messagedestination/MessageDestinationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.messagedestination;
import jakarta.ejb.EJB;
import jakarta.jms.Message;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests message-destination resolution
*
*/
@RunWith(Arquillian.class)
@ServerSetup({MessageDestinationTestCase.JmsQueueSetup.class})
public class MessageDestinationTestCase {
@EJB (mappedName = "java:module/MessagingEjb")
private MessagingEjb messagingMdb;
static class JmsQueueSetup implements ServerSetupTask {
private JMSOperations jmsAdminOperations;
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient.getControllerClient());
jmsAdminOperations.createJmsQueue("messagedestinationtest/queue", "java:jboss/mdbtest/messageDestinationQueue");
jmsAdminOperations.createJmsQueue("messagedestinationtest/replyQueue", "java:jboss/mdbtest/messageDestinationReplyQueue");
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
if (jmsAdminOperations != null) {
jmsAdminOperations.removeJmsQueue("messagedestinationtest/queue");
jmsAdminOperations.removeJmsQueue("messagedestinationtest/replyQueue");
jmsAdminOperations.close();
}
}
}
@Deployment
public static Archive getDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "MessageDestinationTestCase.jar");
ejbJar.addPackage(MessageDestinationTestCase.class.getPackage());
ejbJar.addPackage(JMSOperations.class.getPackage());
ejbJar.addClass(JmsQueueSetup.class);
ejbJar.addAsManifestResource(MessageDestinationTestCase.class.getPackage(), "ejb-jar.xml", "ejb-jar.xml");
ejbJar.addAsManifestResource(MessageDestinationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
ejbJar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr \n"), "MANIFEST.MF");
return ejbJar;
}
/**
* Test a deployment descriptor based MDB
* @throws Exception
*/
@Test
public void testMEssageDestinationResolution() throws Exception {
this.messagingMdb.sendTextMessage("Say hello to " + MessagingEjb.class.getName());
final Message reply = this.messagingMdb.receiveMessage(5000);
Assert.assertNotNull("Reply message was null on reply queue", reply);
}
}
| 4,274 | 42.181818 | 135 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/cdi/MDBRAScopeCdiIntegrationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.cdi;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.io.IOException;
import java.util.Hashtable;
import java.util.List;
import java.util.PropertyPermission;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.as.test.integration.jca.ear.RarInsideEarReDeploymentTestCase;
import org.jboss.as.test.integration.jca.rar.MultipleAdminObject1;
import org.jboss.as.test.integration.management.ManagementOperations;
import org.jboss.as.test.integration.management.base.AbstractMgmtTestBase;
import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase;
import org.jboss.as.test.integration.management.util.MgmtOperationException;
import org.jboss.as.test.shared.TestSuiteEnvironment;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLElementWriter;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests that the CDI request scope is active in MDB invocations.
*
* @author baranowb
*/
@RunWith(Arquillian.class)
@ServerSetup({ MDBRAScopeCdiIntegrationTestCase.JmsQueueSetup.class })
public class MDBRAScopeCdiIntegrationTestCase extends ContainerResourceMgmtTestBase {
public static final String testDeploymentName = "test.jar";
public static final String deploymentName = "test-ear.ear";
public static final String subDeploymentName = "ear_packaged.rar";
private ModelNode raAddress_subdeployment;
private ModelNode raAddress_regular;
static class JmsQueueSetup implements ServerSetupTask {
private JMSOperations jmsAdminOperations;
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient);
jmsAdminOperations.createJmsQueue("mdb-cdi-test/queue", MDBProxy.QUEUE_JNDI_NAME);
jmsAdminOperations.createJmsQueue("mdb-cdi-test/reply-queue", MDBProxy.REPLY_QUEUE_JNDI_NAME);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
if (jmsAdminOperations != null) {
jmsAdminOperations.removeJmsQueue("mdb-cdi-test/queue");
jmsAdminOperations.removeJmsQueue("mdb-cdi-test/reply-queue");
jmsAdminOperations.close();
}
}
}
@Before
public void setup() throws Exception {
setupStandaloneRA();
setupSubdeployedRA();
}
@Override
protected void remove(ModelNode address) throws IOException, MgmtOperationException {
ModelNode operation = Util.createRemoveOperation(PathAddress.pathAddress(address));
operation.get(ModelDescriptionConstants.OPERATION_HEADERS, ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART).set(true);
ManagementOperations.executeOperation(getModelControllerClient(), operation);
}
/**
*
*/
private void setupSubdeployedRA() throws Exception {
// since it is created after deployment it needs activation
raAddress_subdeployment = new ModelNode();
raAddress_subdeployment.add("subsystem", "resource-adapters");
raAddress_subdeployment.add("resource-adapter", deploymentName + "#" + subDeploymentName);
raAddress_subdeployment.protect();
setup(raAddress_subdeployment, true);
}
/**
*
*/
private void setupStandaloneRA() throws Exception {
raAddress_regular = new ModelNode();
raAddress_regular.add("subsystem", "resource-adapters");
raAddress_regular.add("resource-adapter", subDeploymentName);
raAddress_regular.protect();
setup(raAddress_regular, false);
}
private void setup(final ModelNode address, final boolean activate) throws Exception {
ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
List<ModelNode> list = address.asList();
operation.get("archive").set(list.get(list.size() - 1).get("resource-adapter").asString());
executeOperation(operation);
ModelNode addr = address.clone();
addr.add("admin-objects", "Pool3");
operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(addr);
operation.get("jndi-name").set("java:jboss/exported/redeployed/Name3");
operation.get("class-name").set("org.jboss.as.test.integration.jca.rar.MultipleAdminObject1Impl");
executeOperation(operation);
if (activate) {
operation = new ModelNode();
operation.get(OP).set("activate");
operation.get(OP_ADDR).set(address);
executeOperation(operation);
}
}
@After
public void tearDown() throws Exception {
try {
remove(raAddress_subdeployment);
} finally {
remove(raAddress_regular);
}
}
@Deployment(name = deploymentName, order = 1)
public static EnterpriseArchive createEAR() throws Exception {
ResourceAdapterArchive raa = createRAR();
JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "xxx-ejbs.jar");
ejbJar.addClasses(/* MDBRAScopeCdiIntegrationTestCase.class, */CdiIntegrationMDB.class, RequestScopedCDIBean.class,
MDBProxy.class, MDBProxyBean.class, JMSMessagingUtil.class, JmsQueueSetup.class, TimeoutUtil.class)
.addPackage(JMSOperations.class.getPackage());
ejbJar.addAsManifestResource(new StringAsset(
"Dependencies: org.jboss.as.controller-client, org.jboss.as.controller, org.jboss.dmr \n"), "MANIFEST.MF");
ejbJar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, deploymentName);
ear.addAsModule(raa);
ear.addAsModule(ejbJar);
ear.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml");
return ear;
}
@Deployment(name = subDeploymentName, order = 2)
public static ResourceAdapterArchive createRAR() throws Exception {
ResourceAdapterArchive raa = ShrinkWrap.create(ResourceAdapterArchive.class, subDeploymentName);
JavaArchive ja = ShrinkWrap.create(JavaArchive.class, "multiple.jar");
ja.addPackage(MultipleAdminObject1.class.getPackage()).addClasses(MgmtOperationException.class, XMLElementReader.class,
XMLElementWriter.class);
ja.addPackage(AbstractMgmtTestBase.class.getPackage());
raa.addAsLibrary(ja);
raa.addAsManifestResource(RarInsideEarReDeploymentTestCase.class.getPackage(), "ra.xml", "ra.xml")
.addAsManifestResource(
new StringAsset(
"Dependencies: org.jboss.as.controller-client, org.jboss.as.controller, org.jboss.dmr\n"),
"MANIFEST.MF");
return raa;
}
@Deployment(name = testDeploymentName, order = 3)
public static JavaArchive createTestDeployment() throws Exception {
JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "test.jar");
testJar.addClass(MDBRAScopeCdiIntegrationTestCase.class);
return testJar;
}
private static String getEJBJNDIBinding() {
final String appName = "test-ear";
final String moduleName = "xxx-ejbs";
final String beanName = MDBProxyBean.class.getSimpleName();
final String viewName = MDBProxy.class.getName();
return "ejb:" + appName + "/" + moduleName + "/" + beanName + "!" + viewName;
}
@Test
public void testMe() throws Exception {
Assert.assertNotNull(getModelControllerClient());
try {
// deployer.deploy(deploymentName);
MDBProxy mdbProxy = (MDBProxy) getInitialContext().lookup(getEJBJNDIBinding());
mdbProxy.trigger();
} finally {
try {
} finally {
// deployer.undeploy(deploymentName);
}
}
}
private static InitialContext getInitialContext() throws NamingException {
final Hashtable env = new Hashtable();
env.put(Context.URL_PKG_PREFIXES, "org.wildfly.naming.client");
env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory.class.getName());
env.put(Context.PROVIDER_URL, "remote+http://" + TestSuiteEnvironment.getServerAddress() + ":" + 8080);
return new InitialContext(env);
}
}
| 11,111 | 41.412214 | 135 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/cdi/MDBCdiIntegrationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.cdi;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.jms.Message;
import jakarta.jms.Queue;
import jakarta.jms.TextMessage;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.common.jms.JMSOperations;
import org.jboss.as.test.integration.common.jms.JMSOperationsProvider;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.PropertyPermission;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Tests that the CDI request scope is active in MDB invocations.
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
@ServerSetup({MDBCdiIntegrationTestCase.JmsQueueSetup.class})
public class MDBCdiIntegrationTestCase {
private static final String REPLY_QUEUE_JNDI_NAME = "java:/mdb-cdi-test/replyQueue";
public static final String QUEUE_JNDI_NAME = "java:/mdb-cdi-test/mdb-cdi-test";
@EJB(mappedName = "java:module/JMSMessagingUtil")
private JMSMessagingUtil jmsUtil;
@Resource(mappedName = REPLY_QUEUE_JNDI_NAME)
private Queue replyQueue;
@Resource(mappedName = QUEUE_JNDI_NAME)
private Queue queue;
static class JmsQueueSetup implements ServerSetupTask {
private JMSOperations jmsAdminOperations;
@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
jmsAdminOperations = JMSOperationsProvider.getInstance(managementClient.getControllerClient());
jmsAdminOperations.createJmsQueue("mdb-cdi-test/queue", QUEUE_JNDI_NAME);
jmsAdminOperations.createJmsQueue("mdb-cdi-test/reply-queue", REPLY_QUEUE_JNDI_NAME);
}
@Override
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
if (jmsAdminOperations != null) {
jmsAdminOperations.removeJmsQueue("mdb-cdi-test/queue");
jmsAdminOperations.removeJmsQueue("mdb-cdi-test/reply-queue");
jmsAdminOperations.close();
}
}
}
@Deployment
public static Archive getDeployment() {
final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "mdb-cdi-integration-test.jar");
ejbJar.addClasses(CdiIntegrationMDB.class, RequestScopedCDIBean.class, JMSMessagingUtil.class, MDBCdiIntegrationTestCase.class,
JmsQueueSetup.class, TimeoutUtil.class)
.addPackage(JMSOperations.class.getPackage());
ejbJar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller-client, org.jboss.dmr \n"), "MANIFEST.MF");
ejbJar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
ejbJar.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission(TimeoutUtil.FACTOR_SYS_PROP, "read")), "permissions.xml");
return ejbJar;
}
@Test
public void testRequestScopeActiveDuringMdbInvocation() throws Exception {
final String goodMorning = "Good morning";
// send as ObjectMessage
this.jmsUtil.sendTextMessage(goodMorning, this.queue, this.replyQueue);
// wait for an reply
final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
// test the reply
final TextMessage textMessage = (TextMessage) reply;
Assert.assertEquals("Unexpected reply message on reply queue: " + this.replyQueue, CdiIntegrationMDB.REPLY, textMessage.getText());
}
}
| 5,183 | 41.491803 | 139 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/mdb/cdi/ScopeCdiIntegrationMDB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.mdb.cdi;
import jakarta.ejb.ActivationConfigProperty;
import jakarta.ejb.EJB;
import jakarta.ejb.MessageDriven;
import jakarta.inject.Inject;
import jakarta.jms.JMSException;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
import org.jboss.as.test.integration.ejb.mdb.JMSMessagingUtil;
import org.jboss.ejb3.annotation.ResourceAdapter;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = MDBProxy.QUEUE_JNDI_NAME)
})
@ResourceAdapter(value = MDBRAScopeCdiIntegrationTestCase.subDeploymentName)
public class ScopeCdiIntegrationMDB implements MessageListener {
private static final Logger logger = Logger.getLogger(ScopeCdiIntegrationMDB.class);
public static final String REPLY = "Successful message delivery!";
@EJB
private JMSMessagingUtil jmsMessagingUtil;
@Inject
private RequestScopedCDIBean requestScopedCDIBean;
@Override
public void onMessage(Message message) {
logger.trace("Received message " + message);
try {
if (message.getJMSReplyTo() != null) {
logger.trace("Replying to " + message.getJMSReplyTo());
// send a reply
this.jmsMessagingUtil.sendTextMessage(requestScopedCDIBean.sayHello(), message.getJMSReplyTo(), null);
}
} catch (JMSException jmse) {
throw new RuntimeException(jmse);
}
}
}
| 2,569 | 34.694444 | 118 |
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.