// Path: web-api/EJBHelloWorld/src/main/java/com/sample/beans/SampleBean.java
// @Remote
// public interface SampleBean {
// 
//     void addEntity(String o);
// 
//     List<String> getEntity();
// 
// }
// 
// Path: web-api/EJBHelloWorld/src/main/java/com/sample/entity/IBeanOne.java
// @Remote
// public interface IBeanOne {
// 
//     /**
//      * Greet message method
//      *
//      * @param name
//      */
//     public void greet(String name);
// 
// }


import com.sample.beans.SampleBean;
import com.sample.entity.IBeanOne;
import org.apache.log4j.BasicConfigurator;
import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
package com.sample.client;



/**
 * StandALone client to fetch and call methods on the {@link Remote} {@link EJB} objects deployed in the container
 *
 * @author saifasif
 */
public class StandAloneClient {

    public static void main(String[] args) {

        BasicConfigurator.configure();

        Properties jndiProperties = new Properties();
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
        jndiProperties.put(Context.SECURITY_PRINCIPAL, "admin");
        jndiProperties.put(Context.SECURITY_CREDENTIALS, "admin");
        jndiProperties.put("jboss.naming.client.ejb.context", true);

        Context ctx;
        try {
            ctx = new InitialContext(jndiProperties);

            getStatefulBeans(ctx);
            getStatelessBeans(ctx);

            IBeanOne bean = (IBeanOne) ctx.lookup("/EJBHelloWorld/BeanOneImpl!com.sample.entity.IBeanOne");
            bean.greet("'Saif Asif'");

        } catch (NamingException e) {
            e.printStackTrace();
        }
    }

    /**
     * Attempts to fetch the stateless bean.<br>
     * For each call to <code>addEntity</code>, a new object will be created by calling the constructor and the state of the
     * previous one will be lost. Thus the name 'stateless'
     *
     * @param ctx
     * @throws NamingException
     */
    private static void getStatelessBeans(Context ctx) throws NamingException {
// Path: web-api/EJBHelloWorld/src/main/java/com/sample/beans/SampleBean.java
// @Remote
// public interface SampleBean {
// 
//     void addEntity(String o);
// 
//     List<String> getEntity();
// 
// }
// 
// Path: web-api/EJBHelloWorld/src/main/java/com/sample/entity/IBeanOne.java
// @Remote
// public interface IBeanOne {
// 
//     /**
//      * Greet message method
//      *
//      * @param name
//      */
//     public void greet(String name);
// 
// }


// Path: web-api/EJBHelloWorld/src/main/java/com/sample/client/StandAloneClient.java
import com.sample.beans.SampleBean;
import com.sample.entity.IBeanOne;
import org.apache.log4j.BasicConfigurator;
import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;

package com.sample.client;



/**
 * StandALone client to fetch and call methods on the {@link Remote} {@link EJB} objects deployed in the container
 *
 * @author saifasif
 */
public class StandAloneClient {

    public static void main(String[] args) {

        BasicConfigurator.configure();

        Properties jndiProperties = new Properties();
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
        jndiProperties.put(Context.SECURITY_PRINCIPAL, "admin");
        jndiProperties.put(Context.SECURITY_CREDENTIALS, "admin");
        jndiProperties.put("jboss.naming.client.ejb.context", true);

        Context ctx;
        try {
            ctx = new InitialContext(jndiProperties);

            getStatefulBeans(ctx);
            getStatelessBeans(ctx);

            IBeanOne bean = (IBeanOne) ctx.lookup("/EJBHelloWorld/BeanOneImpl!com.sample.entity.IBeanOne");
            bean.greet("'Saif Asif'");

        } catch (NamingException e) {
            e.printStackTrace();
        }
    }

    /**
     * Attempts to fetch the stateless bean.<br>
     * For each call to <code>addEntity</code>, a new object will be created by calling the constructor and the state of the
     * previous one will be lost. Thus the name 'stateless'
     *
     * @param ctx
     * @throws NamingException
     */
    private static void getStatelessBeans(Context ctx) throws NamingException {
        SampleBean statelessBean = (SampleBean) ctx.lookup("/EJBHelloWorld/SampleStatelessBean!com.sample.beans.SampleBean");