facebook

Stand Alone Client applications

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #226489 Reply

    imm102
    Member

    Hi

    I wonder if anyone can help me. Im in the middle of my first J2EE project and have sucessfully made a working applcation with EJBs, Servlets, JSPs etc. I want to add a stand alone local client with a swing gui etc. I can’t seem to find any tuts on how to do this. I know i have to include the java properties etc mentioned here:
    http://www.jboss.org/wiki/Wiki.jsp?page=J2EEClient
    My question is more related to the ME environment. How do i deploy a client using ME. Where do i place the client class in my project structure (Project, EJB or Web)? Does a stand alone client have any Xdoclet support to build the jboss-client.xml and application-client.xml? Is it sufficent just to run it from the command line as with normal java programs.

    If anyone can answer these questions it would be great.

    Ian Mckay

    OS:Win XP SP2
    ME:3.8.3
    Eclipse 3.0.1
    JBoss: 4.0.1RC2

    #226494 Reply

    Riyad Kalla
    Member

    Ian,
    I would suggest you make your thick client a standard Java Project. Although I don’t have knowledge of how to design with this setup so I cannot provide more information for you of the top of my head… however if you provide specifics about which portions of the app need what classes, then I can help more.

    #226511 Reply

    imm102
    Member

    thanks for that:) Does anyone know if the client app needs to be deployed? Or any tutorials thats may help?

    #227555 Reply

    tojx
    Member

    If you’re developing a Java Swing application you don’t really need to deploy your application. As you said above already, you can just run it from the command line for example.
    You still need to deploy your business layer though, in your case the EJBs onto the application server.

    Your swing application (or whatever client you’re using) talks to the EJBs in the same way a web application would.

    Here’s a simple example.
    It just requires that you have some kind of EJB project set up, and deployed.
    Just create a new standard Java project and add the EJB project as a required project on the build path of the client project.
    The code below refers to a HelloBean on the server side and uses a hello() method. It basically authenticates a user and calls the hello() method.
    For more info I recommend reading the J2EE tutorial on the SUN website and one of the many good J2EE books 😉

    public class HelloClient
    {
        public static void main(String[] args)
        {
            try
            {
    
                Properties props = System.getProperties();
    
                props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                props.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099/");
                props.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                props.setProperty("java.security.auth.login.config", "auth.conf");
                
                //String name = "Tom";
                //String passwd = "password";
                String name = "Tom";
                String passwd = EncryptUtils.encryptSHA("password");
                char[] password = passwd.toCharArray();
                
                AppCallbackHandler handler = new AppCallbackHandler(name, password);
    
                LoginContext lc = new LoginContext("client-login", handler);
    
                lc.login();
    
                System.out.println("1:"+lc.toString());
                System.out.println("2:"+lc.getSubject().toString());
                System.out.println("3:"+lc.getSubject().getPrincipals().size());
                
                Context ctx = new InitialContext(props);
    
                Object objRef = ctx.lookup("ejb/Hello");
    
                HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(objRef, HelloHome.class);
    
                Hello hello = home.create(10);
    
                System.out.println(hello.hello());
    
                hello.remove();
            }
            catch (LoginException le)
            {
                System.out.println("Login failed1");
                le.printStackTrace();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    
        static class AppCallbackHandler implements CallbackHandler
        {
            private String username;
            private char[] password;
            public AppCallbackHandler(String username, char[] password)
            {
                this.username = username;
                this.password = password;
            }
            public void handle(Callback[] callbacks) throws java.io.IOException, UnsupportedCallbackException
            {
                for (int i = 0; i < callbacks.length; i++)
                {
                    if (callbacks[i] instanceof NameCallback)
                    {
                        NameCallback nc = (NameCallback)callbacks[i];
                        nc.setName(username);
                    }
                    else if (callbacks[i] instanceof PasswordCallback)
                    {
                        PasswordCallback pc = (PasswordCallback)callbacks[i];
                        pc.setPassword(password);
                    }
                    else
                    {
                        throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
                    }
                }
            }
        }
    }
Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Stand Alone Client applications

You must be logged in to post in the forum log in