12 Replies Latest reply on Nov 14, 2005 1:53 AM by VikramjitSingh

    Create an application with Jboss

    Esther Delgado Newbie

      Well, I don't know how to start (Bad beginning)
      I was used to work with Tomcat 4.1.31 as a application server, but I've found it's not able to work with ejb and someone told me the need to use Jboss. I've downloaded from the web Jboss 4.0.0 and I want to create a application like I had with Tomcat. If I modify the file server.xml located in JBOSS_HOME/server/default/deploy/jbossweb-tomcat50.sar with the context I used to have in Tomcat, it doesn't work. I've been looking for information about this topic, but I did't find anything.
      Is there anybody who can help me please?
      Thanks for all your time.
      Esther

        • 1. Re: Create an application with Jboss
          Russ Loucks Newbie

          Download the 'Getting Started with JBoss' guide. This talks about how to run an example application (Duke's Bank).

          Modifying the server.xml descriptor seems like a bad thing.... Look at what the example has for 'application.xml' in the 'ear' file and 'web.xml' in the UI war file.

          • 2. Re: Create an application with Jboss
            Esther Delgado Newbie

            Hi!
            First of all, thanks for spending your time answering me. I've read the guide but it desn't help me as muach as I'd wish. Before reading your answer, I've got my html and jsp working, but I don't know how to make my servlet and connection pool run. My DataBase is Oracle and Duke's Bank is working with HSQL.
            I had my application running just with Tomcat. Why doesn't it work now? :_(
            I think I'll never get it... Maybe the problem is being a mathematician... That's not my job!
            Please, help me!
            Esther

            • 3. Re: Create an application with Jboss
              Russ Loucks Newbie

              Without knowing (or seeing) the exact errors you're experiencing, I can't point you to exact changes you need to make. However, I can point you to some general things:

              1) if you're deploying a JSP/servlet-based application, you should be able to deploy a working (in Tomcat, that is) 'war' file to JBoss. The 'context' of the application will be (in my experience) the name of the 'war' file without the '.war' extension.

              2) Create an 'oracle-ds.xml' configuration file and deploy that. The 'Getting started' guide shows an example for MySQL (e.g., mysql-ds.xml). I suspect you should figure out how to build up an oracle-ds.xml file and deploy that.

              3) I don't know how you reference your Oracle-based datasource from your application, but I suspect you'll probably have to change references to this datasource to use JNDI.

              • 4. Re: Create an application with Jboss
                Esther Delgado Newbie

                Thanks again for spending your spare time in helping me.
                Ifinally, I left the possibility of reusing the application I had with Tomcat. I've read the Startup Guide in jboss.org as you recomended and I tried to follow the steps:
                1. I uncommented the Pad attribute in jboss-service.xml,
                2. Add the classes12.jar at default/lib folder.
                3. I created oracle-xa-ds.xml configuring the url, user and password.
                The process says the connection is created but when I try to execute the servlet which makes the connection appears the following error:

                19:01:23,269 INFO [STDOUT] javax.naming.NameNotFoundException: jdbc not bound
                19:01:23,271 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
                19:01:23,271 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
                19:01:23,271 INFO [STDOUT] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
                19:01:23,272 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
                19:01:23,272 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
                19:01:23,272 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:529)
                19:01:23,272 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:508)
                19:01:23,273 INFO [STDOUT] at servlet.DataBaseServlet.doGet(DataBaseServlet.java:41)
                19:01:23,273 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
                19:01:23,273 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                19:01:23,273 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)

                That's my default/deploy/oracle-xa-ds.xml:


                -
                <xa-datasource>
                <jndi-name>XAOracleDS</jndi-name>
                <track-connection-by-tx>true</track-connection-by-tx>
                <isSameRM-override-value>false</isSameRM-override-value>
                <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
                <xa-datasource-property name="URL">jdbc:oracle:thin:@192.168.30.99:1521:PorDB2</xa-datasource-property>
                <xa-datasource-property name="User">servijob</xa-datasource-property>
                <xa-datasource-property name="Password">Servi_Ds</xa-datasource-property>
                -
                <exception-sorter-class-name>
                org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter
                </exception-sorter-class-name>
                <no-tx-separate-pools/>
                </xa-datasource>
                -
                <!--
                mbean code="org.jboss.resource.adapter.jdbc.xa.oracle.OracleXAExceptionFormatter"
                name="jboss.jca:service=OracleXAExceptionFormatter"
                -->
                -
                <!--
                depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager</depends
                -->
                <!--/mbean-->


                What's more do I have to configure?
                Thanks,
                Esther

                • 5. Re: Create an application with Jboss
                  Russ Loucks Newbie

                  Hmmm.

                  1) I see you copied something called 'classes12.jar' to 'default/lib'. Does this contain the Java/Oracle connector foo (e.g., oracle.jdbc.xa.client.OracleXADataSource)? If so, that is good. I forgot to mention that before.... :|

                  2) how are you accessing your Oracle DB? I've never done exactly what you're trying to do (access an Oracle DB from a servlet in JBoss), but it seems like you should be able to call the JDBC 'connection' routines with the same parameters as you were before. You probably don't need to use JNDI.... Can you post the lines of code that access the DB as well as those that are causing the error?

                  • 6. Re: Create an application with Jboss
                    Esther Delgado Newbie

                    Hi redbeard!
                    Of course, classes12.jar contains the class I need (oracle.jdbc.xa.OracleXADataSOurce).
                    That's my servlet:


                    package servlet;

                    import java.io.IOException;
                    import java.io.PrintWriter;
                    import java.sql.Connection;
                    import java.sql.PreparedStatement;
                    import java.sql.ResultSet;
                    import javax.naming.Context;
                    import javax.naming.InitialContext;
                    import javax.servlet.ServletException;
                    import javax.servlet.http.HttpServlet;
                    import javax.servlet.http.HttpServletRequest;
                    import javax.servlet.http.HttpServletResponse;
                    import javax.sql.DataSource;

                    public class DataBaseServlet extends HttpServlet {

                    public void doGet(HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException {
                    PrintWriter out = null;
                    try {
                    out = response.getWriter();
                    Context initContext = new InitialContext();
                    Context envContext = (Context)initContext.lookup("java:/comp/env");
                    DataSource ds = (DataSource)envContext.lookup("jdbc/myoracle");
                    Connection conn = ds.getConnection();
                    String sql = "SELECT nombre FROM candidatos WHERE id_cand=49851";
                    PreparedStatement pstmt = conn.prepareStatement(sql);
                    ResultSet rs = pstmt.executeQuery();
                    while (rs.next()) {
                    out.println("MAXIM ID :" + rs.getString(1));
                    }

                    } catch (Exception e) {
                    out = response.getWriter();
                    out.println("error: " + e.getMessage());
                    e.printStackTrace();

                    }
                    }

                    public void doPost(HttpServletRequest request, HttpServletResponse response)
                    throws ServletException, IOException {
                    doGet(request, response);
                    }

                    }

                    What error do you want me to post? The one which Apache shows or the one when i call my servlet?

                    The first one is:

                    error: jdbc not bound

                    The second one:

                    15:41:53,444 INFO [STDOUT] javax.naming.NameNotFoundException: jdbc not bound
                    15:41:53,448 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
                    15:41:53,590 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
                    15:41:53,591 INFO [STDOUT] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
                    15:41:53,591 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
                    15:41:53,591 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
                    15:41:53,652 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:529)
                    15:41:53,653 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:508)
                    15:41:53,653 INFO [STDOUT] at servlet.DataBaseServlet.doGet(DataBaseServlet.java:41)
                    15:41:53,653 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
                    15:41:53,655 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                    15:41:53,656 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
                    15:41:53,656 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
                    15:41:53,656 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
                    15:41:53,656 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
                    15:41:53,657 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
                    15:41:53,657 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
                    15:41:53,657 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
                    15:41:53,658 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
                    15:41:53,658 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
                    15:41:53,658 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
                    15:41:53,658 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
                    15:41:53,659 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:44)
                    15:41:53,659 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
                    15:41:53,659 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:169)
                    15:41:53,659 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
                    15:41:53,660 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
                    15:41:53,660 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
                    15:41:53,660 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
                    15:41:53,661 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
                    15:41:53,661 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
                    15:41:53,661 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
                    15:41:53,661 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                    15:41:53,662 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
                    15:41:53,662 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
                    15:41:53,662 INFO [STDOUT] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
                    15:41:53,663 INFO [STDOUT] at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
                    15:41:53,663 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
                    15:41:53,663 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
                    15:41:53,658 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
                    15:41:53,658 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
                    15:41:53,659 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:44)
                    15:41:53,659 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
                    15:41:53,659 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:169)

                    During the deploy it seems as if everything was working fine... That's the message about the connection I get.

                    15:39:59,724 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=XAOracleDS,service=DataSourceBinding to JNDI name 'java:XAOracleDS'

                    which is the same with the default database

                    15:39:53,305 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:name=DefaultDS,service=DataSourceBinding to JNDI name 'java:DefaultDS'

                    Again, thaks for everything.
                    Huge kisses,
                    Esther

                    • 7. Re: Create an application with Jboss
                      Russ Loucks Newbie

                      Esther,

                      I see that JNDI is complaining about not being able to find the data source ('javax.naming.NameNotFoundException: jdbc not bound ').

                      I also see that your 'oracle-xa-ds.xml' contains the following lines:

                      <xa-datasource>
                       <jndi-name>XAOracleDS</jndi-name>
                      

                      The JNDI-based name you're telling JBoss to offer is 'XAOracleDS'. Sooo, you need to look for that name in your code (e.g., 'java:/comp/env/jdbc/XAOracleDS') vs 'jdbc/myoracle'.

                      Try that once and see what happens. Also, should you get a traceback, you only need to post the first couple of lines, the remainder 90% is usually not helpful.

                      • 8. Re: Create an application with Jboss
                        Esther Delgado Newbie

                        Hello!
                        I made the changes you suggested in my servlet, that is,

                        out = response.getWriter();
                        Context initContext = new InitialContext();
                        Context envContext = (Context)initContext.lookup("java:/comp/env");
                        DataSource ds = (DataSource)envContext.lookup("java:/comp/env/jdbc/XAOracleDS");
                        Connection conn = ds.getConnection();
                        String sql = "SELECT nombre FROM candidatos WHERE id_cand=49851";

                        and that's the error I get in Apache

                        error: comp not bound

                        and the ones i get in Jboss

                        16:44:07,480 INFO [STDOUT] javax.naming.NameNotFoundException: comp not bound
                        16:44:07,482 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
                        16:44:07,697 INFO [STDOUT] at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
                        16:44:07,697 INFO [STDOUT] at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
                        16:44:07,698 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
                        16:44:07,698 INFO [STDOUT] at org.jnp.server.NamingServer.lookup(NamingServer.java:256)
                        16:44:07,806 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:529)
                        16:44:07,807 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:508)
                        16:44:07,807 INFO [STDOUT] at servlet.DataBaseServlet.doGet(DataBaseServlet.java:41)
                        16:44:07,808 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
                        16:44:07,922 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                        16:44:07,923 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)

                        I've tried all the possible combinations, with no success. Is there any other way to solve my problem? What's exactly what I've to do to configure this connection pool?

                        Thanks again,
                        Esther

                        • 9. 3848946
                          Russ Loucks Newbie

                          Esther,

                          I think the problem (now is how you're specifying the JNDI-based name to the 'lookup()' method. Here's some code I used for a BMP bean I wrote:

                           private DataSource jdbcFactory;
                          
                           private Connection getConnection () throws Exception {
                           InitialContext c = null;
                           Connection conn = null;
                          
                           try {
                           if (jdbcFactory == null) {
                           c = new InitialContext();
                           jdbcFactory = (DataSource) c.lookup
                           ("java:comp/env/jdbc/MySQL-esb");
                           }
                           conn = jdbcFactory.getConnection();
                           } catch (Exception e) {
                           throw e;
                           }
                           return conn;
                           }
                          

                          Try specifying the name as 'java:comp/env/jdbc/...' vs. 'java:/comp/env/jdbc/...' and see what happens.

                          • 10. Re: Create an application with Jboss
                            Esther Delgado Newbie

                            I entered here to tell you I solved my problem when I see your answer.
                            Finally, I changed my oracle-xa-ds.xml for the oracle-ds.xml defined in docs/examples/jca, changing the url, user and passwords.
                            In my servlet, i made the connection in that way..

                            DataSource ds = (DataSource)initContext.lookup("java:/OracleDS");
                            Connection conn = ds.getConnection();

                            as I found in I-don't-know-which forum.

                            Then, an error appeared, telling me it wasn't able to find oracle.dms.consolo.DMSconsole class. So a friend of my sent me the file and it worked!!!

                            Thanks for everything. I couldn't see where the mistake was without your help. I didn't realize I wasn't calling the ddbb with the appropiate name.

                            You're the only one who has spent time with me... Thanks a lot!!!

                            Huge kisses,
                            Esther

                            • 11. Re: Create an application with Jboss
                              Russ Loucks Newbie

                              Glad to hear you're on your way....

                              • 12. Re: Create an application with Jboss
                                VikramjitSingh Newbie

                                Hi,
                                Am also having same problem could u send me that file.
                                or u can send me the link to download it.

                                thanks.