[JNDI/Naming/Network] - Can't connect to global namespace datasource from servlet
by LostJBossIdeUser
I just recently started playing with JBoss. I have been successful so far. But now I am stuck on a datasource issue. I need to access a MySQL DB from a servlet to read/write xml content.
Here is what I have so far:
mysql-ds.xml ?
<local-tx-datasource>
<jndi-name>jdbc/MySqlDS</jndi-name>
<use-java-context>false</use-java-context>
<connection-url>jdbc:mysql://localhost:3306/proxyServletDB</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
pword
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<type-mapping>mySQL</type-mapping>
</local-tx-datasource>
web.xml ?
<web-app>
<!-- JDBC DataSources (java:comp/env/jdbc) -->
<resource-ref>
The default DS
<res-ref-name>jdbc/MySqlDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
< ? >
</web-app>
jboss-web.xml ?
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/MySqlDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/MySqlDS</jndi-name>
</resource-ref>
</jboss-web>
Servlet ?
Context ctx = new InitialContext();
DataSource ds = DataSource)ctx.lookup("java:/comp/env/jdbc/MySqlDS");
I think these are the relevant files. I could access the datasource from the local jndi namespace by using lookup(?java:/jdbc/MySqlDS?). But I need it to be global so that other servlets, from other machines can use it. Which is when I added: <use-java-context>false</use-java-context> to my mysql-ds.xml file so that the default, local java:/ namespace won?t be used.
But now whenever the servlet is invoked I get the error that says MySqlDS not bound (complete trace shown below).
Error I get when I try to invoke the servlet:
16:34:47,328 ERROR [STDERR] javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.N
ameNotFoundException: MySqlDS not bound]
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067)
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700)
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:716)
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
16:34:47,328 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351)
16:34:47,328 ERROR [STDERR] at ReadServlet.doGet(ReadServlet.java:28)
16:34:47,328 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
16:34:47,328 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCha
in.java:252)
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
173)
16:34:47,328 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCha
in.java:202)
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
173)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
16:34:47,343 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValv
e.java:175)
16:34:47,343 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
16:34:47,343 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
16:34:47,343 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection
(Http11BaseProtocol.java:664)
16:34:47,343 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
16:34:47,343 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:1
12)
16:34:47,343 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
16:34:47,343 ERROR [STDERR] Caused by: javax.naming.NameNotFoundException: MySqlDS not bound
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
16:34:47,343 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351)
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061)
16:34:47,343 ERROR [STDERR] ... 25 more
service=jndiview ?
+- jdbc (class: org.jnp.interfaces.NamingContext)
| +- MySqlDS (class: javax.sql.DataSource)
Any ideas/suggestions? I?ve been stuck on this thing for almost 3 days now.
Thanks!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961642#3961642
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961642
19 years, 9 months
[Datasource Configuration] - Can't connect to global namespace datasource from servlet
by LostJBossIdeUser
I just recently started playing with JBoss. I have been successful so far. But now I am stuck on a datasource issue. I need to access a MySQL DB from a servlet to read/write xml content.
Here is what I have already:
mysql-ds.xml ?
<local-tx-datasource>
<jndi-name>jdbc/MySqlDS</jndi-name>
<use-java-context>false</use-java-context>
<connection-url>jdbc:mysql://localhost:3306/proxyServletDB</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
pword
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<type-mapping>mySQL</type-mapping>
</local-tx-datasource>
web.xml ?
<web-app>
<!-- JDBC DataSources (java:comp/env/jdbc) -->
<resource-ref>
The default DS
<res-ref-name>jdbc/MySqlDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
< ? >
</web-app>
jboss-web.xml ?
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/MySqlDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/MySqlDS</jndi-name>
</resource-ref>
</jboss-web>
Servlet ?
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/MySqlDS");
I think these are the relevant files. I could access the datasource from the local jndi namespace by using lookup(?java:/jdbc/MySqlDS?). But I need it to be global so that other servlets, from other machines can use it. Which is when I added: <use-java-context>false</use-java-context> to my mysql-ds.xml file so that the default, local java:/ namespace won?t be used.
But now whenever the servlet is invoked I get the error that says MySqlDS not bound (complete trace shown below).
Error I get when I try to invoke the servlet:
16:34:47,328 ERROR [STDERR] javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.N
ameNotFoundException: MySqlDS not bound]
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1067)
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:700)
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:716)
16:34:47,328 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
16:34:47,328 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351)
16:34:47,328 ERROR [STDERR] at ReadServlet.doGet(ReadServlet.java:28)
16:34:47,328 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
16:34:47,328 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCha
in.java:252)
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
173)
16:34:47,328 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCha
in.java:202)
16:34:47,328 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
173)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
16:34:47,343 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValv
e.java:175)
16:34:47,343 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
16:34:47,343 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
16:34:47,343 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
16:34:47,343 ERROR [STDERR] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection
(Http11BaseProtocol.java:664)
16:34:47,343 ERROR [STDERR] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
16:34:47,343 ERROR [STDERR] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:1
12)
16:34:47,343 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
16:34:47,343 ERROR [STDERR] Caused by: javax.naming.NameNotFoundException: MySqlDS not bound
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
16:34:47,343 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
16:34:47,343 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:351)
16:34:47,343 ERROR [STDERR] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1061)
16:34:47,343 ERROR [STDERR] ... 25 more
service=jndiview -
Global JNDI Namespace
+- jdbc (class: org.jnp.interfaces.NamingContext)
| +- MySqlDS (class: javax.sql.DataSource)
Any ideas/suggestions? I?ve been stuck on this thing for almost 3 days now.
Thanks!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961637#3961637
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961637
19 years, 9 months
[Beginners Corner] - Drools 3.0 and constraints
by AllenABQ
Maybe I've just not found the documentation that explains how to deal with this.
I'm using Drools and want to compare to values in the same object as a condition for executing the RHS.
For example I might have:
public class Battery {
| private double charge;
|
| public void setCharge(double charge) {
| this.charge = charge;
| }
|
| public double getCharge() {
| return charge;
| }
| }
|
| public class DoubleA extends Battery {
| private double optimal;
|
| public double getOptimal(){
| return optimal;
| }
| }
In my main function I set up all my pieces to get the rule base working with some instantiated objects. Lets say for DoubleA #1, I say the charge is .68 and the optimal value is .75. For DoubleA #2, the charge is .72 and the optimal value is .70.
In my rule base, I want to monitor all my DoubleA batteries for when they are less than optimal. It would make sense that I would write the rule somehow like this...
rule "DoubleA less than optimal"
| when
| b : DoubleA(charge < optimal);
| then
| b.chargeBattery();
| end
However, this does not work. I get an error message in Eclipse saying "Unable to return Declaration for identifier 'optimal'". In haven't been able to find anything in the documentation about comparing the internal values of single objects, and the contraints on the RHS of the comparison operator only appears to work for literals or bound variables. I've tired many different permutations of making a bound variable out of 'optimal', but nothing seems to work, and I'm stumped. There HAS to be a way to do this. I can't imagine it was not thought of.
Any help appreciated!
Allen
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3961632#3961632
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3961632
19 years, 9 months