[jboss-user] [EJB 3.0] - Re: ClassCastException in Stateful Session-Bean
te-bachi
do-not-reply at jboss.com
Wed Jan 17 08:29:49 EST 2007
Ahh... ok! Remote Interface don't work, but Local Interface does!
| import org.jboss.tutorial.stateful.bean.ShoppingCart;
|
| import javax.servlet.http.HttpServlet;
| import javax.servlet.http.HttpServletRequest;
| import javax.servlet.http.HttpServletResponse;
| import javax.servlet.ServletException;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
| import java.io.IOException;
| import java.io.PrintWriter;
| import java.util.HashMap;
|
| public class TestServlet extends HttpServlet {
|
| protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
| process(request, response);
| }
|
| protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
| process(request, response);
| }
|
| private void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
| PrintWriter out = response.getWriter();
|
| try {
| InitialContext ctx = new InitialContext();
| ShoppingCart shoppingCart = (ShoppingCart) ctx.lookup("MyApplication/ShoppingCartBean/local");
| out.println("Buying 1 memory stick");
| shoppingCart.buy("Memory stick", 1);
| out.println("Buying another memory stick");
| shoppingCart.buy("Memory stick", 1);
|
| out.println("Buying a laptop");
| shoppingCart.buy("Laptop", 1);
|
| out.println("Print cart:");
| HashMap<String, Integer> fullCart = shoppingCart.getCartContents();
| for (String product : fullCart.keySet()) {
| out.println(fullCart.get(product) + " " + product);
| }
|
| out.println("Checkout");
| shoppingCart.checkout();
|
| out.println("Should throw an object not found exception by invoking on cart after @Remove method");
| try {
| shoppingCart.getCartContents();
| }
| catch (Exception e) {
| out.println("Successfully caught no such object exception.");
| }
| } catch (NamingException e) {
| out.println("Exception: " + e.getMessage());
| }
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4002764#4002764
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4002764
More information about the jboss-user
mailing list