EJB and JNDI
Hi,
Suppose if I want to register a string with the JNDI and access it
within the bean using the lookup, how should I go doing this. The binded
string should be permanent. How this could be achieved in the weblogic
environment.
Thanks!
Answered in the ejb newsgroup. Please do not cross-post to multiple
newsgroups.
-- Rob
hari wrote:
>
Hi,
Suppose if I want to register a string with the JNDI and access it
within the bean using the lookup, how should I go doing this. The binded
string should be permanent. How this could be achieved in the weblogic
environment.
Thanks!--
Coming Soon: Building J2EE Applications & BEA WebLogic Server
by Michael Girdley, Rob Woollen, and Sandra Emerson
http://learnweblogic.com
Similar Messages
-
Help with EJB and JNDI, please
Hello. My name is Santiago, and i am a student from the University of Valladolid, in Spain. I am newcome in the world of EJB, I have done the first EJB from de Sun tutorial (I�m using the Sun Java System Application Server PE 8.2) and now I am trying to improve it in that way: I have the EJB and the client in diferent machines conected.
I am trying to understand how to use JNDI, but i have not good results :( I have read about using ldap but i dont know if it is apropiated, or if it is installed automaticaly with the sun aplication, or if i have to download and install it... i am not sure about anything :)
This is my client�s code (part of it)
Hashtable envirom = new Hashtable();
envirom.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
envirom.put("java.naming.factory.url.pkgs","com.sun.enterprise.naming");
envirom.put(Context.PROVIDER_URL,"iiop://Santiago:389");
envirom.put(Context.PROVIDER_URL,"ldap://192.168.1.101:389");
envirom.put(Context.SECURITY_AUTHENTICATION,"none");
InitialContext ctx = new InitialContext(envirom);
Object objref = ctx.lookup("java:comp/env/ejb/Multiplica");
When I try to connect in local mode (client and EJB in the same machine) i get something like that:
javax.naming.CommunicationException: 192.168.1.101:389 [Root exception is java.n
et.ConnectException: Connection refused: connect]
at com.sun.jndi.ldap.Connection.<init>(Connection.java:204)
at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:118)
at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1578)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2596)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:283)
It is even worse when i try it in different machines:
10-mar-2006... com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImp1<init>
ADVERTENCIA: "IOP00410201: <COMM_FAILURE> Fallo de conexion: Tipo de socket: IIOP_CLEAR_TEXT;
name of host: portatil; puerto: 3700"
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code:201 completed:No
Both SSOO are XP and I have disabled Firewalls.
PLEASE, if you colud help me It would fantastic, because I am in that trouble, i have tryed 1000 solutions but i am not able to understand it.
Hoping you can help me.
Santiago.This thread is now being followed up in:
http://swforum.sun.com/jive/thread.jspa?threadID=64092 -
I am encountering this problem while deploying my stateless session bean on WLS
6.x. My JNDI Tree shows two entries for the bean that i deploy.
This does not happens when i deploy a stateful or entity bean on the server. The
first entry in JNDI is ofcourse named to the Bean and the other is the name of
the bean followed by underscore and EO.
Can anyone throw some light on this and let me know that whether i am doing something
wrong here or its the normal behiaviour of stateless session beans when they are
deployed on WLS.
Thanks in advanceNo, you are not doing anything wrong - this is some internal
WebLogic thing.
Ashish Jain <[email protected]> wrote:
I am encountering this problem while deploying my stateless session bean on WLS
6.x. My JNDI Tree shows two entries for the bean that i deploy.
This does not happens when i deploy a stateful or entity bean on the server. The
first entry in JNDI is ofcourse named to the Bean and the other is the name of
the bean followed by underscore and EO.
Can anyone throw some light on this and let me know that whether i am doing something
wrong here or its the normal behiaviour of stateless session beans when they are
deployed on WLS.
Thanks in advance--
Dimitri -
EJB 3.0 @Stateless @EJB @Resource and JNDI clarity..
Hi,
I am trying to configure an EJB 3.0 but not able to do so properly.
I have a single business interface and 2 bean implementation class of the same business interface doing different things. How do I access the EJB's if I have the same business interface class.I am getting JNDI error while trying to lookup.
Also what does the "name" and "mappedName" in @Stateless(name ="...",mappedName="") signify.
Then in case of Dependency injection,how should I look for the EJB? What would be it's JNDI name in this case?
@EJB(name="",beanName="",mappedName="")
private HelloEJB hello;
What does the name,benaName and mappedName in case of an @EJB annotation signify??
Please clear me with these attributes of @Stateless and @EJB and @Resource. I am getting toatlly confused with what should be the logic name and what is the JNDI name????
ThanksIn @Stateless, @name() is the annotation equivalent of <ejb-name> in ejb-jar.xml. It gives a unique bean name identifier to the component within the ejb-jar. It is completely independent of mappedName. If no @Stateless name() is specified, it defaults to the unqualified bean class name.
In @Stateless, mappedName() is used to assign a global JNDI name to the bean's remote interface. This can be used to explicitly lookup the EJB reference to that interface or as one way to resolve a caller's EJB dependency.
In @EJB, if the target of the dependency lives within the same application, you can always fully resolve it using only beanName(). beanName() takes the value specified in @Stateless name(), or the default as described above.
@EJB name() assigns a name to the client dependency within the caller's component environment. It is optional. In most cases that value doesn't matter since if the dependency is being injected you never have to refer to the name() attribute anywhere else.
@EJB mappedName() is used to resolve an EJB dependency that spans applications. It holds a global JNDI name, e.g. the one specified in @Stateless mappedName(). mappedName() is not required to be supported by all vendors.
So, to sum it all up, it's fine to have two different beans that expose the same interface. E.g. :
@Stateless(name="A1", mappedName="A1Global")
public class A1 implements A { ... }
@Stateless(mappedName="A2Global") // name() defaults to "A2"
public class A2 implements A { ... }
In a caller within the same application :
@EJB(beanName="A1")
private A a;
@EJB(beanName="A2")
private A a;
In a caller within a different application :
@EJB(mappedName="A1Global")
private A a;
@EJB(mappedName="A2Global")
private A a;
You can find additional information in our EJB FAQ :
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#EJB_ejb-ref_ejb_local_ref -
Ejb-ref and JNDI lookup problem
Hi,
I use WLS6.1sp2. I created one EntityBean and SessionBean jar files. I tried to
use session bean to refer entity bean, I failed. The details are as following:
In EntityBean's weblogic-ejb-jar.xml, I set:
<jndi-name>cabin.CabinHome</jndi-name>
In sessionbean's ejb-jar.xml
<ejb-ref>
<ejb-ref-name>ejb/CabinHome</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.titan.cabin.CabinHome</home>
<remote>com.titan.cabin.Cabin</remote>
</ejb-ref>
In sessionbean's weblogic-ejb-jar.xml
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>ejb/CabinHome</ejb-ref-name>
<jndi-name>ejb/CabinHome</jndi-name>
</ejb-reference-description>
</reference-descriptor>
At sessionbean's client, I use
javax.naming.Context jndiContext = getInitialContext();
Object obj = jndiContext.lookup("java:comp/env/ejb/CabinHome");
When I run client file, I get the following error message:
- with nested exception:
[javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException:
Unable to resolve ejb.CabinHome Resolved: '' Unresolved:'ejb' ; remaining name
'CabinHome']; Link Remaining Name: 'ejb/CabinHome']>
javax.naming.LinkException: . Root exception is javax.naming.NameNotFoundException:
Unable to resolve ejb.CabinHome Resolved: '' Unresolved:'ejb' ; remaining name
'CabinHome'
<<no stack trace available>>
--------------- nested within: ------------------
javax.ejb.EJBException
- with nested exception:
[javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException:
Unable to resolve ejb.CabinHome Resolved: '' Unresolved:'ejb' ; remaining name
'CabinHome']; Link Remaining Name: 'ejb/CabinHome']
at com.titan.travelagent.TravelAgentBean.listCabins(TravelAgentBean.java:45)
at com.titan.travelagent.TravelAgentBean_a4c3ph_EOImpl.listCabins(TravelAgentBean_a4c3ph_EOImpl.java:37)
at com.titan.travelagent.TravelAgentBean_a4c3ph_EOImpl_WLSkel.invoke(Unknown
Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:298)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:267)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
####<Feb 1, 2002 11:32:40 PM PST> <Info> <Management> <dj> <travelServer> <ExecuteThread:
'14' for queue: 'default'> <system> <> <140009> <Configuration changes for domain
saved to the repository.>
Do you know what's wrong? how to fix this problem?
Thanks in advance.
DJSlava,
I took "cabin." out from weblogic-ejb-jar.xml, I got the same error.
DJ
"Slava Imeshev" <[email protected]> wrote:
Hi DJ,
I think you don't need "cabin." in weblogic-ejb-jar.xml :
<jndi-name>cabin.CabinHome</jndi-name>
Regards,
Slava Imeshev
"DJ" <[email protected]> wrote in message
news:[email protected]...
Hi,
I use WLS6.1sp2. I created one EntityBean and SessionBean jar files.I
tried to
use session bean to refer entity bean, I failed. The details are asfollowing:
In EntityBean's weblogic-ejb-jar.xml, I set:
<jndi-name>cabin.CabinHome</jndi-name>
In sessionbean's ejb-jar.xml
<ejb-ref>
<ejb-ref-name>ejb/CabinHome</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.titan.cabin.CabinHome</home>
<remote>com.titan.cabin.Cabin</remote>
</ejb-ref>
In sessionbean's weblogic-ejb-jar.xml
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>ejb/CabinHome</ejb-ref-name>
<jndi-name>ejb/CabinHome</jndi-name>
</ejb-reference-description>
</reference-descriptor>
At sessionbean's client, I use
javax.naming.Context jndiContext = getInitialContext();
Object obj = jndiContext.lookup("java:comp/env/ejb/CabinHome");
When I run client file, I get the following error message:
- with nested exception:
[javax.naming.LinkException: [Root exception is
javax.naming.NameNotFoundException:>> Unable to resolve ejb.CabinHome Resolved: '' Unresolved:'ejb' ; remaining>name>> 'CabinHome'; Link Remaining Name: 'ejb/CabinHome']>
javax.naming.LinkException: . Root exception isjavax.naming.NameNotFoundException:
Unable to resolve ejb.CabinHome Resolved: '' Unresolved:'ejb' ; remainingname
'CabinHome'
<<no stack trace available>>
--------------- nested within: ------------------
javax.ejb.EJBException
- with nested exception:
[javax.naming.LinkException: [Root exception is
javax.naming.NameNotFoundException:>> Unable to resolve ejb.CabinHome Resolved: '' Unresolved:'ejb' ; remaining>name>> 'CabinHome'; Link Remaining Name: 'ejb/CabinHome']
atcom.titan.travelagent.TravelAgentBean.listCabins(TravelAgentBean.java:45)
atcom.titan.travelagent.TravelAgentBean_a4c3ph_EOImpl.listCabins(TravelAgentBe
an_a4c3ph_EOImpl.java:37)
atcom.titan.travelagent.TravelAgentBean_a4c3ph_EOImpl_WLSkel.invoke(Unknown
Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:298)
atweblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java
:93)
atweblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:267)
atweblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:2
2)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
####<Feb 1, 2002 11:32:40 PM PST> <Info> <Management> <dj> <travelServer><ExecuteThread:
'14' for queue: 'default'> <system> <> <140009> <Configuration changesfor
domain
saved to the repository.>
Do you know what's wrong? how to fix this problem?
Thanks in advance.
DJ -
EJB Refs ( coded name and JNDI name )
Hi
I am just starting to develop EJBs . I can't get to work the EJB refs as expected . In a session bean I have a lookup for an Entity bean . Both beans are in separate JAR files , but in the same ear .
The lookup from session bean to entity bean only works when
the coded name in EJB ref is defined exactly the same as JNDI name for enity bean , also the name in lookup method must be the same in session bean .
To my surprise , the JNDI name for the target EJB , defined in EJB ref for session bean , does not mater at all . Even if I change it to a non existant name , the bean lookup works .
Theoritacally I understand that EJB ref is there to provide a mapping between the name of bean mentioned in code to the actual JNDI name of another bean , at the time of deployment .
The above is happening in J2EE 1.4 envoirment .
Please let me know , what am I doing here that is wrong .
( All examples and tutorials , usually give coded name same as JNDI name ) .
Thanks
TarunHi Tarun,
The ejb-ref-name lives in a different namespace than the global JNDI names. Any names of ejb-refs, ejb-local-refs, resource-refs, etc. are scoped within a particular component's private namespace. All environment references are accessed via the java:comp/env namespace at runtime. So, if your ejb-ref-name(a.k.a "coded name") is ejb/foo in the deployment descriptor, you would access it from the code as follows :
initialContext.lookup("java:comp/env/ejb/foo");
This way, neither the standard deployment descriptor nor the code has any dependency on the global JNDI name. That's a good thing since the decision about which target EJB should be linked to is often not made until deployment time rather than development time. Furthermore, it means if you want to change the linking you can always do it without recompiling your code.
As for the global JNDI names, the first thing to note is that they are completely vendor-specific. That's why they don't appear in the standard deployment descriptor. In the J2EE SDK, each EJB that exposes a Remote view is assigned a global JNDI name in sun-ejb-jar.xml. This JNDI name is assigned from the global namespace of the application server. There's nothing stopping it from also being "ejb/foo", but it refers to a different thing than the "ejb/foo" above.
Now we have an ejb-ref called ejb/foo and an ejb whose JNDI name is ejb/foo, but we haven't linked the two. When it comes to linking, you have two choices:
1. If the target ejb is in the same .ear as the client component, you can use the ejb-link mechanism. This allows you to specify the target ejb by referring to its ejb-name. Since ejb-name is only guaranteed to be unique within an ejb-jar, the syntax allows for you to give the uri of the containing ejb-jar, followed by #, followed by ejb-name.
2. Alternatively, you can specify the global JNDI name of the target ejb using sun-ejb-jar.xml Note that this will work whether the target ejb is in the same .ear or not. However, it's the only option if the target ejb is in a different .ear. In this case, you would create an ejb-ref entry for the client component within the sun-ejb-jar.xml. e.g. :
<ejb>
<ejb-name>MyClientBean</ejb-name>
<ejb-ref>
<ejb-ref-name>ejb/foo</ejb-ref-name>
<jndi-name>ejb/foo</jndi-name>
</ejb-ref>
</ejb>
Again, it's just a coincidence that both names happen to be ejb/foo. They refer to different things.
When you do a global lookup from your code, initialContext.lookup('ejb/foo"), it will work in some environments because you're simply bypassing the level of indirection provided by your component environment and going straight to the global namespace. This is non-portable and not a good idea, since you've now tightly coupled the name of the target ejb to your client component. That means if it changes you need to recompile your code. Hope this helps.
--ken -
Fail to lookup the local EJB by JNDI in Managed Server
Hi all,
I currently in a deep problem, and can't figure out the cause of it. It just annoying me for week.
In my app, I have binded to the local ejb to JNDI (let's say "ejb/CustomerLocal"), then the client lookup the Local EJB by the following code.
localIc = new InitialContext();
home = (EJBLocalHome)localIc.lookup("ejb/CustomerLocal");
It works well as I do development in the Domain Admin Server. However, when I do the System Integration Test and deploy my app to the managed server, the app fail. It just can't do the Local EJB lookup. Following is the exception.
javax.naming.NameNotFoundException: Unable to resolve 'ejb/CustomerLocal' Resolved ejb[Root exc
eption is javax.naming.NameNotFoundException: Unable to resolve 'ejb.CustomerLocal' Resolved ejb
]; remaining name CustomerLocal'
Does anybody know the cause of it and have solution?
Thanks a lotHi,
Just now I replicated the same problem what you are facing. I created one managed server. When I deployed my ejb to admin server I did not get any problem. But when I deploy the same into my managed server I got Naming Exception. Because I did n/t specify Context.PROVIDER_URL. A provider URL contains bootstrap server information that the initial context factory can use to obtain an initial context. So when you deploy EJB on another server, you have to get the Naming service from that server. Hence provider URL must pointing to that server. So I included following statements before lookup my ejb in managed server.
Properties p=new Properties ();
p.put (Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put (Context.PROVIDER_URL,"t3://localhost: 7003");
Context ctx=new InitialContext (p);
FacadeHome home=(FacadeHome) ctx.lookup ("ejb/CustomerLocal");
In my case managed server port number is 7003. Now onwards managed server (Port number 7003) will provide ‘Naming Service’, not by admin server (port number 7001), which is default.
Note: Context.PROVIDER_URL— specifies the URL of the WebLogic Server that provides the name service. The default is t3://localhost: 7001. When you are not specified it will assume that POVIDER_URL is t3://localhost: 7001 this is nothing but your admin server in your case. However, a JNDI client may need to access a name space other than the one identified in its environment. In this case, it is necessary to explicitly set the java.naming.provider.url (provider URL) property used by the InitialContext constructor.
I hope it helps.
Regards,
Kuldeep Singh. -
How to rename a EJB's jndi name?
Using Sun Appserver, having deployed all EJBs, I want to rename a EJB's jndi name, for instance,
to rename object "java:comp/env/ejb/User" to "java:comp/env/ejb/User1". By using InitialContext.rename(oldName,newName), a NamingException is thrown and its message is "java:comp namespace cannot be modified ". How to solve it?It is not possible.
Prohibited by the EJB spec. -
Problem of javafx2 remote call ejb3 and jndi data source
netbean7.2 javafx2 glassfish3.1.2.2
My javafx2 project through jndi remote access the ejb and data source,
I select to run as an independent in netbeans ,without problems!
However, When I select it to run as the web start. Or in the browser inside always error!
Want a lot of ways it is not solved, especially to help!
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
at sun.plugin2.applet.Plugin2ClassLoader $ 2.run (Unknown Source)
at java.security.AccessController.doPrivileged (Native Method)
at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper (Unknown Source)
at sun.plugin2.applet.JNLP2ClassLoader.findClass (Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0 (Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass (Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass (Unknown Source)
at java.lang.ClassLoader.loadClass (ClassLoader.java: 356)
at java.lang.Class.forName0 (Native Method)
at java.lang.Class.forName (Class.java: 264)
at com.sun.naming.internal.VersionHelper12.loadClass (VersionHelper12.java: 63)
at javax.naming.spi.NamingManager.getInitialContext (NamingManager.java: 671)
... 47 moreThe program has been signed (unlimited access). This is jvm tracking information, What can I do?
java.io.FileNotFoundException: \D:\eejj\JavaFXApplication18\dist\modules\jsr173_1.0_api.jar
at com.sun.deploy.security.DeployURLClassPath$JarLoader.getJarFile(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$JarLoader.access$1000(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$JarLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.deploy.security.DeployURLClassPath$JarLoader.ensureOpen(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$JarLoader.<init>(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath.getLoader(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath.access$000(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$1.next(Unknown Source)
at com.sun.deploy.security.DeployURLClassPath$1.hasMoreElements(Unknown Source)
at java.net.URLClassLoader$3$1.run(Unknown Source)
at java.net.URLClassLoader$3$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader$3.next(Unknown Source)
at java.net.URLClassLoader$3.hasMoreElements(Unknown Source)
at sun.misc.CompoundEnumeration.next(Unknown Source)
at sun.misc.CompoundEnumeration.hasMoreElements(Unknown Source)
at com.sun.naming.internal.VersionHelper12$InputStreamEnumeration$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.naming.internal.VersionHelper12$InputStreamEnumeration.getNextElement(Unknown Source)
at com.sun.naming.internal.VersionHelper12$InputStreamEnumeration.hasMore(Unknown Source)
at com.sun.naming.internal.ResourceManager.getApplicationResources(Unknown Source)
at com.sun.naming.internal.ResourceManager.getInitialEnvironment(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
java.io.FileNotFoundException: \D:\eejj\JavaFXApplication18\dist\lib\grizzly-websockets.jar
java.io.FileNotFoundException: \D:\eejj\JavaFXApplication18\dist\lib\grizzly-http-ajp.jar
eg.....(<font color=red > a lot of *.jar find nothing </font> )
java.lang.RuntimeException: java.lang.ExceptionInInitializerError
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:251)
at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
at com.sun.glass.ui.View.notifyMouse(View.java:922)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:67)
at java.lang.Thread.run(Unknown Source)
<font color=red >
Caused by: java.lang.ExceptionInInitializerError
</font>
at com.sun.enterprise.module.single.SingleModulesRegistry.<init>(SingleModulesRegistry.java:79)
at com.sun.enterprise.module.single.SingleModulesRegistry.<init>(SingleModulesRegistry.java:67)
at com.sun.enterprise.module.single.StaticModulesRegistry.<init>(StaticModulesRegistry.java:66)
at org.glassfish.internal.api.Globals.getStaticHabitat(Globals.java:84)
at com.sun.enterprise.naming.impl.SerialInitContextFactory.<init>(SerialInitContextFactory.java:236)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at javafxapplication18.NewClass.v(NewClass.java:51)
at javafxapplication18.JavaFXApplication18$1.handle(JavaFXApplication18.java:50)
at javafxapplication18.JavaFXApplication18$1.handle(JavaFXApplication18.java:42)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Node.fireEvent(Node.java:6863)
at javafx.scene.control.Button.fire(Button.java:179)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193)
at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:336)
at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3324)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3164)
at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3119)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1559)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2261)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:228)
... 6 more
<font color=red>
Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.class.path" "read")
</font>
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at com.sun.enterprise.module.single.ProxyModuleDefinition.<clinit>(ProxyModuleDefinition.java:185)
... 59 more
帖子经 user7993481编辑过
帖子经 user7993481编辑过
帖子经 user7993481编辑过
帖子经 user7993481编辑过 -
List of EJBs and their methods.
We have an App Server from which I'd like to get a list of all EJBs and a list of all the methods contained in a selected EJB.
Is this possible? How? Use JNDI?I think that, sadly, the answer is different for each App Server. I've used Sybase's, WebLogic and WebSphere and only Jaguar (Sybase) allows that, but with proprietary (com.sybase.*) classes.
Which one are you using? -
Relation between EJB and CORBA
Hi,
I'm confused as to the relation between EJB and CORBA. Some books I've read say that CORBA is used to implement the underlying RMI protocol in EJB while others say it is an alternative to EJB.
Could someone please clarify.
ThanksCould you pleae restate your question.
I'm assuming you want to bind a Corba object to a
CosNaming service from within a j2ee component. JNDI
supports this case fully via their CosNaming service provider
(see http://java.sun.com/products/jndi/serviceproviders.html) JNDI is part of J2SE, so it's fully available to any J2EE component.
Amlan on behalf of Kenneth Saks -
Hi,
I am trying to hook up a web service that talks to one of my EJBs. I feel that
I have followed the instructions to the letter, but no matter what I do I keep
getting a ServletException when I try to deploy it.
The EJB I am trying to invoke is deployed in an ejb module called SunstartEJBModule
which is deployed within an application called SunstartApplication.
This is the build file I am using:
<project name="buildWebservice" default="generate-typeinfo">
<target name="generate-typeinfo">
<source2wsdd
javaSource="sunstart/ejbs/webservices/StudentWS.java"
ejbLink="SunstartEJBModule.jar#ejb/StudentWS"
ddFile="ddfiles/web-services.xml"
serviceURI="/StudentService"
/>
</target>
<target name="generate-webservice">
<wspackage
output="ears/SunstartApplication.ear"
contextURI="web_services"
webAppClasses="com.sun.ad.sunstart.ejbs.webservices.StudentWS"
ddFile="ddfiles/web-services.xml"
overwrite="false"
/>
</target>
</project>
The SunstartWS ejb is definitely deployed as I can access it using my ServiceLocator
using java:comp/env/ejb/StudentWS. I notice in the server error log it is trying
to use a slightly different JNDI name to this - java:/app/ejb/SunstartEJBModule.jar#ejb/StudentWS/home
but I can't see how I can control this in the ant script because whenever I remove
the "SunstartEJBModule.jar#ejb/StudentWS" part and change it to "ejb/StudentWS"
it won't even deploy.
The full exception trace I am seeing is:
javax.servlet.ServletException: ERROR: The EJB component named: StudentWS specified
an ejb-link to SunstartEJBModule.jar#ejb/StudentWS, but this ejb-link could not
be found in JNDI. Please ensure that this ejb-link refers to a valid EJB, and
this EJB has already deployed. The exception was: javax.naming.NamingException:
Could not lookup EJB home, tried java:/app/ejb/SunstartEJBModule.jar#ejb/StudentWS/home
and java:/app/ejb/SunstartEJBModule.jar#ejb/StudentWS/localhome
at weblogic.webservice.server.servlet.WebServiceServlet.initLocal(WebServiceServlet.java:132)
at weblogic.webservice.server.servlet.WebServiceServlet.init(WebServiceServlet.java:86)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at weblogic.servlet.internal.ServletStubImpl$ServletInitAction.run(ServletStubImpl.java:993)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:869)
at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:848)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:787)
at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:3252)
at weblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServletContext.java:3197)
at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:3174)
at weblogic.servlet.internal.WebAppServletContext.setStarted(WebAppServletContext.java:5647)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:869)
at weblogic.j2ee.J2EEApplicationContainer.start(J2EEApplicationContainer.java:2022)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2063)
at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.activateContainer(SlaveDeployer.java:2592)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2515)
at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2317)
at weblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDeployer.java:2399)
at weblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.java:2311)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDeployer.java:2479)
at weblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeployer.java:798)
at weblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.java:507)
at weblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.java:465)
at weblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.java:25)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
>
If anyone know what I Am doing wrong I would be grateful if they would let me
know as this has been driving me nuts over the past few days!
Cheers,
Lucas.Here is am working example of how to use source2wsdd
with an EJB.
http://manojc.com/?sample10
Please check if this works ok for you.
Regards,
-manoj
http://manojc.com
"Lucas King" <[email protected]> wrote in message
news:40d9b346$1@mktnews1...
>
Hi,
I am trying to hook up a web service that talks to one of my EJBs. I feelthat
I have followed the instructions to the letter, but no matter what I do Ikeep
getting a ServletException when I try to deploy it.
The EJB I am trying to invoke is deployed in an ejb module calledSunstartEJBModule
which is deployed within an application called SunstartApplication.
This is the build file I am using:
<project name="buildWebservice" default="generate-typeinfo">
<target name="generate-typeinfo">
<source2wsdd
javaSource="sunstart/ejbs/webservices/StudentWS.java"
ejbLink="SunstartEJBModule.jar#ejb/StudentWS"
ddFile="ddfiles/web-services.xml"
serviceURI="/StudentService"
/>
</target>
<target name="generate-webservice">
<wspackage
output="ears/SunstartApplication.ear"
contextURI="web_services"
webAppClasses="com.sun.ad.sunstart.ejbs.webservices.StudentWS"
ddFile="ddfiles/web-services.xml"
overwrite="false"
/>
</target>
</project>
The SunstartWS ejb is definitely deployed as I can access it using myServiceLocator
using java:comp/env/ejb/StudentWS. I notice in the server error log it istrying
to use a slightly different JNDI name to this -java:/app/ejb/SunstartEJBModule.jar#ejb/StudentWS/home
but I can't see how I can control this in the ant script because wheneverI remove
the "SunstartEJBModule.jar#ejb/StudentWS" part and change it to"ejb/StudentWS"
it won't even deploy.
The full exception trace I am seeing is:
javax.servlet.ServletException: ERROR: The EJB component named: StudentWSspecified
an ejb-link to SunstartEJBModule.jar#ejb/StudentWS, but this ejb-linkcould not
be found in JNDI. Please ensure that this ejb-link refers to a valid EJB,and
this EJB has already deployed. The exception was:javax.naming.NamingException:
Could not lookup EJB home, triedjava:/app/ejb/SunstartEJBModule.jar#ejb/StudentWS/home
and java:/app/ejb/SunstartEJBModule.jar#ejb/StudentWS/localhome
atweblogic.webservice.server.servlet.WebServiceServlet.initLocal(WebServiceSer
vlet.java:132)
atweblogic.webservice.server.servlet.WebServiceServlet.init(WebServiceServlet.
java:86)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
atweblogic.servlet.internal.ServletStubImpl$ServletInitAction.run(ServletStubI
mpl.java:993)
atweblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubjec
t.java:317)
atweblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
atweblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java
:869)
atweblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.ja
va:848)
atweblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.jav
a:787)
atweblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletC
ontext.java:3252)
atweblogic.servlet.internal.WebAppServletContext.preloadServlets(WebAppServlet
Context.java:3197)
atweblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServle
tContext.java:3174)
atweblogic.servlet.internal.WebAppServletContext.setStarted(WebAppServletConte
xt.java:5647)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:869)
atweblogic.j2ee.J2EEApplicationContainer.start(J2EEApplicationContainer.java:2
022)
atweblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.jav
a:2063)
atweblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.activat
eContainer(SlaveDeployer.java:2592)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2515)
atweblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.jav
a:2317)
atweblogic.management.deploy.slave.SlaveDeployer$Task.checkAutoCommit(SlaveDep
loyer.java:2399)
atweblogic.management.deploy.slave.SlaveDeployer$Task.prepare(SlaveDeployer.ja
va:2311)
atweblogic.management.deploy.slave.SlaveDeployer$ActivateTask.prepare(SlaveDep
loyer.java:2479)
atweblogic.management.deploy.slave.SlaveDeployer.processPrepareTask(SlaveDeplo
yer.java:798)
atweblogic.management.deploy.slave.SlaveDeployer.prepareDelta(SlaveDeployer.ja
va:507)
atweblogic.management.deploy.slave.SlaveDeployer.prepareUpdate(SlaveDeployer.j
ava:465)
atweblogic.drs.internal.SlaveCallbackHandler$1.execute(SlaveCallbackHandler.ja
va:25)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
>
If anyone know what I Am doing wrong I would be grateful if they would letme
know as this has been driving me nuts over the past few days!
Cheers,
Lucas. -
To use JMS and JNDI in JDev 9.0.3.4
Do I need to add additional librararies in order to use JMS and JNDI along with EJB's in the enterprise application I'm creating?
No the article is not applicable for 9.0.3 I've never tested the compatibility of the 9.0.3 + Struts integration - obviously it does not work.
What does work is the ADF bindings used in 9.0.5 and above which can be safely used with newer versions of Struts. -
Problem with EJB and JMS - Failed to obtain/create connection
hello ejb and jms programmers,
My problem is my topic MDB keep on retrieving the same message when there is a database connection failure. Maybe somebody could help me how to prevent to retrieve the same data?
Given:
- I purposedly turn off the pointbase database because im testing my error handling.
- Im using SJSAS 8 as my application server.
- My message Driven Bean of topic type.
- Im using CMP for my entity bean
Here is the scenario of whats happening - step by step:
1. A separate application publishes a message to JMS queue server
2. My MDB retrieves this message and do some processing then inserts a record (transaction history) in my database
3. But my db is turned off or down
4. My MDB sends a successful processing reply to the JMS queue server
5. Then i noticed that my server.log keeps on growing so when i opened it, the record was not inserted and printed the stacktrace below "RAR5117 : Failed to obtain/create connection. Reason : javax.transaction.SystemException" (complete stacktrace below)
6. I understand the cause of the stacktrace is because the DB is turned off. But what i dont understand is that my MDB keeps on reading the same message. Since my MDB is of topic type, isnt a topic MDB supposedly reads a message only once???
So my questions are:
1. how do i handle insert database error?
2. how can i stop my MDB from processing the same message?
3. any better suggestions?
Thank you in advance :)
leigh
*** more complete stack trace ***
[#|2005-01-09T15:35:57.097+0800|WARNING|sun-appserver-pe8.0.0_01|javax.enterprise.system.core.transaction|_ThreadID=17;|JTS5041: The resource manager is doing work outside a global transaction
javax.transaction.xa.XAException
at com.pointbase.xa.xaException.getXAException(Unknown Source)
at com.pointbase.xa.xaConnectionResource.start(Unknown Source)
at com.sun.gjc.spi.XAResourceImpl.start(XAResourceImpl.java:162)
[#|2005-01-09T15:35:57.167+0800|SEVERE|sun-appserver-pe8.0.0_01|javax.enterprise.resource.resourceadapter|_ThreadID=17;|RAR5027:Unexpected exception in resource pooling
javax.transaction.SystemException
at com.sun.jts.jta.TransactionImpl.enlistResource(TransactionImpl.java:185)
at com.sun.enterprise.distributedtx.J2EETransaction.enlistResource(J2EETransaction.java:360)
at com.sun.enterprise.distributedtx.J2EETransactionManagerImpl.enlistResource(J2EETransactionManagerImpl.java:303)
at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.enlistResource(J2EETransactionManagerOpt.java:115)
[#|2005-01-09T15:35:57.177+0800|WARNING|sun-appserver-pe8.0.0_01|javax.enterprise.resource.resourceadapter|_ThreadID=17;|RAR5117 : Failed to obtain/create connection. Reason : javax.transaction.SystemException|#]
[#|2005-01-09T15:35:57.227+0800|WARNING|sun-appserver-pe8.0.0_01|javax.enterprise.resource.resourceadapter|_ThreadID=17;|RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: javax.transaction.SystemException]|#]
[#|2005-01-09T15:35:57.237+0800|SEVERE|sun-appserver-pe8.0.0_01|javax.enterprise.system.container.ejb|_ThreadID=17;|EJB5071: Some remote or transactional roll back exception occurred
com.sun.jdo.api.persistence.support.JDODataStoreException: JDO77006: SQL exception: state = null, error code = 0.
NestedException: java.sql.SQLException: Error in allocating a connection. Cause: javax.transaction.SystemException
FailedObjectArray: [[email protected]5ac]
at com.sun.jdo.spi.persistence.support.sqlstore.impl.TransactionImpl.getConnectionInternal(TransactionImpl.java:1444)
at com.sun.jdo.spi.persistence.support.sqlstore.impl.TransactionImpl.getConnection(TransactionImpl.java:1339)Hi annie,
Wherever you are handling database transactions,
you'd not be able to create a Connection if database
is closed (I think you mentioned turning off the
database) then at this condition, you should
certainly throw a System level exception and stop all
processing with some meaningful flow to indicate a
failure (like display message on UI). Even
network problems are handled by exceptions... so I
don't see a reason why you didn't wrap it in the
first place.
Anyway, try handling specific exceptions rather than
the general Exception... this will give you a better
idea of what to do in case of an exception.Yes i know this. I am practicing this in my non-j2ee server applications. But the j2ee app im making, i just pass the db url in the descriptor and the app server automatically creates the connection for my app. So where would i put exception handling?
2. how can i stop my MDB from processing the same
message?Guaranteed delivery is not supposed to stop
processing. It will continue to process the message
after certain intervals till the message is
delivered. You shouldn't deliver it at all, if you
are able to detect that the database is off
The problem here is that my MDB automatically retrieves the message from the JMS queue server. Im not the one retrieving the messages manually.
My assumed behavior of topic MDB is once the a certain MDB retrieves a message it will not retrieve the same message anymore.
thank you in advance.
leigh -
Problem with OpenLDAP and JNDI
I'm having problem working with OpenLDAP and JNDI.
First I have changed LDAP's slapd.conf file:
suffix "dc=antipodes,dc=com"
rootdn cn=Manager,dc=antipodes,dc=com
directory "C:/Program Files/OpenLDAP/data"
rootpw secret
schemacheck offthan i used code below, to create root context:
package test;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NameAlreadyBoundException;
import javax.naming.directory.*;
import java.util.*;
public class MakeRoot {
final static String ldapServerName = "localhost";
final static String rootdn = "cn=Manager,dc=antipodes,dc=com";
final static String rootpass = "secret";
final static String rootContext = "dc=antipodes,dc=com";
public static void main( String[] args ) {
// set up environment to access the server
Properties env = new Properties();
env.put( Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory" );
env.put( Context.PROVIDER_URL, "ldap://" + ldapServerName + "/" );
env.put( Context.SECURITY_PRINCIPAL, rootdn );
env.put( Context.SECURITY_CREDENTIALS, rootpass );
try {
// obtain initial directory context using the environment
DirContext ctx = new InitialDirContext( env );
// now, create the root context, which is just a subcontext
// of this initial directory context.
ctx.createSubcontext( rootContext );
} catch ( NameAlreadyBoundException nabe ) {
System.err.println( rootContext + " has already been bound!" );
} catch ( Exception e ) {
System.err.println( e );
}this worked fine, I could see that by using "LDAP Browser/Editor".
and then I tried to create group with code:
package test;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.ldap.*;
import javax.naming.directory.*;
public class MakeGroup
public static void main (String[] args)
Hashtable env = new Hashtable();
String adminName = "cn=Manager,dc=antipodes,dc=com";
String adminPassword = "secret";
String ldapURL = "ldap://127.0.0.1:389";
String groupName = "CN=Evolution,OU=Research,DC=antipodes,DC=com";
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
//set security credentials, note using simple cleartext authentication
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
//connect to my domain controller
env.put(Context.PROVIDER_URL,ldapURL);
try {
// Create the initial directory context
LdapContext ctx = new InitialLdapContext(env,null);
// Create attributes to be associated with the new group
Attributes attrs = new BasicAttributes(true);
attrs.put("objectClass","group");
attrs.put("samAccountName","Evolution");
attrs.put("cn","Evolution");
attrs.put("description","Evolutionary Theorists");
//group types from IAds.h
int ADS_GROUP_TYPE_GLOBAL_GROUP = 0x0002;
int ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP = 0x0004;
int ADS_GROUP_TYPE_LOCAL_GROUP = 0x0004;
int ADS_GROUP_TYPE_UNIVERSAL_GROUP = 0x0008;
int ADS_GROUP_TYPE_SECURITY_ENABLED = 0x80000000;
attrs.put("groupType",Integer.toString(ADS_GROUP_TYPE_UNIVERSAL_GROUP + ADS_GROUP_TYPE_SECURITY_ENABLED));
// Create the context
Context result = ctx.createSubcontext(groupName, attrs);
System.out.println("Created group: " + groupName);
ctx.close();
catch (NamingException e) {
System.err.println("Problem creating group: " + e);
}got the error code: Problem creating group: javax.naming.directory.InvalidAttributeIdentifierException: [LDAP: error code 17 - groupType: attribute type undefined]; remaining name 'CN=Evolution,OU=Research,DC=antipodes,DC=com'
I tried by creating organizational unit "ou=Research" from "LDAP Browser/Editor", and then running the same code -> same error.
also I have tried code for adding users:
package test;
import java.util.Hashtable;
import javax.naming.ldap.*;
import javax.naming.directory.*;
import javax.naming.*;
import javax.net.ssl.*;
import java.io.*;
public class MakeUser
public static void main (String[] args)
Hashtable env = new Hashtable();
String adminName = "cn=Manager,dc=antipodes,dc=com";
String adminPassword = "secret";
String userName = "cn=Albert Einstein,ou=Research,dc=antipodes,dc=com";
String groupName = "cn=All Research,ou=Research,dc=antipodes,dc=com";
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
//set security credentials, note using simple cleartext authentication
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
//connect to my domain controller
env.put(Context.PROVIDER_URL, "ldap://127.0.0.1:389");
try {
// Create the initial directory context
LdapContext ctx = new InitialLdapContext(env,null);
// Create attributes to be associated with the new user
Attributes attrs = new BasicAttributes(true);
//These are the mandatory attributes for a user object
//Note that Win2K3 will automagically create a random
//samAccountName if it is not present. (Win2K does not)
attrs.put("objectClass","user");
attrs.put("samAccountName","AlbertE");
attrs.put("cn","Albert Einstein");
//These are some optional (but useful) attributes
attrs.put("giveName","Albert");
attrs.put("sn","Einstein");
attrs.put("displayName","Albert Einstein");
attrs.put("description","Research Scientist");
attrs.put("userPrincipalName","[email protected]");
attrs.put("mail","[email protected]");
attrs.put("telephoneNumber","999 123 4567");
//some useful constants from lmaccess.h
int UF_ACCOUNTDISABLE = 0x0002;
int UF_PASSWD_NOTREQD = 0x0020;
int UF_PASSWD_CANT_CHANGE = 0x0040;
int UF_NORMAL_ACCOUNT = 0x0200;
int UF_DONT_EXPIRE_PASSWD = 0x10000;
int UF_PASSWORD_EXPIRED = 0x800000;
//Note that you need to create the user object before you can
//set the password. Therefore as the user is created with no
//password, user AccountControl must be set to the following
//otherwise the Win2K3 password filter will return error 53
//unwilling to perform.
attrs.put("userAccountControl",Integer.toString(UF_NORMAL_ACCOUNT + UF_PASSWD_NOTREQD + UF_PASSWORD_EXPIRED+ UF_ACCOUNTDISABLE));
// Create the context
Context result = ctx.createSubcontext(userName, attrs);
System.out.println("Created disabled account for: " + userName);
//now that we've created the user object, we can set the
//password and change the userAccountControl
//and because password can only be set using SSL/TLS
//lets use StartTLS
StartTlsResponse tls = (StartTlsResponse)ctx.extendedOperation(new StartTlsRequest());
tls.negotiate();
//set password is a ldap modfy operation
//and we'll update the userAccountControl
//enabling the acount and force the user to update ther password
//the first time they login
ModificationItem[] mods = new ModificationItem[2];
//Replace the "unicdodePwd" attribute with a new value
//Password must be both Unicode and a quoted string
String newQuotedPassword = "\"Password2000\"";
byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE");
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("unicodePwd", newUnicodePassword));
mods[1] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userAccountControl",Integer.toString(UF_NORMAL_ACCOUNT + UF_PASSWORD_EXPIRED)));
// Perform the update
ctx.modifyAttributes(userName, mods);
System.out.println("Set password & updated userccountControl");
//now add the user to a group.
try {
ModificationItem member[] = new ModificationItem[1];
member[0]= new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("member", userName));
ctx.modifyAttributes(groupName,member);
System.out.println("Added user to group: " + groupName);
catch (NamingException e) {
System.err.println("Problem adding user to group: " + e);
//Could have put tls.close() prior to the group modification
//but it seems to screw up the connection or context ?
tls.close();
ctx.close();
System.out.println("Successfully created User: " + userName);
catch (NamingException e) {
System.err.println("Problem creating object: " + e);
catch (IOException e) {
System.err.println("Problem creating object: " + e); }
}same error.
I haven't done any chages to any schema manually.
I know I'm missing something crucial but have no idea what. I have tried many other code from tutorials from net, but they are all very similar and throwing the same error I showed above.
thanks in advance for help.I've solved this.
The problem was that all codes were using classes from Microsoft Active Directory, and they are not supported in OpenLDAP (microsoft.schema in OpenLDAP is just for info). Due to this some fields are not the same in equivalent classes ("user" and "person").
so partial code for creating user in root would be:
import java.util.Hashtable;
import javax.naming.ldap.*;
import javax.naming.directory.*;
import javax.naming.*;
import javax.net.ssl.*;
import java.io.*;
public class MakeUser
public static void main (String[] args)
Hashtable env = new Hashtable();
String adminName = "cn=Manager,dc=antipodes,dc=com";
String adminPassword = "secret";
String userName = "cn=Albert Einstein,ou=newgroup,dc=antipodes,dc=com";
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
//set security credentials, note using simple cleartext authentication
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,adminName);
env.put(Context.SECURITY_CREDENTIALS,adminPassword);
//connect to my domain controller
env.put(Context.PROVIDER_URL, "ldap://127.0.0.1:389");
try {
// Create the initial directory context
LdapContext ctx = new InitialLdapContext(env,null);
// Create attributes to be associated with the new user
Attributes attrs = new BasicAttributes(true);
attrs.put("objectClass","user");
attrs.put("cn","Albert Einstein");
attrs.put("userPassword","Nale");
attrs.put("sn","Einstein");
attrs.put("description","Research Scientist");
attrs.put("telephoneNumber","999 123 4567");
// Create the context
Context result = ctx.createSubcontext(userName, attrs);
System.out.println("Successfully created User: " + userName);
catch (NamingException e) {
System.err.println("Problem creating object: " + e);
}hope this will help anyone.
Maybe you are looking for
-
Hello, Please could anyone tell me if it is possible to look for "product ID" in the knowledge search (SDB)? And how could I get it? it is CRM 4.0 winclient Thanks in advance
-
EmptyPoints behaviour is not consistent
I am using RDLC in asp.net. The behavior of the empty points is not consistent. Sometimes it draws a line and connects the empty points and sometimes it skips the line. I don't want to connect two points when the in between data does not exist. Pleas
-
Bad performance in sending IDOCs from WAS to R3
Hi all, We have the following scenario: WAS 7.0 XI R3 with protocol: SOAP XI IDOC When IDOC comes from WAS to R3, it appers always at first time a 405 error (we see it in sxmb_moni transaction of WAS). After 3 or 4 minutes it is reprocessed
-
(NSURLErrorDomain erro -3001.)(102) to update safari
I can't update de safari, In my macbook air I have a new update but doesn not work
-
"image capture extension" consuming all resources
Image Capture Extension is hogging all my ram... What is going on with that thing? I wiped and restored system last week, I have 16 gig ram and a 1 TB disk. I should have more then enough of everything. I noticed that for the last couple of days Imag