Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

how to pass Principal name from the client in EJB

Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wrote a stateless session bean as below.
I am using weblogic 8.1 SP5.
This ejb has been deployed successfully, but the problem is how can i call the business methods by passing the 'principal' name.
I request you to please help me in writing the client by passing my principal name. (Component Interface)
package mysessionpkg;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;

public interface MySession extends EJBObject {
public int add(int a, int b)throws RemoteException;
public int sub(int a, int b)throws RemoteException;

} (Home Interface)
package mysessionpkg;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface MySessionHome extends EJBHome {
public MySession create() throws RemoteException, CreateException;

} (Bean class)
package mysessionpkg;

import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

public class MySessionBean implements SessionBean {

SessionContext ctx;
public void setSessionContext(SessionContext arg0) throws
EJBException,RemoteException {
ctx = arg0;
System.out.println("from seSessionContext()....");


public void ejbRemove() throws EJBException, RemoteException {

System.out.println("from ejbRemove().....");

public void ejbActivate() throws EJBException, RemoteException {

System.out.println("from ejbActivate()....");

public void ejbPassivate() throws EJBException, RemoteException {

System.out.println("from ejbPassivate().....");
public void ejbCreate() {
System.out.println("from ejbCreate().....");
System.out.println("principal name = " + ctx.getCallerPrincipal
public int add(int a, int b){
System.out.println("from add().....");
System.out.println("principal name = " + ctx.getCallerPrincipal
return (a+b);
public int sub(int a, int b){
System.out.println("from sub().....");
return (a-b);


<!-- ?xml version="1.0" encoding="UTF-8"? -->
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'



<!DOCTYPE weblogic-ejb-jar PUBLIC
'-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN'




Thank you.

Yugandhar Akkaldevi
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic