[RESOLVIDO]Erro cdi + jsf2 + ejb3.1

Ninguẽm respondeu…

Erro ao executar um exemplo com jboss:
Alguém pode ajudar a encontrar o erro?

[code]package org.jboss.as.quickstarts.ejb.remote.client;

import org.jboss.as.quickstarts.ejb.remote.stateful.RemoteCounter;
import org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import java.util.Hashtable;

/**

  • A sample program which acts a remote client for a EJB deployed on AS7 server.

  • This program shows how to lookup stateful and stateless beans via JNDI and then invoke on them

  • @author Jaikiran Pai
    */
    public class RemoteEJBClient {

    public static void main(String[] args) throws Exception {
    // Invoke a stateless bean
    invokeStatelessBean();

     // Invoke a stateful bean
     invokeStatefulBean();
    

    }

    /**

    • Looks up a stateless bean and invokes on it
    • @throws NamingException
      */
      private static void invokeStatelessBean() throws NamingException {
      // Let’s lookup the remote stateless calculator
      final RemoteCalculator statelessRemoteCalculator = lookupRemoteStatelessCalculator();
      System.out.println(“Obtained a remote stateless calculator for invocation”);
      // invoke on the remote calculator
      int a = 204;
      int b = 340;
      System.out.println(“Adding " + a + " and " + b + " via the remote stateless calculator deployed on the server”);
      int sum = statelessRemoteCalculator.add(a, b);
      System.out.println("Remote calculator returned sum = " + sum);
      if (sum != a + b) {
      throw new RuntimeException("Remote stateless calculator returned an incorrect sum " + sum + " ,expected sum was " + (a + b));
      }
      // try one more invocation, this time for subtraction
      int num1 = 3434;
      int num2 = 2332;
      System.out.println(“Subtracting " + num2 + " from " + num1 + " via the remote stateless calculator deployed on the server”);
      int difference = statelessRemoteCalculator.subtract(num1, num2);
      System.out.println("Remote calculator returned difference = " + difference);
      if (difference != num1 - num2) {
      throw new RuntimeException("Remote stateless calculator returned an incorrect difference " + difference + " ,expected difference was " + (num1 - num2));
      }
      }

    /**

    • Looks up a stateful bean and invokes on it
    • @throws NamingException
      */
      private static void invokeStatefulBean() throws NamingException {
      // Let’s lookup the remote stateful counter
      final RemoteCounter statefulRemoteCounter = lookupRemoteStatefulCounter();
      System.out.println(“Obtained a remote stateful counter for invocation”);
      // invoke on the remote counter bean
      final int NUM_TIMES = 5;
      System.out.println(“Counter will now be incremented " + NUM_TIMES + " times”);
      for (int i = 0; i < NUM_TIMES; i++) {
      System.out.println(“Incrementing counter”);
      statefulRemoteCounter.increment();
      System.out.println("Count after increment is " + statefulRemoteCounter.getCount());
      }
      // now decrementing
      System.out.println(“Counter will now be decremented " + NUM_TIMES + " times”);
      for (int i = NUM_TIMES; i > 0; i–) {
      System.out.println(“Decrementing counter”);
      statefulRemoteCounter.decrement();
      System.out.println("Count after decrement is " + statefulRemoteCounter.getCount());
      }
      }

    /**

    • Looks up and returns the proxy to remote stateless calculator bean
    • @return
    • @throws NamingException
      */
      private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException {
      final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
      jndiProperties.put(Context.URL_PKG_PREFIXES, “org.jboss.ejb.client.naming”);
      final Context context = new InitialContext(jndiProperties);

    // The JNDI lookup name for a stateless session bean has the syntax of:
    // ejb:///!
    //
    // The application name is the name of the EAR that the EJB is deployed in
    // (without the .ear). If the EJB JAR is not deployed in an EAR then this is
    // blank. The app name can also be specified in the EAR’s application.xml
    //
    // By the default the module name is the name of the EJB JAR file (without the
    // .jar suffix). The module name might be overridden in the ejb-jar.xml
    //
    // : AS7 allows each deployment to have an (optional) distinct name.
    // This example does not use this so leave it blank.
    //
    // : The name of the session been to be invoked.
    //
    // : The fully qualified classname of the remote interface. Must include
    // the whole package name.

     // let's do the lookup
    

    return (RemoteCalculator) context.lookup(
    “ejb:/jboss-as-ejb-remote-server-side/CalculatorBean!” + RemoteCalculator.class.getName()
    );
    }

    /**

    • Looks up and returns the proxy to remote stateful counter bean
    • @return
    • @throws NamingException
      */
      private static RemoteCounter lookupRemoteStatefulCounter() throws NamingException {
      final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
      jndiProperties.put(Context.URL_PKG_PREFIXES, “org.jboss.ejb.client.naming”);
      final Context context = new InitialContext(jndiProperties);

    // The JNDI lookup name for a stateful session bean has the syntax of:
    // ejb:///!?stateful
    //
    // The application name is the name of the EAR that the EJB is deployed in
    // (without the .ear). If the EJB JAR is not deployed in an EAR then this is
    // blank. The app name can also be specified in the EAR’s application.xml
    //
    // By the default the module name is the name of the EJB JAR file (without the
    // .jar suffix). The module name might be overridden in the ejb-jar.xml
    //
    // : AS7 allows each deployment to have an (optional) distinct name.
    // This example does not use this so leave it blank.
    //
    // : The name of the session been to be invoked.
    //
    // : The fully qualified classname of the remote interface. Must include
    // the whole package name.

    // let’s do the lookup
    return (RemoteCounter) context.lookup(
    “ejb:/jboss-as-ejb-remote-server-side/CounterBean!” + RemoteCounter.class.getName()+"?stateful"
    );
    }
    }[/code]

[code]package org.jboss.as.quickstarts.ejb.remote.stateful;

/**

  • @author Jaikiran Pai
    */
    public interface RemoteCounter {

    void increment();

    void decrement();

    int getCount();
    }[/code]

[code]package org.jboss.as.quickstarts.ejb.remote.stateful;

import javax.ejb.Remote;
import javax.ejb.Stateful;

/**

  • @author Jaikiran Pai
    */
    @Stateful
    @Remote(RemoteCounter.class)
    public class CounterBean implements RemoteCounter {

    private int count = 0;

    @Override
    public void increment() {
    this.count++;
    }

    @Override
    public void decrement() {
    this.count–;
    }

    @Override
    public int getCount() {
    return this.count;
    }
    }[/code]

[code]package org.jboss.as.quickstarts.ejb.remote.stateless;

/**

  • @author Jaikiran Pai
    */
    public interface RemoteCalculator {

    int add(int a, int b);

    int subtract(int a, int b);
    }[/code]

[code]package org.jboss.as.quickstarts.ejb.remote.stateless;

import javax.ejb.Remote;
import javax.ejb.Stateless;

/**

  • @author Jaikiran Pai
    */
    @Stateless
    @Remote(RemoteCalculator.class)
    public class CalculatorBean implements RemoteCalculator {

    @Override
    public int add(int a, int b) {
    return a + b;
    }

    @Override
    public int subtract(int a, int b) {
    return a - b;
    }
    }[/code]

Poste o log.

[code]Out 11, 2013 8:01:49 PM org.jboss.as.quickstarts.ejb.asynchronous.client.AsynchronousClient <init>
Informações: Lookup Bean >ejb:/jboss-as-ejb-asynchronous-ejb/AsynchronousAccessBean!org.jboss.as.quickstarts.ejb.asynchronous.AsynchronousAccess
Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.jboss.as.quickstarts.ejb.asynchronous.client.AsynchronousClient.<init>(AsynchronousClient.java:63)
at org.jboss.as.quickstarts.ejb.asynchronous.client.AsynchronousClient.main(AsynchronousClient.java:158)

[/code]