Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to pass Principal name from the client in EJB  RSS feed

 
aaaaaaaa aaaaaaaaaaaa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,

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.

#MySession.java (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;

}

#MySessionHome.java (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;

}

#MySessionBean.java (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
().getName());
}
public int add(int a, int b){
System.out.println("from add().....");
System.out.println("principal name = " + ctx.getCallerPrincipal
().getName());
return (a+b);
}
public int sub(int a, int b){
System.out.println("from sub().....");
return (a-b);
}

}

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


<ejb-jar>
<display-name>MySession</display-name>
<enterprise-beans>
<session>
<display-name>MySession</display-name>
<ejb-name>MySession</ejb-name>
<home>mysessionpkg.MySessionHome</home>
<remote>mysessionpkg.MySession</remote>
<ejb-class>mysessionpkg.MySessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>

<assembly-descriptor>
<security-role>
<role-name>CEO</role-name>
</security-role>
<method-permission>
<role-name>CEO</role-name>
<method>
<ejb-name>MySession</ejb-name>
<method-name>add</method-name>
</method>
<method>
<ejb-name>MySession</ejb-name>
<method-name>sub</method-name>
</method>
</method-permission>
</assembly-descriptor>
</ejb-jar>


weblogic-ejb-jar.xml
---------------------------
<!DOCTYPE weblogic-ejb-jar PUBLIC
'-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN'
'http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd'>

<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>MySession</ejb-name>
<jndi-name>MySession</jndi-name>
</weblogic-enterprise-bean>

<security-role-assignment>
<role-name>
CEO
</role-name>
<principal-name>
Yugi
</principal-name>

</security-role-assignment>
</weblogic-ejb-jar>


Thank you.

regards,
Yugandhar Akkaldevi
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!