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/remote/worker/NonDefaultRemoteWorkerTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.remote.worker;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.LEVEL;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESPONSE_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SERVER;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WARNING;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WARNINGS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
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.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.logging.ControllerLogger;
import org.jboss.as.test.integration.ejb.jndi.Echo;
import org.jboss.as.test.integration.ejb.jndi.EchoBean;
import org.jboss.as.test.integration.ejb.jndi.RemoteEcho;
import org.jboss.as.test.shared.ServerSnapshot;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Simple test case to check if we get proper feedback on write op to listener->worker
* @author baranowb
*
*/
@RunWith(Arquillian.class)
@RunAsClient
public class NonDefaultRemoteWorkerTestCase {
@ArquillianResource
protected ManagementClient managementClient;
private static final String NAME_DEPLOYMENT = "echo-ejb-candy"; // module
private static final String NAME_WORKER = "puppeteer";
private static final PathAddress ADDRESS_WORKER = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, "io"),
PathElement.pathElement("worker", NAME_WORKER));
private static final PathAddress ADDRESS_HTTP_LISTENER = PathAddress.pathAddress(
PathElement.pathElement(SUBSYSTEM, "undertow"), PathElement.pathElement(SERVER, "default-server"),
PathElement.pathElement("http-listener", "default"));
private static final String BAD_LEVEL = "X_X";
private AutoCloseable serverSnapshot;
@Before
public void before() throws Exception {
serverSnapshot = ServerSnapshot.takeSnapshot(managementClient);
addWorker();
}
@After
public void after() throws Exception {
serverSnapshot.close();
}
@Test
public void testMe() throws Exception {
ModelNode result = setHttpListenerWorkerTo(NAME_WORKER,BAD_LEVEL);
Assert.assertTrue(result.toString(), Operations.isSuccessfulOutcome(result));
Assert.assertTrue(result.hasDefined(RESPONSE_HEADERS));
ModelNode responseHeaders = result.get(RESPONSE_HEADERS);
Assert.assertTrue(responseHeaders.hasDefined(WARNINGS));
List<ModelNode> warnings = responseHeaders.get(WARNINGS).asList();
Assert.assertTrue(warnings.size() == 2);
ModelNode warningLoggerLevel = warnings.get(0);
String message = warningLoggerLevel.get(WARNING).asString();
Assert.assertEquals(ControllerLogger.ROOT_LOGGER.couldntConvertWarningLevel(BAD_LEVEL), message);
Level level = Level.parse(warningLoggerLevel.get(LEVEL).asString());
Assert.assertEquals(Level.ALL,level);
ModelNode warningWorker = warnings.get(1);
message = warningWorker.get(WARNING).asString();
Assert.assertTrue(String.format("Expected message to start with WFLYUT0097: found %s", message), message.startsWith("WFLYUT0097:"));
level = Level.parse(warningWorker.get(LEVEL).asString());
Assert.assertEquals(Level.WARNING,level);
//default level is "WARNING, set to severe and check if there are warnings
result = setHttpListenerWorkerTo("default","SEVERE");
responseHeaders = result.get(RESPONSE_HEADERS);
Assert.assertFalse(responseHeaders.hasDefined(WARNINGS));
}
@Deployment(name = NAME_DEPLOYMENT)
public static JavaArchive create() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, NAME_DEPLOYMENT);
archive.addClass(EchoBean.class);
archive.addClass(RemoteEcho.class);
archive.addClass(Echo.class);
return archive;
}
private ModelNode setHttpListenerWorkerTo(final String name, final String level) throws IOException {
ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP_ADDR).set(ADDRESS_HTTP_LISTENER.toModelNode());
op.get(ModelDescriptionConstants.OP).set(WRITE_ATTRIBUTE_OPERATION);
op.get(NAME).set("worker");
op.get(VALUE).set(name);
op.get(OPERATION_HEADERS).get(ModelDescriptionConstants.WARNING_LEVEL).set(level);
final ModelControllerClient client = managementClient.getControllerClient();
ModelNode result = client.execute(op);
return result;
}
private void addWorker() throws Exception {
ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP_ADDR).set(ADDRESS_WORKER.toModelNode());
op.get(ModelDescriptionConstants.OP).set(ADD);
ModelNode result = managementClient.getControllerClient().execute(op);
Assert.assertTrue(result.toString(), Operations.isSuccessfulOutcome(result));
}
}
| 7,326 | 46.270968 | 140 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/security/RemoteIdentityTestCase.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.remote.security;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
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.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.security.common.Utils;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.permission.ElytronPermission;
import javax.security.auth.AuthPermission;
/**
* A test case to test an unsecured EJB setting the username and password before the call reaches a secured EJB.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class RemoteIdentityTestCase {
@ArquillianResource
private ManagementClient mgmtClient;
/**
* Creates a deployment application for this test.
*
* @return
* @throws IOException
*/
@Deployment
public static JavaArchive createDeployment() throws IOException {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, EJBUtil.APPLICATION_NAME + ".jar");
jar.addClasses(SecurityInformation.class, IntermediateAccess.class, EntryBean.class, SecuredBean.class, Util.class);
jar.addAsManifestResource(createPermissionsXmlAsset(
// testSwitched(), i.e. org.jboss.as.test.shared.integration.ejb.security.Util#getCLMLoginContext(username, password), needs the following
new AuthPermission("modifyPrincipals"),
// testSwitched(), i.e. org.jboss.as.test.shared.integration.ejb.security.Util#switchIdentity(String, String, Callable<T>, boolean), i.e. SecurityDomain.getCurrent(), needs the following
new ElytronPermission("getSecurityDomain"),
// and testSwitched() -> Util.switchIdentity() -> securityDomain.authenticate(...) needs the following
new ElytronPermission("authenticate")
), "permissions.xml");
return jar;
}
@Test
public void testDirect() throws Exception {
final Properties ejbClientConfiguration = EJBUtil.createEjbClientConfiguration(Utils.getHost(mgmtClient));
final SecurityInformation targetBean = EJBUtil.lookupEJB(SecuredBean.class, SecurityInformation.class, ejbClientConfiguration);
assertEquals("guest", targetBean.getPrincipalName());
}
@Test
public void testUnsecured() throws Exception {
final Properties ejbClientConfiguration = EJBUtil.createEjbClientConfiguration(Utils.getHost(mgmtClient));
final IntermediateAccess targetBean = EJBUtil.lookupEJB(EntryBean.class, IntermediateAccess.class, ejbClientConfiguration);
assertEquals("anonymous", targetBean.getPrincipalName());
}
@Test
public void testSwitched() throws Exception {
final Properties ejbClientConfiguration = EJBUtil.createEjbClientConfiguration(Utils.getHost(mgmtClient));
final IntermediateAccess targetBean = EJBUtil.lookupEJB(EntryBean.class, IntermediateAccess.class, ejbClientConfiguration);
assertEquals("user1", targetBean.getPrincipalName("user1", "password1"));
}
@Test
public void testNotSwitched() throws Exception {
final Properties ejbClientConfiguration = EJBUtil.createEjbClientConfiguration(Utils.getHost(mgmtClient));
final IntermediateAccess targetBean = EJBUtil.lookupEJB(EntryBean.class, IntermediateAccess.class, ejbClientConfiguration);
assertEquals("guest", targetBean.getPrincipalName(null, null));
}
}
| 5,048 | 44.486486 | 202 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/security/EntryBean.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.remote.security;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.ejb.EJBContext;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* An unsecured EJB used to test switching the identity before calling a secured EJB.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@Stateless
@Remote(IntermediateAccess.class)
public class EntryBean implements IntermediateAccess {
@Resource
private EJBContext context;
@EJB
private SecurityInformation ejb;
@Override
public String getPrincipalName() {
return context.getCallerPrincipal().getName();
}
@Override
public String getPrincipalName(String username, String password) {
try {
return Util.switchIdentity(username, password, () -> ejb.getPrincipalName());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
| 2,061 | 32.803279 | 89 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/security/IntermediateAccess.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.remote.security;
/**
* An extension to {@link SecurityInformation} that allows a username and password to be specified for calling a subsequent
* bean.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
public interface IntermediateAccess extends SecurityInformation {
String getPrincipalName(final String userName, final String password);
}
| 1,448 | 40.4 | 123 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/security/EJBUtil.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.remote.security;
import java.net.UnknownHostException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Utility class for looking up EJBs. It contains also some common constants for this test.
*
* @author Josef Cacek
*/
class EJBUtil {
protected static final String APPLICATION_NAME = "ejb-remote-security-test";
protected static final String CONNECTION_USERNAME = "guest";
protected static final String CONNECTION_PASSWORD = "guest";
// Public methods --------------------------------------------------------
/**
* Lookup for remote EJBs.
*
* @param beanImplClass
* @param remoteInterface
* @param ejbProperties
* @return
* @throws NamingException
*/
@SuppressWarnings("unchecked")
public static <T> T lookupEJB(Class<? extends T> beanImplClass, Class<T> remoteInterface, Properties ejbProperties) throws Exception {
final Properties jndiProperties = new Properties();
jndiProperties.putAll(ejbProperties);
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
// jndiProperties.put("jboss.naming.client.ejb.context", "true");
final Context context = new InitialContext(jndiProperties);
return (T) context.lookup("ejb:/" + APPLICATION_NAME + "/" + beanImplClass.getSimpleName() + "!"
+ remoteInterface.getName());
}
/**
* Creates {@link Properties} for the EJB client configuration.
*
* <pre>
* remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
*
* remote.connections=default
*
* remote.connection.default.host=localhost
* remote.connection.default.port = 8080
* remote.connection.default.username=guest
* remote.connection.default.password=guest
*
* remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
* </pre>
*
* @param hostName
* @return
* @throws UnknownHostException
*/
public static Properties createEjbClientConfiguration(String hostName) throws UnknownHostException {
final Properties pr = new Properties();
pr.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
pr.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
pr.put("remote.connections", "default");
pr.put("remote.connection.default.host", hostName);
pr.put("remote.connection.default.port", "8080");
pr.put("remote.connection.default.username", CONNECTION_USERNAME);
pr.put("remote.connection.default.password", CONNECTION_PASSWORD);
return pr;
}
}
| 3,879 | 38.191919 | 138 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/security/SecuredBean.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.remote.security;
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;
/**
* Simple EJB to return information about the current Principal.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@Stateless
@Remote(SecurityInformation.class)
@SecurityDomain("other")
@PermitAll
public class SecuredBean implements SecurityInformation {
@Resource
private EJBContext context;
@Override
public String getPrincipalName() {
return context.getCallerPrincipal().getName();
}
}
| 1,761 | 32.884615 | 75 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/security/HttpRemoteIdentityTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.security;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
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.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.shared.integration.ejb.security.Util;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.naming.client.WildFlyInitialContextFactory;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.MatchRule;
/**
* A test case to test an unsecured EJB setting the username and password before the call reaches a secured EJB.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class HttpRemoteIdentityTestCase {
@ContainerResource
private ManagementClient managementClient;
private static AuthenticationContext old;
@BeforeClass
public static void setup() {
AuthenticationConfiguration config = AuthenticationConfiguration.empty().useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, config);
old = AuthenticationContext.captureCurrent();
AuthenticationContext.getContextManager().setGlobalDefault(context);
}
@AfterClass
public static void after() {
AuthenticationContext.getContextManager().setGlobalDefault(old);
}
/**
* Creates a deployment application for this test.
*
* @return
* @throws IOException
*/
@Deployment
public static JavaArchive createDeployment() throws IOException {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, EJBUtil.APPLICATION_NAME + ".jar");
jar.addClasses(SecurityInformation.class, IntermediateAccess.class, EntryBean.class, SecuredBean.class, Util.class);
return jar;
}
@Test
public void testDirect() throws Exception {
final SecurityInformation targetBean = lookupEJB(SecuredBean.class, SecurityInformation.class);
assertEquals("user1", targetBean.getPrincipalName());
}
@Test
public void testUnsecured() throws Exception {
final IntermediateAccess targetBean = lookupEJB(EntryBean.class, IntermediateAccess.class);
assertEquals("anonymous", targetBean.getPrincipalName());
}
private Context getRemoteHTTPContext() throws Exception {
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
URI namingUri = getHttpUri();
env.put(Context.PROVIDER_URL, namingUri.toString());
return new InitialContext(env);
}
private URI getHttpUri() throws URISyntaxException {
URI webUri = managementClient.getWebUri();
return new URI("http", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "/wildfly-services", "", "");
}
private <T> T lookupEJB(Class<? extends T> beanImplClass, Class<T> remoteInterface) throws Exception {
final Context context = getRemoteHTTPContext();
return (T) context.lookup("ejb:/ejb-remote-security-test/" + beanImplClass.getSimpleName() + "!"
+ remoteInterface.getName());
}
}
| 4,886 | 38.41129 | 124 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/security/SecurityInformation.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.remote.security;
/**
* Interface to session beans to obtain information about the current identity of the caller.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
public interface SecurityInformation {
String getPrincipalName();
}
| 1,338 | 38.382353 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/invocationtimeout/EJBClientInvocationTimeoutTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.remote.invocationtimeout;
import java.net.URI;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import jakarta.ejb.EJBException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
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.network.NetworkUtils;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.EJBClientConnection;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.protocol.remote.RemoteTransportProvider;
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 org.wildfly.naming.client.WildFlyInitialContextFactory;
/**
* Test that it is possible to set invocation timeouts for EJB client invocations.
* @author Jan Martiska
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EJBClientInvocationTimeoutTestCase {
private static final String MODULE_NAME = "ejb-client-invocation-timeout";
final String INVOCATION_URL = "remote+http://" +
NetworkUtils.formatPossibleIpv6Address(System.getProperty("node0", "localhost")) + ":8080";
@Deployment(testable = false)
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(EJBClientInvocationTimeoutTestCase.class.getPackage());
return jar;
}
/**
* Set the timeout on a single EJB proxy using EJBClient.setInvocationTimeout method
*/
@Test
public void testSettingTimeoutOnParticularProxy() throws NamingException {
final Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
properties.put(Context.PROVIDER_URL, INVOCATION_URL);
final InitialContext ejbCtx = new InitialContext(properties);
try {
LongRunningBeanRemote bean = lookup(ejbCtx);
EJBClient.setInvocationTimeout(bean, 1, TimeUnit.SECONDS);
try {
bean.longRunningOperation();
Assert.fail("Call shouldn't be allowed to finish without throwing an exception");
} catch (EJBException e) {
Assert.assertTrue("Call should fail with a TimeoutException, but was: ",
e.getCausedByException() instanceof TimeoutException);
}
} finally {
ejbCtx.close();
}
}
/**
* Set the timeout for all invocations using a scoped context
*/
@Test
public void testScopedContext() throws NamingException {
final Properties properties = new Properties();
properties.put("org.jboss.ejb.client.scoped.context", "true");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
properties.put("remote.connections", "main");
properties.put("remote.connection.main.host", System.getProperty("node0", "127.0.0.1"));
properties.put("remote.connection.main.port", "8080");
properties.put("invocation.timeout", "1");
final InitialContext ejbCtx = new InitialContext(properties);
try {
LongRunningBeanRemote bean = lookup(ejbCtx);
try {
bean.longRunningOperation();
Assert.fail("Call shouldn't be allowed to finish without throwing an exception");
} catch (EJBException e) {
Assert.assertEquals("Call should fail with a TimeoutException",
TimeoutException.class, e.getCausedByException().getClass());
}
} finally {
ejbCtx.close();
}
}
/**
* Test setting the invocation timeout when initializing an EJB client context programmatically.
*/
@Test
public void testEjbClientContextBuilder() {
final EJBClientContext.Builder builder = new EJBClientContext.Builder();
builder.setInvocationTimeout(1);
builder.addTransportProvider(new RemoteTransportProvider());
builder.addClientConnection(
new EJBClientConnection.Builder().setDestination(URI.create(INVOCATION_URL)).build()
);
builder.build().run(() -> {
final Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
InitialContext ejbCtx = null;
try {
ejbCtx = new InitialContext(properties);
LongRunningBeanRemote bean = lookup(ejbCtx);
try {
bean.longRunningOperation();
Assert.fail("Call shouldn't be allowed to finish without throwing an exception");
} catch (EJBException e) {
Assert.assertEquals("Call should fail with a TimeoutException",
TimeoutException.class, e.getCausedByException().getClass());
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (ejbCtx != null) {
try {
ejbCtx.close();
} catch (NamingException e) {
}
}
}
});
}
public LongRunningBeanRemote lookup(InitialContext ctx) throws NamingException {
return (LongRunningBeanRemote)ctx.lookup(
"ejb:/" + MODULE_NAME + "/" + LongRunningBean.class.getSimpleName() + "!"
+ LongRunningBeanRemote.class.getName());
}
}
| 6,995 | 40.642857 | 106 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/invocationtimeout/LongRunningBean.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.remote.invocationtimeout;
import java.util.concurrent.TimeUnit;
import jakarta.ejb.Stateless;
/**
* @author Jan Martiska
*/
@Stateless
public class LongRunningBean implements LongRunningBeanRemote {
@Override
public void longRunningOperation() {
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
}
}
}
| 1,441 | 31.772727 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/invocationtimeout/LongRunningBeanRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.remote.invocationtimeout;
import jakarta.ejb.Remote;
/**
* @author Jan Martiska
*/
@Remote
public interface LongRunningBeanRemote {
void longRunningOperation();
}
| 1,239 | 33.444444 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/Echo.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.remote.distinctname;
/**
* @author Jaikiran Pai
*/
public interface Echo {
String echo(String msg);
}
| 1,175 | 36.935484 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/StatelessEcho.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.remote.distinctname;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@Remote(Echo.class)
public class StatelessEcho implements Echo {
@Override
public String echo(String msg) {
return msg;
}
}
| 1,334 | 32.375 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/SingletonEcho.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.remote.distinctname;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
/**
* @author Jaikiran Pai
*/
@Singleton
@Remote(Echo.class)
public class SingletonEcho implements Echo {
@Override
public String echo(String msg) {
return msg;
}
}
| 1,333 | 33.205128 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/EarDeploymentDistinctNameTestCase.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.remote.distinctname;
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.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.runner.RunWith;
/**
* Tests that the distinct-name configured in the jboss-app.xml of an EAR deployment is taken into
* consideration during remote EJB invocations.
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EarDeploymentDistinctNameTestCase extends DistinctNameTestCase {
private static final String APP_NAME = "remote-ejb-distinct-name";
private static final String DISTINCT_NAME = "distinct-name-in-jboss-app-xml";
private static final String MODULE_NAME = "remote-ejb-distinct-name-ear-test-case";
@Deployment(testable = false)
public static EnterpriseArchive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(EarDeploymentDistinctNameTestCase.class.getPackage());
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
ear.addAsModule(jar);
ear.addAsManifestResource(EarDeploymentDistinctNameTestCase.class.getPackage(), "jboss-app.xml", "jboss-app.xml");
return ear;
}
@Override
protected String getAppName() {
return APP_NAME;
}
@Override
protected String getModuleName() {
return MODULE_NAME;
}
@Override
protected String getDistinctName() {
return DISTINCT_NAME;
}
}
| 2,787 | 36.675676 | 122 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/JarDeploymentDistinctNameTestCase.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.remote.distinctname;
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.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.runner.RunWith;
/**
* Tests that the distinct-name configured in the jboss-ejb3.xml of an EJB jar deployment is taken into
* consideration during remote EJB invocations.
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@RunAsClient
public class JarDeploymentDistinctNameTestCase extends DistinctNameTestCase {
private static final String APP_NAME = "";
private static final String DISTINCT_NAME = "distinct-name-in-jboss-ejb3-xml";
private static final String MODULE_NAME = "remote-ejb-distinct-name-jar-test-case";
@Deployment(testable = false)
public static JavaArchive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(JarDeploymentDistinctNameTestCase.class.getPackage());
jar.addAsManifestResource(JarDeploymentDistinctNameTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml");
return jar;
}
@Override
protected String getAppName() {
return APP_NAME;
}
@Override
protected String getModuleName() {
return MODULE_NAME;
}
@Override
protected String getDistinctName() {
return DISTINCT_NAME;
}
}
| 2,580 | 34.356164 | 124 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/DistinctNameTestCase.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.remote.distinctname;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
/**
* Tests that invocation on EJBs deployed in a deployment with distinct name works successfully
*
* @author Jaikiran Pai
*/
public abstract class DistinctNameTestCase {
private static Context context;
@BeforeClass
public static void beforeClass() throws Exception {
final Hashtable props = new Hashtable();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
context = new InitialContext(props);
}
/**
* Test that invocation on a stateless bean, deployed in a deployment with distinct-name, works fine
*
* @throws Exception
*/
@Test
public void testRemoteSLSBInvocation() throws Exception {
final Echo bean = (Echo) context.lookup("ejb:" + getAppName() + "/" + getModuleName() + "/" + getDistinctName()
+ "/" + StatelessEcho.class.getSimpleName() + "!" + Echo.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", bean);
final String msg = "Hello world from a really remote client!!!";
final String echo = bean.echo(msg);
Assert.assertEquals("Unexpected echo returned from remote stateless bean", msg, echo);
}
/**
* Test that invocation on a stateful bean, deployed in a deployment with distinct-name, works fine
*
* @throws Exception
*/
@Test
public void testRemoteSFSBInvocation() throws Exception {
final Echo bean = (Echo) context.lookup("ejb:" + getAppName() + "/" + getModuleName() + "/" + getDistinctName()
+ "/" + StatefulEcho.class.getSimpleName() + "!" + Echo.class.getName() + "?stateful");
Assert.assertNotNull("Lookup returned a null bean proxy", bean);
final String msg = "Hello world from a really remote client!!!";
final String echo = bean.echo(msg);
Assert.assertEquals("Unexpected echo returned from remote stateful bean", msg, echo);
}
/**
* Test that invocation on a singleton bean, deployed in a deployment with distinct-name, works fine
*
* @throws Exception
*/
@Test
public void testRemoteSingletonInvocation() throws Exception {
final Echo bean = (Echo) context.lookup("ejb:" + getAppName() + "/" + getModuleName() + "/" + getDistinctName()
+ "/" + SingletonEcho.class.getSimpleName() + "!" + Echo.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", bean);
final String msg = "Hello world from a really remote client!!!";
final String echo = bean.echo(msg);
Assert.assertEquals("Unexpected echo returned from remote singleton bean", msg, echo);
}
protected abstract String getAppName();
protected abstract String getModuleName();
protected abstract String getDistinctName();
}
| 4,071 | 38.921569 | 119 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/StatefulEcho.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.remote.distinctname;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
/**
* @author Jaikiran Pai
*/
@Stateful
@Remote(Echo.class)
public class StatefulEcho implements Echo {
@Override
public String echo(String msg) {
return msg;
}
}
| 1,330 | 33.128205 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/defaultname/Echo.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.remote.distinctname.defaultname;
/**
* @author Jaikiran Pai
*/
public interface Echo {
String echo(String msg);
}
| 1,188 | 36.15625 | 74 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/defaultname/StatelessEcho.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.remote.distinctname.defaultname;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* @author Jaikiran Pai
*/
@Stateless
@Remote(Echo.class)
public class StatelessEcho implements Echo {
@Override
public String echo(String msg) {
return msg;
}
}
| 1,346 | 32.675 | 74 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/defaultname/SingletonEcho.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.remote.distinctname.defaultname;
import jakarta.ejb.Remote;
import jakarta.ejb.Singleton;
/**
* @author Jaikiran Pai
*/
@Singleton
@Remote(Echo.class)
public class SingletonEcho implements Echo {
@Override
public String echo(String msg) {
return msg;
}
}
| 1,345 | 33.512821 | 74 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/defaultname/StatefulEcho.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.remote.distinctname.defaultname;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
/**
* @author Jaikiran Pai
*/
@Stateful
@Remote(Echo.class)
public class StatefulEcho implements Echo {
@Override
public String echo(String msg) {
return msg;
}
}
| 1,342 | 33.435897 | 74 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/distinctname/defaultname/DefaultDistinctNameTestCase.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.remote.distinctname.defaultname;
import javax.naming.Context;
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.ejb.remote.common.EJBManagementUtil;
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 invocation on EJBs deployed in a deployment with distinct name works successfully
*
* @author Jaikiran Pai
*/
@ServerSetup(DefaultDistinctNameTestCase.DefaultDistinctNameTestCaseSetup.class)
@RunWith(Arquillian.class)
public class DefaultDistinctNameTestCase {
@ArquillianResource
private Context context;
private static final String APP_NAME = "";
private static final String DISTINCT_NAME = "distinct-name-in-jboss-ejb3-xml";
private static final String MODULE_NAME = "remote-ejb-distinct-name-jar-test-case";
static class DefaultDistinctNameTestCaseSetup implements ServerSetupTask {
@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
EJBManagementUtil.setDefaultDistinctName(managementClient, DISTINCT_NAME);
}
@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
EJBManagementUtil.setDefaultDistinctName(managementClient, null);
}
}
@Deployment(testable = false)
public static JavaArchive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(DefaultDistinctNameTestCase.class.getPackage());
return jar;
}
/**
* Test that invocation on a stateless bean, deployed in a deployment with distinct-name, works fine
*
* @throws Exception
*/
@Test
public void testRemoteSLSBInvocation() throws Exception {
final Echo bean = (Echo) context.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME
+ "/" + StatelessEcho.class.getSimpleName() + "!" + Echo.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", bean);
final String msg = "Hello world from a really remote client!!!";
final String echo = bean.echo(msg);
Assert.assertEquals("Unexpected echo returned from remote stateless bean", msg, echo);
}
/**
* Test that invocation on a stateful bean, deployed in a deployment with distinct-name, works fine
*
* @throws Exception
*/
@Test
public void testRemoteSFSBInvocation() throws Exception {
final Echo bean = (Echo) context.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME
+ "/" + StatefulEcho.class.getSimpleName() + "!" + Echo.class.getName() + "?stateful");
Assert.assertNotNull("Lookup returned a null bean proxy", bean);
final String msg = "Hello world from a really remote client!!!";
final String echo = bean.echo(msg);
Assert.assertEquals("Unexpected echo returned from remote stateful bean", msg, echo);
}
/**
* Test that invocation on a singleton bean, deployed in a deployment with distinct-name, works fine
*
* @throws Exception
*/
@Test
public void testRemoteSingletonInvocation() throws Exception {
final Echo bean = (Echo) context.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME
+ "/" + SingletonEcho.class.getSimpleName() + "!" + Echo.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", bean);
final String msg = "Hello world from a really remote client!!!";
final String echo = bean.echo(msg);
Assert.assertEquals("Unexpected echo returned from remote singleton bean", msg, echo);
}
}
| 5,237 | 41.241935 | 114 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/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.remote.async;
import jakarta.ejb.Local;
import java.util.concurrent.Future;
/**
* @author Stuart Douglas
*/
@Local
public interface LocalInterface {
void passByReference(String[] value);
Future<Void> alwaysFail() throws AppException;
}
| 1,308 | 34.378378 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/AppException.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.remote.async;
import jakarta.ejb.ApplicationException;
/**
*
*/
@ApplicationException
public class AppException extends Exception {
public AppException(final String message) {
super(message);
}
}
| 1,286 | 32.868421 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/RemoteAsyncInvocationTestCase.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.remote.async;
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.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 javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.PropertyPermission;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
/**
* Simple remote ejb tests
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class RemoteAsyncInvocationTestCase {
private static final String ARCHIVE_NAME = "RemoteInvocationTest";
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar");
jar.addPackage(RemoteAsyncInvocationTestCase.class.getPackage());
jar.addClass(TimeoutUtil.class);
jar.addAsManifestResource(createPermissionsXmlAsset(
new PropertyPermission("ts.timeout.factor", "read")
), "permissions.xml");
return jar;
}
@ArquillianResource
private InitialContext iniCtx;
protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException {
return interfaceType.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanName + "!" + interfaceType.getName()));
}
@Test
public void testRemoteAsyncInvocationByValue() throws Exception {
StatelessRemoteBean.reset();
String[] array = {"hello"};
RemoteInterface remote = lookup(StatelessRemoteBean.class.getSimpleName(), RemoteInterface.class);
remote.modifyArray(array);
StatelessRemoteBean.startLatch.countDown();
if (!StatelessRemoteBean.doneLatch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("Invocation was not asynchronous");
}
Assert.assertEquals("hello", array[0]);
}
@Test
public void testRemoteAsyncInvocationByValueFromEjbInjcation() throws Exception {
StatelessRemoteBean.reset();
String[] array = {"hello"};
StatelessRunningBean remote = lookup(StatelessRunningBean.class.getSimpleName(), StatelessRunningBean.class);
remote.modifyArray(array);
StatelessRemoteBean.startLatch.countDown();
if (!StatelessRemoteBean.doneLatch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("Invocation was not asynchronous");
}
Assert.assertEquals("hello", array[0]);
}
@Test
public void testLocalAsyncInvocationByValue() throws Exception {
StatelessRemoteBean.reset();
String[] array = {"hello"};
LocalInterface remote = lookup(StatelessRemoteBean.class.getSimpleName(), LocalInterface.class);
remote.passByReference(array);
StatelessRemoteBean.startLatch.countDown();
if (!StatelessRemoteBean.doneLatch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("Invocation was not asynchronous");
}
Assert.assertEquals("goodbye", array[0]);
}
@Test
public void testReturnAsyncInvocationReturningValue() throws Exception {
RemoteInterface remote = lookup(StatelessRemoteBean.class.getSimpleName(), RemoteInterface.class);
Future<String> value = remote.hello();
Assert.assertEquals("hello", value.get(5, TimeUnit.SECONDS));
}
/**
* Tests that an exception thrown from a async EJB invocation, leads to the returned
* {@link Future} to be marked as {@link Future#isDone() done}
*
* @throws Exception
* @see <a href="https://issues.jboss.org/browse/WFLY-9624">WFLY-9624</a> for more details
*/
@Test
public void testFutureDoneInLocalAsyncInvocation() throws Exception {
final LocalInterface localBean = lookup(StatelessRemoteBean.class.getSimpleName(), LocalInterface.class);
final Future<Void> future = localBean.alwaysFail();
// try a few times to make sure it's "done". it should be done immediately, so trying just
// a few times should be fine
for (int i = 0; i < 5; i++) {
if (future.isDone()) {
break;
}
// wait for a while
Thread.sleep(TimeoutUtil.adjust(500));
}
Assert.assertTrue("Async invocation which was expected to fail immediately, wasn't considered \"done\"", future.isDone());
try {
// once the future is marked as done, the get should immediately return, but we
// do send the timeouts here, just so that we don't end up blocking in this testcase
// due to any bugs in the implementation of the returned future
future.get(1, TimeUnit.SECONDS);
Assert.fail("Async invocation was expected to throw an application exception, but it didn't");
} catch (ExecutionException ee) {
// we expect a AppException
if (!(ee.getCause() instanceof AppException)) {
throw ee;
}
}
}
}
| 6,480 | 40.280255 | 130 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/StatelessRunningBean.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.remote.async;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless
public class StatelessRunningBean {
@EJB
private RemoteInterface remoteInterface;
public void modifyArray(final String[] array) {
remoteInterface.modifyArray(array);
}
}
| 1,370 | 32.439024 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/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.remote.async;
import jakarta.ejb.Remote;
import java.util.concurrent.Future;
/**
* @author Stuart Douglas
*/
@Remote
public interface RemoteInterface {
void modifyArray(final String[] array);
Future<String> hello();
}
| 1,291 | 33 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/StatelessRemoteBean.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.remote.async;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Stateless;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/**
*
*/
@Stateless
public class StatelessRemoteBean implements RemoteInterface, LocalInterface {
public static volatile CountDownLatch doneLatch = new CountDownLatch(1);
public static volatile CountDownLatch startLatch = new CountDownLatch(1);
public static void reset() {
doneLatch = new CountDownLatch(1);
startLatch = new CountDownLatch(1);
}
@Asynchronous
public void modifyArray(final String[] array) {
try {
if(!startLatch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("Invocation was not asynchronous");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
array[0] = "goodbye";
doneLatch.countDown();
}
@Asynchronous
public Future<String> hello() {
return new AsyncResult<String>("hello");
}
@Override
@Asynchronous
public Future<Void> alwaysFail() throws AppException {
throw new AppException("Intentionally thrown");
}
@Override
@Asynchronous
public void passByReference(final String[] array) {
try {
if(!startLatch.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException("Invocation was not asynchronous");
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
array[0] = "goodbye";
doneLatch.countDown();
}
}
| 2,759 | 31.470588 | 78 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/classloading/ReturnObject.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, 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.remote.async.classloading;
import java.io.Serializable;
/**
* @author baranowb
*
*/
public class ReturnObject implements Serializable {
private final String value;
private static int count = 0;
/**
* @param value
*/
public ReturnObject(String value) {
super();
this.value = value;
ReturnObject.count++;
}
/**
* @return the value
*/
public String getValue() {
return value;
}
/**
* @return the count
*/
public static int getCount() {
return count;
}
}
| 1,640 | 26.813559 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/classloading/AsyncRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, 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.remote.async.classloading;
import java.util.concurrent.Future;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Remote;
/**
* @author baranowb
*
*/
@Remote
public interface AsyncRemote {
@Asynchronous
Future<ReturnObject> testAsync(String x);
@Asynchronous
Future<ReturnObject> testAsyncNull(String x);
}
| 1,397 | 32.285714 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/classloading/AsyncReceiverServlet.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, 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.remote.async.classloading;
import java.io.IOException;
import jakarta.ejb.EJB;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
/**
* @author baranowb
*
*/
@WebServlet(name = "AsyncReceiverServer", urlPatterns = { "/*" })
public class AsyncReceiverServlet extends HttpServlet {
@EJB(lookup="java:global/wildName/ejbjar/AsyncRemoteEJB!org.jboss.as.test.integration.ejb.remote.async.classloading.AsyncRemote")
private AsyncRemote remoter;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
if(req.getParameter("null")!=null){
ReturnObject value = remoter.testAsyncNull("NULL!").get();
} else {
ReturnObject value = remoter.testAsync("Trololo").get();
}
} catch (Exception e) {
e.printStackTrace();
throw new ServletException(e);
}
resp.setStatus(200);
resp.flushBuffer();
}
}
| 2,251 | 36.533333 | 133 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/classloading/AsyncRemoteEJB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, 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.remote.async.classloading;
import java.util.concurrent.Future;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Stateless;
/**
* @author baranowb
*
*/
@Stateless
public class AsyncRemoteEJB implements AsyncRemote {
@Override
@Asynchronous
public Future<ReturnObject> testAsync(final String x) {
return new AsyncResult<ReturnObject>(new ReturnObject(x));
}
@Override
@Asynchronous
public Future<ReturnObject> testAsyncNull(String x) {
return null;
}
}
| 1,609 | 30.568627 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/async/classloading/AsyncFutureTestCase.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.remote.async.classloading;
import java.io.IOException;
import org.junit.Assert;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
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.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.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Test if Future can be returned as Async call
*
* @author baranowb
*/
@RunWith(Arquillian.class)
@RunAsClient
public class AsyncFutureTestCase {
public static final String DEPLOYMENT_UNIT_JAR = "ejbjar";
public static final String DEPLOYMENT_NAME_JAR = DEPLOYMENT_UNIT_JAR + ".jar";
public static final String DEPLOYMENT_UNIT_EAR = "wildName";
public static final String DEPLOYMENT_NAME_EAR = DEPLOYMENT_UNIT_EAR + ".ear";
public static final String DEPLOYMENT_UNIT_WAR = "war-with-attitude";
public static final String DEPLOYMENT_NAME_WAR = DEPLOYMENT_UNIT_WAR + ".war";
public static final String DEPLOYMENT_NAME_COMMON_JAR = "common.jar";
private static HttpClient HTTP_CLIENT;
@BeforeClass
public static void beforeClass() throws Exception {
HTTP_CLIENT = new DefaultHttpClient();
}
@AfterClass
public static void afterClass() {
HTTP_CLIENT = null;
}
@ContainerResource
private ManagementClient managementClient;
@Deployment(name = DEPLOYMENT_UNIT_EAR, order = 0)
public static Archive<EnterpriseArchive> createEAR() throws Exception {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, DEPLOYMENT_NAME_JAR);
jar.addClass(AsyncRemoteEJB.class);
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, DEPLOYMENT_NAME_EAR);
ear.addAsModule(jar);
ear.addAsLibraries(createCommonJar());
return ear;
}
@Deployment(name = DEPLOYMENT_UNIT_WAR, order = 1)
public static Archive<WebArchive> createWAR() throws Exception {
final WebArchive war = ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME_WAR);
war.addClass(AsyncReceiverServlet.class);
war.addAsLibraries(createCommonJar());
return war;
}
private static JavaArchive createCommonJar() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, DEPLOYMENT_NAME_COMMON_JAR);
jar.addClasses(ReturnObject.class, AsyncRemote.class);
return jar;
}
@Test
public void testAsyncResultInServlet() throws Exception {
final String requestURL = managementClient.getWebUri() + "/" + DEPLOYMENT_UNIT_WAR + "/x";
final HttpGet get = new HttpGet(requestURL);
final HttpResponse response = HTTP_CLIENT.execute(get);
// consume!!
consume(response);
Assert.assertEquals(requestURL + ">" + response.getStatusLine().getReasonPhrase(), 200, response.getStatusLine().getStatusCode());
}
@Test
public void testAsyncNullResultInServlet() throws Exception {
final String requestURL = managementClient.getWebUri() + "/" + DEPLOYMENT_UNIT_WAR + "/x?null=true";
final HttpGet get = new HttpGet(requestURL);
final HttpResponse response = HTTP_CLIENT.execute(get);
// consume!!
consume(response);
Assert.assertEquals(requestURL + ">" + response.getStatusLine().getReasonPhrase(), 200, response.getStatusLine().getStatusCode());
}
private void consume(final HttpResponse httpResponse) {
final HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
try {
EntityUtils.consume(httpEntity);
} catch (IOException e) {
//dont care?
e.printStackTrace();
}
}
}
}
| 5,433 | 38.093525 | 138 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/common/EJBManagementUtil.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.remote.common;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.COMPOSITE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PORT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REMOVE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_GROUP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SOCKET_BINDING_REF;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STEPS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
import static org.jboss.as.test.integration.management.util.ModelUtil.createOpNode;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import javax.security.auth.callback.CallbackHandler;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.ClientConstants;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.network.NetworkUtils;
import org.jboss.as.remoting.RemotingExtension;
import org.jboss.dmr.ModelNode;
import org.jboss.logging.Logger;
/**
* @author Jaikiran Pai
*/
public class EJBManagementUtil {
public static final String MESSAGE_DRIVEN = "message-driven-bean";
public static final String SINGLETON = "singleton-bean";
public static final String STATELESS = "stateless-session-bean";
public static final String STATEFUL = "stateful-session-bean";
private static final String CONNECTOR_REF = "connector-ref";
private static final String DEFAULT_ENTITY_BEAN_INSTANCE_POOL = "default-entity-bean-instance-pool";
private static final String DEFAULT_ENTITY_BEAN_OPTIMISTIC_LOCKING = "default-entity-bean-optimistic-locking";
private static final String INSTANCE_ACQUISITION_TIMEOUT = "timeout";
private static final String INSTANCE_ACQUISITION_TIMEOUT_UNIT = "timeout-unit";
private static final String MAX_POOL_SIZE = "max-pool-size";
private static final String REMOTE = "remote";
private static final String SERVICE = "service";
private static final String STRICT_MAX_BEAN_INSTANCE_POOL = "strict-max-bean-instance-pool";
private static final String SUBSYSTEM_NAME = "ejb3";
private static final Logger logger = Logger.getLogger(EJBManagementUtil.class);
/**
* Returns the EJB remoting connector port that can be used for EJB remote invocations
*
* @param managementServerHostName The hostname of the server
* @param managementPort The management port
* @return
*/
public static int getEJBRemoteConnectorPort(final String managementServerHostName, final int managementPort, final CallbackHandler handler) {
final ModelControllerClient modelControllerClient = getModelControllerClient(managementServerHostName, managementPort, handler);
try {
// first get the remote-connector from the EJB3 subsystem to find the remote connector ref
// /subsystem=ejb3/service=remote:read-attribute(name=connector-ref)
final ModelNode readConnectorRefAttribute = new ModelNode();
readConnectorRefAttribute.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION);
readConnectorRefAttribute.get(NAME).set(CONNECTOR_REF);
final PathAddress ejbRemotingServiceAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME),
PathElement.pathElement(SERVICE, REMOTE));
readConnectorRefAttribute.get(OP_ADDR).set(ejbRemotingServiceAddress.toModelNode());
// execute the read-attribute
final ModelNode connectorRefResult = execute(modelControllerClient, readConnectorRefAttribute);
final String connectorRef = connectorRefResult.get(RESULT).asString();
// now get the socket-binding ref for this connector ref, from the remoting subsystem
// /subsystem=remoting/connector=<connector-ref>:read-attribute(name=socket-binding)
final ModelNode readSocketBindingRefAttribute = new ModelNode();
readSocketBindingRefAttribute.get(OP).set(READ_ATTRIBUTE_OPERATION);
readSocketBindingRefAttribute.get(NAME).set(SOCKET_BINDING);
final PathAddress remotingSubsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME),
PathElement.pathElement("connector", connectorRef));
readSocketBindingRefAttribute.get(OP_ADDR).set(remotingSubsystemAddress.toModelNode());
// execute the read-attribute
final ModelNode socketBindingRefResult = execute(modelControllerClient, readSocketBindingRefAttribute);
final String socketBindingRef = socketBindingRefResult.get(RESULT).asString();
// now get the port value of that socket binding ref
// /socket-binding-group=standard-sockets/socket-binding=<socket-binding-ref>:read-attribute(name=port)
final ModelNode readPortAttribute = new ModelNode();
readPortAttribute.get(OP).set(READ_ATTRIBUTE_OPERATION);
readPortAttribute.get(NAME).set(PORT);
// TODO: "standard-sockets" group is hardcoded for now
final PathAddress socketBindingAddress = PathAddress.pathAddress(PathElement.pathElement(SOCKET_BINDING_GROUP, "standard-sockets"),
PathElement.pathElement(SOCKET_BINDING, socketBindingRef));
readPortAttribute.get(OP_ADDR).set(socketBindingAddress.toModelNode());
// execute the read-attribute
final ModelNode portResult = execute(modelControllerClient, readPortAttribute);
return portResult.get(RESULT).asInt();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} finally {
// close the controller client connection
try {
modelControllerClient.close();
} catch (IOException e) {
logger.warn("Error closing model controller client", e);
}
}
}
public static void createRemoteOutboundSocket(final String managementServerHostName, final int managementPort,
final String socketGroupName, final String outboundSocketName, final String destinationHost, final int destinationPort,
final CallbackHandler callbackHandler) {
final ModelControllerClient modelControllerClient = getModelControllerClient(managementServerHostName, managementPort, callbackHandler);
try {
// /socket-binding-group=<group-name>/remote-destination-outbound-socket-binding=<name>:add(host=<host>, port=<port>)
final ModelNode outboundSocketAddOperation = new ModelNode();
outboundSocketAddOperation.get(OP).set(ADD);
final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(SOCKET_BINDING_GROUP, socketGroupName),
PathElement.pathElement(ModelDescriptionConstants.REMOTE_DESTINATION_OUTBOUND_SOCKET_BINDING, outboundSocketName));
outboundSocketAddOperation.get(OP_ADDR).set(address.toModelNode());
// setup the other parameters for the add operation
outboundSocketAddOperation.get(HOST).set(destinationHost);
outboundSocketAddOperation.get(PORT).set(destinationPort);
// execute the add operation
execute(modelControllerClient, outboundSocketAddOperation);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} finally {
// close the controller client connection
try {
modelControllerClient.close();
} catch (IOException e) {
logger.warn("Error closing model controller client", e);
}
}
}
public static final void createSocketBinding(final ModelControllerClient modelControllerClient, final String name, int port) {
ModelNode op = createOpNode("socket-binding-group=standard-sockets/socket-binding=" + name, ADD);
op.get(NAME).set("port");
op.get(VALUE).set(port);
try {
execute(modelControllerClient, op);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static final void removeSocketBinding(final ModelControllerClient modelControllerClient, final String name) {
ModelNode op = createOpNode("socket-binding-group=standard-sockets/socket-binding=" + name, REMOVE);
try {
execute(modelControllerClient, op);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void createLocalOutboundSocket(final ModelControllerClient modelControllerClient,
final String socketGroupName, final String outboundSocketName,
final String socketBindingRef,
final CallbackHandler callbackHandler) {
try {
// /socket-binding-group=<group-name>/local-destination-outbound-socket-binding=<name>:add(socket-binding-ref=<ref>)
final ModelNode outboundSocketAddOperation = new ModelNode();
outboundSocketAddOperation.get(OP).set(ADD);
final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(SOCKET_BINDING_GROUP, socketGroupName),
PathElement.pathElement(ModelDescriptionConstants.LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING, outboundSocketName));
outboundSocketAddOperation.get(OP_ADDR).set(address.toModelNode());
// setup the other parameters for the add operation
outboundSocketAddOperation.get(SOCKET_BINDING_REF).set(socketBindingRef);
// execute the add operation
execute(modelControllerClient, outboundSocketAddOperation);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public static void removeLocalOutboundSocket(final ModelControllerClient modelControllerClient,
final String socketGroupName, final String outboundSocketName,
final CallbackHandler callbackHandler) {
try {
// /socket-binding-group=<group-name>/local-destination-outbound-socket-binding=<name>:remove()
final ModelNode outboundSocketRemoveOperation = new ModelNode();
outboundSocketRemoveOperation.get(OP).set(REMOVE);
final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(SOCKET_BINDING_GROUP, socketGroupName),
PathElement.pathElement(ModelDescriptionConstants.LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING, outboundSocketName));
outboundSocketRemoveOperation.get(OP_ADDR).set(address.toModelNode());
outboundSocketRemoveOperation.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
// execute the remove operation
execute(modelControllerClient, outboundSocketRemoveOperation);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public static void createRemoteOutboundConnection(final ModelControllerClient modelControllerClient,
final String connectionName, final String outboundSocketRef,
final Map<String, String> connectionCreationOptions, final CallbackHandler callbackHandler) {
try {
// /subsystem=remoting/remote-outbound-connection=<name>:add(outbound-socket-ref=<ref>)
final ModelNode addRemoteOutboundConnection = new ModelNode();
addRemoteOutboundConnection.get(OP).set(ADD);
final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME),
PathElement.pathElement("remote-outbound-connection", connectionName));
addRemoteOutboundConnection.get(OP_ADDR).set(address.toModelNode());
// set the other properties
addRemoteOutboundConnection.get("outbound-socket-binding-ref").set(outboundSocketRef);
addRemoteOutboundConnection.get("authentication-context").set("outbound");
final ModelNode op = Util.getEmptyOperation(COMPOSITE, new ModelNode());
final ModelNode steps = op.get(STEPS);
final ModelNode addAuthConfig = Util.createAddOperation(
PathAddress.pathAddress(
PathElement.pathElement(SUBSYSTEM, "elytron"),
PathElement.pathElement("authentication-configuration", "outbound")));
addAuthConfig.get("authentication-name").set("user1");
final ModelNode credentialReference = new ModelNode();
credentialReference.get("clear-text").set("password1");
addAuthConfig.get("credential-reference").set(credentialReference);
addAuthConfig.get("protocol").set("remote+http");
final ModelNode addAuthContext = Util.createAddOperation(
PathAddress.pathAddress(
PathElement.pathElement(SUBSYSTEM, "elytron"),
PathElement.pathElement("authentication-context", "outbound")));
final ModelNode matchRule = new ModelNode();
matchRule.get("authentication-configuration").set("outbound");
addAuthContext.get("match-rules").add(matchRule);
steps.add(addAuthConfig);
steps.add(addAuthContext);
steps.add(addRemoteOutboundConnection);
// execute the add operation
if (!connectionCreationOptions.isEmpty()) {
for (Map.Entry<String, String> property : connectionCreationOptions.entrySet()) {
ModelNode propertyOp = new ModelNode();
propertyOp.get(OP).set(ADD);
propertyOp.get(OP_ADDR).set(address.toModelNode()).add("property", property.getKey());
propertyOp.get("value").set(property.getValue());
steps.add(propertyOp);
}
}
execute(modelControllerClient, op);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public static void removeRemoteOutboundConnection(final ModelControllerClient modelControllerClient,
final String connectionName, final CallbackHandler callbackHandler) {
try {
// /subsystem=remoting/remote-outbound-connection=<name>:remove()
final ModelNode removeRemoteOutboundConnection = new ModelNode();
removeRemoteOutboundConnection.get(OP).set(REMOVE);
final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME),
PathElement.pathElement("remote-outbound-connection", connectionName));
removeRemoteOutboundConnection.get(OP_ADDR).set(address.toModelNode());
final ModelNode removeAuthConfig = Util.createRemoveOperation(
PathAddress.pathAddress(
PathElement.pathElement(SUBSYSTEM, "elytron"),
PathElement.pathElement("authentication-configuration", "outbound")));
final ModelNode removeAuthContext = Util.createRemoveOperation(
PathAddress.pathAddress(
PathElement.pathElement(SUBSYSTEM, "elytron"),
PathElement.pathElement("authentication-context", "outbound")));
final ModelNode op = Util.getEmptyOperation(COMPOSITE, new ModelNode());
final ModelNode steps = op.get(STEPS);
steps.add(removeRemoteOutboundConnection);
steps.add(removeAuthContext);
steps.add(removeAuthConfig);
// execute the remove operation
execute(modelControllerClient, op);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
/**
* Creates a strict max pool in the EJB3 subsystem, with the passed <code>poolName</code> and pool attributes
*
* @param poolName Pool name
* @param maxPoolSize Max pool size
* @param timeout Instance acquisition timeout for the pool
* @param unit Instance acquisition timeout unit for the pool
*/
public static void createStrictMaxPool(final ModelControllerClient modelControllerClient,
final String poolName, final int maxPoolSize,
final long timeout, final TimeUnit unit) {
try {
// first get the remote-connector from the EJB3 subsystem to find the remote connector ref
// /subsystem=ejb3/strict-max-bean-instance-pool=<name>:add(....)
final ModelNode addStrictMaxPool = new ModelNode();
addStrictMaxPool.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
final PathAddress strictMaxPoolAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME),
PathElement.pathElement(STRICT_MAX_BEAN_INSTANCE_POOL, poolName));
addStrictMaxPool.get(OP_ADDR).set(strictMaxPoolAddress.toModelNode());
// set the params
addStrictMaxPool.get(MAX_POOL_SIZE).set(maxPoolSize);
addStrictMaxPool.get(INSTANCE_ACQUISITION_TIMEOUT).set(timeout);
addStrictMaxPool.get(INSTANCE_ACQUISITION_TIMEOUT_UNIT).set(unit.name());
// execute the add operation
execute(modelControllerClient, addStrictMaxPool);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
/**
* Removes an already created strict max pool from the EJB3 subsystem
*
* @param poolName The name of the pool to be removed
*/
public static void removeStrictMaxPool(final ModelControllerClient controllerClient, final String poolName) {
try {
// /subsystem=ejb3/strict-max-bean-instance-pool=<name>:remove()
final ModelNode removeStrictMaxPool = new ModelNode();
removeStrictMaxPool.get(OP).set(REMOVE);
final PathAddress strictMaxPoolAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME),
PathElement.pathElement(STRICT_MAX_BEAN_INSTANCE_POOL, poolName));
removeStrictMaxPool.get(OP_ADDR).set(strictMaxPoolAddress.toModelNode());
removeStrictMaxPool.get(ModelDescriptionConstants.OPERATION_HEADERS, ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART).set(true);
// execute the remove operation
execute(controllerClient, removeStrictMaxPool);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public static void editEntityBeanInstancePool(final ModelControllerClient controllerClient, final String poolName, final boolean optimisticLocking) {
try {
// /subsystem=ejb3
final PathAddress ejb3SubsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME));
// /subsystem=ejb3:write-attribute(name="default-entity-bean-instance-pool", value=<poolName>)
final ModelNode defaultEntityBeanInstancePool = new ModelNode();
// set the operation
defaultEntityBeanInstancePool.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
// set the address
defaultEntityBeanInstancePool.get(OP_ADDR).set(ejb3SubsystemAddress.toModelNode());
// setup the parameters for the write attribute operation
defaultEntityBeanInstancePool.get(NAME).set(DEFAULT_ENTITY_BEAN_INSTANCE_POOL);
defaultEntityBeanInstancePool.get(VALUE).set(poolName);
// execute the operation
execute(controllerClient, defaultEntityBeanInstancePool);
// /subsystem=ejb3:write-attribute(name="default-entity-bean-optimistic-locking", value=<optimisticLocking>)
final ModelNode defaultEntityBeanOptimisticLocking = new ModelNode();
// set the operation
defaultEntityBeanOptimisticLocking.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
// set the address
defaultEntityBeanOptimisticLocking.get(OP_ADDR).set(ejb3SubsystemAddress.toModelNode());
// setup the parameters for the write attribute operation
defaultEntityBeanOptimisticLocking.get(NAME).set(DEFAULT_ENTITY_BEAN_OPTIMISTIC_LOCKING);
defaultEntityBeanOptimisticLocking.get(VALUE).set(optimisticLocking);
// execute the operation
execute(controllerClient, defaultEntityBeanOptimisticLocking);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public static void undefineEntityBeanInstancePool(final ModelControllerClient controllerClient) {
try {
// /subsystem=ejb3
final PathAddress ejb3SubsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME));
// /subsystem=ejb3:undefine-attribute(name="default-entity-bean-instance-pool")
final ModelNode defaultEntityBeanInstancePool = new ModelNode();
// set the operation
defaultEntityBeanInstancePool.get(OP).set(UNDEFINE_ATTRIBUTE_OPERATION);
// set the address
defaultEntityBeanInstancePool.get(OP_ADDR).set(ejb3SubsystemAddress.toModelNode());
// setup the parameters for the undefine attribute operation
defaultEntityBeanInstancePool.get(NAME).set(DEFAULT_ENTITY_BEAN_INSTANCE_POOL);
// execute the operation
execute(controllerClient, defaultEntityBeanInstancePool);
// /subsystem=ejb3:undefine-attribute(name="default-entity-bean-optimistic-locking")
final ModelNode defaultEntityBeanOptimisticLocking = new ModelNode();
// set the operation
defaultEntityBeanOptimisticLocking.get(OP).set(UNDEFINE_ATTRIBUTE_OPERATION);
// set the address
defaultEntityBeanOptimisticLocking.get(OP_ADDR).set(ejb3SubsystemAddress.toModelNode());
// setup the parameters for the undefine attribute operation
defaultEntityBeanOptimisticLocking.get(NAME).set(DEFAULT_ENTITY_BEAN_OPTIMISTIC_LOCKING);
// execute the operation
execute(controllerClient, defaultEntityBeanOptimisticLocking);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public static void undefinePassByValueForRemoteInterfaceInvocations(ManagementClient managementClient) {
final ModelControllerClient modelControllerClient = managementClient.getControllerClient();
try {
final ModelNode undefineAttribute = Util.getUndefineAttributeOperation(
PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME)),
"in-vm-remote-interface-invocation-pass-by-value");
// execute the operations
execute(modelControllerClient, undefineAttribute);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public static void disablePassByValueForRemoteInterfaceInvocations(ManagementClient managementClient) {
editPassByValueForRemoteInterfaceInvocations(managementClient, false);
}
private static void editPassByValueForRemoteInterfaceInvocations(ManagementClient managementClient, final boolean passByValue) {
final ModelControllerClient modelControllerClient = managementClient.getControllerClient();
try {
// /subsystem=ejb3:write-attribute(name="in-vm-remote-interface-invocation-pass-by-value", value=<passByValue>)
final ModelNode passByValueWriteAttributeOperation = new ModelNode();
// set the operation
passByValueWriteAttributeOperation.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
// set the address
final PathAddress ejb3SubsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME));
passByValueWriteAttributeOperation.get(OP_ADDR).set(ejb3SubsystemAddress.toModelNode());
// setup the parameters for the write attribute operation
passByValueWriteAttributeOperation.get(NAME).set("in-vm-remote-interface-invocation-pass-by-value");
passByValueWriteAttributeOperation.get(VALUE).set(passByValue);
// execute the operations
execute(modelControllerClient, passByValueWriteAttributeOperation);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
public static void setDefaultDistinctName(ManagementClient managementClient, final String distinctName) {
final ModelControllerClient modelControllerClient = managementClient.getControllerClient();
try {
final ModelNode op = new ModelNode();
if (distinctName != null) {
op.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
op.get(VALUE).set(distinctName);
} else {
op.get(OP).set(UNDEFINE_ATTRIBUTE_OPERATION);
}
// set the address
final PathAddress ejb3SubsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME));
op.get(OP_ADDR).set(ejb3SubsystemAddress.toModelNode());
// setup the parameters for the write attribute operation
op.get(NAME).set("default-distinct-name");
// execute the operations
execute(modelControllerClient, op);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
private static ModelControllerClient getModelControllerClient(final String managementServerHostName, final int managementPort, final CallbackHandler handler) {
try {
return ModelControllerClient.Factory.create(InetAddress.getByName(managementServerHostName), managementPort, handler);
} catch (UnknownHostException e) {
throw new RuntimeException("Cannot create model controller client for host: " + managementServerHostName + " and port " + managementPort, e);
}
}
/**
* Executes the operation and returns the result if successful. Else throws an exception
*
* @param modelControllerClient
* @param operation
* @return
* @throws IOException
*/
private static ModelNode execute(final ModelControllerClient modelControllerClient, final ModelNode operation) throws IOException {
final ModelNode result = modelControllerClient.execute(operation);
if (result.hasDefined(ClientConstants.OUTCOME) && ClientConstants.SUCCESS.equals(result.get(ClientConstants.OUTCOME).asString())) {
//logger.trace("Operation " + operation.toString() + " successful");
return result;
} 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(ClientConstants.OUTCOME));
}
}
// TODO: This method is temporary hack till we figure out the management operation to get the
// jboss.node.name system property from the server http://lists.jboss.org/pipermail/jboss-as7-dev/2011-November/004434.html
public static String getNodeName() {
// Logic copied from org.jboss.as.server.ServerEnvironment constructor
final Properties props = System.getProperties();
final Map<String, String> env = System.getenv();
// Calculate host and default server name
String hostName = props.getProperty("jboss.host.name");
String qualifiedHostName = props.getProperty("jboss.qualified.host.name");
if (qualifiedHostName == null) {
// if host name is specified, don't pick a qualified host name that isn't related to it
qualifiedHostName = hostName;
if (qualifiedHostName == null) {
// POSIX-like OSes including Mac should have this set
qualifiedHostName = env.get("HOSTNAME");
}
if (qualifiedHostName == null) {
// Certain versions of Windows
qualifiedHostName = env.get("COMPUTERNAME");
}
if (qualifiedHostName == null) {
try {
qualifiedHostName = NetworkUtils.canonize(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
qualifiedHostName = null;
}
}
if (qualifiedHostName != null && qualifiedHostName.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$|:")) {
// IP address is not acceptable
qualifiedHostName = null;
}
if (qualifiedHostName == null) {
// Give up
qualifiedHostName = "unknown-host.unknown-domain";
}
qualifiedHostName = qualifiedHostName.trim().toLowerCase(Locale.ENGLISH);
}
if (hostName == null) {
// Use the host part of the qualified host name
final int idx = qualifiedHostName.indexOf('.');
hostName = idx == -1 ? qualifiedHostName : qualifiedHostName.substring(0, idx);
}
// Set up the server name for management purposes
String serverName = props.getProperty("jboss.server.name");
if (serverName == null) {
serverName = hostName;
}
// Set up the clustering node name
String nodeName = props.getProperty("jboss.node.name");
if (nodeName == null) {
nodeName = serverName;
}
return nodeName;
}
}
| 33,276 | 53.374183 | 169 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/ValueWrapper.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.remote.client.api;
import java.io.Serializable;
/**
* Java serialization will not invoke the class initializer during unmarshalling, resulting in
* shouldBeNilAfterUnmarshalling being left as null. This helps test if JBoss marshalling does the same.
*/
public class ValueWrapper implements Serializable {
public static String INITIALIZER_CONSTANT = "FIVE";
private transient String shouldBeNilAfterUnmarshalling = initializer();
private String initializer() {
return INITIALIZER_CONSTANT;
}
public String getShouldBeNilAfterUnmarshalling() {
return shouldBeNilAfterUnmarshalling;
}
}
| 1,700 | 36.8 | 105 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/Employee.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.remote.client.api;
import java.io.Serializable;
/**
* User: jpai
*/
public class Employee implements Serializable {
private final String name;
private final int id;
public Employee(final int id, final String name) {
this.id = id;
this.name = name;
}
public String getName() {
return this.name;
}
public int getId() {
return this.id;
}
}
| 1,477 | 28.56 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/EmployeeBean.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.remote.client.api;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* User: jpai
*/
@Stateless
@Remote(EmployeeManager.class)
public class EmployeeBean implements EmployeeManager {
@Override
public AliasedEmployee addNickNames(final Employee employee, final String... nickNames) {
final AliasedEmployee aliasedEmployee = new AliasedEmployee(employee.getId(), employee.getName());
for (int i=0; i<nickNames.length; i++) {
aliasedEmployee.addNick(nickNames[i]);
}
return aliasedEmployee;
}
}
| 1,630 | 35.244444 | 106 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/InterceptorTwo.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.remote.client.api;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
/**
* User: jpai
*/
public class InterceptorTwo {
public static final String MESSAGE_SEPARATOR = ",";
@AroundInvoke
public Object aroundInvoke(final InvocationContext context) throws Exception {
final Object[] methodParams = context.getParameters();
if (methodParams.length == 1 && methodParams[0] instanceof String) {
final String message = (String) methodParams[0];
final String interceptedMessage = message + MESSAGE_SEPARATOR + this.getClass().getSimpleName();
context.setParameters(new Object[] {interceptedMessage});
}
return context.proceed();
}
}
| 1,817 | 38.521739 | 108 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/InterceptorOne.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.remote.client.api;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
/**
* User: jpai
*/
public class InterceptorOne {
public static final String MESSAGE_SEPARATOR = ",";
@AroundInvoke
public Object aroundInvoke(final InvocationContext context) throws Exception {
final Object[] methodParams = context.getParameters();
if (methodParams.length == 1 && methodParams[0] instanceof String) {
final String message = (String) methodParams[0];
final String interceptedMessage = message + MESSAGE_SEPARATOR + this.getClass().getSimpleName();
context.setParameters(new Object[] {interceptedMessage});
}
return context.proceed();
}
}
| 1,817 | 38.521739 | 108 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/EchoRemote.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.remote.client.api;
import java.util.concurrent.Future;
/**
* User: jpai
*/
public interface EchoRemote {
String echo(String message);
Future<String> asyncEcho(String message, long delayInMilliSec);
EchoRemote getBusinessObject();
boolean testRequestScopeActive();
ValueWrapper getValue();
}
| 1,386 | 32.02381 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/ExceptionThrowingRemote.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.remote.client.api;
/**
* User: jpai
*/
public interface ExceptionThrowingRemote {
void alwaysThrowApplicationException(final String state) throws StatefulApplicationException;
void alwaysThrowSystemException(final String state);
}
| 1,310 | 37.558824 | 97 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/EJBClientAPIUsageTestCase.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.remote.client.api;
import java.util.ArrayList;
import java.util.List;
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 jakarta.ejb.EJBException;
import jakarta.ejb.NoSuchEJBException;
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.ejb.client.EJBClient;
import org.jboss.ejb.client.StatefulEJBLocator;
import org.jboss.ejb.client.StatelessEJBLocator;
import org.jboss.logging.Logger;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* Tests the various common use cases of the EJB remote client API
* <p/>
* User: Jaikiran Pai
*/
@RunWith(Arquillian.class)
@RunAsClient
public class EJBClientAPIUsageTestCase {
private static final Logger logger = Logger.getLogger(EJBClientAPIUsageTestCase.class);
private static final String APP_NAME = "ejb-remote-client-api-test";
private static final String MODULE_NAME = "ejb";
/**
* Creates an EJB deployment
*
* @return
*/
@Deployment
public static Archive<?> createDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(EJBClientAPIUsageTestCase.class.getPackage());
jar.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
ear.addAsModule(jar);
return ear;
}
/**
* Create and setup the EJB client context backed by the remoting receiver
*
* @throws Exception
*/
@Before
public void beforeTest() throws Exception {
// TODO Elytron: Determine how this should be adapted once the transaction client changes are in
//final EJBClientTransactionContext localUserTxContext = EJBClientTransactionContext.createLocal();
// set the tx context
//EJBClientTransactionContext.setGlobalContext(localUserTxContext);
}
/**
* Test a simple invocation on a remote view of a Stateless session bean method
*
* @throws Exception
*/
@Test
public void testRemoteSLSBInvocation() throws Exception {
final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator(EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), "");
final EchoRemote proxy = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", proxy);
final String message = "Hello world from a really remote client";
final String echo = proxy.echo(message);
Assert.assertEquals("Unexpected echo message", message, echo);
}
/**
* Test bean returning a value object with a transient field. Will test that the transient field is set to null (just like java serialization would do)
* instead of a non-null value (non-null came ValueWrapper class initializer if this fails).
*
* @throws Exception
*/
@Test
public void testValueObjectWithTransientField() throws Exception {
final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator(EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), "");
final EchoRemote proxy = EJBClient.createProxy(locator);
String shouldBeNil = proxy.getValue().getShouldBeNilAfterUnmarshalling();
Assert.assertNull("transient field should be serialized as null but was '" + shouldBeNil + "'",
shouldBeNil);
}
/**
* Test an invocation on the remote view of a stateless bean which is configured for user interceptors
*
* @throws Exception
*/
@Test
public void testRemoteSLSBWithInterceptors() throws Exception {
final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator(EchoRemote.class, APP_NAME, MODULE_NAME, InterceptedEchoBean.class.getSimpleName(), "");
final EchoRemote proxy = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", proxy);
final String message = "Hello world from a really remote client";
final String echo = proxy.echo(message);
final String expectedEcho = message + InterceptorTwo.MESSAGE_SEPARATOR + InterceptorOne.class.getSimpleName() + InterceptorOne.MESSAGE_SEPARATOR + InterceptorTwo.class.getSimpleName();
Assert.assertEquals("Unexpected echo message", expectedEcho, echo);
}
/**
* Test an invocation on a stateless bean method which accepts and returns custom objects
*
* @throws Exception
*/
@Test
public void testRemoteSLSBWithCustomObjects() throws Exception {
final StatelessEJBLocator<EmployeeManager> locator = new StatelessEJBLocator(EmployeeManager.class, APP_NAME, MODULE_NAME, EmployeeBean.class.getSimpleName(), "");
final EmployeeManager proxy = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", proxy);
final String[] nickNames = new String[]{"java-programmer", "ruby-programmer", "php-programmer"};
final Employee employee = new Employee(1, "programmer");
// invoke on the bean
final AliasedEmployee employeeWithNickNames = proxy.addNickNames(employee, nickNames);
// check the id of the returned employee
Assert.assertEquals("Unexpected employee id", 1, employeeWithNickNames.getId());
// check the name of the returned employee
Assert.assertEquals("Unexpected employee name", "programmer", employeeWithNickNames.getName());
// check the number of nicknames
Assert.assertEquals("Unexpected number of nick names", nickNames.length, employeeWithNickNames.getNickNames().size());
// make sure the correct nick names are present
for (int i = 0; i < nickNames.length; i++) {
Assert.assertTrue("Employee was expected to have nick name: " + nickNames[i], employeeWithNickNames.getNickNames().contains(nickNames[i]));
}
}
/**
* Tests that invocations on a stateful session bean work after a session is created and the stateful
* session bean really acts as a stateful bean
*
* @throws Exception
*/
@Test
public void testSFSBInvocation() throws Exception {
final StatefulEJBLocator<Counter> locator = EJBClient.createSession(Counter.class, APP_NAME, MODULE_NAME, CounterBean.class.getSimpleName(), "");
final Counter counter = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", counter);
// invoke the bean
final int initialCount = counter.getCount();
logger.trace("Got initial count " + initialCount);
Assert.assertEquals("Unexpected initial count from stateful bean", 0, initialCount);
final int NUM_TIMES = 50;
for (int i = 1; i <= NUM_TIMES; i++) {
final int count = counter.incrementAndGetCount();
logger.trace("Got next count " + count);
Assert.assertEquals("Unexpected count after increment", i, count);
}
final int finalCount = counter.getCount();
logger.trace("Got final count " + finalCount);
Assert.assertEquals("Unexpected final count", NUM_TIMES, finalCount);
}
/**
* Tests that invocations on a stateful session bean with a stateless locator work
*/
@Test
public void testSFSBInvocationWithSLSBLocator() {
final StatelessEJBLocator<Counter> locator = new StatelessEJBLocator<>(Counter.class, APP_NAME, MODULE_NAME, CounterBean.class.getSimpleName());
final Counter counter = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", counter);
// invoke the bean
final int initialCount = counter.getCount();
logger.trace("Got initial count " + initialCount);
Assert.assertEquals("Unexpected initial count from stateful bean", 0, initialCount);
Assert.assertTrue("Unexpected stateless locator", EJBClient.getLocatorFor(counter).isStateful());
final int NUM_TIMES = 50;
for (int i = 1; i <= NUM_TIMES; i++) {
final int count = counter.incrementAndGetCount();
logger.trace("Got next count " + count);
Assert.assertEquals("Unexpected count after increment", i, count);
}
final int finalCount = counter.getCount();
logger.trace("Got final count " + finalCount);
Assert.assertEquals("Unexpected final count", NUM_TIMES, finalCount);
}
/**
* Tests that invoking a non-existent EJB leads to a {@link IllegalStateException} as a result of
* no EJB receivers able to handle the invocation
*
* @throws Exception
*/
@Test
public void testNonExistentEJBAccess() throws Exception {
final StatelessEJBLocator<NotAnEJBInterface> locator = new StatelessEJBLocator<NotAnEJBInterface>(NotAnEJBInterface.class, "non-existen-app-name", MODULE_NAME, "blah", "");
final NotAnEJBInterface nonExistentBean = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", nonExistentBean);
// invoke on the (non-existent) bean
try {
nonExistentBean.echo("Hello world to a non-existent bean");
Assert.fail("Expected an IllegalStateException");
} catch (IllegalStateException | EJBException ise) {
// expected
logger.trace("Received the expected exception", ise);
}
}
/**
* Tests that the invocation on a non-existent view of an (existing) EJB leads to a {@link NoSuchEJBException}
*
* @throws Exception
*/
@Test
public void testNonExistentViewForEJB() throws Exception {
final StatelessEJBLocator<NotAnEJBInterface> locator = new StatelessEJBLocator<NotAnEJBInterface>(NotAnEJBInterface.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), "");
final NotAnEJBInterface nonExistentBean = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", nonExistentBean);
// invoke on the (non-existent) view of a bean
try {
nonExistentBean.echo("Hello world to a non-existent view of a bean");
Assert.fail("Expected an IllegalStateException");
} catch (IllegalStateException | EJBException nsee) {
// expected
logger.trace("Received the expected exception", nsee);
}
}
/**
* Tests that an {@link jakarta.ejb.ApplicationException} thrown by a SLSB method is returned back to the
* client correctly
*
* @throws Exception
*/
@Test
public void testApplicationExceptionOnSLSBMethod() throws Exception {
final StatelessEJBLocator<ExceptionThrowingRemote> locator = new StatelessEJBLocator<ExceptionThrowingRemote>(ExceptionThrowingRemote.class, APP_NAME, MODULE_NAME, ExceptionThrowingBean.class.getSimpleName(), "");
final ExceptionThrowingRemote exceptionThrowingBean = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", exceptionThrowingBean);
final String exceptionState = "2342348723Dsbjlfjal#";
try {
exceptionThrowingBean.alwaysThrowApplicationException(exceptionState);
Assert.fail("Expected a " + StatefulApplicationException.class.getName() + " exception");
} catch (StatefulApplicationException sae) {
// expected
logger.trace("Received the expected exception", sae);
Assert.assertEquals("Unexpected state in the application exception", exceptionState, sae.getState());
}
}
/**
* Tests that a system exception thrown from a SLSB method is conveyed back to the client
*
* @throws Exception
*/
@Test
public void testSystemExceptionOnSLSBMethod() throws Exception {
final StatelessEJBLocator<ExceptionThrowingRemote> locator = new StatelessEJBLocator<ExceptionThrowingRemote>(ExceptionThrowingRemote.class, APP_NAME, MODULE_NAME, ExceptionThrowingBean.class.getSimpleName(), "");
final ExceptionThrowingRemote exceptionThrowingBean = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", exceptionThrowingBean);
final String exceptionState = "bafasfaj;l";
try {
exceptionThrowingBean.alwaysThrowSystemException(exceptionState);
Assert.fail("Expected a " + EJBException.class.getName() + " exception");
} catch (EJBException ejbe) {
// expected
logger.trace("Received the expected exception", ejbe);
final Throwable cause = ejbe.getCause();
Assert.assertTrue("Unexpected cause in EJBException", cause instanceof RuntimeException);
Assert.assertEquals("Unexpected state in the system exception", exceptionState, cause.getMessage());
}
}
/**
* Tests that a SLSB method which is marked as asynchronous and returns a {@link java.util.concurrent.Future}
* is invoked asynchronously and the client isn't blocked for the lifetime of the method
*
* @throws Exception
*/
@Test
public void testAsyncFutureMethodOnSLSB() throws Exception {
final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator<EchoRemote>(EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), "");
final EchoRemote echoRemote = EJBClient.createProxy(locator);
Assert.assertNotNull("Received a null proxy", echoRemote);
final String message = "You are supposed to be an asynchronous method";
final long DELAY = 5000;
final long start = System.currentTimeMillis();
// invoke the asynchronous method
final Future<String> futureEcho = echoRemote.asyncEcho(message, DELAY);
final long end = System.currentTimeMillis();
logger.trace("Asynchronous invocation returned a Future: " + futureEcho + " in " + (end - start) + " milliseconds");
// test that the invocation did not act like a synchronous invocation and instead returned "immediately"
Assert.assertFalse("Asynchronous invocation behaved like a synchronous invocation", (end - start) >= DELAY);
Assert.assertNotNull("Future is null", futureEcho);
// Check if the result is marked as complete (it shouldn't be this soon)
Assert.assertFalse("Future result is unexpectedly completed", futureEcho.isDone());
// wait for the result
final String echo = futureEcho.get();
Assert.assertEquals("Unexpected echo message", message, echo);
}
/**
* Test a simple invocation on a remote view of a Stateless session bean method
*
* @throws Exception
*/
@Test
public void testGetBusinessObjectRemote() throws Exception {
final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator(EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), "");
final EchoRemote proxy = EJBClient.createProxy(locator);
final EchoRemote getBusinessObjectProxy = proxy.getBusinessObject();
Assert.assertNotNull("Received a null proxy", getBusinessObjectProxy);
final String message = "Hello world from a really remote client";
final String echo = getBusinessObjectProxy.echo(message);
Assert.assertEquals("Unexpected echo message", message, echo);
}
/**
* AS7-3129
* <p/>
* Make sure that the Jakarta Contexts and Dependency Injection request scope is activated for remote EJB invocations
*/
@Test
public void testCdiRequestScopeActive() {
final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator(EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), "");
final EchoRemote proxy = EJBClient.createProxy(locator);
Assert.assertTrue(proxy.testRequestScopeActive());
}
/**
* AS7-3402
*
* Tests that a NonSerializableException does not break the channel
*
*/
@Test
public void testNonSerializableResponse() throws InterruptedException, ExecutionException {
final StatelessEJBLocator<NonSerialiazableResponseRemote> locator = new StatelessEJBLocator(NonSerialiazableResponseRemote.class, APP_NAME, MODULE_NAME, NonSerializableResponseEjb.class.getSimpleName(), "");
final NonSerialiazableResponseRemote proxy = EJBClient.createProxy(locator);
Callable<Object> task = new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
proxy.nonSerializable();
Assert.fail();
} catch (Exception e) {
logger.trace("expected " + e);
}
Thread.sleep(1000);
Assert.assertEquals("hello", proxy.serializable());
return null;
}
};
final ExecutorService executor = Executors.newFixedThreadPool(10);
try {
final List<Future> tasks = new ArrayList<Future>();
for (int i = 0; i < 100; ++i) {
tasks.add(executor.submit(task));
}
for (Future result : tasks) {
result.get();
}
} finally {
executor.shutdown();
}
}
}
| 18,958 | 45.241463 | 221 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/Counter.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.remote.client.api;
/**
* User: jpai
*/
public interface Counter {
int incrementAndGetCount();
int getCount();
}
| 1,191 | 34.058824 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/ExceptionThrowingBean.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.remote.client.api;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
/**
* User: jpai
*/
@Stateless
@Remote (ExceptionThrowingRemote.class)
public class ExceptionThrowingBean implements ExceptionThrowingRemote {
@Override
public void alwaysThrowApplicationException(String state) throws StatefulApplicationException {
throw new StatefulApplicationException(state);
}
@Override
public void alwaysThrowSystemException(String state) {
throw new RuntimeException(state);
}
}
| 1,590 | 34.355556 | 99 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/NonSerialiableException.java
|
package org.jboss.as.test.integration.ejb.remote.client.api;
/**
* @author Stuart Douglas
*/
public class NonSerialiableException extends RuntimeException {
public Object nonSerialiable = new Object();
}
| 214 | 18.545455 | 64 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/StatefulApplicationException.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.remote.client.api;
import jakarta.ejb.ApplicationException;
import java.io.Serializable;
/**
* User: jpai
*/
@ApplicationException
public class StatefulApplicationException extends Exception implements Serializable {
private final String state;
public StatefulApplicationException(final String state) {
this.state = state;
}
public String getState() {
return this.state;
}
}
| 1,484 | 32.75 | 85 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/CounterBean.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.remote.client.api;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
/**
* User: jpai
*/
@Stateful
@Remote (Counter.class)
public class CounterBean implements Counter {
private int count;
@PostConstruct
private void onConstruct() {
this.count = 0;
}
@Override
public int incrementAndGetCount() {
this.count ++;
return this.count;
}
@Override
public int getCount() {
return this.count;
}
}
| 1,582 | 28.314815 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/NonSerializableResponseEjb.java
|
package org.jboss.as.test.integration.ejb.remote.client.api;
import jakarta.ejb.Stateless;
/**
* @author Stuart Douglas
*/
@Stateless
public class NonSerializableResponseEjb implements NonSerialiazableResponseRemote {
@Override
public Object nonSerializable() {
throw new NonSerialiableException();
}
@Override
public String serializable() {
return "hello";
}
}
| 409 | 17.636364 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/AliasedEmployee.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.remote.client.api;
import java.util.HashSet;
import java.util.Set;
/**
* User: jpai
*/
public class AliasedEmployee extends Employee {
private Set<String> nickNames = new HashSet<String>();
public AliasedEmployee(final int id, final String name) {
super(id, name);
}
public void addNick(final String nick) {
this.nickNames.add(nick);
}
public Set<String> getNickNames() {
return this.nickNames;
}
}
| 1,528 | 29.58 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/NonSerialiazableResponseRemote.java
|
package org.jboss.as.test.integration.ejb.remote.client.api;
import jakarta.ejb.Remote;
/**
* @author Stuart Douglas
*/
@Remote
public interface NonSerialiazableResponseRemote {
Object nonSerializable();
String serializable();
}
| 244 | 14.3125 | 60 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/NotAnEJBInterface.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.remote.client.api;
/**
* User: jpai
*/
public interface NotAnEJBInterface {
String echo(String msg);
}
| 1,177 | 35.8125 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/InterceptedEchoBean.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.remote.client.api;
import java.util.concurrent.Future;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@Stateless
@Remote(EchoRemote.class)
@Interceptors(InterceptorOne.class)
public class InterceptedEchoBean implements EchoRemote {
private static final Logger logger = Logger.getLogger(InterceptedEchoBean.class);
@Override
@Interceptors(InterceptorTwo.class)
public String echo(String message) {
logger.trace(this.getClass().getSimpleName() + " echoing message " + message);
return message;
}
@Asynchronous
@Override
public Future<String> asyncEcho(String message, long delayInMilliSec) {
logger.trace("Going to delay the echo of \"" + message + "\" for " + delayInMilliSec + " milliseconds");
try {
Thread.sleep(delayInMilliSec);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
logger.trace(this.getClass().getSimpleName() + " echoing message: " + message);
return new AsyncResult<String>(message);
}
@Override
public EchoRemote getBusinessObject() {
return null;
}
@Override
public boolean testRequestScopeActive() {
//not used
return false;
}
@Override
public ValueWrapper getValue() {
return null;
}
}
| 2,566 | 30.691358 | 112 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/RequestScopedBean.java
|
package org.jboss.as.test.integration.ejb.remote.client.api;
import jakarta.enterprise.context.RequestScoped;
/**
* @author Stuart Douglas
*/
@RequestScoped
public class RequestScopedBean {
private int state = 0;
public int getState() {
return state;
}
public void setState(final int state) {
this.state = state;
}
}
| 359 | 17 | 60 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/EmployeeManager.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.remote.client.api;
/**
* User: jpai
*/
public interface EmployeeManager {
AliasedEmployee addNickNames(final Employee employee, final String... nickNames);
}
| 1,232 | 37.53125 | 85 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/EchoBean.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.remote.client.api;
import java.util.concurrent.Future;
import jakarta.annotation.Resource;
import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.Remote;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
/**
* User: jpai
*/
@Stateless
@Remote(EchoRemote.class)
public class EchoBean implements EchoRemote {
@Resource
private SessionContext sessionContext;
@Inject
private RequestScopedBean requestScopedBean;
private static final Logger logger = Logger.getLogger(EchoBean.class);
@Override
public String echo(String message) {
logger.trace(this.getClass().getSimpleName() + " echoing message " + message);
return message;
}
@Asynchronous
@Override
public Future<String> asyncEcho(final String message, final long delayInMilliSec) {
logger.trace("Going to delay the echo of \"" + message + "\" for " + delayInMilliSec + " milliseconds");
try {
Thread.sleep(delayInMilliSec);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
logger.trace(this.getClass().getSimpleName() + " echoing message: " + message);
return new AsyncResult<String>(message);
}
@Override
public EchoRemote getBusinessObject() {
return sessionContext.getBusinessObject(EchoRemote.class);
}
@Override
public boolean testRequestScopeActive() {
requestScopedBean.setState(10);
requestScopedBean.setState(requestScopedBean.getState() + 10);
return requestScopedBean.getState() == 20;
}
@Override
public ValueWrapper getValue() {
return new ValueWrapper();
}
}
| 2,841 | 31.295455 | 112 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/SimpleEJBClientInterceptor.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.remote.client.api.interceptor;
import org.jboss.ejb.client.EJBClientInterceptor;
import org.jboss.ejb.client.EJBClientInvocationContext;
import java.util.Map;
/**
* An EJB client side interceptor
*
* @author Jaikiran Pai
*/
public class SimpleEJBClientInterceptor implements EJBClientInterceptor {
private final Map<String, Object> data;
SimpleEJBClientInterceptor(final Map<String, Object> data) {
this.data = data;
}
@Override
public void handleInvocation(EJBClientInvocationContext context) throws Exception {
// add all the data to the EJB client invocation context so that it becomes available to the server side
context.getContextData().putAll(data);
// proceed "down" the invocation chain
context.sendRequest();
}
@Override
public Object handleInvocationResult(EJBClientInvocationContext context) throws Exception {
// we don't have anything special to do with the result so just return back the result
// "up" the invocation chain
return context.getResult();
}
}
| 2,148 | 36.051724 | 112 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/RemoteViewInvoker.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.remote.client.api.interceptor;
import java.util.Map;
/**
* @author Jaikiran Pai
*/
public interface RemoteViewInvoker {
Map<String, Object> invokeRemoteViewAndGetInvocationData(final String... key);
Map<String, Object> getDataSetupForInvocationContext();
}
| 1,337 | 36.166667 | 82 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/RemoteSFSB.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.remote.client.api.interceptor;
import java.util.Map;
/**
* @author Jaikiran Pai
*/
public interface RemoteSFSB {
Map<String, Object> getInvocationData(final String... key);
}
| 1,250 | 35.794118 | 72 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/EJBClientInterceptorTestCase.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.remote.client.api.interceptor;
import static org.jboss.as.test.shared.integration.ejb.security.PermissionUtils.createPermissionsXmlAsset;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
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.ejb.client.EJBClientContext;
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 org.wildfly.common.context.ContextPermission;
/**
* Tests that JBoss EJB API specific client side EJB interceptors work as expected
*
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
public class EJBClientInterceptorTestCase {
private static final String APP_NAME = "";
private static final String DISTINCT_NAME = "";
private static final String MODULE_NAME = "ejb-client-interceptor-test-module";
@Deployment(testable = false)
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(RemoteSFSB.class.getPackage());
jar.addAsManifestResource(
createPermissionsXmlAsset(new ContextPermission("org.wildfly.transaction.client.context.remote", "get")),
"permissions.xml");
return jar;
}
/**
* @throws Exception
*/
@Test
@RunAsClient // run as a truly remote client
public void testEJBClientInterceptionFromRemoteClient() throws Exception {
// create some data that the client side interceptor will pass along during the EJB invocation
final Map<String, Object> interceptorData = new HashMap<String, Object>();
final String keyOne = "foo";
final Object valueOne = "bar";
final String keyTwo = "blah";
final Object valueTwo = new Integer("12");
interceptorData.put(keyOne, valueOne);
interceptorData.put(keyTwo, valueTwo);
final SimpleEJBClientInterceptor clientInterceptor = new SimpleEJBClientInterceptor(interceptorData);
// get hold of the EJBClientContext and register the client side interceptor
final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(clientInterceptor);
final Hashtable props = new Hashtable();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context jndiContext = new InitialContext(props);
ejbClientContext.runCallable(() -> {
final RemoteSFSB remoteSFSB = (RemoteSFSB) jndiContext.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME
+ "/" + SimpleSFSB.class.getSimpleName() + "!" + RemoteSFSB.class.getName() + "?stateful");
// invoke the bean and ask it for the invocation data that it saw on the server side
final Map<String, Object> valuesSeenOnServerSide = remoteSFSB.getInvocationData(keyOne, keyTwo);
// make sure the server side bean was able to get the data which was passed on by the client side
// interceptor
Assert.assertNotNull("Server side context data was expected to be non-null", valuesSeenOnServerSide);
Assert.assertFalse("Server side context data was expected to be non-empty", valuesSeenOnServerSide.isEmpty());
for (final Map.Entry<String, Object> clientInterceptorDataEntry : interceptorData.entrySet()) {
final String key = clientInterceptorDataEntry.getKey();
final Object expectedValue = clientInterceptorDataEntry.getValue();
Assert.assertEquals("Unexpected value in bean, on server side, via InvocationContext.getContextData() for key " + key, expectedValue, valuesSeenOnServerSide.get(key));
}
return null;
});
}
/**
* Tests that when the client to a remote view of a bean resides on the same server as the EJBs and invokes on it, then the
* context data populated by the client interceptors gets passed on to the server side interceptors and the bean.
*
* @throws Exception
* @see https://issues.jboss.org/browse/AS7-6356
*/
@Test
public void testEJBClientInterceptionFromInVMClient() throws Exception {
final Hashtable props = new Hashtable();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context jndiContext = new InitialContext(props);
final RemoteViewInvoker remoteViewInvokingBean = (RemoteViewInvoker) jndiContext.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/"
+ DISTINCT_NAME + "/" + RemoteViewInvokingBean.class.getSimpleName() + "!" + RemoteViewInvoker.class.getName() + "?stateful");
// get the data that the local bean is going to populate before invoking the remote bean
final Map<String, Object> interceptorData = remoteViewInvokingBean.getDataSetupForInvocationContext();
// invoke the bean and ask it for the invocation data that it saw on the server side
final Map<String, Object> valuesSeenOnServerSide = remoteViewInvokingBean.invokeRemoteViewAndGetInvocationData(interceptorData.keySet().toArray(new String[interceptorData.size()]));
// make sure the server side bean was able to get the data which was passed on by the client side
// interceptor
Assert.assertNotNull("Server side context data was expected to be non-null", valuesSeenOnServerSide);
Assert.assertFalse("Server side context data was expected to be non-empty", valuesSeenOnServerSide.isEmpty());
for (final Map.Entry<String, Object> clientInterceptorDataEntry : interceptorData.entrySet()) {
final String key = clientInterceptorDataEntry.getKey();
final Object expectedValue = clientInterceptorDataEntry.getValue();
Assert.assertEquals("Unexpected value in bean, on server side, via InvocationContext.getContextData() for key " + key, expectedValue, valuesSeenOnServerSide.get(key));
}
}
}
| 7,367 | 51.628571 | 189 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/RemoteViewInvokingBean.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.remote.client.api.interceptor;
import org.jboss.ejb.client.EJBClientContext;
import jakarta.annotation.PostConstruct;
import jakarta.ejb.EJB;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
import java.util.HashMap;
import java.util.Map;
/**
* @author Jaikiran Pai
*/
@Stateful(passivationCapable = false)
@Remote(RemoteViewInvoker.class)
public class RemoteViewInvokingBean implements RemoteViewInvoker {
@EJB
private RemoteSFSB remoteViewSFSB;
private Map<String, Object> interceptorData;
private EJBClientContext ejbClientContext;
@PostConstruct
void setupClientInterceptor() {
// create some data that the client side interceptor will pass along during the EJB invocation
this.interceptorData = new HashMap<String, Object>();
final String keyOne = "abc";
final Object valueOne = "def";
final String keyTwo = "blah";
final Object valueTwo = new Integer("12");
interceptorData.put(keyOne, valueOne);
interceptorData.put(keyTwo, valueTwo);
final SimpleEJBClientInterceptor clientInterceptor = new SimpleEJBClientInterceptor(interceptorData);
// get hold of the EJBClientContext and register the client side interceptor
ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(clientInterceptor);
}
@Override
public Map<String, Object> invokeRemoteViewAndGetInvocationData(final String... key) {
try {
return ejbClientContext.runCallable(() -> remoteViewSFSB.getInvocationData(key));
} catch (Exception e) {
return null;
}
}
@Override
public Map<String, Object> getDataSetupForInvocationContext() {
return this.interceptorData;
}
}
| 2,828 | 35.269231 | 109 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/SimpleSFSB.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.remote.client.api.interceptor;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import java.util.HashMap;
import java.util.Map;
/**
* @author Jaikiran Pai
*/
@Stateful(passivationCapable = false)
@Remote(RemoteSFSB.class)
public class SimpleSFSB implements RemoteSFSB {
private Map<String, Object> invocationData;
@Override
public Map<String, Object> getInvocationData(final String... keys) {
// return the data that was requested for the passed keys
final Map<String, Object> subset = new HashMap<String, Object>();
for (final String key : keys) {
subset.put(key, invocationData.get(key));
}
return subset;
}
@AroundInvoke
private Object aroundInvoke(final InvocationContext invocationContext) throws Exception {
// keep track of the context data that was passed during this invocation
this.invocationData = invocationContext.getContextData();
return invocationContext.proceed();
}
}
| 2,156 | 36.189655 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/annotation/EJBClientInterceptorAddedByAnnotation.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.remote.client.api.interceptor.annotation;
import org.jboss.ejb.client.EJBClientInterceptor;
import org.jboss.ejb.client.EJBClientInvocationContext;
/**
* A client interceptor which adds a value "bar" with key "foo" to the context data
* @author Jan Martiska
*/
public class EJBClientInterceptorAddedByAnnotation implements EJBClientInterceptor {
@Override
public void handleInvocation(EJBClientInvocationContext context) throws Exception {
context.getContextData().put("foo", "bar");
context.sendRequest();
}
@Override
public Object handleInvocationResult(EJBClientInvocationContext context) throws Exception {
return context.getResult();
}
}
| 1,764 | 38.222222 | 95 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/annotation/SLSBReturningContextData.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.remote.client.api.interceptor.annotation;
import jakarta.annotation.Resource;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
/**
* @author Jan Martiska
*/
@Stateless
public class SLSBReturningContextData implements SLSBReturningContextDataRemote {
@Resource
private SessionContext ctx;
@Override
public Object getContextData(String key) {
return ctx.getContextData().get(key);
}
}
| 1,498 | 34.690476 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/annotation/SLSBReturningContextDataRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.remote.client.api.interceptor.annotation;
import jakarta.ejb.Remote;
import org.jboss.ejb.client.annotation.ClientInterceptors;
/**
* @author Jan Martiska
*/
@Remote
@ClientInterceptors({EJBClientInterceptorAddedByAnnotation.class})
public interface SLSBReturningContextDataRemote {
/**
* Returns the value from server-visible context data corresponding to the requested key.
*/
Object getContextData(String key);
}
| 1,507 | 34.904762 | 93 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/interceptor/annotation/ClientInterceptorsEJBAnnotationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2017, 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.remote.client.api.interceptor.annotation;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
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.network.NetworkUtils;
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 org.wildfly.naming.client.WildFlyInitialContextFactory;
/**
* Test that the @org.jboss.ejb.client.annotation.ClientInterceptors annotation works for adding EJB client interceptors.
* @author Jan Martiska
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ClientInterceptorsEJBAnnotationTestCase {
private static final String MODULE_NAME = "ejb-client-interceptor-annotated";
@Deployment(testable = false)
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(ClientInterceptorsEJBAnnotationTestCase.class.getPackage());
return jar;
}
@Test
public void check() throws NamingException {
final Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
properties.put(Context.PROVIDER_URL, "remote+http://" +
NetworkUtils.formatPossibleIpv6Address(System.getProperty("node0", "localhost"))
+ ":8080");
final InitialContext ejbCtx = new InitialContext(properties);
try {
SLSBReturningContextDataRemote bean = (SLSBReturningContextDataRemote)ejbCtx.lookup(
"ejb:/" + MODULE_NAME + "/" + SLSBReturningContextData.class.getSimpleName() + "!"
+ SLSBReturningContextDataRemote.class.getName());
final Object valueSeenOnServer = bean.getContextData("foo");
Assert.assertEquals("bar", valueSeenOnServer);
} finally {
ejbCtx.close();
}
}
}
| 3,316 | 39.950617 | 121 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/GracefulTxnShutdownSetup.java
|
/*
* Copyright 2017 Red Hat, Inc.
*
* 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.remote.client.api.tx;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
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.operations.common.Util;
import org.jboss.dmr.ModelNode;
/**
* Sets up the server with graceful txn shutdown enabled in the EJB3 subsystem.
*
* @author Flavia Rainone
*/
public class GracefulTxnShutdownSetup implements ServerSetupTask {
private static final String ENABLE_GRACEFUL_TXN_SHUTDOWN = "enable-graceful-txn-shutdown";
public void setup(ManagementClient managementClient, String containerId) throws Exception {
final ModelNode operation = Util
.createOperation(WRITE_ATTRIBUTE_OPERATION, PathAddress.pathAddress(SUBSYSTEM, "ejb3"));
operation.get(NAME).set(ENABLE_GRACEFUL_TXN_SHUTDOWN);
operation.get(VALUE).set(true);
managementClient.getControllerClient().execute(operation);
}
public void tearDown(ManagementClient managementClient, String containerId) throws Exception {
final ModelNode operation = Util
.createOperation(UNDEFINE_ATTRIBUTE_OPERATION, PathAddress.pathAddress(SUBSYSTEM, "ejb3"));
operation.get(NAME).set(ENABLE_GRACEFUL_TXN_SHUTDOWN);
managementClient.getControllerClient().execute(operation);
}
}
| 2,454 | 46.211538 | 107 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/HTTPEJBClientUserTransactionTestCase.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.remote.client.api.tx;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import jakarta.transaction.UserTransaction;
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.ejb.client.Affinity;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.StatelessEJBLocator;
import org.jboss.logging.Logger;
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.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.naming.client.WildFlyInitialContextFactory;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.MatchRule;
/**
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@RunAsClient
public class HTTPEJBClientUserTransactionTestCase {
private static final Logger logger = Logger.getLogger(HTTPEJBClientUserTransactionTestCase.class);
private static final String APP_NAME = "ejb-remote-client-api-usertx-test";
private static final String MODULE_NAME = "ejb";
@ContainerResource
private ManagementClient managementClient;
/**
* Creates an EJB deployment
*
* @return
*/
@Deployment
public static Archive<?> createDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(HTTPEJBClientUserTransactionTestCase.class.getPackage());
jar.addAsManifestResource(HTTPEJBClientUserTransactionTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
ear.addAsModule(jar);
return ear;
}
private static AuthenticationContext old;
@BeforeClass
public static void setup() {
AuthenticationConfiguration config = AuthenticationConfiguration.empty().useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, config);
old = AuthenticationContext.captureCurrent();
AuthenticationContext.getContextManager().setGlobalDefault(context);
}
@AfterClass
public static void after() {
AuthenticationContext.getContextManager().setGlobalDefault(old);
}
public Context getRemoteHTTPContext() throws Exception {
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
URI namingUri = getHttpUri();
env.put(Context.PROVIDER_URL, namingUri.toString());
env.put(Context.SECURITY_PRINCIPAL, "user1");
env.put(Context.SECURITY_CREDENTIALS, "password1");
return new InitialContext(env);
}
private URI getHttpUri() throws URISyntaxException {
URI webUri = managementClient.getWebUri();
return new URI("http", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "/wildfly-services", "", "");
}
UserTransaction getUserTransaction() throws Exception {
return (UserTransaction) getRemoteHTTPContext().lookup("txn:UserTransaction");
}
/**
* Tests an empty begin()/commit()
*
* @throws Exception
*/
@Test
public void testEmptyTxCommit() throws Exception {
final UserTransaction userTransaction = getUserTransaction();
userTransaction.begin();
userTransaction.commit();
}
/**
* Tests an empty begin()/rollback()
*
* @throws Exception
*/
@Test
public void testEmptyTxRollback() throws Exception {
final UserTransaction userTransaction = getUserTransaction();
userTransaction.begin();
userTransaction.rollback();
}
/**
* Tests a call to a bean method with a Mandatory tx attribute, by initiating a UserTransaction on the
* remote client side. This test ensures that the tx is propagated to the server during the bean invocation
*
* @throws Exception
*/
@Test
public void testMandatoryTxOnSLSB() throws Exception {
final StatelessEJBLocator<CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<CMTRemote>(CMTRemote.class, APP_NAME, MODULE_NAME, CMTBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
final CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
final UserTransaction userTransaction = getUserTransaction();
userTransaction.begin();
cmtRemoteBean.mandatoryTxOp();
userTransaction.commit();
}
/**
* Tests various possibilities with a user initiated UserTransaction and subsequent bean invocations
*
* @throws Exception
*/
@Test
public void testBatchOperationsInTx() throws Exception {
final StatelessEJBLocator<RemoteBatch> batchBeanLocator = new StatelessEJBLocator<RemoteBatch>(RemoteBatch.class, APP_NAME, MODULE_NAME, BatchCreationBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
final RemoteBatch batchBean = EJBClient.createProxy(batchBeanLocator);
final StatelessEJBLocator<BatchRetriever> batchRetrieverLocator = new StatelessEJBLocator<BatchRetriever>(BatchRetriever.class, APP_NAME, MODULE_NAME, BatchFetchingBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
final BatchRetriever batchRetriever = EJBClient.createProxy(batchRetrieverLocator);
final UserTransaction userTransaction = getUserTransaction();
final String batchName = "Simple Batch";
// create a batch
userTransaction.begin();
try {
batchBean.createBatch(batchName);
} catch (Exception e) {
userTransaction.rollback();
throw e;
}
userTransaction.commit();
// add step1 to the batch
final String step1 = "Simple step1";
userTransaction.begin();
try {
batchBean.step1(batchName, step1);
} catch (Exception e) {
userTransaction.rollback();
throw e;
}
userTransaction.commit();
String successFullyCompletedSteps = step1;
// fetch the batch and make sure it contains the right state
final Batch batchAfterStep1 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step1 was null", batchAfterStep1);
Assert.assertEquals("Unexpected steps in batch, after step1", successFullyCompletedSteps, batchAfterStep1.getStepNames());
// now add a failing step2
final String appExceptionStep2 = "App exception Step 2";
userTransaction.begin();
try {
batchBean.appExceptionFailingStep2(batchName, appExceptionStep2);
Assert.fail("Expected an application exception");
} catch (SimpleAppException sae) {
// expected
userTransaction.rollback();
}
final Batch batchAfterAppExceptionStep2 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after app exception step2 was null", batchAfterAppExceptionStep2);
Assert.assertEquals("Unexpected steps in batch, after app exception step2", successFullyCompletedSteps, batchAfterAppExceptionStep2.getStepNames());
// now add a successful step2
final String step2 = "Simple Step 2";
userTransaction.begin();
try {
batchBean.successfulStep2(batchName, step2);
} catch (Exception e) {
userTransaction.rollback();
throw e;
}
// don't yet commit and try and retrieve the batch
final Batch batchAfterStep2BeforeCommit = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step2, before commit was null", batchAfterStep2BeforeCommit);
Assert.assertEquals("Unexpected steps in batch, after step2 before commit", successFullyCompletedSteps, batchAfterStep2BeforeCommit.getStepNames());
// now commit
userTransaction.commit();
// keep track of successfully completely steps
successFullyCompletedSteps = successFullyCompletedSteps + "," + step2;
// now retrieve and check the batch
final Batch batchAfterStep2 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step2 was null", batchAfterStep2);
Assert.assertEquals("Unexpected steps in batch, after step2", successFullyCompletedSteps, batchAfterStep2.getStepNames());
// now add independent Step3 (i.e. the bean method has a REQUIRES_NEW semantics, so that the
// client side tx doesn't play a role)
final String step3 = "Simple Step 3";
userTransaction.begin();
batchBean.independentStep3(batchName, step3);
// rollback (but it shouldn't end up rolling back step3 because that was done in server side independent tx)
userTransaction.rollback();
// keep track of successfully completely steps
successFullyCompletedSteps = successFullyCompletedSteps + "," + step3;
// now retrieve and check the batch
final Batch batchAfterStep3 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step3 was null", batchAfterStep3);
Assert.assertEquals("Unexpected steps in batch, after step3", successFullyCompletedSteps, batchAfterStep3.getStepNames());
// now add step4 but don't commit
final String step4 = "Simple Step 4";
userTransaction.begin();
batchBean.step4(batchName, step4);
// now add a system exception throwing step
final String sysExceptionStep2 = "Sys exception step2";
try {
batchBean.systemExceptionFailingStep2(batchName, sysExceptionStep2);
Assert.fail("Expected a system exception");
} catch (Exception e) {
// expected exception
// TODO: We currently don't return the tx status from the server to the client, so the
// client has no knowledge of the tx status. This is something that can be implemented
// by passing along the tx status as a return attachment from a remote method invocation.
// For now, let's ignore it
//Assert.assertEquals("Unexpected transaction state", Status.STATUS_ROLLEDBACK, userTransaction.getStatus());
userTransaction.rollback();
}
// now retrieve and check the batch
final Batch batchAfterSysException = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after system exception was null", batchAfterSysException);
Assert.assertEquals("Unexpected steps in batch, after system exception", successFullyCompletedSteps, batchAfterSysException.getStepNames());
}
}
| 12,403 | 41.772414 | 235 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/CMTBean.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.remote.client.api.tx;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionAttribute;
import jakarta.ejb.TransactionAttributeType;
/**
* User: jpai
*/
@Stateless
@Remote(CMTRemote.class)
public class CMTBean implements CMTRemote {
@TransactionAttribute(value = TransactionAttributeType.MANDATORY)
@Override
public void mandatoryTxOp() {
// do nothing
}
}
| 1,484 | 33.534884 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/HTTPEJBClientXidTransactionTestCase.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.remote.client.api.tx;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import com.arjuna.ats.internal.jbossatx.jta.jca.XATerminator;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple;
import com.arjuna.ats.jta.common.JTAEnvironmentBean;
import com.arjuna.ats.jta.common.jtaPropertyManager;
import jakarta.transaction.TransactionManager;
import jakarta.transaction.TransactionSynchronizationRegistry;
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.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.dmr.ModelNode;
import org.jboss.ejb.client.Affinity;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.StatelessEJBLocator;
import org.jboss.logging.Logger;
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.tm.XAResourceRecovery;
import org.jboss.tm.XAResourceRecoveryRegistry;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.MatchRule;
import org.wildfly.transaction.client.ContextTransactionManager;
import org.wildfly.transaction.client.ContextTransactionSynchronizationRegistry;
import org.wildfly.transaction.client.LocalTransactionContext;
import org.wildfly.transaction.client.provider.jboss.JBossLocalTransactionProvider;
/**
* @author Jaikiran Pai
* @author Flavia Rainone
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup({GracefulTxnShutdownSetup.class})
public class HTTPEJBClientXidTransactionTestCase {
private static final Logger logger = Logger.getLogger(HTTPEJBClientXidTransactionTestCase.class);
private static final String APP_NAME = "ejb-remote-client-api-xidtx-test";
private static final String MODULE_NAME = "ejb";
private static TransactionManager txManager;
private static TransactionSynchronizationRegistry txSyncRegistry;
@ArquillianResource
private ManagementClient managementClient;
/**
* Creates an EJB deployment
*
* @return
*/
@Deployment
public static Archive<?> createDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(HTTPEJBClientXidTransactionTestCase.class.getPackage());
jar.addAsManifestResource(HTTPEJBClientXidTransactionTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
ear.addAsModule(jar);
return ear;
}
private URI getHttpUri() throws URISyntaxException {
URI webUri = managementClient.getWebUri();
return new URI("http", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "/wildfly-services", "", "");
}
private static AuthenticationContext old;
/**
* Create and setup the remoting connection
*
* @throws Exception
*/
@BeforeClass
public static void beforeTestClass() throws Exception {
// These system properties are required or else we end up picking up JTS transaction manager,
// which is not what we want
final JTAEnvironmentBean jtaEnvironmentBean = jtaPropertyManager.getJTAEnvironmentBean();
jtaEnvironmentBean.setTransactionManagerClassName(TransactionManagerImple.class.getName());
jtaEnvironmentBean.setTransactionSynchronizationRegistryClassName(TransactionSynchronizationRegistryImple.class.getName());
final TransactionManager narayanaTm = jtaEnvironmentBean.getTransactionManager();
final XATerminator xat = new XATerminator();
final JBossLocalTransactionProvider.Builder builder = JBossLocalTransactionProvider.builder();
builder.setExtendedJBossXATerminator(xat);
builder.setTransactionManager(narayanaTm);
builder.setXAResourceRecoveryRegistry(new XAResourceRecoveryRegistry() {
@Override public void addXAResourceRecovery(
XAResourceRecovery xaResourceRecovery) {}
@Override public void removeXAResourceRecovery(
XAResourceRecovery xaResourceRecovery) {}
});
builder.setXARecoveryLogDirRelativeToPath(new File("target").toPath());
LocalTransactionContext.getContextManager().setGlobalDefault(new LocalTransactionContext(builder.build()));
txManager = ContextTransactionManager.getInstance();
txSyncRegistry = ContextTransactionSynchronizationRegistry.getInstance();
// setup the tx manager and tx sync registry
AuthenticationConfiguration config = AuthenticationConfiguration.empty().useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, config);
old = AuthenticationContext.captureCurrent();
AuthenticationContext.getContextManager().setGlobalDefault(context);
}
@AfterClass
public static void after() {
AuthenticationContext.getContextManager().setGlobalDefault(old);
}
/**
* Tests that a CMT stateless bean method, with Mandatory tx attribute, invocation works as expected
* when the transaction is remotely started on the client side using a client side transaction manager
*
* @throws Exception
*/
@Test
public void testSLSBMandatoryTx() throws Exception {
final StatelessEJBLocator<CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<CMTRemote>(CMTRemote.class, APP_NAME, MODULE_NAME, CMTBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
final CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
// start the transaction
txManager.begin();
// invoke the bean
cmtRemoteBean.mandatoryTxOp();
// end the tx
txManager.commit();
}
/**
* Tests various transaction scenarios managed on the client side via the client side transaction manager
*
* @throws Exception
*/
@Test
public void testClientTransactionManagement() throws Exception {
final StatelessEJBLocator<RemoteBatch> batchBeanLocator = new StatelessEJBLocator<RemoteBatch>(RemoteBatch.class, APP_NAME, MODULE_NAME, BatchCreationBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
final RemoteBatch batchBean = EJBClient.createProxy(batchBeanLocator);
final StatelessEJBLocator<BatchRetriever> batchRetrieverLocator = new StatelessEJBLocator<BatchRetriever>(BatchRetriever.class, APP_NAME, MODULE_NAME, BatchFetchingBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
final BatchRetriever batchRetriever = EJBClient.createProxy(batchRetrieverLocator);
final String batchName = "Simple Batch";
// create a batch
txManager.begin();
try {
batchBean.createBatch(batchName);
} catch (Exception e) {
txManager.rollback();
throw e;
}
txManager.commit();
// fetch the batch and make sure it contains the right state
final Batch batchAfterCreation = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch was null after creation", batchAfterCreation);
Assert.assertNull("Unexpected steps in batch, after creation", batchAfterCreation.getStepNames());
// add step1 to the batch
final String step1 = "Simple step1";
txManager.begin();
try {
batchBean.step1(batchName, step1);
} catch (Exception e) {
txManager.rollback();
throw e;
}
txManager.commit();
String successFullyCompletedSteps = step1;
// fetch the batch and make sure it contains the right state
final Batch batchAfterStep1 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step1 was null", batchAfterStep1);
Assert.assertEquals("Unexpected steps in batch, after step1", successFullyCompletedSteps, batchAfterStep1.getStepNames());
// now add a failing step2
final String appExceptionStep2 = "App exception Step 2";
txManager.begin();
try {
batchBean.appExceptionFailingStep2(batchName, appExceptionStep2);
Assert.fail("Expected an application exception");
} catch (SimpleAppException sae) {
// expected
txManager.rollback();
}
final Batch batchAfterAppExceptionStep2 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after app exception step2 was null", batchAfterAppExceptionStep2);
Assert.assertEquals("Unexpected steps in batch, after app exception step2", successFullyCompletedSteps, batchAfterAppExceptionStep2.getStepNames());
// now add a successful step2
final String step2 = "Simple Step 2";
txManager.begin();
try {
batchBean.successfulStep2(batchName, step2);
} catch (Exception e) {
txManager.rollback();
throw e;
}
// don't yet commit and try and retrieve the batch
final Batch batchAfterStep2BeforeCommit = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step2, before commit was null", batchAfterStep2BeforeCommit);
Assert.assertEquals("Unexpected steps in batch, after step2 before commit", successFullyCompletedSteps, batchAfterStep2BeforeCommit.getStepNames());
// now commit
txManager.commit();
// keep track of successfully completely steps
successFullyCompletedSteps = successFullyCompletedSteps + "," + step2;
// now retrieve and check the batch
final Batch batchAfterStep2 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step2 was null", batchAfterStep2);
Assert.assertEquals("Unexpected steps in batch, after step2", successFullyCompletedSteps, batchAfterStep2.getStepNames());
// now add independent Step3 (i.e. the bean method has a REQUIRES_NEW semantics, so that the
// client side tx doesn't play a role)
final String step3 = "Simple Step 3";
txManager.begin();
batchBean.independentStep3(batchName, step3);
// rollback (but it shouldn't end up rolling back step3 because that was done in server side independent tx)
txManager.rollback();
// keep track of successfully completely steps
successFullyCompletedSteps = successFullyCompletedSteps + "," + step3;
// now retrieve and check the batch
final Batch batchAfterStep3 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step3 was null", batchAfterStep3);
Assert.assertEquals("Unexpected steps in batch, after step3", successFullyCompletedSteps, batchAfterStep3.getStepNames());
// now add step4 but don't commit
final String step4 = "Simple Step 4";
txManager.begin();
batchBean.step4(batchName, step4);
// now add a system exception throwing step
final String sysExceptionStep2 = "Sys exception step2";
try {
batchBean.systemExceptionFailingStep2(batchName, sysExceptionStep2);
Assert.fail("Expected a system exception");
} catch (Exception e) {
// expected
//Assert.assertEquals("Unexpected transaction state", Status.STATUS_ROLLEDBACK, userTransaction.getStatus());
txManager.rollback();
}
// now retrieve and check the batch
final Batch batchAfterSysException = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after system exception was null", batchAfterSysException);
Assert.assertEquals("Unexpected steps in batch, after system exception", successFullyCompletedSteps, batchAfterSysException.getStepNames());
}
/**
* Calls for a preexistent transaction are allowed and calls for a non-preexistent transaction are not allowed
* on server suspension.
*
* @throws Exception
*/
@Test
public void testServerSuspension() throws Exception {
final StatelessEJBLocator<CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<CMTRemote>(
CMTRemote.class, APP_NAME, MODULE_NAME, CMTBean.class.getSimpleName(), "", Affinity.forUri(getHttpUri()));
final CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
// begin a transaction, and make sure that the server now works normally
txManager.begin();
try {
// invoke the bean
cmtRemoteBean.mandatoryTxOp();
} finally {
// end the tx
txManager.commit();
}
// begin the transaction
txManager.begin();
try {
// invoke the bean
cmtRemoteBean.mandatoryTxOp();
ModelNode op = new ModelNode();
op.get(OP).set("suspend");
managementClient.getControllerClient().execute(op);
txManager.commit();
} catch (Exception e) {
try {
txManager.rollback();
} catch (Exception exc) {
}
throw e;
} finally {
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
}
try {
// begin a transaction
txManager.begin();
long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
while (true) {
try {
// can invoke bean
cmtRemoteBean.mandatoryTxOp();
break;
} catch (Exception e) {
if (System.currentTimeMillis() > fin) {
throw e;
}
}
Thread.sleep(300);
}
// suspend server
ModelNode op = new ModelNode();
op.get(OP).set("suspend");
managementClient.getControllerClient().execute(op);
// FIXME check with remoting team why this transaction is not recognized as active in EJBSuspendHandlerService
// can continue invoking bean with current transaction
//cmtRemoteBean.mandatoryTxOp();
} catch (Exception e) {
e.printStackTrace();
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
throw e;
} finally {
// rollback current transaction
txManager.commit();
}
// still cannot begin a new transaction
txManager.begin();
try {
cmtRemoteBean.mandatoryTxOp();
Assert.fail("Exception expected, server is shutdown");
} catch (Exception expected) {
// expected
} finally {
txManager.rollback();
}
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
try {
// begin a transaction, and make sure that the server now works normally
txManager.begin();
long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
while (true) {
try {
// can invoke bean
cmtRemoteBean.mandatoryTxOp();
break;
} catch (Exception e) {
if (System.currentTimeMillis() > fin) {
throw e;
}
}
Thread.sleep(300);
}
// end the tx
txManager.commit();
} catch (Exception e) {
txManager.rollback();
throw e;
}
}
}
| 17,873 | 40.761682 | 235 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/Batch.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.remote.client.api.tx;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import java.io.Serializable;
/**
* User: jpai
*/
@Entity
public class Batch implements Serializable {
@Id
private String batchName;
private String stepNames;
public String getBatchName() {
return batchName;
}
public void setBatchName(String batchName) {
this.batchName = batchName;
}
public String getStepNames() {
return stepNames;
}
public void addStep(String stepName) {
if (this.stepNames == null) {
this.stepNames = stepName;
return;
}
this.stepNames = this.stepNames + "," + stepName;
}
}
| 1,775 | 28.6 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/BatchFetchingBean.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.remote.client.api.tx;
import org.jboss.logging.Logger;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionAttribute;
import jakarta.ejb.TransactionAttributeType;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
/**
* User: jpai
*/
@Stateless
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
@Remote (BatchRetriever.class)
public class BatchFetchingBean implements BatchRetriever {
private static final Logger logger = Logger.getLogger(BatchFetchingBean.class);
@PersistenceContext(unitName = "ejb-client-tx-pu")
private EntityManager entityManager;
public Batch fetchBatch(final String batchName) {
logger.trace("Fetching batch " + batchName);
return this.entityManager.find(Batch.class, batchName);
}
}
| 1,910 | 35.75 | 83 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/RemoteBatch.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.remote.client.api.tx;
/**
* User: jpai
*/
public interface RemoteBatch {
void createBatch(final String batchName);
void step1(final String batchName, final String stepName);
void successfulStep2(final String batchName, final String stepName);
void appExceptionFailingStep2(final String batchName, final String stepName) throws SimpleAppException;
void systemExceptionFailingStep2(final String batchName, final String stepName);
void independentStep3(final String batchName, final String stepName);
void step4(final String batchName, final String stepName);
}
| 1,663 | 36.818182 | 107 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/EJBClientUserTransactionTestCase.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.remote.client.api.tx;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import jakarta.transaction.UserTransaction;
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.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.integration.ejb.remote.common.EJBManagementUtil;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.dmr.ModelNode;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.StatelessEJBLocator;
import org.jboss.logging.Logger;
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.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* @author Jaikiran Pai
* @author Flavia Rainone
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup(GracefulTxnShutdownSetup.class)
public class EJBClientUserTransactionTestCase {
private static final Logger logger = Logger.getLogger(EJBClientUserTransactionTestCase.class);
private static final String APP_NAME = "ejb-remote-client-api-usertx-test";
private static final String MODULE_NAME = "ejb";
private static String nodeName;
@ArquillianResource
private ManagementClient managementClient;
/**
* Creates an EJB deployment
*
* @return
*/
@Deployment
public static Archive<?> createDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(EJBClientUserTransactionTestCase.class.getPackage());
jar.addAsManifestResource(EJBClientUserTransactionTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
ear.addAsModule(jar);
return ear;
}
/**
* Create and setup the remoting connection
*
* @throws Exception
*/
@BeforeClass
public static void beforeTestClass() throws Exception {
// the node name that the test methods can use
nodeName = EJBManagementUtil.getNodeName();
logger.trace("Using node name " + nodeName);
}
/**
* Tests an empty begin()/commit()
*
* @throws Exception
*/
@Test
public void testEmptyTxCommit() throws Exception {
final UserTransaction userTransaction = EJBClient.getUserTransaction(nodeName);
userTransaction.begin();
userTransaction.commit();
}
/**
* Tests an empty begin()/rollback()
*
* @throws Exception
*/
@Test
public void testEmptyTxRollback() throws Exception {
final UserTransaction userTransaction = EJBClient.getUserTransaction(nodeName);
userTransaction.begin();
userTransaction.rollback();
}
/**
* Tests a call to a bean method with a Mandatory tx attribute, by initiating a UserTransaction on the
* remote client side. This test ensures that the tx is propagated to the server during the bean invocation
*
* @throws Exception
*/
@Test
public void testMandatoryTxOnSLSB() throws Exception {
final StatelessEJBLocator<CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<CMTRemote>(CMTRemote.class, APP_NAME, MODULE_NAME, CMTBean.class.getSimpleName(), "");
final CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
final UserTransaction userTransaction = EJBClient.getUserTransaction(nodeName);
userTransaction.begin();
cmtRemoteBean.mandatoryTxOp();
userTransaction.commit();
}
/**
* Tests various possibilities with a user initiated UserTransaction and subsequent bean invocations
*
* @throws Exception
*/
@Test
public void testBatchOperationsInTx() throws Exception {
final StatelessEJBLocator<RemoteBatch> batchBeanLocator = new StatelessEJBLocator<RemoteBatch>(RemoteBatch.class, APP_NAME, MODULE_NAME, BatchCreationBean.class.getSimpleName(), "");
final RemoteBatch batchBean = EJBClient.createProxy(batchBeanLocator);
final StatelessEJBLocator<BatchRetriever> batchRetrieverLocator = new StatelessEJBLocator<BatchRetriever>(BatchRetriever.class, APP_NAME, MODULE_NAME, BatchFetchingBean.class.getSimpleName(), "");
final BatchRetriever batchRetriever = EJBClient.createProxy(batchRetrieverLocator);
final UserTransaction userTransaction = EJBClient.getUserTransaction(nodeName);
final String batchName = "Simple Batch";
// create a batch
userTransaction.begin();
try {
batchBean.createBatch(batchName);
} catch (Exception e) {
userTransaction.rollback();
throw e;
}
userTransaction.commit();
// add step1 to the batch
final String step1 = "Simple step1";
userTransaction.begin();
try {
batchBean.step1(batchName, step1);
} catch (Exception e) {
userTransaction.rollback();
throw e;
}
userTransaction.commit();
String successFullyCompletedSteps = step1;
// fetch the batch and make sure it contains the right state
final Batch batchAfterStep1 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step1 was null", batchAfterStep1);
Assert.assertEquals("Unexpected steps in batch, after step1", successFullyCompletedSteps, batchAfterStep1.getStepNames());
// now add a failing step2
final String appExceptionStep2 = "App exception Step 2";
userTransaction.begin();
try {
batchBean.appExceptionFailingStep2(batchName, appExceptionStep2);
Assert.fail("Expected an application exception");
} catch (SimpleAppException sae) {
// expected
userTransaction.rollback();
}
final Batch batchAfterAppExceptionStep2 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after app exception step2 was null", batchAfterAppExceptionStep2);
Assert.assertEquals("Unexpected steps in batch, after app exception step2", successFullyCompletedSteps, batchAfterAppExceptionStep2.getStepNames());
// now add a successful step2
final String step2 = "Simple Step 2";
userTransaction.begin();
try {
batchBean.successfulStep2(batchName, step2);
} catch (Exception e) {
userTransaction.rollback();
throw e;
}
// don't yet commit and try and retrieve the batch
final Batch batchAfterStep2BeforeCommit = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step2, before commit was null", batchAfterStep2BeforeCommit);
Assert.assertEquals("Unexpected steps in batch, after step2 before commit", successFullyCompletedSteps, batchAfterStep2BeforeCommit.getStepNames());
// now commit
userTransaction.commit();
// keep track of successfully completely steps
successFullyCompletedSteps = successFullyCompletedSteps + "," + step2;
// now retrieve and check the batch
final Batch batchAfterStep2 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step2 was null", batchAfterStep2);
Assert.assertEquals("Unexpected steps in batch, after step2", successFullyCompletedSteps, batchAfterStep2.getStepNames());
// now add independent Step3 (i.e. the bean method has a REQUIRES_NEW semantics, so that the
// client side tx doesn't play a role)
final String step3 = "Simple Step 3";
userTransaction.begin();
batchBean.independentStep3(batchName, step3);
// rollback (but it shouldn't end up rolling back step3 because that was done in server side independent tx)
userTransaction.rollback();
// keep track of successfully completely steps
successFullyCompletedSteps = successFullyCompletedSteps + "," + step3;
// now retrieve and check the batch
final Batch batchAfterStep3 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step3 was null", batchAfterStep3);
Assert.assertEquals("Unexpected steps in batch, after step3", successFullyCompletedSteps, batchAfterStep3.getStepNames());
// now add step4 but don't commit
final String step4 = "Simple Step 4";
userTransaction.begin();
batchBean.step4(batchName, step4);
// now add a system exception throwing step
final String sysExceptionStep2 = "Sys exception step2";
try {
batchBean.systemExceptionFailingStep2(batchName, sysExceptionStep2);
Assert.fail("Expected a system exception");
} catch (Exception e) {
// expected exception
// TODO: We currently don't return the tx status from the server to the client, so the
// client has no knowledge of the tx status. This is something that can be implemented
// by passing along the tx status as a return attachment from a remote method invocation.
// For now, let's ignore it
//Assert.assertEquals("Unexpected transaction state", Status.STATUS_ROLLEDBACK, userTransaction.getStatus());
userTransaction.rollback();
}
// now retrieve and check the batch
final Batch batchAfterSysException = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after system exception was null", batchAfterSysException);
Assert.assertEquals("Unexpected steps in batch, after system exception", successFullyCompletedSteps, batchAfterSysException.getStepNames());
}
/**
* Calls for a preexistent transaction are allowed and calls for a non-preexistent transaction are not allowed
* on server suspension.
*
* @throws Exception
*/
@Test
public void testServerSuspension() throws Exception {
final StatelessEJBLocator<CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<CMTRemote>(CMTRemote.class, APP_NAME, MODULE_NAME, CMTBean.class.getSimpleName(), "");
final CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
// begin the transaction
UserTransaction userTransaction = EJBClient.getUserTransaction(nodeName);
userTransaction.begin();
try {
// invoke the bean
cmtRemoteBean.mandatoryTxOp();
ModelNode op = new ModelNode();
op.get(OP).set("suspend");
managementClient.getControllerClient().execute(op);
userTransaction.commit();
} catch (Exception e) {
try {
userTransaction.rollback();
} catch (Exception exc) {}
throw e;
} finally {
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
}
try {
// begin a transaction
userTransaction.begin();
long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
while (true) {
try {
// can invoke bean
cmtRemoteBean.mandatoryTxOp();
break;
} catch (Exception e) {
if (System.currentTimeMillis() > fin) {
throw e;
}
}
Thread.sleep(300);
}
// suspend server
ModelNode op = new ModelNode();
op.get(OP).set("suspend");
managementClient.getControllerClient().execute(op);
// can continue invoking bean with current transaction
cmtRemoteBean.mandatoryTxOp();
} catch (Exception e) {
e.printStackTrace();
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
throw e;
} finally {
// rollback current transaction
userTransaction.commit();
}
// still cannot begin a new transaction
userTransaction.begin();
try {
cmtRemoteBean.mandatoryTxOp();
Assert.fail("Exception expected, server is shutdown");
} catch (Exception expected) {
// expected
} finally {
userTransaction.rollback();
}
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
try {
// begin a transaction, and make sure that the server now works normally
userTransaction.begin();
long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
while (true) {
try {
// can invoke bean
cmtRemoteBean.mandatoryTxOp();
break;
} catch (Exception e) {
if (System.currentTimeMillis() > fin) {
throw e;
}
}
Thread.sleep(300);
}
// end the tx
userTransaction.commit();
} catch (Exception e) {
userTransaction.rollback();
throw e;
}
}
}
| 14,992 | 38.664021 | 204 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/BatchCreationBean.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.remote.client.api.tx;
import org.jboss.logging.Logger;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateless;
import jakarta.ejb.TransactionAttribute;
import jakarta.ejb.TransactionAttributeType;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
/**
* @author Jaikiran Pai
*/
@Stateless
@Remote(RemoteBatch.class)
@TransactionAttribute (TransactionAttributeType.MANDATORY)
public class BatchCreationBean implements RemoteBatch {
private static final Logger logger = Logger.getLogger(BatchCreationBean.class);
@PersistenceContext(unitName = "ejb-client-tx-pu")
private EntityManager entityManager;
public void createBatch(final String batchName) {
final Batch batch = new Batch();
batch.setBatchName(batchName);
logger.trace("Persisting new batch " + batchName);
this.entityManager.persist(batch);
}
public void step1(final String batchName, final String stepName) {
this.addStepToBatch(batchName, stepName);
}
public void successfulStep2(final String batchName, final String stepName) {
this.addStepToBatch(batchName, stepName);
}
public void appExceptionFailingStep2(final String batchName, final String stepName) throws SimpleAppException {
this.addStepToBatch(batchName, stepName);
throw new SimpleAppException();
}
public void systemExceptionFailingStep2(final String batchName, final String stepName) {
this.addStepToBatch(batchName, stepName);
throw new RuntimeException("Intentional exception from " + this.getClass().getSimpleName());
}
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public void independentStep3(final String batchName, final String stepName) {
this.addStepToBatch(batchName, stepName);
}
public void step4(final String batchName, final String stepName) {
this.addStepToBatch(batchName, stepName);
}
private Batch requireBatch(final String batchName) {
final Batch batch = this.entityManager.find(Batch.class, batchName);
if (batch == null) {
throw new IllegalArgumentException("No such batch named " + batchName);
}
return batch;
}
private void addStepToBatch(final String batchName, final String stepName) {
final Batch batch = this.requireBatch(batchName);
batch.addStep(stepName);
this.entityManager.persist(batch);
}
}
| 3,546 | 36.336842 | 115 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/CMTRemote.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.remote.client.api.tx;
/**
* User: jpai
*/
public interface CMTRemote {
void mandatoryTxOp();
}
| 1,169 | 35.5625 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/SimpleAppException.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.remote.client.api.tx;
import jakarta.ejb.ApplicationException;
/**
* User: jpai
*/
@ApplicationException
public class SimpleAppException extends Exception {
}
| 1,229 | 36.272727 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/BatchRetriever.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.remote.client.api.tx;
/**
* User: jpai
*/
public interface BatchRetriever {
Batch fetchBatch(final String batchName);
}
| 1,193 | 37.516129 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/client/api/tx/EJBClientXidTransactionTestCase.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.remote.client.api.tx;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import java.io.File;
import jakarta.transaction.TransactionManager;
import jakarta.transaction.TransactionSynchronizationRegistry;
import com.arjuna.ats.internal.jbossatx.jta.jca.XATerminator;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple;
import com.arjuna.ats.jta.common.JTAEnvironmentBean;
import com.arjuna.ats.jta.common.jtaPropertyManager;
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.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.test.shared.TimeoutUtil;
import org.jboss.dmr.ModelNode;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.StatelessEJBLocator;
import org.jboss.logging.Logger;
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.tm.XAResourceRecovery;
import org.jboss.tm.XAResourceRecoveryRegistry;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.transaction.client.ContextTransactionManager;
import org.wildfly.transaction.client.ContextTransactionSynchronizationRegistry;
import org.wildfly.transaction.client.LocalTransactionContext;
import org.wildfly.transaction.client.provider.jboss.JBossLocalTransactionProvider;
/**
* @author Jaikiran Pai
* @author Flavia Rainone
*/
@RunWith(Arquillian.class)
@RunAsClient
@ServerSetup(GracefulTxnShutdownSetup.class)
public class EJBClientXidTransactionTestCase {
private static final Logger logger = Logger.getLogger(EJBClientXidTransactionTestCase.class);
private static final String APP_NAME = "ejb-remote-client-api-xidtx-test";
private static final String MODULE_NAME = "ejb";
private static TransactionManager txManager;
private static TransactionSynchronizationRegistry txSyncRegistry;
@ArquillianResource
private ManagementClient managementClient;
/**
* Creates an EJB deployment
*
* @return
*/
@Deployment
public static Archive<?> createDeployment() {
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, APP_NAME + ".ear");
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(EJBClientXidTransactionTestCase.class.getPackage());
jar.addAsManifestResource(EJBClientXidTransactionTestCase.class.getPackage(), "persistence.xml", "persistence.xml");
ear.addAsModule(jar);
return ear;
}
/**
* Create and setup the remoting connection
*
* @throws Exception
*/
@BeforeClass
public static void beforeTestClass() throws Exception {
// These system properties are required or else we end up picking up JTS transaction manager,
// which is not what we want
final JTAEnvironmentBean jtaEnvironmentBean = jtaPropertyManager.getJTAEnvironmentBean();
jtaEnvironmentBean.setTransactionManagerClassName(TransactionManagerImple.class.getName());
jtaEnvironmentBean.setTransactionSynchronizationRegistryClassName(TransactionSynchronizationRegistryImple.class.getName());
final TransactionManager narayanaTm = jtaEnvironmentBean.getTransactionManager();
final XATerminator xat = new XATerminator();
final JBossLocalTransactionProvider.Builder builder = JBossLocalTransactionProvider.builder();
builder.setExtendedJBossXATerminator(xat);
builder.setTransactionManager(narayanaTm);
builder.setXAResourceRecoveryRegistry(new XAResourceRecoveryRegistry() {
@Override public void addXAResourceRecovery(
XAResourceRecovery xaResourceRecovery) {}
@Override public void removeXAResourceRecovery(
XAResourceRecovery xaResourceRecovery) {}
});
builder.setXARecoveryLogDirRelativeToPath(new File("target").toPath());
LocalTransactionContext.getContextManager().setGlobalDefault(new LocalTransactionContext(builder.build()));
txManager = ContextTransactionManager.getInstance();
txSyncRegistry = ContextTransactionSynchronizationRegistry.getInstance();
// setup the tx manager and tx sync registry
}
/**
* Tests that a CMT stateless bean method, with Mandatory tx attribute, invocation works as expected
* when the transaction is remotely started on the client side using a client side transaction manager
*
* @throws Exception
*/
@Test
public void testSLSBMandatoryTx() throws Exception {
final StatelessEJBLocator<CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<CMTRemote>(CMTRemote.class, APP_NAME, MODULE_NAME, CMTBean.class.getSimpleName(), "");
final CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
// start the transaction
txManager.begin();
// invoke the bean
cmtRemoteBean.mandatoryTxOp();
// end the tx
txManager.commit();
}
/**
* Tests various transaction scenarios managed on the client side via the client side transaction manager
*
* @throws Exception
*/
@Test
public void testClientTransactionManagement() throws Exception {
final StatelessEJBLocator<RemoteBatch> batchBeanLocator = new StatelessEJBLocator<RemoteBatch>(RemoteBatch.class, APP_NAME, MODULE_NAME, BatchCreationBean.class.getSimpleName(), "");
final RemoteBatch batchBean = EJBClient.createProxy(batchBeanLocator);
final StatelessEJBLocator<BatchRetriever> batchRetrieverLocator = new StatelessEJBLocator<BatchRetriever>(BatchRetriever.class, APP_NAME, MODULE_NAME, BatchFetchingBean.class.getSimpleName(), "");
final BatchRetriever batchRetriever = EJBClient.createProxy(batchRetrieverLocator);
final String batchName = "Simple Batch";
// create a batch
txManager.begin();
try {
batchBean.createBatch(batchName);
} catch (Exception e) {
txManager.rollback();
throw e;
}
txManager.commit();
// fetch the batch and make sure it contains the right state
final Batch batchAfterCreation = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch was null after creation", batchAfterCreation);
Assert.assertNull("Unexpected steps in batch, after creation", batchAfterCreation.getStepNames());
// add step1 to the batch
final String step1 = "Simple step1";
txManager.begin();
try {
batchBean.step1(batchName, step1);
} catch (Exception e) {
txManager.rollback();
throw e;
}
txManager.commit();
String successFullyCompletedSteps = step1;
// fetch the batch and make sure it contains the right state
final Batch batchAfterStep1 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step1 was null", batchAfterStep1);
Assert.assertEquals("Unexpected steps in batch, after step1", successFullyCompletedSteps, batchAfterStep1.getStepNames());
// now add a failing step2
final String appExceptionStep2 = "App exception Step 2";
txManager.begin();
try {
batchBean.appExceptionFailingStep2(batchName, appExceptionStep2);
Assert.fail("Expected an application exception");
} catch (SimpleAppException sae) {
// expected
txManager.rollback();
}
final Batch batchAfterAppExceptionStep2 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after app exception step2 was null", batchAfterAppExceptionStep2);
Assert.assertEquals("Unexpected steps in batch, after app exception step2", successFullyCompletedSteps, batchAfterAppExceptionStep2.getStepNames());
// now add a successful step2
final String step2 = "Simple Step 2";
txManager.begin();
try {
batchBean.successfulStep2(batchName, step2);
} catch (Exception e) {
txManager.rollback();
throw e;
}
// don't yet commit and try and retrieve the batch
final Batch batchAfterStep2BeforeCommit = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step2, before commit was null", batchAfterStep2BeforeCommit);
Assert.assertEquals("Unexpected steps in batch, after step2 before commit", successFullyCompletedSteps, batchAfterStep2BeforeCommit.getStepNames());
// now commit
txManager.commit();
// keep track of successfully completely steps
successFullyCompletedSteps = successFullyCompletedSteps + "," + step2;
// now retrieve and check the batch
final Batch batchAfterStep2 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step2 was null", batchAfterStep2);
Assert.assertEquals("Unexpected steps in batch, after step2", successFullyCompletedSteps, batchAfterStep2.getStepNames());
// now add independent Step3 (i.e. the bean method has a REQUIRES_NEW semantics, so that the
// client side tx doesn't play a role)
final String step3 = "Simple Step 3";
txManager.begin();
batchBean.independentStep3(batchName, step3);
// rollback (but it shouldn't end up rolling back step3 because that was done in server side independent tx)
txManager.rollback();
// keep track of successfully completely steps
successFullyCompletedSteps = successFullyCompletedSteps + "," + step3;
// now retrieve and check the batch
final Batch batchAfterStep3 = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after step3 was null", batchAfterStep3);
Assert.assertEquals("Unexpected steps in batch, after step3", successFullyCompletedSteps, batchAfterStep3.getStepNames());
// now add step4 but don't commit
final String step4 = "Simple Step 4";
txManager.begin();
batchBean.step4(batchName, step4);
// now add a system exception throwing step
final String sysExceptionStep2 = "Sys exception step2";
try {
batchBean.systemExceptionFailingStep2(batchName, sysExceptionStep2);
Assert.fail("Expected a system exception");
} catch (Exception e) {
// expected
//Assert.assertEquals("Unexpected transaction state", Status.STATUS_ROLLEDBACK, userTransaction.getStatus());
txManager.rollback();
}
// now retrieve and check the batch
final Batch batchAfterSysException = batchRetriever.fetchBatch(batchName);
Assert.assertNotNull("Batch after system exception was null", batchAfterSysException);
Assert.assertEquals("Unexpected steps in batch, after system exception", successFullyCompletedSteps, batchAfterSysException.getStepNames());
}
/**
* Calls for a preexistent transaction are allowed and calls for a non-preexistent transaction are not allowed
* on server suspension.
*
* @throws Exception
*/
@Test
public void testServerSuspension() throws Exception {
final StatelessEJBLocator<org.jboss.as.test.integration.ejb.remote.client.api.tx.CMTRemote> cmtRemoteBeanLocator = new StatelessEJBLocator<org.jboss.as.test.integration.ejb.remote.client.api.tx.CMTRemote>(
org.jboss.as.test.integration.ejb.remote.client.api.tx.CMTRemote.class, APP_NAME, MODULE_NAME, org.jboss.as.test.integration.ejb.remote.client.api.tx.CMTBean.class.getSimpleName(), "");
final org.jboss.as.test.integration.ejb.remote.client.api.tx.CMTRemote cmtRemoteBean = EJBClient.createProxy(cmtRemoteBeanLocator);
// begin a transaction, and make sure that the server now works normally
txManager.begin();
try {
// invoke the bean
cmtRemoteBean.mandatoryTxOp();
} finally {
// end the tx
txManager.commit();
}
// begin the transaction
txManager.begin();
try {
// invoke the bean
cmtRemoteBean.mandatoryTxOp();
ModelNode op = new ModelNode();
op.get(OP).set("suspend");
managementClient.getControllerClient().execute(op);
txManager.commit();
} catch (Exception e) {
try {
txManager.rollback();
} catch (Exception exc) {}
throw e;
} finally {
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
}
try {
// begin a transaction
txManager.begin();
long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
while (true) {
try {
// can invoke bean
cmtRemoteBean.mandatoryTxOp();
break;
} catch (Exception e) {
if (System.currentTimeMillis() > fin) {
throw e;
}
}
Thread.sleep(300);
}
// suspend server
ModelNode op = new ModelNode();
op.get(OP).set("suspend");
managementClient.getControllerClient().execute(op);
// can continue invoking bean with current transaction
cmtRemoteBean.mandatoryTxOp();
} catch (Exception e) {
e.printStackTrace();
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
throw e;
} finally {
// rollback current transaction
txManager.commit();
}
// still cannot begin a new transaction
txManager.begin();
try {
cmtRemoteBean.mandatoryTxOp();
Assert.fail("Exception expected, server is shutdown");
} catch (Exception expected) {
// expected
} finally {
txManager.rollback();
}
// resume server
ModelNode op = new ModelNode();
op.get(OP).set("resume");
managementClient.getControllerClient().execute(op);
try {
// begin a transaction, and make sure that the server now works normally
txManager.begin();
long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
while (true) {
try {
// can invoke bean
cmtRemoteBean.mandatoryTxOp();
break;
} catch (Exception e) {
if (System.currentTimeMillis() > fin) {
throw e;
}
}
Thread.sleep(300);
}
// end the tx
txManager.commit();
} catch (Exception e) {
txManager.rollback();
throw e;
}
}
}
| 16,797 | 40.682382 | 213 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/EjbInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import org.junit.Assert;
public class EjbInterceptor {
@AroundInvoke
public Object interceptor(InvocationContext context) throws Exception {
Assert.assertNotNull(context.getParameters());
Assert.assertEquals(1, context.getParameters().length);
Assert.assertTrue(context.getParameters()[0] instanceof UseCaseValidator);
// test before the ejb is invoked
UseCaseValidator useCaseValidator = (UseCaseValidator) context.getParameters()[0];
useCaseValidator.test(UseCaseValidator.InvocationPhase.SERVER_INT_BEFORE, context.getContextData());
// test after the ejb is invoked
useCaseValidator = (UseCaseValidator) context.proceed();
useCaseValidator.test(UseCaseValidator.InvocationPhase.SERVER_INT_AFTER, context.getContextData());
return useCaseValidator;
}
}
| 2,024 | 43.021739 | 108 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/UseCaseValidator.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.jboss.logging.Logger;
public class UseCaseValidator implements Serializable {
private final List<UseCase> useCases = new ArrayList<>();
private final Interface iface;
public UseCaseValidator(Interface iface) {
this.iface = iface;
init();
}
public List<UseCase> getUseCases() {
return this.useCases;
}
public static enum Interface {
LOCAL, REMOTE
}
public static enum InvocationPhase {
CLIENT_INT_HANDLE_INVOCATION, SERVER_INT_BEFORE, SERVER_EJB_INVOKE, SERVER_INT_AFTER, CLIENT_INT_HANDLE_INVOCATION_RESULT
}
private void init() {
int i = 1;
// *) We should probably clear the entire ContextData before the client unmarshalls the response, but we are going to try
// this upstream since we do not wnat to potentially break some customer in EAP 7
// - we also need to make sure there is no CDI stuff that needs to keep it.
// Document special keys, like jboss.returned.keys, jboss.source.address, etc Make sure these are in
// Use Case 1 - client interceptor sends data to EJB , but it is not sent back
useCases.add(new UseCase(i++, "client interceptor sends data to EJB , but it is not sent back") {
@Override
public void init() {
// add data to UseCase1 key in the client interceptor and expect to see it until the server interceptor finishes
// we should not see it in the client inteceptor result handle, as we do not include it in the jboss.return.keys
// TODO it looks like the local interface sents back the data even if jboss.returned.keys is not set, this is a hack to handle the difference
String serverUpdatedValue = getSimpleData("server-updated");
// we will set the value on the client side and expect it to never change
if(iface == Interface.REMOTE) {
super.addExpectation(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
} else { // local interface is getting the returned value since it is inVM, so we will expect it to change
super.addExpectation(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION, InvocationPhase.SERVER_INT_AFTER);
super.addExpectation(InvocationPhase.SERVER_INT_AFTER, serverUpdatedValue);
}
super.putData(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
// TODO since the client side does not clear out all keys, it will still see the original value sent by the client
// in the future we should see if we can clear all keys out before unmarshalling the response
// until then, this test will change the value on the server side to validate the new value is not sent back, we will
// just expect the original value
super.putData(InvocationPhase.SERVER_INT_AFTER, serverUpdatedValue);
}
});
// Use Case 2
getUseCases().add(new UseCase(i++, "client interceptor sends data to EJB, EJB sees it and sends back") {
@Override
public void init() {
// add data to UseCase1 key in the client interceptor and expect to see it until the server interceptor finishes
// we should not see it in the client inteceptor result handle, as we do not include it in the jboss.return.keys
// we want this key / value sent back from the server
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
// put a value in the client side to send to the server
super.addExpectation(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION, InvocationPhase.SERVER_INT_AFTER);
super.putData(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
// change the value and expectation to a different value to make sure the value was sent back
String updated = getSimpleData("server-updated");
super.putData(InvocationPhase.SERVER_INT_AFTER, updated);
super.addExpectation(InvocationPhase.SERVER_INT_AFTER, updated);
// addExpectation (adds expectation to start after , and removes the expectation after phase has been checked)
// putData - adds it to the ContextData in the given phase - this happens after testing
}
});
// 3) client interceptor sends data to EJB, EJB modifies and sends back
getUseCases().add(new UseCase(i++, "client interceptor sends data to EJB, EJB modifies and sends back") {
@Override
public void init() {
// we want this key / value sent back from the server
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
// put a value in the client side to send to the server
super.addExpectation(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION, InvocationPhase.SERVER_EJB_INVOKE);
super.putData(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
// change the value and expectation to a different value to make sure the value was sent back
String updated = getSimpleData("server-updated");
super.putData(InvocationPhase.SERVER_EJB_INVOKE, updated);
super.addExpectation(InvocationPhase.SERVER_EJB_INVOKE, updated);
}
});
// 4) client interceptor sends data to EJB, EJB removes it and client sees it removed
getUseCases().add(new UseCase(i++, "client interceptor sends data to EJB, EJB removes it and client sees it removed") {
@Override
public void init() {
// we want this key / value sent back from the server
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
// we will send a set of size 2 and the ejb will remove 1 and send it back
Set<String> data = new HashSet<>();
data.add("A");
data.add("B");
// put a value in the client side to send to the server
super.addExpectation(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION, InvocationPhase.SERVER_EJB_INVOKE, data);
super.putData(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION, data);
// remove B when the EJB invokes
super.addPhaseContextDataConsumer(InvocationPhase.SERVER_EJB_INVOKE, (Consumer<Map<String,Object>> & Serializable) o -> ((Set<String>)o.get(this.getContextDataUseCaseKey())).remove("B") );
// change the expectation to match
Set<String> updated = new HashSet<>();
updated.add("A");
super.addExpectation(InvocationPhase.SERVER_EJB_INVOKE, updated);
}
});
// 5) client interceptor sends data to EJB, EJB removes it and client sees that the value is null as it was not returned
getUseCases().add(new UseCase(i++, "client interceptor sends data to EJB, EJB removes it and client sees that the value is null as it was not returned") {
@Override
public void init() {
// we want this key / value sent back from the server
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
// we will send a set of size 2 and the ejb will remove 1 and send it back
Set<String> data = new HashSet<>();
data.add("A");
data.add("B");
// put a value in the client side to send to the server
super.addExpectation(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION, InvocationPhase.SERVER_EJB_INVOKE, data);
super.putData(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION, data);
// remove the data, and set the expectation that it is not returned
super.removeData(InvocationPhase.SERVER_EJB_INVOKE);
// change the expectation to match , expect null
super.removeExpectation(InvocationPhase.SERVER_EJB_INVOKE);
}
});
// EJB Interceptor setting data:
// 6) EJB Interceptor sets data, EJB sees it
getUseCases().add(new UseCase(i++, "EJB Interceptor sets data, EJB sees it") {
@Override
public void init() {
// put a value in the ejb interceptor
// it will not be returned, so we should see it from Server Interceptor Before -> EJB -> Server Interceptor After for Remote
if(iface == Interface.REMOTE)
super.addExpectation(InvocationPhase.SERVER_INT_BEFORE, InvocationPhase.SERVER_INT_AFTER);
else // local sees it on the return
super.addExpectation(InvocationPhase.SERVER_INT_BEFORE, InvocationPhase.CLIENT_INT_HANDLE_INVOCATION_RESULT);
super.putData(InvocationPhase.SERVER_INT_BEFORE);
}
});
// 7) EJB Interceptor sets data, EJB sees it, client sees it sent back
getUseCases().add(new UseCase(i++, "EJB Interceptor sets data, EJB sees it, client sees it sent back") {
@Override
public void init() {
// put a value in the ejb interceptor
// this is same as 5 , except both will see it sent back since we set the jboss.returned.keys
// the return keys has to be set on the client side before making the call
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
super.addExpectation(InvocationPhase.SERVER_INT_BEFORE, InvocationPhase.CLIENT_INT_HANDLE_INVOCATION_RESULT);
super.putData(InvocationPhase.SERVER_INT_BEFORE);
}
});
// 8) EJB Interceptor sets data, EJB sees it, EJB modifies it, client sees it sent back
getUseCases().add(new UseCase(i++, "EJB Interceptor sets data, EJB sees it, EJB modifies it, client sees it sent back") {
@Override
public void init() {
// put a value in the ejb interceptor
// the return keys has to be set on the client side before making the call
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
super.addExpectation(InvocationPhase.SERVER_INT_BEFORE, InvocationPhase.SERVER_EJB_INVOKE);
super.putData(InvocationPhase.SERVER_INT_BEFORE);
String updated = getSimpleData("server-updated");
super.addExpectation(InvocationPhase.SERVER_EJB_INVOKE, InvocationPhase.CLIENT_INT_HANDLE_INVOCATION_RESULT, updated);
super.putData(InvocationPhase.SERVER_EJB_INVOKE, updated);
}
});
// 9) EJB Interceptor sets data, EJB sees it, EJB removes it, client sees it removed
getUseCases().add(new UseCase(i++, "EJB Interceptor sets data, EJB sees it, EJB removes it, client sees it removed") {
@Override
public void init() {
// put a value in the ejb interceptor
// the return keys has to be set on the client side before making the call
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
super.addExpectation(InvocationPhase.SERVER_INT_BEFORE, InvocationPhase.SERVER_EJB_INVOKE);
super.putData(InvocationPhase.SERVER_INT_BEFORE);
super.removeData(InvocationPhase.SERVER_EJB_INVOKE);
super.addExpectation(InvocationPhase.SERVER_EJB_INVOKE, InvocationPhase.CLIENT_INT_HANDLE_INVOCATION_RESULT, null);
}
});
// 10) EJB Interceptor sets data after EJB call, EJB does not it, client sees it
getUseCases().add(new UseCase(i++, "EJB Interceptor sets data after EJB call, EJB does not it, client sees it") {
@Override
public void init() {
// put a value in the ejb interceptor
// the return keys has to be set on the client side before making the call
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
super.addExpectation(InvocationPhase.SERVER_INT_AFTER, InvocationPhase.CLIENT_INT_HANDLE_INVOCATION_RESULT);
super.putData(InvocationPhase.SERVER_INT_AFTER);
}
});
// EJB Setting data:
// 11) EJB sends data, EJB interceptor sees it at end, client interceptor does not it
getUseCases().add(new UseCase(i++, "EJB sends data, EJB interceptor sees it at end, client interceptor does not it") {
@Override
public void init() {
// put a value in the ejb
// since local sees values without jboss.returned.keys being set, we set the expectations differently
if(iface == Interface.REMOTE)
super.addExpectation(InvocationPhase.SERVER_EJB_INVOKE, InvocationPhase.SERVER_INT_AFTER);
else
super.addExpectation(InvocationPhase.SERVER_EJB_INVOKE, InvocationPhase.CLIENT_INT_HANDLE_INVOCATION_RESULT);
super.putData(InvocationPhase.SERVER_EJB_INVOKE);
}
});
// 12) EJB sends data, EJB interceptor sees it at end, client interceptor sees it
getUseCases().add(new UseCase(i++, "EJB sends data, EJB interceptor sees it at end, client interceptor sees it") {
@Override
public void init() {
// same as 10 except both remote & local will see the same as jboss.returned.keys will be set
// the return keys has to be set on the client side before making the call
super.addReturnKey(InvocationPhase.CLIENT_INT_HANDLE_INVOCATION);
// put a value in the ejb
super.addExpectation(InvocationPhase.SERVER_EJB_INVOKE, InvocationPhase.CLIENT_INT_HANDLE_INVOCATION_RESULT);
super.putData(InvocationPhase.SERVER_EJB_INVOKE);
}
});
}
public void test(InvocationPhase phase, Map<String, Object> contextData) throws TestException {
for(UseCase uc: getUseCases())
uc.test(phase, contextData);
}
public abstract static class UseCase implements Serializable {
protected Logger logger;
protected Map<InvocationPhase, Object> putDataAtPhase = new HashMap<>();
protected Map<InvocationPhase, Object> removeDataAtPhase = new HashMap<>();
protected Map<InvocationPhase, Object> addExpectationAtPhase = new HashMap<>();
protected Map<InvocationPhase, String> addReturnKeyAtPhase = new HashMap<>();
protected Set<InvocationPhase> removeExpectationAtPhase = new HashSet<>();
protected Map<InvocationPhase, Consumer<Map<String,Object>>> phaseContextDataConsumer = new HashMap<>();
protected int useCaseNumber;
protected String description;
protected String contextDataUseCaseKey;
protected Object expected;
public static final String RETURNED_CONTEXT_DATA_KEY = "jboss.returned.keys";
public UseCase(int useCaseNumber, String description) {
this.useCaseNumber = useCaseNumber;
this.description = description;
this.contextDataUseCaseKey = String.format("UseCase-%d", useCaseNumber);
this.logger = Logger.getLogger(String.format("%s-%d", UseCase.class.getName(), useCaseNumber));
init();
}
public abstract void init();
public String getContextDataUseCaseKey() {
return this.contextDataUseCaseKey;
}
private static boolean equal(Object o1, Object o2) {
if(o1 != null)
return o1.equals(o2);
if(o2 != null)
return o2.equals(o1);
return o1 == o2;
}
// test will text expected matches
// the actual value must always match the expected value else an exception will be thrown
// when an expectation is removed, it is null and it is expected the actual value will also be null
public void test(InvocationPhase phase, Map<String, Object> contextData) throws TestException {
// expectations get tested first
// changes to the expectations happen after the test
// so we need to have a before / after
contextData.keySet().forEach(k ->
logger.debugf("%s: ContextData %s -> %s", phase, k, contextData.get(k)));
// test first before making any changes to expectations
logger.debugf("phase: %s Test the current expectation: expected: %s contextDataUseCaseKey: %s value: %s", phase, expected, contextDataUseCaseKey, contextData.get(contextDataUseCaseKey));
// Test the current expectation
if(!equal(expected, contextData.get(contextDataUseCaseKey)))
throw new TestException(String.format("%s : phase: %s expected: %s != actual: %s", this, phase, expected, contextData.get(contextDataUseCaseKey)));
// remove the expected
if (this.removeExpectationAtPhase.contains(phase)) {
logger.debugf("phase: %s removeExpectationAtPhase %s expected: %s", phase, this.removeExpectationAtPhase, expected);
this.expected = null;
}
// in the given phase add or remove an expectation
if(this.addExpectationAtPhase.containsKey(phase)) {
logger.debugf("phase: %s addExpectationAtPhase %s", phase, this.addExpectationAtPhase.get(phase));
this.expected = this.addExpectationAtPhase.get(phase);
}
// in the given phase put the data
if(this.removeDataAtPhase.containsKey(phase)) {
logger.debugf("phase: %s removeDataAtPhase %s", phase, this.removeDataAtPhase.get(phase));
contextData.remove(this.removeDataAtPhase.get(phase));
}
// in the given phase put the data
if(this.putDataAtPhase.containsKey(phase)) {
logger.debugf("phase: %s putDataAtPhase %s", phase, this.putDataAtPhase.get(phase));
put(contextData, this.putDataAtPhase.get(phase));
}
// add any keys to jboss.returned.keys
if(this.addReturnKeyAtPhase.containsKey(phase)) {
logger.debugf("phase: %s addReturnKeyAtPhase %s", phase, addReturnKeyAtPhase);
Set<String> jbossReturnedKeys = (Set<String>) contextData.get(RETURNED_CONTEXT_DATA_KEY);
if(jbossReturnedKeys == null) {
jbossReturnedKeys = new HashSet<String>();
contextData.put(RETURNED_CONTEXT_DATA_KEY, jbossReturnedKeys);
}
jbossReturnedKeys.add(this.addReturnKeyAtPhase.get(phase));
}
// Call back with ContextData for advanced manipulation
Consumer<Map<String,Object>> consumer = this.phaseContextDataConsumer.get(phase);
if(consumer != null) consumer.accept(contextData);
}
@Override
public String toString() {
return String.format("UseCase-%d: %s", useCaseNumber, description);
}
public void addPhaseContextDataConsumer(InvocationPhase phase, Consumer<Map<String,Object>> consumer) {
this.phaseContextDataConsumer.put(phase, consumer);
}
public void put(Map<String, Object> contextData, Object value) {
contextData.put(contextDataUseCaseKey, value);
}
public void putData(InvocationPhase putDataAtPhase, Object value) {
this.putDataAtPhase.put(putDataAtPhase, value);
}
public void putData(InvocationPhase putDataAtPhase) {
putData(putDataAtPhase, getSimpleData());
}
public void removeData(InvocationPhase putDataAtPhase) {
this.removeDataAtPhase.put(putDataAtPhase, this.contextDataUseCaseKey);
}
public String getSimpleData() {
return String.format("%s-Data", contextDataUseCaseKey);
}
public String getSimpleData(String suffix) {
return String.format("%s-%s", getSimpleData(), suffix);
}
public void addReturnKey(InvocationPhase addReturnKeyAtPhase) {
this.addReturnKeyAtPhase.put(addReturnKeyAtPhase, this.contextDataUseCaseKey);
}
public void addExpectation(InvocationPhase addValueAtPhase) {
addExpectation(addValueAtPhase, getSimpleData());
}
public void addExpectation(InvocationPhase addValueAtPhase, Object value) {
this.addExpectationAtPhase.put(addValueAtPhase, value);
}
public void addExpectation(InvocationPhase addValueAtPhase, InvocationPhase removeExpectationAtPhase) {
addExpectation(addValueAtPhase, removeExpectationAtPhase, getSimpleData());
}
public void addExpectation(InvocationPhase addValueAtPhase, InvocationPhase removeExpectationAtPhase, Object value) {
addExpectation(addValueAtPhase, value);
removeExpectation(removeExpectationAtPhase);
}
public void removeExpectation(InvocationPhase removeExpectationAtPhase) {
this.removeExpectationAtPhase.add(removeExpectationAtPhase);
}
}
}
| 22,857 | 48.156989 | 204 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/ClientInterceptorReturnDataLocalTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import jakarta.ejb.EJB;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.ejb.client.EJBClientInterceptor;
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 context data from the server is returned to client interceptors
* for an in-vm invocation.
*
* @author Stuart Douglas
* @author Brad Maxwell
*/
@RunWith(Arquillian.class)
public class ClientInterceptorReturnDataLocalTestCase {
@Deployment()
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ClientInterceptorReturnDataLocalTestCase.class.getSimpleName() + ".jar");
jar.addPackage(ClientInterceptorReturnDataLocalTestCase.class.getPackage());
jar.addAsServiceProvider(EJBClientInterceptor.class, ClientInterceptor.class);
return jar;
}
@EJB
TestRemote testSingleton;
@Test
public void testInvokeWithClientInterceptorData() {
try {
UseCaseValidator useCaseValidator = new UseCaseValidator(UseCaseValidator.Interface.LOCAL);
testSingleton.invoke(useCaseValidator);
} catch(TestException te) {
Assert.fail(te.getMessage());
}
}
}
| 2,499 | 36.313433 | 136 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/ClientInterceptor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import org.jboss.ejb.client.EJBClientInterceptor;
import org.jboss.ejb.client.EJBClientInvocationContext;
import org.jboss.logging.Logger;
import org.junit.Assert;
/**
* Client side JBoss interceptor.
*/
public class ClientInterceptor implements EJBClientInterceptor {
private static final Logger logger = Logger.getLogger(ClientInterceptor.class);
/**
* Creates a new ClientInterceptor object.
*/
public ClientInterceptor() {
}
@Override
public void handleInvocation(EJBClientInvocationContext context) throws Exception {
logger.debugf("%s: ContextData: %s", "handleInvocation", context.getContextData());
Assert.assertNotNull(context.getParameters());
Assert.assertEquals(1, context.getParameters().length);
Assert.assertTrue(context.getParameters()[0] instanceof UseCaseValidator);
((UseCaseValidator)context.getParameters()[0]).test(UseCaseValidator.InvocationPhase.CLIENT_INT_HANDLE_INVOCATION, context.getContextData());
logger.debugf("%s: ContextData: %s", "handleInvocation", context.getContextData());
// Must make this call
context.sendRequest();
}
@Override
public Object handleInvocationResult(EJBClientInvocationContext context) throws Exception {
UseCaseValidator useCaseValidator = (UseCaseValidator) context.getResult();
Assert.assertNotNull(useCaseValidator);
try {
return useCaseValidator; //in case there was an exception
} finally {
logger.debugf("%s: ContextData: %s", "handleInvocationResult", context.getContextData());
useCaseValidator.test(UseCaseValidator.InvocationPhase.CLIENT_INT_HANDLE_INVOCATION_RESULT, context.getContextData());
}
}
}
| 2,776 | 39.838235 | 147 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/ClientInterceptorReturnDataRemoteTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.PrivilegedExceptionAction;
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.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.ejb.client.EJBClientContext;
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 org.wildfly.naming.client.WildFlyInitialContextFactory;
/**
* Tests that context data from the server is returned to client interceptors
* for an true remote invocation.
*
* @author Stuart Douglas
* @author Brad Maxwell
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ClientInterceptorReturnDataRemoteTestCase {
@ArquillianResource
URL url;
@ContainerResource
private ManagementClient managementClient;
private static final String username = "user1";
private static final String password = "password1";
private static enum Protocol {
REMOTE_HTTP("remote+http"),
HTTP("http");
private final String value;
Protocol(String value){
this.value = value;
}
@Override
public String toString() {
return value;
}
}
@Deployment()
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ClientInterceptorReturnDataRemoteTestCase.class.getSimpleName() + ".jar");
jar.addPackage(ClientInterceptorReturnDataRemoteTestCase.class.getPackage());
return jar;
}
@Test
public void testInvokeWithClientInterceptorData() throws Throwable {
EJBClientContext context = EJBClientContext.getCurrent().withAddedInterceptors(new ClientInterceptor());
context.runExceptionAction(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
Context ic = getInitialContext(Protocol.REMOTE_HTTP);
TestRemote bean = (TestRemote) ic.lookup("ejb:/" + ClientInterceptorReturnDataRemoteTestCase.class.getSimpleName() + "/" + TestSLSB.class.getSimpleName() + "!" + TestRemote.class.getName());
UseCaseValidator useCaseValidator = new UseCaseValidator(UseCaseValidator.Interface.REMOTE);
try {
useCaseValidator = bean.invoke(useCaseValidator);
} catch(TestException te) {
Assert.fail(te.getMessage());
}
return useCaseValidator;
}
});
}
@Test
public void testInvokeOverHttpWithClientInterceptorData() throws Throwable {
EJBClientContext context = EJBClientContext.getCurrent().withAddedInterceptors(new ClientInterceptor());
context.runExceptionAction(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws Exception {
Context ic = getInitialContext(Protocol.HTTP);
TestRemote bean = (TestRemote) ic.lookup("ejb:/" + ClientInterceptorReturnDataRemoteTestCase.class.getSimpleName()
+ "/" + TestSLSB.class.getSimpleName() + "!" + TestRemote.class.getName());
UseCaseValidator useCaseValidator = new UseCaseValidator(UseCaseValidator.Interface.REMOTE);
try {
useCaseValidator = bean.invoke(useCaseValidator);
} catch (TestException te) {
Assert.fail(te.getMessage());
}
return useCaseValidator;
}
});
}
private Context getInitialContext(Protocol protocol) throws Exception {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
props.put(Context.PROVIDER_URL, getHttpUri(protocol).toString());
if(username != null && password != null) {
props.put(Context.SECURITY_PRINCIPAL, username);
props.put(Context.SECURITY_CREDENTIALS, password);
}
return new InitialContext(props);
}
private URI getHttpUri(Protocol protocol) throws URISyntaxException {
URI webUri = managementClient.getWebUri();
if(protocol == Protocol.HTTP)
return new URI(protocol.toString(), webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "/wildfly-services", "", "");
else
return new URI(protocol.toString(), null, webUri.getHost(), webUri.getPort(), null, null, null);
}
}
| 6,078 | 38.219355 | 206 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/TestException.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import java.io.Serializable;
/**
* @author Brad Maxwell
*
*/
public class TestException extends Exception implements Serializable {
/**
* @param message
*/
public TestException(String message) {
super(message);
}
}
| 1,334 | 34.131579 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/ClientInterceptorReturnDataEjbOverHttpTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
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.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.naming.client.WildFlyInitialContextFactory;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.MatchRule;
/**
* Tests that context data from the server is returned to client interceptors
* for an invocation using EJB over HTTP.
*
* @author Joerg Baesner
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ClientInterceptorReturnDataEjbOverHttpTestCase {
@ArquillianResource
URL url;
@ContainerResource
private ManagementClient managementClient;
@Deployment()
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ClientInterceptorReturnDataEjbOverHttpTestCase.class.getSimpleName() + ".jar");
jar.addPackage(ClientInterceptorReturnDataEjbOverHttpTestCase.class.getPackage());
return jar;
}
private static AuthenticationContext old;
@BeforeClass
public static void setup() {
AuthenticationConfiguration config = AuthenticationConfiguration.empty().useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, config);
old = AuthenticationContext.captureCurrent();
AuthenticationContext.getContextManager().setGlobalDefault(context);
}
@AfterClass
public static void after() {
AuthenticationContext.getContextManager().setGlobalDefault(old);
}
public Context getContext() throws Exception {
final Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
props.put(Context.PROVIDER_URL, getHttpUri());
return new InitialContext(props);
}
private URI getHttpUri() throws URISyntaxException {
URI webUri = managementClient.getWebUri();
return new URI("http", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "/wildfly-services", "", "");
}
@Test
@RunAsClient
public void testInvokeWithClientInterceptorData() throws Throwable {
final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new ClientInterceptor());
ejbClientContext.runCallable(() -> {
TestRemote bean = (TestRemote) getContext().lookup("ejb:/" + ClientInterceptorReturnDataEjbOverHttpTestCase.class.getSimpleName() + "/" + TestSLSB.class.getSimpleName() + "!" + TestRemote.class.getName());
UseCaseValidator useCaseValidator = new UseCaseValidator(UseCaseValidator.Interface.REMOTE);
try {
useCaseValidator = bean.invoke(useCaseValidator);
} catch(TestException te) {
Assert.fail(te.getMessage());
}
return useCaseValidator;
});
}
}
| 4,813 | 39.116667 | 217 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/TestSLSB.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import jakarta.annotation.Resource;
import jakarta.ejb.SessionContext;
import jakarta.ejb.Stateless;
import jakarta.interceptor.Interceptors;
@Stateless
@Interceptors(EjbInterceptor.class)
public class TestSLSB implements TestRemote {
@Resource
SessionContext sessionContext;
@Override
public UseCaseValidator invoke(UseCaseValidator useCaseValidator) throws TestException {
// test when the ejb is invoked
useCaseValidator.test(UseCaseValidator.InvocationPhase.SERVER_EJB_INVOKE, sessionContext.getContextData());
return useCaseValidator;
}
}
| 1,677 | 37.136364 | 115 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/contextdata/TestRemote.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.contextdata;
import jakarta.ejb.Remote;
@Remote
public interface TestRemote {
UseCaseValidator invoke(UseCaseValidator useCaseValidator) throws TestException;
}
| 1,240 | 37.78125 | 84 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/classloading/CrossDeploymentRemoteInvocationTestCase.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.remote.classloading;
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.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;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Tests cross deployment remote EJB invocation, when the deployments cannot see each others classes
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class CrossDeploymentRemoteInvocationTestCase {
@Deployment(name = "caller")
public static Archive<?> caller() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "caller.jar");
jar.addClasses(CrossDeploymentRemoteInvocationTestCase.class, RemoteInterface.class);
return jar;
}
@Deployment(name = "callee", testable = false)
public static Archive<?> callee() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "callee.jar");
jar.addClasses(StatelessRemoteBean.class, RemoteInterface.class);
return jar;
}
@ArquillianResource
private InitialContext iniCtx;
protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException {
return interfaceType.cast(iniCtx.lookup("java:global/callee/" + beanName + "!" + interfaceType.getName()));
}
@OperateOnDeployment("caller")
@Test
public void testCrossDeploymentInvocation() throws Exception {
RemoteInterface bean = lookup("StatelessRemoteBean", RemoteInterface.class);
Assert.assertEquals("hello bob", bean.hello("bob"));
}
}
| 2,916 | 36.883117 | 115 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/classloading/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.remote.classloading;
import jakarta.ejb.Remote;
/**
* @author Stuart Douglas
*/
@Remote
public interface RemoteInterface {
String hello(final String name);
}
| 1,226 | 34.057143 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/classloading/StatelessRemoteBean.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.remote.classloading;
import jakarta.ejb.Stateless;
/**
*
*/
@Stateless
public class StatelessRemoteBean implements RemoteInterface {
@Override
public String hello(String name ) {
return "hello " + name;
}
}
| 1,300 | 32.358974 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/byvalue/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.remote.byvalue;
import jakarta.ejb.Local;
/**
* @author Stuart Douglas
*/
@Local
public interface LocalInterface {
void modifyArray(final String[] array);
}
| 1,225 | 34.028571 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/byvalue/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.remote.byvalue;
import jakarta.ejb.Remote;
/**
* @author Stuart Douglas
*/
@Remote
public interface RemoteInterface {
void modifyArray(final String[] array);
}
| 1,228 | 34.114286 | 73 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/byvalue/RemoteInvocationByValueTestCase.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.remote.byvalue;
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;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Simple remote ejb tests
*
* @author Stuart Douglas
*/
@RunWith(Arquillian.class)
public class RemoteInvocationByValueTestCase {
private static final String ARCHIVE_NAME = "RemoteInvocationTest";
@Deployment
public static Archive<?> deploy() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, ARCHIVE_NAME + ".jar");
jar.addPackage(RemoteInvocationByValueTestCase.class.getPackage());
return jar;
}
@ArquillianResource
private InitialContext iniCtx;
protected <T> T lookup(String beanName, Class<T> interfaceType) throws NamingException {
return interfaceType.cast(iniCtx.lookup("java:global/" + ARCHIVE_NAME + "/" + beanName + "!" + interfaceType.getName()));
}
@Test
public void testInvocationOnRemoteInterface() throws Exception {
String[] array = {"hello"};
RemoteInterface remote = lookup(StatelessRemoteBean.class.getSimpleName(), RemoteInterface.class);
remote.modifyArray(array);
Assert.assertEquals("hello", array[0]);
LocalInterface local = lookup(StatelessRemoteBean.class.getSimpleName(), LocalInterface.class);
local.modifyArray(array);
Assert.assertEquals("goodbye", array[0]);
}
}
| 2,785 | 36.648649 | 129 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/byvalue/StatelessRemoteBean.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.remote.byvalue;
import jakarta.ejb.Stateless;
/**
*
*/
@Stateless
public class StatelessRemoteBean implements RemoteInterface , LocalInterface{
public void modifyArray(final String[] array) {
array[0] = "goodbye";
}
}
| 1,307 | 33.421053 | 78 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/jndi/RemoteCounter.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.remote.jndi;
/**
* @author Jaikiran Pai
*/
public interface RemoteCounter {
int getCount();
void incrementCount();
void decrementCount();
}
| 1,224 | 33.027778 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/jndi/EchoMessage.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.remote.jndi;
import java.io.Serializable;
/**
*
*/
public class EchoMessage implements Serializable {
private String message;
public void setMessage(final String msg) {
this.message = msg;
}
public String getMessage() {
return this.message;
}
}
| 1,358 | 29.886364 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/jndi/HttpRemoteEJBJndiBasedInvocationTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, 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
* 2110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.ejb.remote.jndi;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Hashtable;
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.as.arquillian.api.ContainerResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.naming.client.WildFlyInitialContextFactory;
import org.wildfly.security.auth.client.AuthenticationConfiguration;
import org.wildfly.security.auth.client.AuthenticationContext;
import org.wildfly.security.auth.client.MatchRule;
/**
* @author Jaikiran Pai
*/
@RunWith(Arquillian.class)
@RunAsClient
public class HttpRemoteEJBJndiBasedInvocationTestCase {
private static final String APP_NAME = "";
private static final String DISTINCT_NAME = "";
private static final String MODULE_NAME = "remote-ejb-jndi-test-case";
@ContainerResource
private ManagementClient managementClient;
@Deployment(testable = false) // the incorrectly named "testable" attribute tells Arquillian whether or not
// it should add Arquillian specific metadata to the archive (which ultimately transforms it to a WebArchive).
// We don't want that, so set that flag to false
public static Archive createDeployment() {
final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar");
jar.addPackage(RemoteCounter.class.getPackage());
return jar;
}
private static AuthenticationContext old;
@BeforeClass
public static void setup() {
AuthenticationConfiguration config = AuthenticationConfiguration.empty().useName("user1").usePassword("password1");
AuthenticationContext context = AuthenticationContext.empty().with(MatchRule.ALL, config);
old = AuthenticationContext.captureCurrent();
AuthenticationContext.getContextManager().setGlobalDefault(context);
}
@AfterClass
public static void after() {
AuthenticationContext.getContextManager().setGlobalDefault(old);
}
public Context getContext() throws Exception {
final Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
props.put(Context.PROVIDER_URL, getHttpUri());
return new InitialContext(props);
}
@Test
public void testRemoteSLSBInvocation() throws Exception {
final RemoteEcho remoteEcho = (RemoteEcho) getContext().lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME
+ "/" + EchoBean.class.getSimpleName() + "!" + RemoteEcho.class.getName());
Assert.assertNotNull("Lookup returned a null bean proxy", remoteEcho);
final String msg = "Hello world from a really remote client!!!";
final String echo = remoteEcho.echo(msg);
Assert.assertEquals("Unexpected echo returned from remote bean", msg, echo);
// invoke a method which uses application specific type instead of primitives
final EchoMessage message = new EchoMessage();
message.setMessage("Hello");
final EchoMessage echoResponse = remoteEcho.echo(message);
Assert.assertNotNull("Echo response was null", echoResponse);
Assert.assertEquals("Unexpected echo returned from the bean", message.getMessage(), echoResponse.getMessage());
}
@Test
public void testRemoteSFSBInvocation() throws Exception {
final RemoteCounter remoteCounter = (RemoteCounter) getContext().lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME
+ "/" + CounterBean.class.getSimpleName() + "!" + RemoteCounter.class.getName() + "?stateful");
Assert.assertNotNull("Lookup returned a null bean proxy", remoteCounter);
Assert.assertEquals("Unexpected initial count returned by bean", 0, remoteCounter.getCount());
final int NUM_TIMES = 25;
// test increment
for (int i = 0; i < NUM_TIMES; i++) {
remoteCounter.incrementCount();
final int currentCount = remoteCounter.getCount();
Assert.assertEquals("Unexpected count after increment", i + 1, currentCount);
}
Assert.assertEquals("Unexpected total count after increment", NUM_TIMES, remoteCounter.getCount());
// test decrement
for (int i = NUM_TIMES; i > 0; i--) {
remoteCounter.decrementCount();
final int currentCount = remoteCounter.getCount();
Assert.assertEquals("Unexpected count after decrement", i - 1, currentCount);
}
Assert.assertEquals("Unexpected total count after decrement", 0, remoteCounter.getCount());
}
private URI getHttpUri() throws URISyntaxException {
URI webUri = managementClient.getWebUri();
return new URI("http", webUri.getUserInfo(), webUri.getHost(), webUri.getPort(), "/wildfly-services", "", "");
}
}
| 6,378 | 43.608392 | 139 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/jndi/RemoteEcho.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.remote.jndi;
/**
* @author Jaikiran Pai
*/
public interface RemoteEcho {
String echo(String msg);
EchoMessage echo(EchoMessage message);
}
| 1,218 | 34.852941 | 70 |
java
|
null |
wildfly-main/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/remote/jndi/CounterBean.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.remote.jndi;
import jakarta.ejb.Remote;
import jakarta.ejb.Stateful;
/**
* @author Jaikiran Pai
*/
@Stateful
@Remote(RemoteCounter.class)
public class CounterBean implements RemoteCounter {
private int count = 0;
@Override
public int getCount() {
return count;
}
@Override
public void incrementCount() {
count++;
}
@Override
public void decrementCount() {
count--;
}
}
| 1,507 | 28 | 70 |
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.