Newbie ?: EJB vs servlets
I'm just starting out teaching myself J2EE related technologies. I have extensive development experience in other environments. I've only dabbled in Java quite a few years ago.
I have a general sense of the difference between EJB and servlets but couldn't find an official description/comparison in any of the FAQs that I've read. Could someone please compare and contrast the two technologies?
Also, I'd welcome any tips/suggestions regarding my learning experience, including but not limited to:
- suggested sequence of learning supporting/related technologies (e.g. Java, JSP, servlets, JavaBeans, EJB, JDBC, JavaServer Faces, CORBA, OOAD, UML etc.)
- recommended/popular development tools/IDEs etc.
- learning resources/books etc.
I'm currently reading the free PDF version of "Core Servlets and JSP" by Marty Hall.
Thanks,
Gary White
Few Diffs:-
1. Servlets run in a web container and EJBs run in a EJB Container.
2. Use of Servlets is thru HTTP protocol and EJBs by look-up(internally RMI-IIOP)
3. Developers has to explicity code for dattabaase transaction and security. EJBs: Container will manage every thing.
4. Mainly: Servlets are server side code that generate dydnamic web page content to display. But EJBs are reusable component run in container.
The sequence is: Java, JavaBeans, JDBC, Servlets, JSP, JSF & EJB
I recommened JCreator LE IDE as it is developed in VC++ which runs fast. But another powerfull IDE is the Eclipse.
Books:
Java. Thinking in Java, Sun Tutorial
JSP & Servlets: the book you are following work fine
EJB> Mastering EJB by Ed Romans
Similar Messages
-
Access EJB from Servlet that in different archive?
<font class="mediumtxt">package kyro.ejb.session;
import javax.ejb.*;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless(name="StandAlone")
@Remote(StandAlone.class)
public class StandAloneBean
implements StandAlone, StandAloneLocal
public StandAloneBean() {
public String sayHello() {
return "sayHello";
I want to access ejb from servlet that .war and .jar not in single .ear. I want to try that just with annotation not xml descriptor cause is easy to understand for me. I use Glassfish. But i can't lookup that ejb. How can i lookup that ejb with jndi? Can't you give me example of servlet to access that? I not use JNDI.properties, are that caused i can't access my ejb? I just thing .war and.jar in one server, are i have to used JNDI.properties. can you explain how to use JNDI.properties in servlet or separate file?
</font>But i can't lookup that ejb. How are you trying and what exception is occurring?
How can i lookup that ejb with jndi? [https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html|https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html]
m -
hi all
How to inject ejb in servlet ?
please explain how to config my servlet and my paroject
I have an ear file with two jar files
Thanks in advancehi
I have this error in my project
I have an ear file ,two war file and three jar file in it
and I did configuration
but there was this error
14:19:45,398 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[conference-servlet].[enterLet]] Allocate exception for servlet enterLet: javax.naming.NameNotFoundException: ITrmnlAuthenticationBL not bound
@Remote
public interface ITrmnlAuthenticationBL{
@Stateless
public class TrmnlAuthenticationBL implements ITrmnlAuthenticationBL{
public class EnterLet extends HttpServlet {
@EJB(mappedName = "ITrmnlAuthenticationBL")
private ITrmnlAuthenticationBL trmnlMg;
please explain my mistake -
How to set classpath to EJB and Servlets
Hi all,
How can I add a classpath to EJB and Servlets in Weblogic 6.1, so that that classpath
can be achieved by both EJB jar and war file? I have deployed a .ear file having
the jar and war files. Now the EJBs inside the jar file are not reaching the class
files of the war file and the class files in the war file are not reaching to
the EJBs. Please let me know at the earliest.
AtanuHi.
You might try looking at the petstore example which combines webapps (war files) with
ejbs in an ear file to see how to do this. It may be a simple config problem.
Regards,
Michael
Atanu Dey wrote:
Hi all,
How can I add a classpath to EJB and Servlets in Weblogic 6.1, so that that classpath
can be achieved by both EJB jar and war file? I have deployed a .ear file having
the jar and war files. Now the EJBs inside the jar file are not reaching the class
files of the war file and the class files in the war file are not reaching to
the EJBs. Please let me know at the earliest.
Atanu--
Michael Young
Developer Relations Engineer
BEA Support -
Hi there,
A frontend processing of HTTP request that pass thru WebLogic server that make
API calls thru tuxedo to the application servers that eventually running C, C++
that retrieve data from a backend database of Oracle.
Being the services of EJB and Servlets, EJB is more kind of processes inside the
server but Servlets can handle better in request and respond (talk to the client),
whats your opinions in this kind of integration? Go for pure EJB or Servlets?
Or shall mixed matched? and how should the architecture should looks like?
Thanks
NeoSorry, wrong question, just ignore it.
-
As I mentioned in subject, I am just wondering Whether the java component (Not
ejb, not servlet) can be deployed in App Server and get the services provided
by App Server or not?Nevermind folks - I got it to work. All my configuration was correct; I had other issues with the ejb-jar file that the verifier informed me of (my previous deployments were with the verifier turned-off).
-
EJB and Servlets on different clusters
Say I set up two clusters, one for servlets and one for EJBs.
To lookup to EJBs, the servlets must look up an initial context and provide a URL.
Should the URL be hardcoded in the servlet to the EJB cluster name, or is there a way
to specify this URL at a higher level?
Can you specify something like this in the properties file?
What's the best way to do this?
Please advise,
Dave
David,
How about specifying the EJB cluster URL in the servlets init argument in the
weblogic.properties ??
Sam
David Mrozek wrote:
> Say I set up two clusters, one for servlets and one for EJBs.
> To lookup to EJBs, the servlets must look up an initial context and provide a URL.
> Should the URL be hardcoded in the servlet to the EJB cluster name, or is there a way
> to specify this URL at a higher level?
> Can you specify something like this in the properties file?
> What's the best way to do this?
> Please advise,
> Dave
-
Sequence of deployment for EJBs and Servlets....
Is there any way to control the order in which weblogic 6.0 deploys EJBs
and servlets?
We have a few startup servlets which use EJBs, however, weblogic 6.0
seems to start the Servlets before it deploys the EJBs and thus our
servlets fail.
Haider Abbas Kazmi - Java Mobile App. Developer
[haider.kazmi.vcf]
6.1 solves this problem:
http://e-docs.bea.com/wls/docs61/adminguide/appman.html#1030797
Haider Abbas Kazmi <[email protected]> wrote:
> This is a multi-part message in MIME format.
> --------------9AC9295410C7463D3A71C1A6
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
> Is there any way to control the order in which weblogic 6.0 deploys EJBs
> and servlets?
> We have a few startup servlets which use EJBs, however, weblogic 6.0
> seems to start the Servlets before it deploys the EJBs and thus our
> servlets fail.
> --
> Haider Abbas Kazmi - Java Mobile App. Developer
> --------------9AC9295410C7463D3A71C1A6
> Content-Type: text/x-vcard; charset=us-ascii;
> name="haider.kazmi.vcf"
> Content-Transfer-Encoding: 7bit
> Content-Description: Card for Haider Abbas Kazmi
> Content-Disposition: attachment;
> filename="haider.kazmi.vcf"
> begin:vcard
> n:Kazmi;Haider
> tel;cell:(416)9864702
> tel;fax:(416) 6434832
> tel;work:(416) 3666425 x315
> x-mozilla-html:FALSE
> url:http://www.everypath.com/
> org:Everypath Canada;Research & Development
> adr:;;260 King St;Toronto;Ontario;M5A 4L5;Canada
> version:2.1
> email;internet:[email protected]
> title:Java Mobile App. Developer
> fn:Haider Kazmi
> end:vcard
> --------------9AC9295410C7463D3A71C1A6--
Dimitri
-
Hello everyone,
I'm hoping you can point me in the right direction. I'm looking for
articles or books that cover the pros and cons of implementing solutions
using EJBs and/or servlets. More specifically, when and where it makes the
most sense to use EJBs or servlets or both, and how the two compare. Also,
how well regarded are EJBs in the marketplace (seems to be a love/hate
relationship).
I've read some of Jason Hunter and Richard Monson-Haefel's older material
but I'm hoping you might know of (or have) something more recent.
Thanks in advance!
JoeOf course the best article is the one that Xiang suggested, J2EE blueprints.
If you want something quickly to read, I enjoyed this one very much:
"How to Build a Really Big Distributed J2EE System Using Tools You Have Around
the Office"
http://www.javasuccess.com/design_wp.html
And of course this one:
"J2EE Design Considerations for Weblogic Server"
http://www.bea.com/products/weblogic/server/papers.shtml
Regards,
David
"Joe Martins" <[email protected]> wrote:
>Hello everyone,
>
>I'm hoping you can point me in the right direction. I'm looking for
>articles or books that cover the pros and cons of implementing solutions
>using EJBs and/or servlets. More specifically, when and where it makes
>the
>most sense to use EJBs or servlets or both, and how the two compare.
> Also,
>how well regarded are EJBs in the marketplace (seems to be a love/hate
>relationship).
>
>I've read some of Jason Hunter and Richard Monson-Haefel's older material
>but I'm hoping you might know of (or have) something more recent.
>
>Thanks in advance!
>
>Joe
>
>
-
Unable to access EJB from servlet
Hi,
I have in service method my servlet code.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.ApplicationInitialContextFactory");
env.put(Context.PROVIDER_URL, "ormi://localhost/hello");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "mypwd");
Context ctx = new InitialContext(env);
Object obj = ctx.lookup("HelloName");
HelloHome home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);
Hello hello = home.create();
this is how i have orion-ejb-jar.xml
<enterprise-beans>
<session-deployment name="Hello" location="HelloName" >
</session-deployment>
</enterprise-beans>
ejb-jar.xml
<session>
<ejb-name>Hello</ejb-name>
<home>examples.HelloHome</home>
<remote>examples.Hello</remote>
<local-home>examples.HelloLocalHome</local-home>
<local>examples.HelloLocal</local>
<ejb-class>examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
When i access the servlet i get this error.
javax.naming.NameNotFoundException: HelloName not found
at com.evermind.server.rmi.RMIContext.lookup(RMIContext.java:149)
at com.evermind.server.ApplicationContext.lookup(ApplicationContext.java:217)
at com.evermind.server.ApplicationContext.lookup(ApplicationContext.java:88)
at javax.naming.InitialContext.lookup(InitialContext.java:345)
at examples.HelloServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:772)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:782)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
at java.lang.Thread.run(Thread.java:479)
Is location attribute in orion-ejb-jar.xml used to specify JNDI name? Can i get the JNDI tree showing the name mappings in oc4j? How do i correct this error?
RaviRavi --
The most portable and standards oriented solution is to define an ejb-ref in the web.xml for the servlet, and then look up the name using the formal EJB UNC model.
web.xml:
<ejb-ref>
<ejb-ref-name>ejb/AppSessionFacadeHome</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>faqapp.ejb.AppSessionFacadeHome</home>
<remote>faqapp.ejb.AppSessionFacade</remote>
</ejb-ref>
servlet lookup
InitialContext ctx = new InitialContext();
Object homeObject = ctx.lookup("java:comp/env/ejb/AppSessionFacadeHome");
EJBHome ejbHome = (EJBHome)
portableRemoteObject.narrow (homeObject, AppSessionFacadeHome.class);
cheers
-steve- -
Please let me know where I can find more information regarding iPlanet usage/deployment/configuring/tuning etc for support of technologies - like EJB, JSP/servlets, JDBC, connection pooling, XML, load balancing, JDBC & Transactions
(I have already read the 'Getting Started with the iPlanet Application Server' part five and six - http://developer.iplanet.com/appserver/testdrive/partfive.jsp and partsix.jsp)(I am using the ias testdrive version).Hi,
It's difficult to explain unless the J2EE architecture is understood. Also, explaining things like load balancing, Transactions, tuning, are bit vague and could blow the disk space of this site.
To get started, the best way is to test the sample applications and the best part is you don't require internet connection to follow each steps. Install iWS and iAS, open browser, type in http://hostname:port/ias-samples/index.html. You can find links to the sample applications bundled. Please follow the steps given on deploying the application. This will enable you to a higher level.
Regards
Ganesh .R
Developer Technical Support
Sun Microsystems
http://www.sun.com/developers/support -
Hi, all
I am a newbie in EJB and I am following the example in the URL:
http://www.huihoo.com/jboss/online_manual/3.0/
I am working on the 'interest' example in the first chapter.
When it come to 'Packaging and deploying the bean', I got some meaage like this:
ant intro-interest-jar
Buildfile: build.xml
validate-servlet:
validate-jboss:
fail_if_not_valid:
init:
[echo] Using JBoss directory=/opt/jboss
[echo] Using base classpath=/opt/jboss/client/jboss-j2ee.jar:/opt/jboss/client/jaas.jar:/opt/jboss/client/jbosssx-client.jar:/opt/jboss/client/jboss-client.jar:/opt/jboss/client/jnp-client.jar:/home/xiaobo/learningejb/examples/COULD_NOT_FIND_SERVLET_JAR
[echo] Using Source directory=/home/xiaobo/learningejb/examples
[echo] Using Build directory=/home/xiaobo/learningejb/examples/build-examples
intro-interest-jar:
compile:
ejb-jar:
[delete] Deleting directory /home/xiaobo/learningejb/examples/build-examples/interest/META-INF
[mkdir] Created dir: /home/xiaobo/learningejb/examples/build-examples/interest/META-INF
[copy] Copying 1 file to /home/xiaobo/learningejb/examples/build-examples/interest/META-INF
[copy] Copying 1 file to /home/xiaobo/learningejb/examples/build-examples/interest/META-INF
[jar] Building jar: /home/xiaobo/learningejb/examples/build-examples/interest/interest.jar
BUILD SUCCESSFUL
Total time: 2 seconds
Why did I get this:
/home/xiaobo/learningejb/examples/COULD_NOT_FIND_SERVLET_JAR.
But if I check the "interest.jar" by using 'jar -tvf interest.jar' in the "~/learningejb/examples/build-examples/interest$" directory, it seems it had all files and directories in it.
But if I copy this jar file into the deploy directory in jboss, and I check the log file 'server.log'
I found this error message:
2005-11-28 17:31:03,536 DEBUG [org.jboss.management.j2ee.LocalJBossServerDomain] handleNotification: javax.management.Notification[source=jboss.ejb:service=EJBDeployer,type=org.jboss.deployment.SubDeployer.stop,sequenceNumber=15,timeStamp=1133213463536,message=null,userData=org.jboss.deployment.DeploymentInfo@c36a9f52 { url=file:/opt/jboss-3.2.5/server/default/deploy/interest.jar }
deployer: org.jboss.ejb.EJBDeployer@3c9c31
status: Deployment FAILED reason: ejb-jar.xml must define a valid DOCTYPE!
state: FAILED
watch: file:/opt/jboss-3.2.5/server/default/deploy/interest.jar
lastDeployed: 1133210324921
lastModified: 1133210324000
mbeans:
Then I add the follwoing line into the 'ejb-jar.xml':
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
so the 'ejb-jar.xml' looks like this:
<?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>
<description>JBoss Interest Sample Application</description>
<display-name>Interest EJB</display-name>
<enterprise-beans>
<session>
<ejb-name>Interest</ejb-name>
<home>org.jboss.docs.interest.InterestHome</home>
<remote>org.jboss.docs.interest.Interest</remote>
<ejb-class>org.jboss.docs.interest.InterestBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
and I rejar it and copy the jar file into the deploy directory. I still got the same error message in the log file???!!!
Please help!
X.ChenIt's a no brainer between the AirPort Extreme and Airport Express.
The AirPort Extreme has 6 wireless antennas up at the top of the "tower", while the AirPort Express has four, so the Extreme has significantly better wireless speed and range than the Express.
As you know, the broadcast power of wireless routers is limited by law, and most routers are running full blast. Apple routers are not known for their broadcast power, so what we cannot tell you is whether the Extreme will outperform the existing wireless router that you already have in terms of range.
Also as you know, the speed of your Internet connection is limited to the plan that you have with Verizon. An Apple router cannot take the speed of Internet connection that it receives from your Verizon plan and make it go any faster.
A user who has both the same Verizon router as you and an AirPort Extreme might be able to tell you how the products compare in his home.
But...and this is a big BUT...... the bottom line with any wireless router is that you will not know how well it performs in your home until you try it out in your home. To think otherwise would be foolhardy at best.
Buy from Apple and you have a 14 day return privilege in case things don't work as well as hoped. Other stores may offer a similar option. Check first, before you buy. -
Connecting to Remote EJB from Servlet in same application
Please help!
I was able to connect to SessionBeans and EJB from my sample java client in OCJ4 but when I try to do same thing from my web application using servlets, I get the below NullPointerException error.
The JNDI lookup works fine using java client but difficult from a servlet.
I am sure there is something I am missing.
Thanks
This is what I do in the servlet:
public void init() throws ServletException, NamingException, CreateException, RemoteException
Context jndiContext = getInitialContext();
SessionCartEJBHome home = (SessionCartEJBHome)jndiContext.lookup("SessionCartEJBBean");
sessionEJB = null;
try{
sessionEJB = (SessionCartEJB) home.create();
}catch (Exception e)
e.printStackTrace();
private static Context getInitialContext() throws NamingException
Hashtable env = new Hashtable();
// Standalone OC4J connection details
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");
env.put(Context.PROVIDER_URL, "ormi://Princeton/ejb1");
return new InitialContext(env);
And when I call the following procedure, it blow up at the line sessionEJB.getLineItem(new Long(1304));
sessionEJB is a class variable.
void processCatalogPage(HttpServletRequest request,
HttpServletResponse response,
ActionMapping mapping,
HttpSession session
throws ServletException, IOException , Exception, FinderException{
try {
ActionForward actFor = null;
String itemId = request.getParameter("id");
if ( itemId != null ) {
String[] itemIds = new String[1];
itemIds[0] = itemId;
sessionEJB.getLineItem(new Long(1304));
actFor = mapping.findForward("catalog");
return (mapping.findForward("success"));
} catch (Exception ex)
ex.printStackTrace();
System.err.println(ex.toString());
throw new EJBException(ex.toString());
04/12/11 23:45:24 java.lang.NullPointerException
04/12/11 23:45:24 at com.alashoofi.Cart.processCatalogPage(Cart.java:187)
04/12/11 23:45:24 at com.alashoofi.Cart.execute(Cart.java:86)
04/12/11 23:45:24 at org.apache.struts.action.RequestProcessor.processActi
onPerform(RequestProcessor.java:484)
04/12/11 23:45:24 at org.apache.struts.action.RequestProcessor.process(Req
uestProcessor.java:274)
04/12/11 23:45:24 at org.apache.struts.action.ActionServlet.process(Action
Servlet.java:1482)
04/12/11 23:45:24 at org.apache.struts.action.ActionServlet.doGet(ActionSe
rvlet.java:507)
04/12/11 23:45:24 at javax.servlet.http.HttpServlet.service(HttpServlet.ja
va:740)
04/12/11 23:45:24 at javax.servlet.http.HttpServlet.service(HttpServlet.ja
va:853)
04/12/11 23:45:24 at com.evermind.server.http.ServletRequestDispatcher.inv
oke(ServletRequestDispatcher.java:765)
04/12/11 23:45:24 at com.evermind.server.http.ServletRequestDispatcher.for
wardInternal(ServletRequestDispatcher.java:317)
04/12/11 23:45:24 at com.evermind.server.http.HttpRequestHandler.processRe
quest(HttpRequestHandler.java:790)
04/12/11 23:45:24 at com.evermind.server.http.HttpRequestHandler.run(HttpR
equestHandler.java:270)
04/12/11 23:45:24 at com.evermind.server.http.HttpRequestHandler.run(HttpR
equestHandler.java:112)
04/12/11 23:45:24 at com.evermind.util.ReleasableResourcePooledExecutor$My
Worker.run(ReleasableResourcePooledExecutor.java:192)
04/12/11 23:45:24 at java.lang.Thread.run(Thread.java:534)
04/12/11 23:45:24 java.lang.NullPointerException
Dec 11, 2004 11:45:24 PM org.apache.struts.action.RequestProcessor processExcept
ion
WARNING: Unhandled Exception thrown: class javax.ejb.EJBExceptionAvi,
Thanks for your response. I am actually returning a new InitialContext in a function call in the servlet. What I have noticed though is that JDeveloper creates two ear files for the application. One for the ejbs called ejb1.ear and another for the web files webapp1.ear. These are located in the applications subdirectory in OC4J directory.
I know I have two projects in the application, model and viewController. I am just trying to follow the MVC pattern.
In short, I don't think the web and the ejbs are in same ear file. I made the web project depend on the ejbs though. There is an option to set such. I don't know how to tell JDeveloper to put them all in one ear file.
I will appreciate any suggestion.
Thanks
Matilda -
Unable to call EJB from servlet
Fillowing is my ejb module
package univesity;
import java.rmi.RemoteException;
import javax.ejb.*;
public interface EnrollmentCartHome extends javax.ejb.EJBHome
EnrollementCartObject create() throws CreateException,RemoteException;
package univesity;
import java.rmi.RemoteException;
public interface EnrollementCartObject extends javax.ejb.EJBObject
public void addCourse(int courseID) throws RemoteException;
package univesity;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class EnrollementCartEJBBean implements SessionBean
int courseID;
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
public void addCourse(int courseID)
System.out.println("i am in add course");
System.out.println("i am in add course--->"+courseID);
public void ejbCreate() throws CreateException
System.out.println("i am in ejbCreate");
courseID=0;
}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">
<jndi-name>ejb/EnrollmentCartHome</jndi-name>
<ejb-jar>
<description>Simplest Statefull Session Bean</description>
<display-name>University EJB</display-name>
<enterprise-beans>
<session>
<ejb-name>Enrollement</ejb-name>
<home>university.EnrollementCartHome</home>
<remote>university.EnrollementCartObject</remote>
<ejb-class>university.EnrollementCartEJBBean</ejb-class>
<session-type>Statefull</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>here is my servlet
package university;
import javax.naming.InitialContext;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EnrollCourse extends javax.servlet.http. HttpServlet
public void doGet(HttpServletRequest req,HttpServletResponse res)
public void doPost(HttpServletRequest req,HttpServletResponse res)
try {
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("ejb/EnrollmentCartHome");
university.EnrollementCartHome home=(university.EnrollementCartHome)javax.rmi.PortableRemoteObject.narrow(objref, university.EnrollementCartHome.class);
university.EnrollementCartObject obj=(university.EnrollementCartObject)home.create();
obj.addCourse(5);
catch (Exception ex)
{ ex.printStackTrace(); }
}i am getting following error
java.lang.Error: Unresolved compilation problems:
university.EnrollementCartHome cannot be resolved to a type
university.EnrollementCartHome cannot be resolved to a type
objref cannot be resolved
university.EnrollementCartHome cannot be resolved to a type
university.EnrollementCartObject cannot be resolved to a type
university.EnrollementCartObject cannot be resolved to a type
university.EnrollCourse.doPost(EnrollCourse.java:24)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)Thanks for your continuous reply
i solved all problems i have posted but now i am facing new problem that "EJB is already registerd"
giving you stack trace
15:21:22,109 WARN [ServiceController] Problem creating service jboss.j2ee:module=UniversityProjectEJBModule.jar,uid=22223562,service=EjbModule
javax.management.InstanceAlreadyExistsException: jboss.j2ee:jndiName=ejb/EnrollmentCartHome,service=EJB already registered.
at org.jboss.mx.server.registry.BasicMBeanRegistry.add(BasicMBeanRegistry.java:761)
at org.jboss.mx.server.registry.BasicMBeanRegistry.registerMBean(BasicMBeanRegistry.java:225)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.server.MBeanServerImpl$3.run(MBeanServerImpl.java:1422)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.mx.server.MBeanServerImpl.registerMBean(MBeanServerImpl.java:1417)
at org.jboss.mx.server.MBeanServerImpl.registerMBean(MBeanServerImpl.java:376)
at org.jboss.ejb.EjbModule.createService(EjbModule.java:373)
at org.jboss.system.ServiceMBeanSupport.jbossInternalCreate(ServiceMBeanSupport.java:260)
at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:243)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
-
Security Problem when call EJB in servlet:[Security:090398]Invalid Subject
Hi guys,
I have several years experience with Java and EJB developing,but still I cann't explain this problem although I already knew the fix...
Please,can anyone help me to explain why? Thanks very much!
Ok,the problem is when I call a remote EJB in one method ,that is everything about EJB is in one method,then everything is ok.But when I just return the
*remote service object from an helper class's static method, and call the service in servlet ,then I get java.lang.SecurityException: [Security:090398]Invalid Subject: principals=[sundan076],which sundan076 is username login into the web application.*
The right way, call method directCall(param) ; The wrong way, call method staticToolCall(final Map param) .
public class EJBServletClient extends HttpServlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
this.doPost(request, response);
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException
try
Map<String, String> param = new HashMap<String, String>();
param.put("CTS_CUSTOMER_ID", request.getParameter("CTS_CUSTOMER_ID"));
param.put("CTS_TASK_ID", request.getParameter("CTS_TASK_ID"));
param.put("SERIALNO", request.getParameter("SERIALNO"));
param.put("CUSTOMER_SERVICE_UM", request.getParameter("CUSTOMER_SERVICE_UM"));
Map result = this.directCall(param);
System.out.println(result);
} catch (Exception e)
e.printStackTrace();
throw new ServletException(e);
private Map directCall(Map param) throws Exception
Context context = null;
try
Properties p = new Properties();
p.put(Context.PROVIDER_URL, "t3://10.25.32.13:31256");
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.SECURITY_PRINCIPAL, "username");
p.put(Context.SECURITY_CREDENTIALS, "password");
context = new InitialContext(p);
BizApplyServiceHome home = (BizApplyServiceHome) PortableRemoteObject.narrow(
context.lookup("ejb/rcs-css/BizApplyService"), BizApplyServiceHome.class);
BizApplyService bizApplyService = home.create();
return bizApplyService.modifyApplyCustomerInfo(param);
} finally
if (context != null)
context.close();
private Map staticToolCall(final Map param) throws Exception
BizApplyService bizApplyService = EJBTool.getBizApplyService();
return bizApplyService.modifyApplyCustomerInfo(param);
public class EJBTool
public static BizApplyService getBizApplyService() throws Exception
Context context = null;
try
Properties p = new Properties();
p.put(Context.PROVIDER_URL, "t3://10.25.32.13:31256");
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.SECURITY_PRINCIPAL, "username");
p.put(Context.SECURITY_CREDENTIALS, "password");
context = new InitialContext(p);
BizApplyServiceHome home = (BizApplyServiceHome) PortableRemoteObject.narrow(
context.lookup("ejb/rcs-css/BizApplyService"), BizApplyServiceHome.class);
return home.create();
} finally
if (context != null)
context.close();
java.lang.SecurityException: [Security:090398]Invalid Subject: principals=[sundan076]
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:348)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at com.pingan.rcs.css.biz.service.remote.ejb.bizApplyService_u7jjbk_EOImpl_1032_WLStub.modifyApplyCustomerInfo(Unknown Source)
at com.pingan.pafax.web.EJBServletClient.staticToolCall(EJBServletClient.java:80)
at com.pingan.pafax.web.EJBServletClient.doPost(EJBServletClient.java:43)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3594)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Caused by: java.lang.SecurityException: [Security:090398]Invalid Subject: principals=[sundan076]
at weblogic.security.service.SecurityServiceManager.seal(SecurityServiceManager.java:835)
at weblogic.security.service.SecurityServiceManager.getSealedSubjectFromWire(SecurityServiceManager.java:524)
at weblogic.rjvm.MsgAbbrevInputStream.getSubject(MsgAbbrevInputStream.java:315)
at weblogic.rmi.internal.BasicServerRef.acceptRequest(BasicServerRef.java:875)
at weblogic.rmi.internal.BasicServerRef.dispatch(BasicServerRef.java:310)
at weblogic.rmi.cluster.ClusterableServerRef.dispatch(ClusterableServerRef.java:242)
at weblogic.rjvm.RJVMImpl.dispatchRequest(RJVMImpl.java:1138)
at weblogic.rjvm.RJVMImpl.dispatch(RJVMImpl.java:1020)
at weblogic.rjvm.ConnectionManagerServer.handleRJVM(ConnectionManagerServer.java:240)
at weblogic.rjvm.ConnectionManager.dispatch(ConnectionManager.java:882)
at weblogic.rjvm.MsgAbbrevJVMConnection.dispatch(MsgAbbrevJVMConnection.java:453)
at weblogic.rjvm.t3.MuxableSocketT3.dispatch(MuxableSocketT3.java:322)
at weblogic.socket.BaseAbstractMuxableSocket.dispatch(BaseAbstractMuxableSocket.java:298)
at weblogic.socket.SocketMuxer.readReadySocketOnce(SocketMuxer.java:915)
at weblogic.socket.SocketMuxer.readReadySocket(SocketMuxer.java:854)
at weblogic.socket.EPollSocketMuxer.dataReceived(EPollSocketMuxer.java:215)
at weblogic.socket.EPollSocketMuxer.processSockets(EPollSocketMuxer.java:177)
at weblogic.socket.SocketReaderRequest.run(SocketReaderRequest.java:29)
at weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:42)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:145)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:117)
Edited by: 993478 on 2013-3-12 下午8:40I tried your way,it works! Still ,does anyone know why staticToolCall() raised exception?
By the way,here is the code as you suggested:
public class EJBServletClient extends HttpServlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException
Context context = null;
try
Map<String, String> param = new HashMap<String, String>();
param.put("CTS_CUSTOMER_ID", request.getParameter("CTS_CUSTOMER_ID"));
param.put("CTS_TASK_ID", request.getParameter("CTS_TASK_ID"));
param.put("SERIALNO", request.getParameter("SERIALNO"));
param.put("CUSTOMER_SERVICE_UM", request.getParameter("CUSTOMER_SERVICE_UM"));
//Map result = this.staticToolCall(param);
Properties p = new Properties();
p.put(Context.PROVIDER_URL, "t3://10.25.32.13:31256");
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.SECURITY_PRINCIPAL, "username");
p.put(Context.SECURITY_CREDENTIALS, "password");
context = new InitialContext(p);
Map result=EJBTool.modifyApplyCustomerInfo(context, param);
System.out.println(result);
} catch (Exception e)
e.printStackTrace();
throw new ServletException(e);
}finally
if (context != null)
try{context.close();} catch (NamingException e){e.printStackTrace();}
public class EJBTool
public static Map modifyApplyCustomerInfo(Context context, Map param) throws Exception
BizApplyServiceHome home = (BizApplyServiceHome) PortableRemoteObject.narrow(
context.lookup("ejb/rcs-css/BizApplyService"), BizApplyServiceHome.class);
BizApplyService bizApplyService = home.create();
Map result = bizApplyService.modifyApplyCustomerInfo(param);
return result;
}
Maybe you are looking for
-
The botton to open a new tab is not working. How I can solve this issue?
the bottom next to the tabs, the one that opens a new tab fast is not working, also the ctrl+T keyboard command is not working also. The only way to open a new tab is right click on the mouse, but always on some link, I can not open a new blank tab.
-
How to find ECC tables/ reports based on which a DB View is created?
Hi All, We have customized data source created based on a View/ Table. How can i find the ECC tables/ reports based on which this View has been created and also the logic behind which the different fields extract data from ECC.. Please advice. Than
-
Unidentified error when testing recordset, help please!
Hi, I have created a dsn and a connection string that test fine on my web host (crystaltech), but I get an unidentified error when I test them on DW CS4. Any thoughts? This is my connection string: "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\in
-
Valuated/Non valuated SAles Order Stock
Hi, Can anyone explain the difference between Valuated & Non valuated Sales order Stock Thx & Regards
-
I apologize for the plethora of stupid questions I am about to ask - I am brand new to dreamweaver and atempting to design a very simple website layout for myself. My most glaring problem is this: I wish for text to be in the centre of the webpage an