Re-using UserTransaction JNDI lookups
We are using JDBC directly from servlets. Would it be OK to implement a singleton
that looks up the UserTransaction from the JNDI tree only once at the beginning and
elsewhere in the code we just get it from the singleton? The specification states
only this:
"The container is only required to provide the java:comp/
UserTransaction name for those components that can validly make use of it. Any such
reference to a UserTransaction object is only valid within the component instance
that performed the lookup."
Thanks
With Weblogic 6.x (possibly 7.0) you can safely use the looked up object
but it's not guaranteed to work with other vendors.
--dejan
sandy wrote:
We are using JDBC directly from servlets. Would it be OK to implement a singleton
that looks up the UserTransaction from the JNDI tree only once at the beginning and
elsewhere in the code we just get it from the singleton? The specification states
only this:
"The container is only required to provide the java:comp/
UserTransaction name for those components that can validly make use of it. Any such
reference to a UserTransaction object is only valid within the component instance
that performed the lookup."
Thanks
Similar Messages
-
Problem deploying cmp bean invoking another cmp bean using jndi lookup
I have a cmp BeanA that invokes another cmp BeanB, so I am using a jndi lookup in BeanA to download the localhome object to BeanB using the following:
Context ctx = new InitialContext();
home = (LocalAddressHome) ctx.lookup("java:comp/env/ejb/BeanBHomeRef");
then I specify the ejb/BeanBHomeRef, entity bean, local, BeanB's local home and component interface in EJB ref. when I am packaging BeanA
I also package BeanB in a separate jar file.
When I attempt to deploy the application it throws strange exception that says the folowing:
java.lang.IllegalArgumentException: BeanBEJB says it links to an ejb called BeanBEJB of local home class LocalBeanBHome but no bean with this local home c
lassname and type can be found in this ejb-jar.
yet when I un-jar the package, these class files exitsts.
When I go ahead and delete the reference to BeanB from the BeanA package file, I am able to deploy the application but then correctly fails on jndi lookup.
I have been able to open the cmpcustomer.ear sample application that comes with RI and execute it without any problem. But when I to package the same beans for example CustomerBean and it won't even allow me to create the customer.jar file. I get a screen full of errors.......
I am using Sun RI 1.3.01, is there a known bug that I am not aware of? Is there a fix around it?
Is there any another way to get the home ref. to BeanB so I can invoke create() method?
Any advice or suggestions?
thanksl
-kaisaabWhat app server are you using? may be I can help you
--Ashish Saraf -
Calling non ejb from ejb using jndi lookup
Is it possible to call a non ejb java object from an ejb using a jndi lookup?
For example, we have a java class where main registers itself with our application server (JBoss 3.0.1). We have a test client that can use jndi to look up the object, but we can't get an ejb inside the application server to use the object.
Are we trying to do the impossible? If my question is not clear, please let me know so I can try to clarify.
ThanksJNDI uses factories to create objects.
It's possible that JBoss has a Bean Factory which you can use to create your instance.
Tomcat has a Bean factory in its JNDI implementation. I use it just as you have indicated.
The JBoss documenation may help?
Dave -
JNDI Lookup in JSP fails for EJB 3.0
I am new to Java technology. I read the EJB FAQ, NetBeans docs and may forum discussions and I am still confused with the error I am having.
Background:
I have developed a persistance bean and related sessions beans (similar to the customer-cmp-ear application in the Java App Server samples). Now I am trying to access this bean using a JSP. After deploying the war file in the App Server and try to access the page, I get the following error.
javax.naming.NameNotFoundException: No object bound to name java:comp/env/ConsumerSessionLocal
After reading many articles, I understood that I dont have to prepare any descriptors, or JAR files for EJB 3.0.
Environment Details:
Java App Server Ver 9.0
NetBeans 5.5
I normally build the war files using NetBeans.
I use App Server Admin console to deploy the web applications using the above war file.
EJB details:
Persistance EJB : person.java
Session Objects
Consumer.java (this implements ConsumerSessionLocal, ConsumerSessionRemote). This Stateless bean accesses the methods in person.java.
ConsumerSessionLocal.java - local interface
ConsumerSessionRemote.java - remote interface
SearchConsumer.jsp
This JSP page is calling the ConsumerSessionLocal using the JNDI lookup through InitialContext.
Here is the Code snippet:
try {
InitialContext ic = new InitialContext();
Object o = ic.lookup("java:comp/env/ConsumerSessionLocal");
ConsumerSessionLocal consSession = (ConsumerSessionLocal) o;
I am able to see the jsp page in the browser, however, after a submit action, I get the Java Naming Exception error.
javax.naming.NameNotFoundException: No object bound for java:comp/env/ConsumerSessionLocal
I would appreciate your help/any of your thoughts.
Thanks in advance.
-RamI did not really solve it. Instead I used some of the tutorials that used JNDI lookup and modified those as my way forward. I did not really find out exactly what I was doing wrong.
/Anders -
Problem in Jndi lookup for ITaskService
HI,
I am trying to initiate oracle bpm Human task programatically by using Java remotely.
for this I am using following JNDI lookup for ITaskService.
Hashtable ht = new
Hashtable<IWorkflowServiceClientConstants.CONNECTION_PROPERTY,java.lang.String>();
ht.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL, "t3://localhost:7001");
ht.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL, "username");
ht.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS, "password");
Context ctx = new InitialContext(ht);
ITaskService taskService = (ITaskQueryService)ctx.lookup("ejb/bpel/services/workflow/TaskServiceBean");
taskService.initiateTask(task);
It the right approach or not.
Please help.To access human workflow api remotely try using the following code :
Map properties = new HashMap();
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_PROVIDER_URL, "t3://localhost:8001");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_CREDENTIALS, "welcome1");
properties.put(IWorkflowServiceClientConstants.CONNECTION_PROPERTY.EJB_SECURITY_PRINCIPAL, "weblogic");
IWorkflowServiceClient wfSvcClient =
WorkflowServiceClientFactory.getWorkflowServiceClient(WorkflowServiceClientFactory.REMOTE_CLIENT, properties, null);
//Get the task query service
ITaskQueryService querySvc = wfSvcClient.getTaskQueryService();
//Login as weblogic
IWorkflowContext ctx = querySvc.authenticate("weblogic","welcome1".toCharArray(),null);
after getting the workflow context, you can call any method like query task list. perform actions etc. just see the api doc.
Regards,
Anshul -
How can I use a JNDI Lookup in Dynamic Partner Link ?
Hi,
You can perform JNDI lookups in pretty much the same way as in Java code.
The following code snippet would give you an idea as to how to achieve this:
<%@ page import="javax.naming.InitialContext,
javax.naming.Context,
java.sql.*,
javax.sql.DataSource"
isErrorPage="true"
%>
<html>
<body>
<%
DataSource dataSource = null;
Connection con = null;
Statement stmt = null;
ResultSet result = null;
int empno = 7369;
String empName = null;
String qStringEmp = null;
PreparedStatement pstmt=null;
try
Context initialContext = new InitialContext();
dataSource = (DataSource)initialContext.lookup("jdbc/ejb/otnnewsDS");
con = dataSource.getConnection();
qStringEmp = "SELECT ename FROM emp where empno = ?";
pstmt = con.prepareStatement(qStringEmp);
pstmt.setInt(1, empno);
result = pstmt.executeQuery();
while (result.next())
empName = result.getString(1);
pstmt.close();
result.close();
catch(Exception e)
e.printStackTrace();
%>
The emp name is <%= empName %>
</body>
</html>
Rgds,
Rashmi. -
UserTransaction - Scope using JNDI lookup from jspInit() method
Howdy,
I'm using JSP's with JavaBeans accessing a DataSource and some other enviroment variables using JNDI lookups. I've read that JNDI lookups can take a fair amount of time and should be limited whenever possible. My previous configuration had the JNDI lookups inside the constructors of the JavaBeans but I've recently decided to move them to the jspInit() method of the calling JSP. This way the lookup only needs to be performed once and then I pass the values to the JavaBean in a method called setContextVariables. Two of the references to objects that i'm sending are the UserTransaction and DataSource objects. Within the Javabeans I have userTran.begin() and commit() statements. So far it's running great but i'm starting to wonder about the thread safety of this method. My question lies in the actual delagation of the UserTransaction object to the calling client method. It seems that i'm passing the same transaction to every Javabean (or am I?) Is the transaction actually issued when the begin() method is called, or at the time of the JNDI lookup? To test everything out, I opened two sessions and put a breakpoint inside one of the transactions. When I stopped at the breakpoint I ran another thread (also using a transaction retrieved from the same JSP). Then I went back and resumed the first thread and everything seemed to work ok. So... this seems completely fantabulastic so far (definitely noticable response time increases) but I'm still a little skeptical. If anyone is using a process similar to this I would appreciate some feedback. Thanks.Hi,
The EJB bean will use the client transaction when the following attributes are specified in descriptor.
1) Required
2) Mandatory
3) Supports
In Required case, if the client is associated with Transaction, then the EJB bean will use the same transaction. This is achieved by Transaction context. The EJB bean will use the same transaction context set by client. if the client doesn't have any transaction, then the container will create new transaction context for EJB bean and completes the transaction.
In Mandatory case, the client must be associated with Transaction so that EJB bean will use the same transaction. If the client doesn't associate with transaction, then container will throw TransactionRequiredException for EJB bean.
In Supports case, it works similar to Required case except that if the client doesn't associate with transaction, then there won't be any transaction in EJB bean.
hope this helps. -
JNDI lookup for UserTransaction
Hi all,
in Weblogic, in a typical scenario, do a client provide exactly
one JNDI lookup for the UserTransaction object (interface) or do
the client have to provide a JNDI lookup for each transaction?
In some EJB implementations, a JNDI lookup for UserTransaction
returns always the same reference. For example, in JOnAS, you can
have one static reference which is set when the client starts.
Then, more threads can simultaneously use the same static
UserTransaction reference without any conflict, since the
implementation of UserTransaction recognizes, which thread invoked
a particular method.
In other words, can I make an assumption that two different JNDI
lookups for UserTransaction returns different references or not?
Thanks a lot,
Marek Prochazka
Distributed Systems Research Group
Department of Software Engineering
Charles University, Faculty of Mathematics and Physics
Malostranske namesti 25, 118 00 Prague 1, Czech Republic
phone: +420-2-2191 4236
http://nenya.ms.mff.cuni.cz/thegroup/
Actually, UserTransaction is a singleton and it's not a transaction. It's just
very mis-named.
It should be called UserTransactionManager or UserInterfaceToJTA.
The actual transaction is javax.transaction.Transaction.
-- Rob
Cameron Purdy wrote:
> Within a transaction, it is different instances? For example, if you call
> it two times one right after another?
>
> A transaction is a unit of work. I understand why the transaction object
> changes from transaction to transaction, since a single transaction object
> (UserTransaction) represents exactly one transaction. Why would it be a
> singleton? It is not a transaction manager.
>
> Peace,
>
> --
> Cameron Purdy
> Tangosol, Inc.
> http://www.tangosol.com
> +1.617.623.5782
> WebLogic Consulting Available
>
> "Sarita" <[email protected]> wrote in message
> news:[email protected]...
> >
> > Hi Priscilla--
> >
> > This is not the behavior that I'm seeing, and I'm perplexed.
> > Every time I request a UserTransaction from JNDI, I receive a
> > a different instance. Should the value immediately returned by JNDI be
> the singleton
> > instance? If not, then how do I retrieve the singleton instance?
> >
> > I would like a session bean to start a transaction, and then call a method
> on another
> > session bean (which should operate under the same transaction). How does
> the second
> > session bean grab the correct transaction object? Is that possible?
> >
> > Thanks In Advance,
> > Sarita
> >
> > "Priscilla Fung" <[email protected]> wrote:
> > >
> > >Hi Marek,
> > >
> > >In Weblogic 6.0, JNDI lookup of UserTransaction returns a reference to
> the
> > >singleton
> > >Transaction Manager instance, which is thread-safe and can be used from
> > >multiple
> > >threads for transaction demarcations etc.
> > >
> > >-- Priscilla Fung, BEA Systems, Inc.
> > >
> > >"Marek Prochazka" <[email protected]> wrote:
> > >>
> > >>Hi all,
> > >>
> > >>in Weblogic, in a typical scenario, do a client provide exactly
> > >>one JNDI lookup for the UserTransaction object (interface) or do
> > >>the client have to provide a JNDI lookup for each transaction?
> > >>
> > >>In some EJB implementations, a JNDI lookup for UserTransaction
> > >>returns always the same reference. For example, in JOnAS, you can
> > >>have one static reference which is set when the client starts.
> > >>Then, more threads can simultaneously use the same static
> > >>UserTransaction reference without any conflict, since the
> > >>implementation of UserTransaction recognizes, which thread invoked
> > >>a particular method.
> > >>
> > >>In other words, can I make an assumption that two different JNDI
> > >>lookups for UserTransaction returns different references or not?
> > >>
> > >>Thanks a lot,
> > >>Marek Prochazka
> > >>--------------------------------------------------------------
> > >> Distributed Systems Research Group
> > >> Department of Software Engineering
> > >> Charles University, Faculty of Mathematics and Physics
> > >> Malostranske namesti 25, 118 00 Prague 1, Czech Republic
> > >> phone: +420-2-2191 4236
> > >> http://nenya.ms.mff.cuni.cz/thegroup/
> > >>--------------------------------------------------------------
> > >>
> > >
> >
-
Could not access Local Session Bean using JNDI lookup
Hi EJB Guru,
I am quite new to EJB 3.0 but have had a good deal of success including using JNDI to lookup Remote Stateless Session Bean in EJB 3.0. However, looking up local Stateless Session Bean prove more challenging with I had anticipated.
Here is my code
as follows:
public interface Calculator {
public int add(int x, int y);
public int subtract(int x, int y);
import javax.ejb.Remote;
@Remote
public interface CalculatorRemote extends Calculator {
import javax.ejb.Local;
@Local
public interface CalculatorLocal extends Calculator {
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import bean.CalculatorLocal;
import bean.CalculatorRemote;
@Stateless
public class CalculatorBean implements CalculatorRemote, CalculatorLocal {
public int add(int x, int y) {
return x + y;
public int subtract(int x, int y) {
return x - y;
import bean.*;
import bean.Calculator;
import bean.CalculatorLocal;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ClientAccessLocalCalculator {
public static void main(String[] args) throws NamingException {
InitialContext ctx = new InitialContext();
CalculatorLocal calculator = (CalculatorLocal) ctx.lookup("CalculatorBean/local");
System.out.println("1 + 1 = " + calculator.add(1, 1));
System.out.println("1 - 1 = " + calculator.subtract(1, 1)); }
import bean.Calculator;
import bean.CalculatorRemote;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ClientAccessRemoteCalculator {
public static void main(String[] args) throws NamingException {
InitialContext ctx = new InitialContext();
CalculatorRemote calculator = (CalculatorRemote) ctx.lookup("CalculatorBean/remote");
System.out.println("1 + 1 = " + calculator.add(1, 1));
System.out.println("1 - 1 = " + calculator.subtract(1, 1)); }
}Output when running ClientAccessRemoteCalculator gives
1 + 1 = 2
1 - 1 = 0
Output when running ClientAccessLocalCalculator on JBoss AS 4.0.5 gives:
Exception in thread "main" javax.ejb.EJBException: Invalid invocation of local interface (null container)
at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:75)
at $Proxy0.add(Unknown Source) at ClientAccessLocalCalculator.main(ClientAccessLocalCalculator.java:14)
JNDIView in JMX-Console in JBoss:
+- CalculatorBean (class: org.jnp.interfaces.NamingContext)
| +- local (proxy: $Proxy84 implements interface bean.CalculatorLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
| +- remote (proxy: $Proxy83 implements interface bean.CalculatorRemote,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBObject)
Output when running ClientAccessLocalCalculator on SJSAS 9.0 gives:
Exception in thread "main" javax.naming.NameNotFoundException: bean.CalculatorLocal not found
C:\>asadmin
Use "exit" to exit and "help" for online help.
asadmin> list-jndi-entries
Jndi Entries for server within root context:
bean.CalculatorRemote: javax.naming.Reference
jbi: com.sun.enterprise.naming.TransientContext
jdbc: com.sun.enterprise.naming.TransientContext
UserTransaction: com.sun.enterprise.distributedtx.UserTransactionImpl
bean.CalculatorRemote__3_x_Internal_RemoteBusinessHome__: javax.naming.Reference
bean.CalculatorRemote#bean.CalculatorRemote: javax.naming.Reference
ejb: com.sun.enterprise.naming.TransientContext
Command list-jndi-entries executed successfully.
asadmin>I am using Application Client to lookup these Session Beans on Netbeans 5.5, JBoss AS 4.0.5 (EJB3 installer)/SJSAS
9.0, SDK 1.5.0_11 on Windows XP platform.
Any assistance would be much appreciated.
Many thanks,
HenryHi Henry,
Any direct global JNDI lookup is not portable. It works in some cases but not in others, which
is why we recommend using the portable Java EE approach of declaring an ejb dependency
and looking up that dependency via the bean's component environment (java:comp/env).
This is true whether you're dealing with Remote or Local ejb dependencies.
Local ejbs are not supported in the Application Client tier at all. In the server tier, there is no
guarantee that a Local EJB even is assigned a global JNDI name since there's no requirement
that it be available outside of the application in which the ejb is defined.
You can find more information on these ejb access topics in our EJB FAQ :
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html -
JMS Wrappers can't cache JNDI lookups when using secured queues
Hi All!
We are working on a jms client, inside a webapp(servlets), using Weblogic 9.2 and Weblogic 10.3.
As we want to use secured queues and keep being efficient we tryed to use Weblogic JMS Wrappers, that should work according to the docs:
Enhanced Support for Using WebLogic JMS with EJBs and Servlets
http://download.oracle.com/docs/cd/E12840_01/wls/docs103/jms/j2ee.html
But we are facing a problem:
When we define a JMS Wrapper and try to cache JNDI lookups for the QueueConnectionFactory and Queue, as the docs recommend for efficiency, the connection to the queue is ignoring the user/pwd.
The JMS Wrapper is using <res-auth>Application</res-auth>.
We are creating the connection using createQueueConnection(user, pwd) from QueueConnectionFactory and after several tests it seems that the user and password are ingored unless a jndi lookup is made in the same thread, as if when there are not any thread credentials present user and password are ignored for the connection...
so the question is:
That behaviour goes against Weblogic JMS Wrapper documentation, doesn't it?
Is there then any other way to access efficiently secured queues using a servlet as a client? (iit's not an option for us to use mdbs, or ejbs).
If it helps, this seems related to this still opened spring-weblogic issue: SPR-2941 --> http://jira.springframework.org/browse/SPR-2941 and SPR-4720 --> http://jira.springframework.org/browse/SPR-4720
Thanxs
And here goes our DDs and code to reproduce:
First in pretty format:
web.xml --> http://pastebin.com/f5f85e8d4
weblogic.xml --> http://pastebin.com/f2fbe10cc
Client code --> http://pastebin.com/f586d32d9
And now emmebded in the msg:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<description>WebLogic Descriptor</description>
<resource-description>
<res-ref-name>jms/QCF</res-ref-name>
<jndi-name>weblogic.jms.ConnectionFactory</jndi-name>
</resource-description>
</weblogic-web-app>weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name> QCFWrapperCredentialsTest </display-name>
<description> QCFWrapperCredentialsTest </description>
<servlet id="Servlet_1">
<servlet-name>QCFWrapperCredentialsTest</servlet-name>
<servlet-class>QCFWrapperCredentialsTest</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping id="ServletMapping_1">
<servlet-name>QCFWrapperCredentialsTest</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>jms/QCF</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Application</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>And our test client:
import java.io.*;
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
import javax.servlet.http.*;
public class QCFWrapperCredentialsTest extends HttpServlet {
QueueConnectionFactory factory = null;
Queue queue = null;
String jndiName = "java:comp/env/jms/QCF";
String queueName= "jms/ColaEntradaConsultas";
String user = "usuarioColas";
String pwd = "12345678";
String userjndi = "usuarioColas";
String pwdjndi = "12345678";
String serverT3URL="t3://127.0.0.1:7007";
public void init() {
setupJNDIResources();
private void setupJNDIResources(){
try {
Properties props = new Properties();
props.put("java.naming.factory.initial",
"weblogic.jndi.WLInitialContextFactory");
props.put("java.naming.provider.url",serverT3URL );
props.put("java.naming.security.principal", userjndi);// usr
props.put("java.naming.security.credentials", pwdjndi);// pwd
InitialContext ic = new InitialContext(props);
factory = (QueueConnectionFactory) ic.lookup(jndiName);
queue = (Queue) ic.lookup(queueName);
} catch (NamingException e) {
e.printStackTrace();
public void service(HttpServletRequest req, HttpServletResponse res) {
res.setContentType("text/html");
Writer wr = null;
try {
wr = res.getWriter();
//Comment this out, do a lookup for each request and it will work
//setupJNDIResources();
String user = this.user;
String pwd = this.pwd;
//read users and passwords from the request in case they are present
if (req.getParameter("user") != null) {
user = req.getParameter("user");
if (req.getParameter("pwd") != null) {
pwd = req.getParameter("pwd");
wr.write("JNDI User: *" + userjndi + "* y pwd: *" + pwdjndi + "*<p>");
wr.write("Queue User: *" + user + "* y pwd: *" + pwd + "*<p>");
//Obtain a connection using user/pwd
QueueConnection conn = factory.createQueueConnection(user, pwd);
QueueSession ses = conn.createQueueSession(true,
Session.SESSION_TRANSACTED);
QueueSender sender = ses.createSender(queue);
TextMessage msg = ses.createTextMessage();
msg.setText("Hi there!");
conn.start();
sender.send(msg);
ses.commit();
sender.close();
ses.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
try {
wr.write(e.toString());
} catch (Exception e2) {
e2.printStackTrace();
finally{
try {
wr.close();
} catch (IOException e) {
e.printStackTrace();
}Edited by: user2525402 on Feb 9, 2010 7:14 PMThanks Tom,
Quite a useful response .-)
Leaving aside the fact that weblogic behaviour with jms wrappers and secured queues seems to not be working as the docs says...
Talking about workarounds:
Both workarounds you suggest works, but as you already noted, creating a new JNDI context just to inject credentials into the threads is overkill when high performance is needed.
I also found more information about the same issue here: http://sleeplessinslc.blogspot.com/2009/04/weblogic-jms-standalone-multi-threaded.html
And he suggest the same workaround, injecting credentials
So I tried the second approach, successfully, injecting credentials into the thread using the security API.
This way, using JMS wrappers and injecting credentials into the thread we get the best performance available, caching resource using wrappers and using credentials in a somewhat efficient way.
Now the test snippet looks like this:
import java.io.*;
import java.security.PrivilegedAction;
import java.util.Properties;
import javax.jms.*;
import javax.naming.*;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
import javax.servlet.http.*;
import weblogic.jndi.Environment;
import weblogic.security.auth.Authenticate;
public class JMSWrapperCredentialsTest extends HttpServlet {
QueueConnectionFactory factory = null;
Queue queue = null;
String jndiName = "java:comp/env/jms/QCF";
String queueName= "jms/ColaEntradaConsultas";
String user = "usuarioColas";
String pwd = "12345678";
String userjndi = "usuarioColas";
String pwdjndi = "12345678";
String serverT3URL="t3://127.0.0.1:7007";
public void init() {
setupJNDIResources();
private void setupJNDIResources(){
try {
Properties props = new Properties();
props.put("java.naming.factory.initial",
"weblogic.jndi.WLInitialContextFactory");
props.put("java.naming.provider.url",serverT3URL );
props.put("java.naming.security.principal", userjndi);// usr
props.put("java.naming.security.credentials", pwdjndi);// pwd
InitialContext ic = new InitialContext(props);
factory = (QueueConnectionFactory) ic.lookup(jndiName);
queue = (Queue) ic.lookup(queueName);
} catch (NamingException e) {
e.printStackTrace();
public void service(HttpServletRequest req, HttpServletResponse res) {
final HttpServletRequest fReq=req;
final HttpServletResponse fRes=res;
PrivilegedAction action = new java.security.PrivilegedAction() {
public java.lang.Object run() {
performRequest(fReq,fRes);
return null;
try {
Subject subject=createSingleSubject(serverT3URL,user,pwd);
weblogic.security.Security.runAs(subject, action);
} catch (Exception e) {
e.printStackTrace();
public void performRequest(HttpServletRequest req, HttpServletResponse res) {
res.setContentType("text/html");
Writer wr = null;
try {
wr = res.getWriter();
//Comment this out, do a lookup for each request and it will work
//setupJNDIResources();
String user = this.user;
String pwd = this.pwd;
//read users and passwords from the request in case they are present
if (req.getParameter("user") != null) {
user = req.getParameter("user");
if (req.getParameter("pwd") != null) {
pwd = req.getParameter("pwd");
wr.write("JNDI User: *" + userjndi + "* y pwd: *" + pwdjndi + "*<p>");
wr.write("Queue User: *" + user + "* y pwd: *" + pwd + "*<p>");
//Obtain a connection using user/pwd
QueueConnection conn = factory.createQueueConnection(user, pwd);
QueueSession ses = conn.createQueueSession(true,
Session.SESSION_TRANSACTED);
QueueSender sender = ses.createSender(queue);
TextMessage msg = ses.createTextMessage();
msg.setText("Hi there!");
conn.start();
sender.send(msg);
ses.commit();
sender.close();
ses.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
try {
wr.write(e.toString());
} catch (Exception e2) {
e2.printStackTrace();
finally{
try {
wr.close();
} catch (IOException e) {
e.printStackTrace();
private Subject createSingleSubject(String providerUrl, String userName, String password) {
Subject subject = new Subject();
// Weblogic env class
Environment env = new Environment();
if(providerUrl!=null)
env.setProviderUrl(providerUrl);
env.setSecurityPrincipal(userName);
env.setSecurityCredentials(password);
try {
// Weblogic Authenticate class will populate and Seal the subject
Authenticate.authenticate(env, subject);
return subject;
catch (LoginException e) {
throw new RuntimeException("Unable to Authenticate User", e);
catch (Exception e) {
throw new RuntimeException("Error authenticating user", e);
}Thanks a lot for the help -
JNDI lookup using a proxy server
Hi,
I'm trying to use a weblogic server as a proxy server for a cluster of
weblogic servers. The static and dynamic content delivery works fine but
when I try to do a JNDI lookup from an applet client, I get a name not
resolved exception. I guess, it happens because the proxy server tries to
resolve the name from it's JNDI tree, whereas I expect it to forward this
request to one of the servers in the cluster. Is this possible? If it is, do
I need to set up some parameters in the proxy server? If not, can I do this
myself by writing a name resolution class which in turn will forward the
request to one of the servers in the cluster?
Any help would be greatly appreciated.
thanks
- sanjaywhen u say "cluster of weblogic servers"..u mean the weblogic`s inbuilt
cluster..
the reason i ask is weblogic`s cluster do provide JNDI clustering too by using
cluster-wide naming tree..
Sanjay Aggarwal wrote:
Hi,
I'm trying to use a weblogic server as a proxy server for a cluster of
weblogic servers. The static and dynamic content delivery works fine but
when I try to do a JNDI lookup from an applet client, I get a name not
resolved exception. I guess, it happens because the proxy server tries to
resolve the name from it's JNDI tree, whereas I expect it to forward this
request to one of the servers in the cluster. Is this possible? If it is, do
I need to set up some parameters in the proxy server? If not, can I do this
myself by writing a name resolution class which in turn will forward the
request to one of the servers in the cluster?
Any help would be greatly appreciated.
thanks
- sanjay -
Hello everyone,
I developed a Web Service prototype accessing remote EJB using the EJB
control with special syntax in the jndi-name attribute: @jws:ejb
home-jndi-name="t3://10.10.245.70:7131/AccountDelegatorEJB"
Everything works fine, but I get an error when I restrict access to my web
service with a declarative security model by implementing steps provided in
help doc:
- Define the web resource you wish to protect
- Define which security role is required to access the web resource
- Define which users are granted the required security role
- Configure WebLogic Server security for my web service(Compatibility
Security/Users)
I launch the service by entering the address in a web browser. When prompted
to accept the digital certificate, click Yes, when prompted for network
authentication information, enter username and password, navigate to the
Test Form tab of Test View, invoke the method by clicking the button and I
get the following exception:
<error>
<faultcode>JWSError</faultcode>
<faultstring>Error during JNDI lookup from
jndi:t3://10.10.245.70:7131/AccountDelegatorEJB[Lookup failed for
name:t3://10.10.245.70:7131/AccountDelegatorEJB]</faultstring>
<detail>
<jwErrorDetail> weblogic.jws.control.ControlException: Error during JNDI
lookup from jndi:t3://10.10.245.70:7131/AccountDelegatorEJB[Lookup failed
for name:t3://10.10.245.70:7131/AccountDelegatorEJB] at
weblogic.knex.control.EJBControlImpl.acquireResources(EJBControlImpl.java:27
8) at
weblogic.knex.context.JwsInternalContext.acquireResources(JwsInternalContext
.java:220) at
weblogic.knex.control.ControlHandler.invoke(ControlHandler.java:260) at
ibas.AccountControl.getTransactionHistory(AccountControl.ctrl) at
ibas.GetSecure.retrieveVisaHistoryTxn(GetSecure.jws:64) </jwErrorDetail>
</detail>
</error>
I have a simple Hello method as well in my WebService (which is also
restricted) and it works fine, but remote EJB access doesn't. I tested my
prototype on Weblogic 7.2 and 8.1 platforms - same result.
Is that a bug or I am missing some additional configuration in order to get
that working. Has anyone seen similar behavior? Is there a known resolution?
Or a suggested way to work around the problem?
Thank you.
AndreAndre,
It would be best if this issue is handled as an Eval Support case. Please
BEA Customer Support at http://support.beasys.com along with the required
files, and request that an Eval support case be created for this issue.
Thanks
Raj Alagumalai
WebLogic Workshop Support
"Andre Shergin" <[email protected]> wrote in message
news:[email protected]...
Anurag,
I removed "t3", still get an error but a different one (Unable to create
InitialContext:null):
<error>
<faultcode>JWSError</faultcode>
<faultstring>Error during JNDI lookup from
jndi://secuser1:[email protected]:7131/AccountDelegatorEJB[Unable to
create InitialContext:null]</faultstring>
<detail>
<jwErrorDetail> weblogic.jws.control.ControlException: Error during JNDI
lookup from
jndi://secuser1:[email protected]:7131/AccountDelegatorEJB[Unable to
create InitialContext:null] at
weblogic.knex.control.EJBControlImpl.acquireResources(EJBControlImpl.java:27
8) at
weblogic.knex.context.JwsInternalContext.acquireResources(JwsInternalContext
.java:220) at
weblogic.knex.control.ControlHandler.invoke(ControlHandler.java:260) at
ibas.AccountControl.getTransactionHistory(AccountControl.ctrl) at
ibas.GetVisaHistoryTransactions.getVisaHistoryTxn(GetVisaHistoryTransactions
.jws:67) </jwErrorDetail>
</detail>
</error>
Note: inter-domain communication is configured properly. The Web Service to
remote EJB works fine without a declarative security.
Any other ideas?
Thank you for your help.
Andre
"Anurag" <[email protected]> wrote in message
news:[email protected]...
Andre,
It seems you are using the URL
jndi:t3://secuser1:[email protected]:7131/AccountDelegatorEJB
whereas you should not be specifying the "t3:" protocol.
The URL should be like
jndi://secuser1:[email protected]:7131/AccountDelegatorEJB
Please do let me know if you see any issues with this.
Note that this will only allow you to access remote EJBs in the same WLS
domain. For accessing EJBs on another domain, you need to configure
inter-domain communication by
following a few simple steps as mentioned at
http://e-docs.bea.com/wls/docs81/ConsoleHelp/jta.html#1106135. This link has
been provided in the EJB Control Workshop documentation.
Regards,
Anurag
"Andre Shergin" <[email protected]> wrote in message
news:[email protected]...
Raj,
I tried that before, it didn't help. I got similar error message:
<error>
<faultcode>JWSError</faultcode>
<faultstring>Error during JNDI lookup from
jndi:t3://secuser1:[email protected]:7131/AccountDelegatorEJB[Lookup
failed for
name:t3://secuser1:[email protected]:7131/AccountDelegatorEJB]</faultstr
ing>
<detail>
<jwErrorDetail> weblogic.jws.control.ControlException: Error during JNDI
lookup from
jndi:t3://secuser1:[email protected]:7131/AccountDelegatorEJB[Lookup
failed for
name:t3://secuser1:[email protected]:7131/AccountDelegatorEJB] at
weblogic.knex.control.EJBControlImpl.acquireResources(EJBControlImpl.java:27
8) at
weblogic.knex.context.JwsInternalContext.acquireResources(JwsInternalContext
.java:220) at
weblogic.knex.control.ControlHandler.invoke(ControlHandler.java:260) at
ibas.AccountControl.getTransactionHistory(AccountControl.ctrl) at
ibas.GetSecure.retrieveVisaHistoryTxn(GetSecure.jws:64) </jwErrorDetail>
</detail>
</error>
Anything else should I try?
P.S. AccountDelegatorEJB, the remote EJB my Web Service calls is NOTaccess
restricted.
I hope there is a solution.
Thanks,
Andre
"Raj Alagumalai" <[email protected]> wrote in message
news:[email protected]...
Andre,
Can you try using the following url with username and password
jndi://username:password@host:7001/my.resource.jndi.object ?
once you add webapp level security, the authenticated is the user who
invokes the EJB.
http://e-docs.bea.com/workshop/docs81/doc/en/workshop/guide/controls/ejb/con
CreatingANewEJBControl.html?skipReload=true
has more info on using remote EJB's.
Hope this helps.
Thanks
Raj Alagumalai
WebLogic Workshop Support
"Alla Resnik" <[email protected]> wrote in message
news:[email protected]...
Hello everyone,
I developed a Web Service prototype accessing remote EJB using the EJB
control with special syntax in the jndi-name attribute: @jws:ejb
home-jndi-name="t3://10.10.245.70:7131/AccountDelegatorEJB"
Everything works fine, but I get an error when I restrict access to my
web
service with a declarative security model by implementing steps
provided
in
help doc:
- Define the web resource you wish to protect
- Define which security role is required to access the web resource
- Define which users are granted the required security role
- Configure WebLogic Server security for my web service(Compatibility
Security/Users)
I launch the service by entering the address in a web browser. Whenprompted
to accept the digital certificate, click Yes, when prompted for
network
authentication information, enter username and password, navigate tothe
Test Form tab of Test View, invoke the method by clicking the buttonand
I
get the following exception:
<error>
<faultcode>JWSError</faultcode>
<faultstring>Error during JNDI lookup from
jndi:t3://10.10.245.70:7131/AccountDelegatorEJB[Lookup failed for
name:t3://10.10.245.70:7131/AccountDelegatorEJB]</faultstring>
<detail>
<jwErrorDetail> weblogic.jws.control.ControlException: Error during
JNDI
lookup from jndi:t3://10.10.245.70:7131/AccountDelegatorEJB[Lookupfailed
for name:t3://10.10.245.70:7131/AccountDelegatorEJB] at
weblogic.knex.control.EJBControlImpl.acquireResources(EJBControlImpl.java:27
8) at
weblogic.knex.context.JwsInternalContext.acquireResources(JwsInternalContext
.java:220) at
weblogic.knex.control.ControlHandler.invoke(ControlHandler.java:260)at
ibas.AccountControl.getTransactionHistory(AccountControl.ctrl) at
ibas.GetSecure.retrieveVisaHistoryTxn(GetSecure.jws:64)</jwErrorDetail>
</detail>
</error>
I have a simple Hello method as well in my WebService (which is also
restricted) and it works fine, but remote EJB access doesn't. I testedmy
prototype on Weblogic 7.2 and 8.1 platforms - same result.
Is that a bug or I am missing some additional configuration in order
to
get
that working. Has anyone seen similar behavior? Is there a knownresolution?
Or a suggested way to work around the problem?
Thank you.
Andre -
Using external LDAP server for WL JNDI lookups
I'm trying to find out if it is possible to re-direct JNDI calls to the WL
server to an external LDAP server. I know you can install an external LDAP
server for security purposes, but I would like to use an external LDAP
server to handle all JNDI lookups (like for JNDI EJB name location, etc.).
Is this possible?You typically need to use our JNDI store. We strongly recommend this for
performance reasons..
You can use the JNDI To LDAP bridge which is available from the sun web
site.
Michael Girdley
BEA Systems Inc
"Jack Archer" <[email protected]> wrote in message
news:[email protected]..
I'm trying to find out if it is possible to re-direct JNDI calls to the WL
server to an external LDAP server. I know you can install an external LDAP
server for security purposes, but I would like to use an external LDAP
server to handle all JNDI lookups (like for JNDI EJB name location, etc.).
Is this possible? -
Calling BRM from UDF using JNDI lookup with @EJB annotation
Hi Experts
I am trying to implement a UDF to invoke my BRM Rules set via JNDI Lookup instead of a SOAP Channel lookup.
I have had a look at the following links/docs:
Calling BRM from UDF using Public API
http://www.gleanster.com/system/resources/W1siZiIsIjIwMTIvMDgvMDcvMjAvNDcvNTAvNDMvVGhpbmdzX1lvdV9TaG91bGRfS25vd19hYm91dF9TQVBfTmV0V2VhdmVyX0JSTS5wZGYiXV0/Things%20You%20Should%20Know%20about%20SAP%20NetWeaver%20BRM.pdf
For item 1 above, the example looks really good, but it doesnt explain how I get access to the following required imports from my UDF:
import com.sap.brms.qrules.ejb.*;
import com.sap.brms.qrules.engine.AbstractProject;
import com.sap.brms.qrules.engine.RuleEngine;
import com.sap.brms.qrules.engine.RulesetContext;
import javax.ejb.EJB;
The second document is really good as well, but I could not figure out how to get it to work from my UDF.
So, can anyone help me to understand specifically what is required to get this to work?
Is is possible to invoke the rule set from my UDF?
How do I give my UDF access to all the required jars/imports?
I have manage to create a new DC (Development Component) with a public part and this enables me to get my code to compile on my local PC but I am not able to activate it due to the server not having access to the same java packages as my local copy.
Any help would be greatly appreciated.You resolve the dependency by importing the required jars with using the dependency tab for the mapping program.
As stipulated before, I have managed to resolve the dependency issue but I have now getting the same error as in the forum: Calling BRM from UDF using Public API
The specific error is:
com.sap.engine.services.cross.PortableRemoteObjectContainer.narrow(PortableRemoteObjectContainer.java:238)
Has anyome manage to get invoke a BRM Ruleset using JNDI? -
How to write the jndi lookup for ejb using oc4j server in jdeveloper
Hi All,
i am new to the JDeveloper. i want to develop the session bean in JDeveloper using the OC4J server. how to write the jndi lookup in cllient. what are the xml files need to deploy the application. where can i mention the JNDI name in xml file. so please provide the information as soon as possible.
regards
ramThere is quite in-depth information in the Enterprise JavaBeans Developer's Guide.
Section 2 (Understanding EJB Application Development) explains the xml files needed and Section 29 (Accessing an EJB from a Client) explains how to do a JNDI lookup.
Hope this helps.
Maybe you are looking for
-
When I light up my nano iPod screen an exclamation mark inside of a triangle appears along with this web page address: www.apple.com/support/ipod The iPod is fully charged and has been restored as well as updated with this file: iPodUpdater2006-03-23
-
Addition of new field in existing cube which has data?
I Have service provider field in ods and which is populating data on daily basis. Now I need to populate that field into cube and then reportingu2026u2026.. For this do I need to delete the data from the cube and add that new field and need to load t
-
Basically i have 4 buittons within my movie. Each button goes to a different frame within the timeline. What i want to happen is when you go to one of the 4 points in the movie it plays a different sound. The problem i am having is that when u hit on
-
Which PDF-version on Content Server 4
In what PDF-version must the PDF-files be saved, in order to work properly on ACS4? I have noticed that PDFs that are uploaded in version 1.6 (Actobat 7.x) does not show the first cover image, but a blank page instead, when downloaded (as a library l
-
TabIndex & setFocus issues.
Hi all, I am having a real issue with getting tabIndex and setFocus to work with my custom TextInput component. I have tried everything that I can possibly think of and it just won't work. When I test the component and set tabIndex or setFocus nothin