use of javax.ejb.NoSuchEJBException in project Payara by payara.
the class EjbContainerServicesImpl method remove.
public void remove(Object ejbRef) {
EJBLocalObjectImpl localObjectImpl = getEJBLocalObject(ejbRef);
if (localObjectImpl == null) {
throw new UnsupportedOperationException("Invalid ejb ref");
}
Container container = localObjectImpl.getContainer();
EjbDescriptor ejbDesc = container.getEjbDescriptor();
boolean isStatefulBean = false;
if (ejbDesc.getType().equals(EjbSessionDescriptor.TYPE)) {
EjbSessionDescriptor sessionDesc = (EjbSessionDescriptor) ejbDesc;
isStatefulBean = sessionDesc.isStateful();
}
if (!isStatefulBean) {
// stateless/singleton references via 299 could fail until bug is fixed.
return;
// TODO reenable this after bug is fixed
// throw new UnsupportedOperationException("ejbRef for ejb " +
// ejbDesc.getName() + " is not a stateful bean ");
}
try {
localObjectImpl.remove();
} catch (EJBException e) {
LogFacade.getLogger().log(Level.FINE, "EJBException during remove. ", e);
} catch (javax.ejb.RemoveException re) {
throw new NoSuchEJBException(re.getMessage(), re);
}
}
use of javax.ejb.NoSuchEJBException in project quickstart by wildfly.
the class Client method main.
public static void main(String[] args) throws NamingException {
// avoid INFO output for the client demo
Logger.getLogger("org.xnio").setLevel(Level.WARNING);
Logger.getLogger("org.jboss.remoting").setLevel(Level.WARNING);
Logger.getLogger("org.jboss.ejb.client").setLevel(Level.WARNING);
// Create the JNDI InitialContext, configuring it for use with JBoss EJB
Hashtable<String, String> jndiProperties = new Hashtable<>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(jndiProperties);
/*
* The app name is the application name of the deployed EJBs. This is typically the ear name without the .ear suffix.
* However, the application name could be overridden in the application.xml of the EJB deployment on the server. Since
* we haven't deployed the application as a .ear, the app name for us will be an empty string
*/
final String appName = "";
/*
* This is the module name of the deployed EJBs on the server. This is typically the jar name of the EJB deployment,
* without the .jar suffix, but can be overridden via the ejb-jar.xml. In this example, we have deployed the EJBs in a
* jboss-shopping-cart-server.jar, so the module name is jboss-shopping-cart-server
*/
final String moduleName = "shopping-cart-server";
/*
* JBoss EAP allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for our EJB
* deployment, so this is an empty string
*/
final String distinctName = "";
/*
* The EJB name which by default is the simple class name of the bean implementation class
*/
final String beanName = ShoppingCartBean.class.getSimpleName();
/* The remote view fully qualified class name */
final String viewClassName = ShoppingCart.class.getName();
/* Lookup the remote interface of the shopping cart */
String lookupName = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName + "?stateful";
final ShoppingCart cart = (ShoppingCart) context.lookup(lookupName);
System.out.println("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
System.out.println("Obtained the remote interface to the shopping cart");
/* invoke on the remote interface */
System.out.println("Buying a \"" + ACCESSORIES_2 + "\"");
cart.buy(ACCESSORIES_2, 1);
System.out.println("Buying another \"" + ACCESSORIES_2 + "\"");
cart.buy(ACCESSORIES_2, 1);
System.out.println("Buying a \"" + ACCESSORIES_1 + "\"");
cart.buy(ACCESSORIES_1, 1);
System.out.println("\nPrint cart:");
Map<String, Integer> cartContents = cart.getCartContents();
for (String product : cartContents.keySet()) {
System.out.println(cartContents.get(product) + " " + product);
}
System.out.println("\nCheckout");
cart.checkout();
/* Try to access the cart after checkout */
try {
cart.getCartContents();
System.err.println("ERROR: The cart should not be available after Checkout!");
} catch (NoSuchEJBException e) {
System.out.println("Cart was correctly removed, as expected, after Checkout and is no longer available!");
}
System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
}
use of javax.ejb.NoSuchEJBException in project Payara by payara.
the class MessageBean method onMessage.
public void onMessage(Message message) {
System.out.println("Got message!!!");
QueueConnection connection = null;
try {
System.out.println("Calling hello1 stateless bean");
hello1.hello("local ejb3.0 stateless");
System.out.println("Calling hello2 stateful bean");
hello2.hello("local ejb3.0 stateful");
hello2.removeMethod();
try {
hello2.hello("this call should not go through");
throw new Exception("bean should have been removed " + "after removeMethod()");
} catch (NoSuchEJBException e) {
System.out.println("Successfully caught EJBException after " + " accessing removed SFSB");
}
connection = qcFactory.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(clientQueue);
TextMessage tmessage = session.createTextMessage();
tmessage.setText("mdb() invoked");
System.out.println("Sending message");
sender.send(tmessage);
System.out.println("message sent");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of javax.ejb.NoSuchEJBException in project eap-additional-testsuite by jboss-set.
the class StatefulServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String module = getRequiredParameter(req, MODULE);
String bean = getRequiredParameter(req, BEAN);
HttpSession session = req.getSession(true);
Incrementor incrementor = (Incrementor) session.getAttribute(BEAN);
if (incrementor == null) {
try (LocalEJBDirectory directory = new LocalEJBDirectory(module)) {
incrementor = directory.lookupStateful(bean, Incrementor.class);
} catch (NamingException e) {
throw new ServletException(e);
}
}
try {
resp.setHeader(COUNT, String.valueOf(incrementor.increment()));
session.setAttribute(BEAN, incrementor);
} catch (NoSuchEJBException e) {
resp.setHeader(COUNT, String.valueOf(0));
session.removeAttribute(BEAN);
}
resp.getWriter().write("Success");
}
use of javax.ejb.NoSuchEJBException in project eap-additional-testsuite by jboss-set.
the class TransactionalRemoteStatefulEJBFailoverTestCase method test.
@Test
public void test() throws Exception {
try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = directory.lookupStateful(StatefulIncrementorBean.class, Incrementor.class);
Result<Integer> result = bean.increment();
// Bean should retain weak affinity for this node
String target = result.getNode();
int count = 1;
Assert.assertEquals(count++, result.getValue().intValue());
// Validate that multi-invocations function correctly within a tx
UserTransaction tx = EJBClient.getUserTransaction(target);
// TODO Currently requires environment to be configured with provider URLs.
// UserTransaction tx = directory.lookupUserTransaction();
tx.begin();
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
tx.commit();
// Validate that second invocation fails if target node is undeployed in middle of tx
tx.begin();
result = bean.increment();
Assert.assertEquals(count++, result.getValue().intValue());
Assert.assertEquals(target, result.getNode());
undeploy(this.findDeployment(target));
try {
result = bean.increment();
Assert.fail("Expected a NoSuchEJBException");
} catch (NoSuchEJBException e) {
// Expected
} finally {
tx.rollback();
}
}
}
Aggregations