Results 1 to 2 of 2
  1. #1
    sjunejo is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Default Help: New to J2EE :(

    Hi guys,

    I am new to J2EE development and got a small utility (website) to be created which should be deployable on jBoss (for now) using Servlets.

    I have some knowledge of Web development and using that I have managed to create one small website and deplooyed on jBoss successfully. I can POST data successfully to the target and so far so good but jBhoss is already loaded with following resources;

    Resource Adaptor offering JNDI 'jca/xxConnectionFactory' using file called 'xxxxx-ra.rar' and 'xx-ds.xml' file. In 'xx-ds.xml' all the connection parameter to the Database server is defined like host, port, ....etc etc.

    Now my task is that on runtime user will enter 'connection pool (JNDI) as jca/xxConnectionFactory' on my small utlity and which I need to lookup, connect to it and send message via the resource adaptor which is offering the JNDI at first place within the Servlet.

    Can anyone here help me how and where to start...any good links on internet which give me basic knowledge of these things or code snippet. I tried following but got an exception;

    Java Code:
    Context env = null;
     
      try
      {
    	  env = (Context)new InitialContext().lookup("java:comp/env");
    	  Object homeRef = env.lookup(CxFactory);   // CxFactory is recieved from POST data 
    	  	  
    	  //close the InitialContext
    	  env.close();
     
    	  if (homeRef == null)
    	  {
    		  throw new ServletException(CxFactory + " is an unknown JNDI object");
    	  }
      }
      catch (NamingException ne)
      {
    	  try
    	  {
    		  env.close();
    	  }
    	  catch (NamingException nex)
    	  {
    	  }
     
    	  throw new ServletException(ne);
      }
    And I got following exception as soon as the Servlet loaded on jboss console;
    Java Code:
    14:43:20,931 ERROR [[AgentServlet]] Servlet.service() for servlet AgentServlet threw exception
    java.lang.NullPointerException
            at javax.naming.NameImpl.<init>(Unknown Source)
            at javax.naming.CompoundName.<init>(Unknown Source)
            at org.jnp.interfaces.NamingParser.parse(NamingParser.java:63)
            at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
            at client.AgentServlet.doGet(AgentServlet.java:66)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
            at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
            at java.lang.Thread.run(Unknown Source)
    Your help and suggestion will appreciated.

    Thanks

    --

    SJunejo

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    195
    Rep Power
    5

    Default

    I hate jboss...

    Have you tried running it in debug mode?

    here an example of my working jboss connection
    Java Code:
    public static Connection getOracleConnection() throws Exception
    	{
    		Connection con = null;
    		//Properties properties = System.getProperties();
    		try 
    		{
    			// Obtain our environment naming context
    			
    			Context initCtx = new InitialContext();
    			
    			Context envCtx = (Context) initCtx.lookup("java:comp/env");
    			
    			// Look up our data source
    			
    			DataSource ds = (DataSource) envCtx.lookup("jndi/OracleDSInternal");
    			
    			// this resource monitors the connection details
    			PrintWriter lw = new PrintWriter(System.out);
    			
    			ds.setLogWriter(lw);
    			
    			// Establish connection
    			con = ds.getConnection();
    	    } 
    		catch (Exception e) 
    		{
    			Utility.displayAndLogException("Utility.getOracleConnection() - " + e.getMessage(), e);
    		}
    		return con;
    	}
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

Similar Threads

  1. Migrate from PHP to J2EE
    By venky in forum Advanced Java
    Replies: 0
    Last Post: 06-01-2010, 10:24 PM
  2. Java J2ee 2 - 4 Exp
    By drvijayy2k2 in forum Jobs Offered
    Replies: 1
    Last Post: 10-26-2009, 10:53 PM
  3. Why to Use J2EE and Option for this.
    By mgrprasad90 in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-27-2008, 10:32 AM
  4. How to add JAR to EAR in eclipse J2EE
    By amorfis in forum Eclipse
    Replies: 1
    Last Post: 01-03-2008, 11:34 AM
  5. JAVA and J2EE
    By rgbosque in forum New To Java
    Replies: 9
    Last Post: 12-04-2007, 07:28 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •