Chris Logan

Greenhorn
+ Follow
since Jan 31, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Chris Logan

I solved the problem. I thought that I wrote the code like I read in the book but I made a mistake and instead of declaring the appropriate interface (local / remote) for injected bean I declared the object member of injected bean.


Simple mistake:

@EJB private ObslugaPracownika obslugaPrac -> @EJB private ObslugaPracownikaRemote obslugaPrac;
Hello everyone!


I'm still fighting with EJB 3.0 and today I got an error connected with dependency injection. Namely I was trying to inject stateless session bean called ObslugaPracownika to the other stateless session bean called ObslugaKlienta using the @EJB annotation. I'm going to write what I did and what kind of error occurred.

Bacis information:

EJB 3.0 implementation: JBoss Applicaiton Server
Component using the injection: @Stateless(name="ObslugaKlientaSLSBean") komponenty.ObslugaKlienta implements ObslugaKlientaRemote
Injected component: @Stateless komponenty.ObslugaPracownika implements ObslugaPracownikaRemote, ObslugaPracownikaLocal


First attempt:


Note: Injected component wasn't registered in JNDI ENC.


Server's console:

DEPLOYMENTS MISSING DEPENDENCIES:
Deployment "jboss.j2ee:ear=EJBSklepEAR.ear,jar=EJBSklep.jar,name=ObslugaKlientaSLSBean,service=EJB3" is missing the following dependencies:
Dependency "<UNKNOWN jboss.j2ee:ear=EJBSklepEAR.ear,jar=EJBSklep.jar,name=ObslugaKlientaSLSBean,service=EJB3>" (should be in state "Described", but is actually in state "** UNRESOLVED Demands 'Class:komponenty.ObslugaPracownika' **")

DEPLOYMENTS IN ERROR:
Deployment "<UNKNOWN jboss.j2ee:ear=EJBSklepEAR.ear,jar=EJBSklep.jar,name=ObslugaKlientaSLSBean,service=EJB3>" is in error due to the following reason(s): ** UNRESOLVED Demands 'Class:komponenty.ObslugaPracownika' **


Second attempt:


Note: Injected component was registered in JNDI ENC like this

(fragment of java:comp namespace of ObslugaKlienta component)

+- obslugaPracownikaSLSBean[link -> EJBSklepEAR/ObslugaPracownika] (class: javax.naming.LinkRef)



(fragment of global namespace)

+- EJBSklepEAR (class: org.jnp.interfaces.NamingContext)
| +- ObslugaPracownika (class: org.jnp.interfaces.NamingContext)
| | +- local (class: Proxy for: komponenty.ObslugaPracownikaLocal)
| | +- local-komponenty.ObslugaPracownikaLocal (class: Proxy for: komponenty.ObslugaPracownikaLocal)
| | +- remote-komponenty.ObslugaPracownikaRemote (class: Proxy for: komponenty.ObslugaPracownikaRemote)
| | +- remote (class: Proxy for: komponenty.ObslugaPracownikaRemote)




... but when I tried to get reference to the ObslugaKlienta component in client app I had following errors:


Client side:

Exception in thread "main" javax.ejb.EJBException: java.lang.IllegalArgumentException: failed to inject org.jnp.interfaces.NamingContext@c1c084f (implements [interface javax.naming.event.EventContext, interface java.io.Serializable]) from env/obslugaPracownikaSLSBean (link -> EJBSklepEAR/ObslugaPracownika) into komponenty.ObslugaKlienta.obslugaPrac of komponenty.ObslugaKlienta@74ff364a

Server side:

14:18:44,650 ERROR [FieldBeanProperty] Field Classloader: BaseClassLoader@5fe8bb4c{vfszip:/D:/Programowanie/JAVA/JBOSS/jboss-5.0.1.GA/server/default/deploy/EJBSklepEAR.ear/}
Value ClassLoader: BaseClassLoader@7b6bbeaf{vfsfile:/D:/Programowanie/JAVA/JBOSS/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}
Equal Loaders: false
14:18:44,651 ERROR [FieldBeanProperty] failed to set value org.jnp.interfaces.NamingContext@38b7f14b on field komponenty.ObslugaPracownika komponenty.ObslugaKlienta.obslugaPrac; Reason: ClassLoaders of value and target are not equal
java.lang.IllegalArgumentException: Can not set komponenty.ObslugaPracownika field komponenty.ObslugaKlienta.obslugaPrac to org.jnp.interfaces.NamingContext


Do you maybe know how to solve the problem? Can you help me?

The things that came up to my mind:

First thing first - did you configured persistence.xml file?
It should be in the META-INF catalog with ejb-jar.xml file.

Are you sure that your persistence unit name is "entityManager"? You can check it in persistence.xml file - the tag is <persistence-unit name="yourName">.

I don't have any more ideas I hope it will help you somehow.


Cheers
Thanks for the reply Sib Pete.

I know about this books. Though, I found out Dependency Injection by Dhanji R. Prasanna too complex and as you wrote its limited to the conception of DI and moreover I want to learn about DI in the context of EJB architecture. I read EJB 3 In Action but it was quite time ago so I will reread the interesting to me parts.

In a mean time I came up with some questions I hope you can help me with those.


1) During the deployment configured (by annotations or deployment descriptors) components (session and md beans) are registered in EJB container - that's correct?

2) What is responsible for creating services/resources and where are they registered, is it also the EJB container?

3) Where/when the services, resources and components are bound to the JNDI?

4) In EJB we can inject all resources that are populated in the JNDI, am I right?


Thanks for your attention.


Cheers
Hello everyone.


I spent a lot of time looking for information about EJB container and DI but it was quite worthless because I found only brief infos about it. Can you help me and point some valueable articles or books about this topic (especially DI in EJB)? Thanks in advance.


Chris
Thanks for your answers Mir Mohammed Easin. Though, I think that in some cases you mixed up the RMI JRPC with RMI IIOP architecture. Now I don't have time to move back to RMI related topics but if I find some time for that I will try to answer my own questions in this topic.

Cheers.
13 years ago
Can't argue with that - been there seen that. But I'm still hoping to find some answers over here and verify them with other sources.
13 years ago
Thanks for the reply Jimmy Clark.

Simple question/answer material on an Internet forum is not a replacement for dedicated reading, concentration and study.


I'm copletely agree with you but the heart of the matter is I have to do few different things at the same time not metioned about my job. Sooner or later I'll probably need to look up some new books but I had hoped that earlier I'll find some answers over the Internet. Human brain is such a great repository and it's faster and easier to use someone's knowledge than looking for information often wasting a lot of time founding nothing vauleable.
13 years ago
Hey guys and (probably) girls. It's hard to believe that no one manage to help me answering for at least one of above questions. It's quite disappointing... I hope I'll find here someone with good will who will show me right direction.
13 years ago
First of all I want to say hello to everyone (so - Hello!! ). This is my first post on this forum and it`s actually my first Java related forum that I registered in ever. I hope to spend some quality time over here. ;) I have a tendency to write very long first post in a topic so I hope you will manage to get to the end but back to the topic.

Currently I`m writing my engineer thesis and I`ve been reading for the last few days about RMI-IIOP architecture which I need to discuss. I have opened a tens of tabs in my Firefox and there I have a whole bunch of articles and specifications. I feel like my brain can blow up at any time. I hope you can help me to resolve my deep doubts about RMI-IIOP. It would be great if you could answer at least one my question. Please confirm if my way of thinking is correct.


An example of creation process of RMI-IIOP client and server side:

Server side
1) Creating a so called remote interface which extends javax.rmi.Remote interface all methods must throw a java.rmi.RemoteException.
2) Creating a class of our remote object which implements our remote interface.
3) Creating a stub and tie of remote object.
4) Running an Object Request Broker (orbd.exe) which will also run COS Naming Service.
5) Registering of remote object:
a] by using javax.rmi.PortableRemoteObject exportObject() method,
b] by extending PortableRemoteObject by it (then a creation of remote object will effect in invoking of PortableRemoteObject constructor where will be invoked exportObject() method).
6) Configuring JNDI by jndi.properties file or by passing right arguments (java.naming.factory.initial and java.naming.provider.url parameters - the provider url need to be the same as ORB ip adress and port) to the javax.naming.InitialContext constructor to handle the COS Naming Service.
7) Binding the remote object reference with picked name by calling the InitialContext bind() or rebind() method.

Client side
8) Providing to the client the remote interface of our remote object.
9) Configuring JNDI by the same as on the server side jndi.properties file or right arguments in InitialContext constructor.
10) Connecting with remote object by invoking the InitialContext lookup() method with argument which has to be the name of our remote server object.
11) Casting obtained reference to remote interface using PortableRemoteObject narrow() method.

Hopefully that's all.


That was a quite brief introduction to RMI-IIOP implementation and here are my questions:

1] Didn't I omit anything important in my example of creation process? I`m only checking...

2] I read that "somewhere" in RMI-IIOM results are passed by reference instead of by value? Where is it and how come? If I recall correctly Java is a strictly pass by value language, am I right?

3] I haven't checked it yet. Is it possible to create a stub and tie from remote interface instead of remote object and is it going to work?

4] I'm wondering is it abligatory to create a stub and tie class before registering/exporting the remote object?

5] What do we mean by registering the remote object?

6] The specification says exportObject() method "Makes a server object ready to receive remote calls" I understand that's some thought abbreviation? How object can receive remote calls...? (I guess it has something in common with ORB but that?)

7] I read somewhere that by invoking InitialContext bind() or rebind() method we actually don`t bind name to the remote object reference but to the stub of this object and somewhere else I read that we bind the remote object reference with the name but client looking up for the name receive reference to its stub so where the truth lies?

8] I need to confirm something. I'm sure that looking up for the remote object returns the stub object but I didn't provide the stub class to the client so how is that possible that I didn't received some exception like No Class Definition Found Exception (of course I casted it to some other type like object or remote interface type)? I also read that client need to have a stub class so...? That's really confusing.

9] I quite don't get one thing (or rather another thing). I read (yeah I know, I had a lot of reading lately ;)) that marshalling and unmarshalling is done by stub and tie in the other source I read that it's provided by ORB so how it really looks like?

10] How the communication between client and server looks? It's that correct that stub "speaks to" tie and tie invokes the method on remote object? How tie obtains the remote object reference and where is the place for ORB in this communication?

11] Client communicates with server by IIOP so I guess there is an implementation of IOR in Java and this is how a client can localize a server, am I right? Am I correct that stub and tie stores the information about localization of each other? If that's true then when exactly stub obtains this information?

12] Is that true that ORB provides persistence to remote objects? So if the server is offline remote object is still alive and can receive the RMI calls?

13] I know that COS Naming bind remote object reference with name and this service is launched on the same port as ORB (that`s correct, isn`t it?) but I also read that remote objects are exported to some ports so what does it mean?



Okey now I'm sure that my brain is going to blow up, hehe. This is my the longest post in English ever (sorry for probably a lot of language mistakes) and there is a high possibility I forgot to write about some other stuff that I don't know or I'm not sure about. Thank you very much for your patient and, I hope, your help.
13 years ago