1

I have a problem in a system that I am working as back-end support for. I need to write a test that calls one of the classes handeling the communications with our database so I can log out what it actually returns.

System setup

Our system is developed in Java and deployed on a weblogic server. It consists of many parts that I will not go into detail on here. But the interesting part is that we have a class acting as an adapter for our database. We call it "CMAdapter" and it is an implementations of IBM Content Manager specific code to handle interaction with our database. In this class we have a methid called fetchAct() that take one object with search parameters as an argument and it returns the result of the search. In this case it returns one act. The code we have is running on a weblogic server, that has an IBM Information Integrator for Content installed so that it can communicate with IBM Content Manager that is installed and running on a different server. The system is deployed on the server using a .ejb and a few .jar files.

The problem

I have recieved a case stating that for some acts the users are not recieving the full act as expected but only parts of it. The system itself displays no errors and the documents are present in the database. So what I am trying to do is write a simple test program that calls this "CMAdapter" with a predetermined set of searchcriteria so that I may log out the return of the search.

My question

How can I make a freestading class with a main() method and run it on the server? I need to make a call to the CMAdapter.fetchAct() method in a way so it runs on the server like any normal query?

My test class


    public class TestHamtaAkt
    {    
        public static void main(String[] args) throws BasException
        {
            Log LOG = Log.getLog(TestHamtaAkt.class);

            // Get the CMAdapter
            CMAdapter cmadapter = new CMAdapter();
            // Create empty instance of our query object
            SokVO sokvo = new SokVO(); 

            // Put a value to search for in our query object
            AttributVO aktAttribut = new AttributVO();
            aktAttribut.setNamn(DLAKonstanter.AKT_KORT_R_KOD); 
            aktAttribut.setVarde("090084831574");
            sokvo.aktAttributLista().add(aktAttribut);

            // do the search an recieve the answer
            AktVO  aktvo = cmadapter.hamtaAkt(sokvo);

            // log out the result
            LOG.debug("main", "Akten som hämtades: " + aktvo.toString(), null);
        }
    }
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

0

Thanks to all for reading my question. It appears I have found the answer to my own question. It was hiding with a collegue of mine. The answer to my problem was, to be able to access the server deployed code, I need to get the JNDI context from my webserver and from that do a jndi lookup for the class I need.

I still have some problems making the connection but that is problably just my configurations that are off. I now know how I get a simple java class to make a call to a deployed class on a server.

here is the code I am currently using to get the context from the WLS server:


    private static InitialContext getWLSContext(String url) throws NamingException
    {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, WLS_CONTEXT_FACTORY);
        //env.put(Context.PROVIDER_URL, "t3://" + host + ":" + port);
        env.put(Context.PROVIDER_URL, url);

        return new InitialContext(env);
    }

This is my code for geting the class I need.



    public static EJBObject getRemote(String url, String jndiname, Class homeClass, AppserverTyp typ) throws Exception
    {
      Object obj = getWLSContext(url).lookup(jndiname);
      EJBHome home = (EJBHome) javax.rmi.PortableRemoteObject.narrow(obj, homeClass);

      Class homeBase = home.getClass();
      Method m = homeBase.getMethod("create", (Class[])null);
      EJBObject remote = (EJBObject) m.invoke(home, (Object[])null);
      return remote;
   }

I hope this helps someone with a similar problem to move forward. Like I said I have still to actually get this code working for me but my this is the answer to my initial question on how to make a call to a deployed method from an external class.