Questions on Java Reflection in EJB
Hi,
Recently, I use reflection technology on EJB to get/set properties of a bean.
We need it because we need to encapsulate data in a map to transfer data between
presentation layer and business back end(i.e. the so-called value data object).
A bean is packed into a map as following:
The property name of a bean becomes the key in the map, and its value becomes the
corresponding value in the map.
So we have to do two things:
1)Given a bean, convert it to a map;
2)Given a data map, assign the value to a bean
It would be nice if we can implement the two requirements in a base class. So I use
reflection. And succeed to achieve the goal.
But there are two problems occured and I can't understand why.
1)If I use Class.forName() to load the entity bean implementation class(BMP or CMP abstract
schema) I got a ClassNotFoundException. A workaround is to jar the BMP or CMP bean class
and place it on the classpath.
So, I want to know why there is such restriction.
2)For the classes java.lang.reflect.Method, java.lang.reflect.InvocationTargetException
I reference to in bean class, the IDE(I use IntelliJ Idea) give me a
warning: "Use java.lang.reflect.Method are not allowed in EJB". Are the methods really
dangerous in EJB environment?
Can anyone explain me these pluzzles?
Thank you in advance!
BTW, I develop under weblogic 7.0. Now, my program functions well, I just can't understand
the above phenomena.
Regards,
Justine
1) You should never directly manipulate the EJB implementation class. That class is for the container. When accessing EJBs (no matter the means), you should use the Home/Remote or Local interfaces - those your client should already have. If what you're doing is actually working for you, I can only say that you're not using EJBs properly and are not getting the actual "bang for the buck" you paid for. And you're damn lucky it hasn't blown bits all over the place...
2) Yes, it is potentially dangerous to be dorking around with reflection on EJBs. When you're using the Home/Remote or Local interfaces, you're actually using an Object that the vendor supplies to perform the actual remote operations. Using reflection could potentially invoke one of the "hidden" vendor methods with extremely unpredictable results - like deleting your entire table.
As for using a map for transferring data, I would strongly recommend against it, especially in this case, because you've not only lost the strong typing you get with ValueObjects, but you have to do a lot of extra work on both "sides" (client and EJB) to make sure all your data is present and/or correct.
Similar Messages
-
Question about java reflection and "int" type
hi, using reflections I should invoke a Method (meth3) that have as parameter an INT type (not integer). I've tryed with this code:
int num = 3;
Class[] vettClax = {int.class};
Object[] vettParam = {num};
Method meth3 = temp.getMethod("meth3", vettClax);
meth.invoke(o, vettParam);My problem is that the int value is catched as an Integer value and reflection doesn't found a method that accept an INTEGER as parameter, who can help me?Works fine when I try it.
public class t
public static void main(String args[])
throws Exception
Class temp = t.class;
t o = new t();
int num = 3;
Class[] vettClax = {int.class};
Object[] vettParam = {num};
Method meth = temp.getMethod("meth3", vettClax);
meth.invoke(o, vettParam);
public void meth3(int n)
System.out.println("hello " + n);
}Is your meth3() public? -
Java reflection (interesting question)
hi folks,
class A {
void foo() {
Class B overrides method foo() in A
class B extends A {
void foo() {
Now i create a object of class B and assign to A
A aref = new B();
aref.foo() will call method foo()of class B. //polymorphism
Using reflection, is it possible to call method foo() of class A using the handle aref.
thanks
venkathi bondvenky,
What abt the answer for my original question. How to
access the base class methods using the handle for
child class object using reflection ?as far as i know, this isn't possible - your next question is probably going to be "why". It certainly seems slightly surprising that you can't do this, but you can access private methods. Unless you consider the latter a weaker way of breaking encapsulation (!?).
what was the sun's purpose behind allowing access to
the private methods of an object using Java
Reflection? good question.. its very useful but on the other hand i can't think of a time i've used it that couldn't be classed as a hack.
Is it not a security threat to java security model?it doesn't break anything - ie its not a security loophole. It links in with your question above though - would it have been possible/useful to not allow it period?
sorry for the vague answers :(
asjf -
I have a Java program ( not mine) with import statements like the following:
import com.brainysoftware.tassie.ejb.Search;
import com.brainysoftware.tassie.ejb.SearchHome;
I want to know if Search here corresponds to "Search.class" and SearchHome corresponds to SearchHome.class" respectively. I was confused and for example, thought that Search and SearchHome were directories in the package tree.
Actually I also two other Java files ( actually EJBs) called SearchHome.java and Search.java and their corresponding class files in com.brainysoftware.tassie.ejb
So my question is: is Search in the import statement to be interpreted as Search.class..
I know my question is downright simple and silly. All help is appreciated
thanks in advanceactually, this would recursively import any
subpackages (or rather their classes), so
technically, you can (at least syntactically) import
a package this way!Uhm ... no, it wouldn't ... there is no such thing as a sub-package.
xxx.yyy and xxx.yyy.zzz have no special relationship whatsoever in Java. They are as related as xxx.yyy and xxx.zzz are ... the similarity in naming has no meaning in Java, it's there only to logically group APIs which belong together but you can't automatically import classes from all "sub-packages".
Ever tried to write "import java.*"? It doesn't do anything usefull. -
Can Java reflect not only .Class file
Hi' i'm newbie in this topic, i'm really appreciate if somebody can help me..cos i'm really stuck in here...
My Problems are :
1. i want to ask about this, can Java reflect from .java file?
2. i'm using Eclipse IDE, i'm really interesting about how JTree or Package Explorer in Eclipse can always displaying update information about class structure? but .java files not compiled, how can? if Eclipse using reflection, .java files must be compiled first, correct me if i'm wrong?
The fact is Eclipse don't have to compiled .java files to get the update information about class structure and displaying in JTree or package Explorer...how implement like this?
what i mean like this :
ex : if i type int x = 100; (not only int, it could be anything else..) at the working files, JTree or Package Explorer in Eclipse can always update the informasion about class structure, but .java files not compiled..
i hope my question are easy to understand, i really need some help..
Thanks a lot..hey, thanks for the answers, but i would like to ask :
1) Eclipse performs background compilation of the Java sources, then performs reflection on those temporary classes++ if i'm using this way, how about the performance? seems that it will be compiled all the time right?
2) Eclipse has access to the results of the Java source code parser, and can extract the information from the java syntax parser, before it gets to the compilation stage.++ how to implement this? what do you mean about java syntax parser?
do you know where i can find any article about this?
thanks a lot again... -
Hi
I am just a starter on WLPortal.
I have created a barebone Application from scratch. I have synchronized it properly
from EBCC to WLP. But When I am trying to access the home page of my application,
I am getting from stack trace -
<Nov 6, 2002 5:37:59 PM IST> <Error> <PortalAppflow> <Could not lookup PortalManagerHome
in the JNDI tree using EJB reference java:comp/env/ejb/PortalManager.
javax.naming.NameNotFoundException: Unable to resolve comp/env/ejb/PortalManager
Resolved: 'comp/env' Unresolved:'ejb' ; remaining name 'PortalManager'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:802)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:209)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:173)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:181)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:181)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:323)
at weblogic.jndi.factories.java.ReadOnlyContextWrapper.lookup(ReadOnlyContextWrapper.java:36)
at weblogic.jndi.internal.AbstractURLContext.lookup(AbstractURLContext.java:124)
at javax.naming.InitialContext.lookup(InitialContext.java:350)
at com.bea.p13n.util.JndiHelper.lookupNarrow(JndiHelper.java:96)
at com.bea.portal.appflow.PortalAppflowHelper.<clinit>(PortalAppflowHelper.java:64)
at com.bea.portal.appflow.servlets.internal.PortalWebflowServlet.init(PortalWebflowServlet.java:78)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:700)
at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:643)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:588)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:368)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:242)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:215)
at weblogic.servlet.jsp.PageContextImpl.forward(PageContextImpl.java:112)
at jsp_servlet.__index._jspService(__index.java:92)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:265)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:304)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2459)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2039)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>
<Nov 6, 2002 5:37:59 PM IST> <Error> <HTTP> <[WebAppServletContext(19695286,FirstWebApp,/FirstWebApp)]
Servlet failed with Exception
java.lang.NullPointerException:
at com.bea.portal.appflow.PortalAppflowHelper.createPortalManager(PortalAppflowHelper.java:82)
at com.bea.portal.appflow.servlets.internal.PortalWebflowServlet.setupPortalRequest(PortalWebflowServlet.java:187)
at com.bea.portal.appflow.servlets.internal.PortalWebflowServlet.doGet(PortalWebflowServlet.java:99)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:265)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:215)
at weblogic.servlet.jsp.PageContextImpl.forward(PageContextImpl.java:112)
at jsp_servlet.__index._jspService(__index.java:92)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:265)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:304)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:200)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:2459)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2039)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
When I decompiled the class PortalAppflowHelper, I found a static block in it,
which was as under-
static
debug = Debug.getInstance(com.bea.portal.appflow.PortalAppflowHelper.class);
try
if(debug.ON)
debug.out("Looking up PortalManagerHome using EJB reference java:comp/env/ejb/PortalManager");
portalManagerHome = (PortalManagerHome)JndiHelper.lookupNarrow("java:comp/env/ejb/PortalManager",
com.bea.portal.manager.ejb.PortalManagerHome.class);
if(debug.ON)
debug.out("Successfully retrieved PortalManagerHome " + portalManagerHome);
catch(Exception e)
PortalAppflowLogger.errorFindingPortalManagerHome("java:comp/env/ejb/PortalManager",
e);
I have checked the PortalManager's JNDI name on WLConsole. Its ${APPNAME}.BEA_portal.PortalManager.
Should I change it?
When I tried to change it, I started getting other weird errors.
Thanks
Neeraj HansNeeraj -
The Portal framework code (including PortalAppflowHelper) uses ejb
references to find the PortalManager (and other EJBs) from servlets and
taglibs; that is what is signified by the java:comp/env/... name.
Since you built your webapp from scratch (instead of using the portal
wizard), you will need to make sure the you have the appropriate
<ejb-ref> entries in your web.xml, and the corresponding
<ejb-reference-description> entries in your weblogic.xml. By default,
you will need at least mappings for:
- ejb/PortalManager
- ejb/UserManager
- ejb/GroupManager
- ejb/PipelineExecutor
- ejb/EventService
See either the resulting webapp from using the portal wizard or
BEA_HOME/weblogic700/samples/portal/sampleportalDomain/beaApps/sampleportal/sampleportal/WEB-INF
for example syntax.
Greg
Neeraj Hans wrote:
Hi
I am just a starter on WLPortal.
I have created a barebone Application from scratch. I have
synchronized it properly
from EBCC to WLP. But When I am trying to access the home page of my
application,
I am getting from stack trace -
<Nov 6, 2002 5:37:59 PM IST> <Error> <PortalAppflow> <Could not lookup
PortalManagerHome
in the JNDI tree using EJB reference java:comp/env/ejb/PortalManager.
javax.naming.NameNotFoundException: Unable to resolve
comp/env/ejb/PortalManager
Resolved: 'comp/env' Unresolved:'ejb' ; remaining name 'PortalManager'
at <stack trace lines snipped>
When I decompiled the class PortalAppflowHelper, I found a static
block in it,
which was as under-
static
debug =
Debug.getInstance(com.bea.portal.appflow.PortalAppflowHelper.class);
try
if(debug.ON)
debug.out("Looking up PortalManagerHome using EJB
reference java:comp/env/ejb/PortalManager");
portalManagerHome =
(PortalManagerHome)JndiHelper.lookupNarrow("java:comp/env/ejb/PortalManager",
com.bea.portal.manager.ejb.PortalManagerHome.class);
if(debug.ON)
debug.out("Successfully retrieved PortalManagerHome "
+ portalManagerHome);
catch(Exception e)
PortalAppflowLogger.errorFindingPortalManagerHome("java:comp/env/ejb/PortalManager",
e);
I have checked the PortalManager's JNDI name on WLConsole. Its
${APPNAME}.BEA_portal.PortalManager.
Should I change it?
When I tried to change it, I started getting other weird errors.
Thanks
Neeraj Hans -
Hi
I am getting below error while calling a stateless EJB method. There is some validation checks while performing ejb's modify() method and a RuntimeException is thrown in case of validation failure.The modify() method internally calls other stateless ejb as well.
The problem I'm facing is, instead of getting the expected RuntimeException in the Servlet, i am getting RemoteException. I am using WLS 9 MP1, all participating ejbs are stateless and i am using default transaction attributes(Supports) for these ejbs.
The interesting part is, at the ejb layer RuntimeException is thrown as expected, but this exception changed to RemoteException at the servlet's end where i am catching the ejb call exceptions.
I am new to WLS, please suggest/help me out of this exception.
Any help is truly appreciated.
java.rmi.RemoteException: EJB Exception: ; nested exception is: java.lang.RuntimeException:
at weblogic.ejb.container.internal.EJBRuntimeUtils.throwRemoteException(EJBRuntimeUtils.java:95)
at weblogic.ejb.container.internal.BaseEJBObject.handleSystemException(BaseEJBObject.java:713)
at weblogic.ejb.container.internal.BaseEJBObject.handleSystemException(BaseEJBObject.java:681)
at weblogic.ejb.container.internal.BaseEJBObject.postInvoke1(BaseEJBObject.java:447)
at weblogic.ejb.container.internal.StatelessEJBObject.postInvoke1(StatelessEJBObject.java:72)
at weblogic.ejb.container.internal.BaseEJBObject.postInvokeTxRetry(BaseEJBObject.java:374)
at com.mycomp.base.BaseController_8x2e52_EOImpl.modify(BaseController_8x2e52_EOImpl.java:149)
at com.mycomp.webgui.servlet.FrontComponent.service(FrontComponent.java:207)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:223)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3245)
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:2003)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1909)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1359)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
Thanks!
Edited by: user10721298 on Feb 23, 2009 4:16 AMHi,
If i don't misunderstand, you are using the RuntimeException as an application exception, right?
Have you annotated it or denoted it in deployment descriptor?
Thanks,
Amy -
Java Reflection and dynamic class loading
I am trying to load my classes 'dynamically' using java reflection, which is a feature absolutely necessary for my webapp. I could not get this to work as of yet. Could someone please give me a piece of sample code that would do the following :
- return the value (String) of known method y from class x
- class x is only known at runtime (from the query-string in this case)
- method y is known
Thanks in advance.
cheers,
Tom
PS: Please do not give me any links to tutorials/articles that do not do the EXACT thing that I asked for. Thank you.tried it, but it always gives me a MethodNotFoundException, because its trying to find my class in java.lang.String for some reason...
heres part of the code (its an altered version of the code given in the invoke tutorial):
public String getMethodReturnValue(String methodName, String className) {
String result = null;
Class theModuleClass = String.class;
Class[] parameterTypes = new Class[] {};
Method concatMethod;
//Object[] arguments = new Object[] {parameters};
try {
concatMethod = theModuleClass.getMethod(methodName, null);
result = (String) concatMethod.invoke(createObject(className), parameterTypes);
} catch (NoSuchMethodException e) {
result = e.toString();
} catch (IllegalAccessException e) {
result = e.toString();
} catch (InvocationTargetException e) {
result = e.toString();
return result;
private Object createObject (String className) {
Object object = null;
try {
Class classDefinition = Class.forName(className);
object = classDefinition.newInstance();
} catch (Exception e) {}
return object;
Thanks for any help!
-Tom -
Problems with JNDI lookup for java:comp/env/ejb
Hi all,
I'm using OC4J 9.0.3 and I have problems when looking up for the local
EJB context.
I have a SLSB which refers to another SLSB via a JNDI mapping like
shown below. Both services are deployed within one EAR file.
(snippets of ejb-jar.xml and orion-ejb-jar.xml)
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>ServiceABean</ejb-name>
<home>com.coi.ServiceAHome</home>
<remote>com.coi.ServiceA</remote>
<ejb-class>com.coi.ServiceABean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>ejb/some/sub/packages/ServiceB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.coi.ServiceBHome</home>
<remote>com.coi.ServiceB</remote>
</ejb-ref>
</session>
</enterprise-beans>
</ejb-jar>
<orion-ejb-jar>
<enterprise-beans>
<session-deployment location="global/some/sub/packages/ServiceA" name="ServiceABean">
<ejb-ref-mapping name="ejb/some/sub/packages/ServiceB" location="global/some/sub/packages/ServiceB" />
</session-deployment>
</enterprise-beans>
</orion-ejb-jar>
The ApplicationInitialContextFactory will be used (prepared by the container),
so the lookup for ServiceB within a method of ServiceA should work as follows:
public class ServiceABean implements SessionBean
public void someMethod()
InitialContext con = new InitialContext(); // will be of class ApplicationContext
Context localEjbContext = (Context)con.lookup( "java:comp/env/ejb" );
ServiceBHome serviceBHome = (ServiceBHome) PortableRemoteObject.narrow(
localEjbContext.lookup( "some/sub/packages/ServiceB" ),
ServiceBHome.class );
The problem is now, that the lookup for "java:comp/env/ejb" doesn't work
and throws a NameNotFoundException.
To figure out what's actually happening during lookup I debugged a little bit and
tried a few things:
1. A lookup for "java:comp" works fine. It returns an instance of class FlatMapContext
which consists of a hash map which itself contains an entry for "env".
2. So a lookup for "env" on that FlatMapContext also works and returns an instance of SubContext.
3. A lookup for "ejb" using this SubContext causes a NameNotFoundException
with message "java:comp/env/ejb not found".
4. A lookup like con.lookup( "java:comp/env" ) throws also a NameNotFoundException
with message "java:comp/env not found (not inside a J2EE module, for instance a Web-App,
EJB, or Application-Client)".
Does anyone know something about this?
Regards
--thomasHi Debu,
Great! 9.0.4 will be released in june/july this year, right? Sorry for my ironical reaction, but does that mean, that I don't have any chance to get my whole stuff running in 9.0.3? I cannot believe that. Isn't there a wordaround I could apply? A setting or whatever to substitute the daft FlatCtx by something else that is implemented according to the spec?
Regards
--thomas -
Hi Every1....i have a problem with java reflection n hope some1 will be able to resolve this me.
I am getting the name of the child class as a string argument.
eg String classname = this.getattributes().get("classname");
I need to dynamically create the object of this instance using the classname and call a specific method...i know the name of the base class but the base class doesnt have the method i need....i m not allowed to redesign the base class...
plz helpbut the problem is getting the method nameIf you don't have the method name what exactly is the plan? You've gotta have something ...
.....i have the object of base class with meActually the object is an instance of the derived class ...
....and the method i
need is in the child class.....so how do i invoke the
method???Sigh. You can lead a horse to water but you can't make him drink. See
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Method.html#invoke(java.lang.Object,%20java.lang.Object...) -
Code generation through Java Reflection
Hi
I am after some clarification about the possibility of mapping of method outputs to other method inputs, using java reflection.
The java objects are described in an XML based language (called DAML) as follows
<java:Method rdf:ID="meth1" java:priority="1">
<java:methodName>buildQuery</java:methodName>
<java:parentClass>afsw.query.QueryBuilder</java:parentClass>
<java:methodParameters rdf:parseType="daml:collection">
<java:Parameter>
<java:inORout>input</java:inORout>
<java:type>java.util.Hashtable</java:type>
</java:Parameter>
</java:methodParameters>
</java:Method>
and I want to map them back to method calls and instantiations, so to be able to generate code on the fly. I need to know if its is possible to pass the output of a method such as getQuery() which in this case is a Document to the input of constructor MsgModule as in the following example:
Document queryDoc =qc.getQuery();
MsgModule mg= new MsgModule(queryDoc);
regards
CharlieThis is possible. What you need to do in the 'new' instance case is to find the best constructor. So let's say you have Class clazz, the class you want to create a new instance of, and Class[] params, an array of objects to pass in the constructor. Using the Class api you can do:
Constructor constructor = clazz.getConstructor(params);The getConstructor method will only return an exact match. Let's say one of the parameters was a subclass of an class that is allowable in the constructor. You can get all the constructors via clazz.getConstructors() and get all the parameters types via Constructor.getParameterTypes() and check to see if the params you passed in are compatible. You can use Class.isAssignableFrom() to help resolve this. Once you find the constructor, use Constructor.newInstance(params) to create the new instance. Hope this helps. -
Problem running Java client of EJB deployed on WebSphere
Hi,
I am using websphere studio 5.1.2 with fix pack 3. I have a sample Stateless Session Bean (EJB) deployed and running on websphere.
I wrote a small Java client program as below.
import java.util.Hashtable;
import HelloJavaHome;
import HelloJava;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.ejb.EJBHome;
import javax.ejb.EJBObject;
public class RemoteConn {
public static void main(String[] ar) throws Exception{
String greeting = "";
try{
Hashtable env = new Hashtable();
//env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
//env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ws.naming.util.WsnInitCtxFactory");
//env.put(Context.PROVIDER_URL, "corbaloc:iiop:myhost.mycompany.com:2809/NameServiceCellPersistentRoot");
env.put(Context.PROVIDER_URL, "iiop://localhost:2809");
System.out.println("Before creating context ");
InitialContext initContext = new InitialContext(env);
System.out.println("Before looking up HelloJavaHome.");
//Object obj = initContext.lookup("java:comp/env/ejb/HelloJavaHome");
Object obj = initContext.lookup("ejb/HelloJavaHome");
System.out.println("After lookup javahome.");
HelloJavaHome home = (HelloJavaHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloJavaHome.class);
HelloJava remote = home.create();
greeting = remote.getGreeting("John");
catch(Exception e){
e.printStackTrace();
System.out.println("Greeting::"+ greeting);
I did not have any problem if I write and run this client from Websphere studio environment..
However its giving lot of compilation and runtime errors when I tried to run from command line.
I could eliminated compilation errors by setting the below jar files in the classpath.
testclient.jar; (client jar of my EJB)
j2ee.jar;
naming.jar;ras.jar;
wsexception.jar;
bootstrap.jar;
namingclient.jar;
websphere.jar;server.jar;
ejbcontainer.jar;
ecutils.jar;
Now it is throwing runtime error after the statement, "Before looking up HelloJavaHome.", has printed. Here is the stack trace of exception ..
Exception in thread "main" java.lang.NoClassDefFoundError: com.ibm.CORBA.iiop.GlobalORBFactory
at com.ibm.ejs.oa.EJSORBImpl.class$(EJSORBImpl.java:44)
at com.ibm.ejs.oa.EJSORBImpl.initializeORB(EJSORBImpl.java:195)
at com.ibm.ejs.oa.EJSClientORBImpl.(EJSClientORBImpl.java:93)
at com.ibm.ejs.oa.EJSClientORBImpl.(EJSClientORBImpl.java:65)
at com.ibm.ejs.oa.EJSORB.init(EJSORB.java:385)
at com.ibm.ws.naming.util.Helpers.getOrb(Helpers.java:284)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:369)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:112)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:422)
at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:143)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at RemoteEJBConn.main(RemoteEJBConn.java:38)
I appreciate if sombody could help me ASAP fixing this problem.
Thanks in advance.Try using the IBM JVM (theres one shipped with WebSphere in websphere_home\AppServer\java
Also include idl.jar and ffdc.jar on the classpath -
Question about Java's HttpServer: Threading? Backlog?
Hello,
I have two questions about Java's HttpServer (com.sun.net.httpserver). From the JavaDoc:
>
Management of threads can be done external to this object by providing a Executor object. If none is provided a default implementation is used.
>
How can I get information about the default implementation in 1.6.0_13? Do you know the behavior? From my observations, the default implementation uses no Threads, meaning every request is handled in the same Thread, this results in handling the requests to the HttpServer one after another.
Is this right?
The second question is about this, also from the JavaDoc:
>
When binding to an address and port number, the application can also specify an integer backlog parameter. This represents the maximum number of incoming TCP connections which the system will queue internally. [...]
>
When setting the backlog to -1, it uses the systems default backlog. How can I determine the systems default backlog? Can some lines of Java code reveal it (there is no getBeacklog() method)? Or is it up to the Operating System (we use Redhat Linux)?
Thanks a lot for your help!
Regards,
TimoHow can I determine the systems default backlog?You can't. There is no API for that even at the C level.
Can some lines of Java code reveal itNo.
Or is it up to the Operating System (we use Redhat Linux)?Yes. Linux provides a large default. It seems to be at least 50 on most platforms. This is not something you should be worrying about. -
How to use Java WebStart with EJB ?
hi forum...
how to use Java WebStart with EJB ? examples ?
thanks
minduGreetings,
hi forum...
how to use Java WebStart with EJB ? examples ?Well, for starters these are complementing, not 'cooperating', technologies. I presume, since EJB's do not - directly, at least - communicate with a web browser, that you intend for "Java WebStart" to somehow invoke an EJB?? Java WebStart is a technology for running client-side (Java) applications from the web browser - perceptively, the application resides on the server, but technically it, like an applet, is downloaded to the client and run there. Unlike an applet, however, it is not constrained by "sandbox" restrictions and does not have to be re-downloaded each time it is invoked - though the process allows for automagically updating the client-side with new versions of the application. ;) So, with this in mind, to "use Java WebStart with EJB" means little more than deploying an EJB client application with Java WebStart as the distribution channel.
thanks
minduRegards,
Tony "Vee Schade" Cook -
Java reflection and parameter's names
hi, I have to extract from a method of a given class all types and names of the parameters, i've tryed to use java reflection function:
Method[] metodo = temp.getDeclaredMethods();
for (int i = 0; i < metodo.length; i++) System.out.println(metodo.toString());
and the output is:
public void DinamicLoad.function1.method1()
public void DinamicLoad.function1.method2(java.lang.String)the function extract only the parameter's type, not his nameProbabily all the "dozens, hundreds, thousands of
other people who use reflection" knows very well
classes that they use.
Imagine to produce a class from a wsdl file, how can
you know the content?
How can you pass parameters if you know only the type
and not the MEANING?When building classes from XML it's rare to use the constructor to convey the attributes, far more often each attribute is set independantly using a single argument setter with a signature like:
public void setMyAttribute(String value) {Hence attribute names (e.g. myAttribute) are normally compared against method names, not parameter names.
If constructors are to be used then parameters will be supplied in order.
Maybe you are looking for
-
Ipod Classic not playing sunched content
Please can someone assist me. I am having enless problems synching content to my iPod Classic. I had the same problem on a previous iPod and bought a new one thinking the device was broken. Now the same thing is happening on this device. The music
-
I run Mac OS 10.6.8. When I try to print a PDT file, such as an IRS form, Firefox opens a small dialog box asking what program was used to create the file I wish to print.No matter which of the selections I choose, the file will not print. I have the
-
Iphone 5 video playback problems over quicktime?
ive recently got a new laptop, pre windows 8, and downloaded quicktime pro in order to play my iphone videos right side up because windows media player will play them upside down alot of the time. something i immeadiately noticed was that all my vide
-
My mac keeps freezing, the disk utility states the hardrive is failing
Hi. My desktop was upgraded to the snow leopard and has had increasing problems with freezing. Now it wont start up at all, so I have to open it with the Disk 1 OS.. then I went to the disk utility to try and repair it. But it says the hard drive is
-
Outbound created with zero value against STO PO
Hi experts, I have created an outbound delivery (VL10D) against STO PO. OBD has been created with zero value. in PGI correct accounting entry is getting generated. However, material price is maintained in STO PO. Please highlight the gaps, due to whi