Service cannot be called

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Service cannot be called

Sujit Joshi
 
Hello , I am ofbiz newbie. My first assignment says to write a servicedef.xml to invoke a serivce (method in Java). This is my servicedef.xml file :  
<?xml version="1.0" encoding="UTF-8" ?>

<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/services.xsd">
               
    <description>GreetUsers services</description>
   
    <service name="display_name" engine="java"
          location="in2m.Greet" invoke="greet" use-transaction="false">
        <description>Display the name of the user.</description>
        <attribute name="username" type="String" mode="IN" optional="false"/>
       
    </service>   
   
</services>



     I need to invoke this service by a JUnit testcase. So here goes my GreetTest.java(JUnit testcase)

package in2m;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.jxtest.JXComponentLoader;
import org.ofbiz.service.GenericDispatcher;
import org.ofbiz.service.LocalDispatcher;





public class GreetTest extends TestCase {

        public static final String module= GreetTest.class.getName();
         private Map obj = null;
         private GenericDelegator delegator;
         private LocalDispatcher dispatcher;
         
         public GreetTest(String name) {
                 super(name);
                 delegator = GenericDelegator.getGenericDelegator("default");
                 dispatcher = new GenericDispatcher("default",delegator);
         }

                /**
                 * @see TestCase#setUp()
                 */
                protected void setUp()
                {
                        try {
                                JXComponentLoader.loadComponents("default");
                        } catch (Exception e) {
                                e.printStackTrace();
                        }

                        Debug.logInfo("Getting default delegator", module);
                        setupEntityDelegator();
                        setupServiceDispatcher();
                }
               
                private void setupServiceDispatcher() {
                if(this.dispatcher == null){
                    dispatcher = new GenericDispatcher("default", this.delegator);
                    assertNotNull("Error creating dispatcher",this.dispatcher);
                }
                  }  

                private void setupEntityDelegator()
                {
                        try {
                                if(this.delegator == null ) {
                                        this.delegator = GenericDelegator.getGenericDelegator("default");
                                        assertNotNull(this.delegator);
                                }
                        } catch(Exception e) {
                                Debug.logError("Error creating delegator", module);
                                e.printStackTrace();
                        }
                }
               
         
         
         public void testFirstService(){
                 obj = new HashMap();
                 obj.put("username","Sujit");
                 try{
                         Map serviceResult = dispatcher.runSync("display_name", obj);
                         //System.out.println("This is the user name:"+(String)serviceResult.get("username"));
                         assertEquals("Sujit",(String)serviceResult.get("username"));
          }catch(Exception e){
                  e.printStackTrace();
                  }
          }
         
         public static  Test suite()
         {
                 TestSuite suite=new TestSuite();
                 suite.addTest(new GreetTest("testFirstService"));
                 return suite;
         }
         public static void main(String[] args)
         {  junit.textui.TestRunner.run(GreetTest.class);
                System.exit(0);
               
         }
}

By the way I am using Eclipse 3.1 . When I  run the test, I get one lengthy error on my console which says :

2007-11-21 10:09:09,130 (main) [GenericDelegator.java:getGenericDelegator:124 :INFO ] :: Creating new delegator [default] (main)

2007-11-21 10:09:09,209 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ] :: No ofbiz.home property set in environment

2007-11-21 10:09:09,217 (main) [EntityConfigUtil.java::91  :ERROR] ::
---- exception report ----------------------------------------------------------
Error loading entity config XML file entityengine.xml
Exception: org.ofbiz.entity.GenericEntityConfException
Message: Could not get entity engine XML root element (ERROR: could not find the [entityengine.xml] XML file on the classpath)
---- stack trace ---------------------------------------------------------------
org.ofbiz.entity.GenericEntityConfException: Could not get entity engine XML root element (ERROR: could not find the [entityengine.xml] XML file on the classpath)
org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:75)
org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
in2m.GreetNormal.(GreetNormal.java:18)
in2m.GreetNormal.main(GreetNormal.java:27)
org.ofbiz.base.config.GenericConfigException: ERROR: could not find the [entityengine.xml] XML file on the classpath
org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:73)
org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
in2m.GreetNormal.(GreetNormal.java:18)
in2m.GreetNormal.main(GreetNormal.java:27)
--------------------------------------------------------------------------------


2007-11-21 10:09:09,218 (main) [GenericDelegator.java:getGenericDelegator:129 :ERROR] ::
---- exception report ----------------------------------------------------------
Error creating delegator
Exception: org.ofbiz.entity.GenericEntityConfException
Message: Could not find a delegator with the name default
---- stack trace ---------------------------------------------------------------
org.ofbiz.entity.GenericEntityConfException: Could not find a delegator with the name default
org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:92)
org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
in2m.GreetNormal.(GreetNormal.java:18)
in2m.GreetNormal.main(GreetNormal.java:27)
--------------------------------------------------------------------------------


2007-11-21 10:09:09,219 (main) [GenericDelegator.java:getGenericDelegator:134 :ERROR] :: Could not create delegator with name default, constructor failed (got null value) not sure why/how.

2007-11-21 10:09:09,357 (main) [ServiceDispatcher.java::81  :INFO ] :: [ServiceDispatcher] : Creating new instance.

2007-11-21 10:09:09,384 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ] :: No ofbiz.home property set in environment

2007-11-21 10:09:09,385 (main) [ServiceGroupReader.java:readConfig:50  :ERROR] ::
---- exception report ----------------------------------------------------------
Error getting Service Engine XML root element
Exception: org.ofbiz.base.config.GenericConfigException
Message: ERROR: could not find the [serviceengine.xml] XML file on the classpath
---- stack trace ---------------------------------------------------------------
org.ofbiz.base.config.GenericConfigException: ERROR: could not find the [serviceengine.xml] XML file on the classpath
org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
org.ofbiz.service.group.ServiceGroupReader.readConfig(ServiceGroupReader.java:48)
org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:83)
org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
in2m.GreetNormal.(GreetNormal.java:19)
in2m.GreetNormal.main(GreetNormal.java:27)
--------------------------------------------------------------------------------


2007-11-21 10:09:09,391 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ] :: No ofbiz.home property set in environment

2007-11-21 10:09:09,392 (main) [ServiceEcaUtil.java:readConfig:64  :ERROR] ::
---- exception report ----------------------------------------------------------
Error getting Service Engine XML root element
Exception: org.ofbiz.base.config.GenericConfigException
Message: ERROR: could not find the [serviceengine.xml] XML file on the classpath
---- stack trace ---------------------------------------------------------------
org.ofbiz.base.config.GenericConfigException: ERROR: could not find the [serviceengine.xml] XML file on the classpath
org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
org.ofbiz.service.eca.ServiceEcaUtil.readConfig(ServiceEcaUtil.java:62)
org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:84)
org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
in2m.GreetNormal.(GreetNormal.java:19)
in2m.GreetNormal.main(GreetNormal.java:27)
--------------------------------------------------------------------------------


2007-11-21 10:09:09,425 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ] :: No ofbiz.home property set in environment

Exception in thread "main" java.lang.NullPointerException
        at org.ofbiz.service.job.JobManager.(JobManager.java:74)
        at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:101)
        at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
        at org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
        at org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
        at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
        at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
        at in2m.GreetNormal.(GreetNormal.java:19)
        at in2m.GreetNormal.main(GreetNormal.java:27)


Just to inform you I am troubleshooting for the last 2 days. Used all the tricks in the book.But to no avail.
I hope the information provided is sufficient enough. Thanks is advance.
Reply | Threaded
Open this post in threaded view
|

Re: Service cannot be called

cjhowe
Have you confirmed that your deployment is installed correctly?  Are you able to access any web applications.

----- Original Message ----
From: Sujit Joshi <[hidden email]>
To: [hidden email]
Sent: Tuesday, November 20, 2007 11:06:30 PM
Subject: Service cannot be called


 
Hello , I am ofbiz newbie. My first assignment says to write a
servicedef.xml to invoke a serivce (method in Java). This is my
servicedef.xml file :  
<?xml version="1.0" encoding="UTF-8" ?>

<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       
xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/services.xsd">
       
    <description>GreetUsers services</description>
   
    <service name="display_name" engine="java"
              location="in2m.Greet" invoke="greet"
 use-transaction="false">
        <description>Display the name of the user.</description>
        <attribute name="username" type="String" mode="IN"
optional="false"/>
       <!-- <attribute name="response" type="java.util.Map" mode="OUT"
optional="false"/>-->
    </service>  
   
</services>



     I need to invoke this service by a JUnit testcase. So here goes my
GreetTest.java(JUnit testcase)

package in2m;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.jxtest.JXComponentLoader;
import org.ofbiz.service.GenericDispatcher;
import org.ofbiz.service.LocalDispatcher;





public class GreetTest extends TestCase {

    public static final String module= GreetTest.class.getName();
     private Map obj = null;
     private GenericDelegator delegator;
     private LocalDispatcher dispatcher;
     
     public GreetTest(String name) {
         super(name);
         delegator = GenericDelegator.getGenericDelegator("default");
         dispatcher = new GenericDispatcher("default",delegator);
     }

        /**
         * @see TestCase#setUp()
         */
        protected void setUp()
        {
            try {
                JXComponentLoader.loadComponents("default");
            } catch (Exception e) {            
                e.printStackTrace();            
            }

            Debug.logInfo("Getting default delegator", module);        
            setupEntityDelegator();
            setupServiceDispatcher();
        }
       
        private void setupServiceDispatcher() {
            if(this.dispatcher == null){
                dispatcher = new GenericDispatcher("default",
 this.delegator);
                assertNotNull("Error creating
 dispatcher",this.dispatcher);
            }
          }  

        private void setupEntityDelegator()
        {
            try {
                if(this.delegator == null ) {
                    this.delegator =
 GenericDelegator.getGenericDelegator("default");
                    assertNotNull(this.delegator);
                }
            } catch(Exception e) {
                Debug.logError("Error creating delegator", module);
                e.printStackTrace();
            }
        }
       
     
     
     public void testFirstService(){
         obj = new HashMap();
         obj.put("username","Sujit");
         try{
             Map serviceResult = dispatcher.runSync("display_name",
 obj);
             //System.out.println("This is the user
name:"+(String)serviceResult.get("username"));
           
 assertEquals("Sujit",(String)serviceResult.get("username"));
      }catch(Exception e){
          e.printStackTrace();
          }
      }
     
     public static  Test suite()
     {
         TestSuite suite=new TestSuite();
         suite.addTest(new GreetTest("testFirstService"));
         return suite;
     }
     public static void main(String[] args)
     {  junit.textui.TestRunner.run(GreetTest.class);
        System.exit(0);
       
     }
}

By the way I am using Eclipse 3.1 . When I  run the test, I get one
 lengthy
error on my console which says :

2007-11-21 10:09:09,130 (main)
[GenericDelegator.java:getGenericDelegator:124 :INFO ] :: Creating new
delegator [default] (main)

2007-11-21 10:09:09,209 (main) [UtilURL.java:fromOfbizHomePath:110
 :WARN ]
:: No ofbiz.home property set in environment

2007-11-21 10:09:09,217 (main) [EntityConfigUtil.java::91  :ERROR] ::
---- exception report
----------------------------------------------------------
Error loading entity config XML file entityengine.xml
Exception: org.ofbiz.entity.GenericEntityConfException
Message: Could not get entity engine XML root element (ERROR: could not
 find
the [entityengine.xml] XML file on the classpath)
---- stack trace
---------------------------------------------------------------
org.ofbiz.entity.GenericEntityConfException: Could not get entity
 engine XML
root element (ERROR: could not find the [entityengine.xml] XML file on
 the
classpath)
org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:75)
org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
in2m.GreetNormal.(GreetNormal.java:18)
in2m.GreetNormal.main(GreetNormal.java:27)
org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
[entityengine.xml] XML file on the classpath
org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:73)
org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
in2m.GreetNormal.(GreetNormal.java:18)
in2m.GreetNormal.main(GreetNormal.java:27)
--------------------------------------------------------------------------------


2007-11-21 10:09:09,218 (main)
[GenericDelegator.java:getGenericDelegator:129 :ERROR] ::
---- exception report
----------------------------------------------------------
Error creating delegator
Exception: org.ofbiz.entity.GenericEntityConfException
Message: Could not find a delegator with the name default
---- stack trace
---------------------------------------------------------------
org.ofbiz.entity.GenericEntityConfException: Could not find a delegator
 with
the name default
org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:92)
org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
in2m.GreetNormal.(GreetNormal.java:18)
in2m.GreetNormal.main(GreetNormal.java:27)
--------------------------------------------------------------------------------


2007-11-21 10:09:09,219 (main)
[GenericDelegator.java:getGenericDelegator:134 :ERROR] :: Could not
 create
delegator with name default, constructor failed (got null value) not
 sure
why/how.

2007-11-21 10:09:09,357 (main) [ServiceDispatcher.java::81  :INFO ] ::
[ServiceDispatcher] : Creating new instance.

2007-11-21 10:09:09,384 (main) [UtilURL.java:fromOfbizHomePath:110
 :WARN ]
:: No ofbiz.home property set in environment

2007-11-21 10:09:09,385 (main) [ServiceGroupReader.java:readConfig:50
:ERROR] ::
---- exception report
----------------------------------------------------------
Error getting Service Engine XML root element
Exception: org.ofbiz.base.config.GenericConfigException
Message: ERROR: could not find the [serviceengine.xml] XML file on the
classpath
---- stack trace
---------------------------------------------------------------
org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
[serviceengine.xml] XML file on the classpath
org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
org.ofbiz.service.group.ServiceGroupReader.readConfig(ServiceGroupReader.java:48)
org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:83)
org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
in2m.GreetNormal.(GreetNormal.java:19)
in2m.GreetNormal.main(GreetNormal.java:27)
--------------------------------------------------------------------------------


2007-11-21 10:09:09,391 (main) [UtilURL.java:fromOfbizHomePath:110
 :WARN ]
:: No ofbiz.home property set in environment

2007-11-21 10:09:09,392 (main) [ServiceEcaUtil.java:readConfig:64
  :ERROR]
::
---- exception report
----------------------------------------------------------
Error getting Service Engine XML root element
Exception: org.ofbiz.base.config.GenericConfigException
Message: ERROR: could not find the [serviceengine.xml] XML file on the
classpath
---- stack trace
---------------------------------------------------------------
org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
[serviceengine.xml] XML file on the classpath
org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
org.ofbiz.service.eca.ServiceEcaUtil.readConfig(ServiceEcaUtil.java:62)
org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:84)
org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
in2m.GreetNormal.(GreetNormal.java:19)
in2m.GreetNormal.main(GreetNormal.java:27)
--------------------------------------------------------------------------------


2007-11-21 10:09:09,425 (main) [UtilURL.java:fromOfbizHomePath:110
 :WARN ]
:: No ofbiz.home property set in environment

Exception in thread "main" java.lang.NullPointerException
    at org.ofbiz.service.job.JobManager.(JobManager.java:74)
    at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:101)
    at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
    at
org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
    at
 org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
    at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
    at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
    at in2m.GreetNormal.(GreetNormal.java:19)
    at in2m.GreetNormal.main(GreetNormal.java:27)


Just to inform you I am troubleshooting for the last 2 days. Used all
 the
tricks in the book.But to no avail.
I hope the information provided is sufficient enough. Thanks is
 advance.
--
View this message in context:
 http://www.nabble.com/Service-cannot-be-called-tf4848124.html#a13871200
Sent from the OFBiz - User mailing list archive at Nabble.com.




Reply | Threaded
Open this post in threaded view
|

Re: Service cannot be called

BJ Freeman
In reply to this post by Sujit Joshi
first assignment should be to read the documentation on ofbiz.
http://docs.ofbiz.org/display/OFBADMIN/OFBiz+Documentation+Index
then go thru the code to find examples of what you want to do.
get something like xmlbuddy to view and create your xml files.
from what I see your xml is not formatted correctly.
ofcourse that may be you mail client to best to use attached files.


Sujit Joshi sent the following on 11/20/2007 8:57 PM:

> Hello ,
> I am ofbiz newbie. My first assignment says to write a servicedef.xml to
> invoke a serivce (method in Java).
> This is my servicedef.xml file :
> <?xml version="1.0" encoding="UTF-8" ?>
>
>
>
>     GreetUsers services
>    
>    
>         Display the name of the user.
>        
>        
>        
>
>
>
> I need to invoke this service by  a JUnit testcase. So here goes my
> GreetTest.java
>
> package in2m;
>
> import java.util.HashMap;
> import java.util.Map;
>
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
>
> import org.ofbiz.base.util.Debug;
> import org.ofbiz.entity.GenericDelegator;
> import org.ofbiz.jxtest.JXComponentLoader;
> import org.ofbiz.service.GenericDispatcher;
> import org.ofbiz.service.LocalDispatcher;
>
>
>
>
>
> public class GreetTest extends TestCase {
>
> public static final String module= GreetTest.class.getName();
> private Map obj = null;
> private GenericDelegator delegator;
> private LocalDispatcher dispatcher;
>
> public GreetTest(String name) {
> super(name);
> delegator = GenericDelegator.getGenericDelegator("default");
> dispatcher = new GenericDispatcher("default",delegator);
> }
>
> /**
> * @see TestCase#setUp()
> */
> protected void setUp()
> {
> try {
> JXComponentLoader.loadComponents("default");
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> Debug.logInfo("Getting default delegator", module);
> setupEntityDelegator();
> setupServiceDispatcher();
> }
>
> private void setupServiceDispatcher() {
>        if(this.dispatcher == null){
>            dispatcher = new GenericDispatcher("default", this.delegator);
>            assertNotNull("Error creating dispatcher",this.dispatcher);
>        }
>  }  
>
> private void setupEntityDelegator()
> {
> try {
> if(this.delegator == null ) {
> this.delegator = GenericDelegator.getGenericDelegator("default");
> assertNotNull(this.delegator);
> }
> } catch(Exception e) {
> Debug.logError("Error creating delegator", module);
> e.printStackTrace();
> }
> }
>
>
>
> public void testFirstService(){
> obj = new HashMap();
> obj.put("username","Sujit");
> try{
> Map serviceResult = dispatcher.runSync("display_name", obj);
> //System.out.println("This is the user
> name:"+(String)serviceResult.get("username"));
> assertEquals("Sujit",(String)serviceResult.get("username"));
>  }catch(Exception e){
>  e.printStackTrace();
>  }
>  }
>
> public static  Test suite()
> {
> TestSuite suite=new TestSuite();
> suite.addTest(new GreetTest("testFirstService"));
> return suite;
> }
> public static void main(String[] args)
> {  junit.textui.TestRunner.run(GreetTest.class);
> System.exit(0);
>
> }
> }
>
>
> By the way I am using Eclipse 3.1 . When I run the test I get one lengthy
> error on my console which is :
>
> 2007-11-21 10:09:09,130 (main)
> [GenericDelegator.java:getGenericDelegator:124 :INFO ] :: Creating new
> delegator [default] (main)
>
> 2007-11-21 10:09:09,209 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
> :: No ofbiz.home property set in environment
>
> 2007-11-21 10:09:09,217 (main) [EntityConfigUtil.java::91  :ERROR] ::
> ---- exception report
> ----------------------------------------------------------
> Error loading entity config XML file entityengine.xml
> Exception: org.ofbiz.entity.GenericEntityConfException
> Message: Could not get entity engine XML root element (ERROR: could not find
> the [entityengine.xml] XML file on the classpath)
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.entity.GenericEntityConfException: Could not get entity engine XML
> root element (ERROR: could not find the [entityengine.xml] XML file on the
> classpath)
> org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:75)
> org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
> in2m.GreetNormal.(GreetNormal.java:18)
> in2m.GreetNormal.main(GreetNormal.java:27)
> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
> [entityengine.xml] XML file on the classpath
> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
> org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:73)
> org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
> in2m.GreetNormal.(GreetNormal.java:18)
> in2m.GreetNormal.main(GreetNormal.java:27)
> --------------------------------------------------------------------------------
>
>
> 2007-11-21 10:09:09,218 (main)
> [GenericDelegator.java:getGenericDelegator:129 :ERROR] ::
> ---- exception report
> ----------------------------------------------------------
> Error creating delegator
> Exception: org.ofbiz.entity.GenericEntityConfException
> Message: Could not find a delegator with the name default
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.entity.GenericEntityConfException: Could not find a delegator with
> the name default
> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:92)
> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
> in2m.GreetNormal.(GreetNormal.java:18)
> in2m.GreetNormal.main(GreetNormal.java:27)
> --------------------------------------------------------------------------------
>
>
> 2007-11-21 10:09:09,219 (main)
> [GenericDelegator.java:getGenericDelegator:134 :ERROR] :: Could not create
> delegator with name default, constructor failed (got null value) not sure
> why/how.
>
> 2007-11-21 10:09:09,357 (main) [ServiceDispatcher.java::81  :INFO ] ::
> [ServiceDispatcher] : Creating new instance.
>
> 2007-11-21 10:09:09,384 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
> :: No ofbiz.home property set in environment
>
> 2007-11-21 10:09:09,385 (main) [ServiceGroupReader.java:readConfig:50
> :ERROR] ::
> ---- exception report
> ----------------------------------------------------------
> Error getting Service Engine XML root element
> Exception: org.ofbiz.base.config.GenericConfigException
> Message: ERROR: could not find the [serviceengine.xml] XML file on the
> classpath
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
> [serviceengine.xml] XML file on the classpath
> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
> org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
> org.ofbiz.service.group.ServiceGroupReader.readConfig(ServiceGroupReader.java:48)
> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:83)
> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
> org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
> in2m.GreetNormal.(GreetNormal.java:19)
> in2m.GreetNormal.main(GreetNormal.java:27)
> --------------------------------------------------------------------------------
>
>
> 2007-11-21 10:09:09,391 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
> :: No ofbiz.home property set in environment
>
> 2007-11-21 10:09:09,392 (main) [ServiceEcaUtil.java:readConfig:64  :ERROR]
> ::
> ---- exception report
> ----------------------------------------------------------
> Error getting Service Engine XML root element
> Exception: org.ofbiz.base.config.GenericConfigException
> Message: ERROR: could not find the [serviceengine.xml] XML file on the
> classpath
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
> [serviceengine.xml] XML file on the classpath
> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
> org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
> org.ofbiz.service.eca.ServiceEcaUtil.readConfig(ServiceEcaUtil.java:62)
> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:84)
> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
> org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
> in2m.GreetNormal.(GreetNormal.java:19)
> in2m.GreetNormal.main(GreetNormal.java:27)
> --------------------------------------------------------------------------------
>
>
> 2007-11-21 10:09:09,425 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
> :: No ofbiz.home property set in environment
>
> Exception in thread "main" java.lang.NullPointerException
> at org.ofbiz.service.job.JobManager.(JobManager.java:74)
> at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:101)
> at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
> at
> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
> at org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
> at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
> at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
> at in2m.GreetNormal.(GreetNormal.java:19)
> at in2m.GreetNormal.main(GreetNormal.java:27)
>
>
> Just to inform you I am troubleshooting for the last 2 days. I hope the
> information provided is sufficient enough.
> Thanks is advance.
>
Reply | Threaded
Open this post in threaded view
|

Re: Service cannot be called

BJ Freeman
http://ofbizwiki.go-integral.com/Wiki.jsp?page=ProposedOFBizTestFramework


BJ Freeman sent the following on 11/21/2007 12:48 AM:

> first assignment should be to read the documentation on ofbiz.
> http://docs.ofbiz.org/display/OFBADMIN/OFBiz+Documentation+Index
> then go thru the code to find examples of what you want to do.
> get something like xmlbuddy to view and create your xml files.
> from what I see your xml is not formatted correctly.
> ofcourse that may be you mail client to best to use attached files.
>
>
> Sujit Joshi sent the following on 11/20/2007 8:57 PM:
>> Hello ,
>> I am ofbiz newbie. My first assignment says to write a servicedef.xml to
>> invoke a serivce (method in Java).
>> This is my servicedef.xml file :
>> <?xml version="1.0" encoding="UTF-8" ?>
>>
>>
>>
>>     GreetUsers services
>>    
>>    
>>         Display the name of the user.
>>        
>>        
>>        
>>
>>
>>
>> I need to invoke this service by  a JUnit testcase. So here goes my
>> GreetTest.java
>>
>> package in2m;
>>
>> import java.util.HashMap;
>> import java.util.Map;
>>
>> import junit.framework.Test;
>> import junit.framework.TestCase;
>> import junit.framework.TestSuite;
>>
>> import org.ofbiz.base.util.Debug;
>> import org.ofbiz.entity.GenericDelegator;
>> import org.ofbiz.jxtest.JXComponentLoader;
>> import org.ofbiz.service.GenericDispatcher;
>> import org.ofbiz.service.LocalDispatcher;
>>
>>
>>
>>
>>
>> public class GreetTest extends TestCase {
>>
>> public static final String module= GreetTest.class.getName();
>> private Map obj = null;
>> private GenericDelegator delegator;
>> private LocalDispatcher dispatcher;
>>
>> public GreetTest(String name) {
>> super(name);
>> delegator = GenericDelegator.getGenericDelegator("default");
>> dispatcher = new GenericDispatcher("default",delegator);
>> }
>>
>> /**
>> * @see TestCase#setUp()
>> */
>> protected void setUp()
>> {
>> try {
>> JXComponentLoader.loadComponents("default");
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>>
>> Debug.logInfo("Getting default delegator", module);
>> setupEntityDelegator();
>> setupServiceDispatcher();
>> }
>>
>> private void setupServiceDispatcher() {
>>        if(this.dispatcher == null){
>>            dispatcher = new GenericDispatcher("default", this.delegator);
>>            assertNotNull("Error creating dispatcher",this.dispatcher);
>>        }
>>  }  
>>
>> private void setupEntityDelegator()
>> {
>> try {
>> if(this.delegator == null ) {
>> this.delegator = GenericDelegator.getGenericDelegator("default");
>> assertNotNull(this.delegator);
>> }
>> } catch(Exception e) {
>> Debug.logError("Error creating delegator", module);
>> e.printStackTrace();
>> }
>> }
>>
>>
>>
>> public void testFirstService(){
>> obj = new HashMap();
>> obj.put("username","Sujit");
>> try{
>> Map serviceResult = dispatcher.runSync("display_name", obj);
>> //System.out.println("This is the user
>> name:"+(String)serviceResult.get("username"));
>> assertEquals("Sujit",(String)serviceResult.get("username"));
>>  }catch(Exception e){
>>  e.printStackTrace();
>>  }
>>  }
>>
>> public static  Test suite()
>> {
>> TestSuite suite=new TestSuite();
>> suite.addTest(new GreetTest("testFirstService"));
>> return suite;
>> }
>> public static void main(String[] args)
>> {  junit.textui.TestRunner.run(GreetTest.class);
>> System.exit(0);
>>
>> }
>> }
>>
>>
>> By the way I am using Eclipse 3.1 . When I run the test I get one lengthy
>> error on my console which is :
>>
>> 2007-11-21 10:09:09,130 (main)
>> [GenericDelegator.java:getGenericDelegator:124 :INFO ] :: Creating new
>> delegator [default] (main)
>>
>> 2007-11-21 10:09:09,209 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
>> :: No ofbiz.home property set in environment
>>
>> 2007-11-21 10:09:09,217 (main) [EntityConfigUtil.java::91  :ERROR] ::
>> ---- exception report
>> ----------------------------------------------------------
>> Error loading entity config XML file entityengine.xml
>> Exception: org.ofbiz.entity.GenericEntityConfException
>> Message: Could not get entity engine XML root element (ERROR: could not find
>> the [entityengine.xml] XML file on the classpath)
>> ---- stack trace
>> ---------------------------------------------------------------
>> org.ofbiz.entity.GenericEntityConfException: Could not get entity engine XML
>> root element (ERROR: could not find the [entityengine.xml] XML file on the
>> classpath)
>> org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:75)
>> org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
>> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
>> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
>> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
>> in2m.GreetNormal.(GreetNormal.java:18)
>> in2m.GreetNormal.main(GreetNormal.java:27)
>> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
>> [entityengine.xml] XML file on the classpath
>> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
>> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
>> org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:73)
>> org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
>> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
>> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
>> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
>> in2m.GreetNormal.(GreetNormal.java:18)
>> in2m.GreetNormal.main(GreetNormal.java:27)
>> --------------------------------------------------------------------------------
>>
>>
>> 2007-11-21 10:09:09,218 (main)
>> [GenericDelegator.java:getGenericDelegator:129 :ERROR] ::
>> ---- exception report
>> ----------------------------------------------------------
>> Error creating delegator
>> Exception: org.ofbiz.entity.GenericEntityConfException
>> Message: Could not find a delegator with the name default
>> ---- stack trace
>> ---------------------------------------------------------------
>> org.ofbiz.entity.GenericEntityConfException: Could not find a delegator with
>> the name default
>> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:92)
>> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
>> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
>> in2m.GreetNormal.(GreetNormal.java:18)
>> in2m.GreetNormal.main(GreetNormal.java:27)
>> --------------------------------------------------------------------------------
>>
>>
>> 2007-11-21 10:09:09,219 (main)
>> [GenericDelegator.java:getGenericDelegator:134 :ERROR] :: Could not create
>> delegator with name default, constructor failed (got null value) not sure
>> why/how.
>>
>> 2007-11-21 10:09:09,357 (main) [ServiceDispatcher.java::81  :INFO ] ::
>> [ServiceDispatcher] : Creating new instance.
>>
>> 2007-11-21 10:09:09,384 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
>> :: No ofbiz.home property set in environment
>>
>> 2007-11-21 10:09:09,385 (main) [ServiceGroupReader.java:readConfig:50
>> :ERROR] ::
>> ---- exception report
>> ----------------------------------------------------------
>> Error getting Service Engine XML root element
>> Exception: org.ofbiz.base.config.GenericConfigException
>> Message: ERROR: could not find the [serviceengine.xml] XML file on the
>> classpath
>> ---- stack trace
>> ---------------------------------------------------------------
>> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
>> [serviceengine.xml] XML file on the classpath
>> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
>> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
>> org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
>> org.ofbiz.service.group.ServiceGroupReader.readConfig(ServiceGroupReader.java:48)
>> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:83)
>> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
>> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
>> org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
>> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
>> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
>> in2m.GreetNormal.(GreetNormal.java:19)
>> in2m.GreetNormal.main(GreetNormal.java:27)
>> --------------------------------------------------------------------------------
>>
>>
>> 2007-11-21 10:09:09,391 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
>> :: No ofbiz.home property set in environment
>>
>> 2007-11-21 10:09:09,392 (main) [ServiceEcaUtil.java:readConfig:64  :ERROR]
>> ::
>> ---- exception report
>> ----------------------------------------------------------
>> Error getting Service Engine XML root element
>> Exception: org.ofbiz.base.config.GenericConfigException
>> Message: ERROR: could not find the [serviceengine.xml] XML file on the
>> classpath
>> ---- stack trace
>> ---------------------------------------------------------------
>> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
>> [serviceengine.xml] XML file on the classpath
>> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
>> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
>> org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
>> org.ofbiz.service.eca.ServiceEcaUtil.readConfig(ServiceEcaUtil.java:62)
>> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:84)
>> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
>> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
>> org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
>> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
>> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
>> in2m.GreetNormal.(GreetNormal.java:19)
>> in2m.GreetNormal.main(GreetNormal.java:27)
>> --------------------------------------------------------------------------------
>>
>>
>> 2007-11-21 10:09:09,425 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
>> :: No ofbiz.home property set in environment
>>
>> Exception in thread "main" java.lang.NullPointerException
>> at org.ofbiz.service.job.JobManager.(JobManager.java:74)
>> at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:101)
>> at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
>> at
>> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
>> at org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
>> at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
>> at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
>> at in2m.GreetNormal.(GreetNormal.java:19)
>> at in2m.GreetNormal.main(GreetNormal.java:27)
>>
>>
>> Just to inform you I am troubleshooting for the last 2 days. I hope the
>> information provided is sufficient enough.
>> Thanks is advance.
>>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Service cannot be called

Brett
In reply to this post by Sujit Joshi
First of all I'm not sure the JXComponentLoader even works anymore.  I
wrote it to load the service and entity engine for local development
testing.  AFAIK it has not been maintained.

You could try setting an ofbiz.home environment variable for the junit
test you run in eclipse (I.e -Dofbiz.home=your path).

You can also run a unit test from the build.  There are some examples
in the code base for that.

You can also run your service from webtools to test it.


Brett

On 11/20/07, Sujit Joshi <[hidden email]> wrote:

>
> Hello ,
> I am ofbiz newbie. My first assignment says to write a servicedef.xml to
> invoke a serivce (method in Java).
> This is my servicedef.xml file :
> <?xml version="1.0" encoding="UTF-8" ?>
>
>
>
>     GreetUsers services
>
>
>         Display the name of the user.
>
>
>
>
>
>
> I need to invoke this service by  a JUnit testcase. So here goes my
> GreetTest.java
>
> package in2m;
>
> import java.util.HashMap;
> import java.util.Map;
>
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
>
> import org.ofbiz.base.util.Debug;
> import org.ofbiz.entity.GenericDelegator;
> import org.ofbiz.jxtest.JXComponentLoader;
> import org.ofbiz.service.GenericDispatcher;
> import org.ofbiz.service.LocalDispatcher;
>
>
>
>
>
> public class GreetTest extends TestCase {
>
> public static final String module= GreetTest.class.getName();
> private Map obj = null;
> private GenericDelegator delegator;
> private LocalDispatcher dispatcher;
>
> public GreetTest(String name) {
> super(name);
> delegator = GenericDelegator.getGenericDelegator("default");
> dispatcher = new GenericDispatcher("default",delegator);
> }
>
> /**
> * @see TestCase#setUp()
> */
> protected void setUp()
> {
> try {
> JXComponentLoader.loadComponents("default");
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> Debug.logInfo("Getting default delegator", module);
> setupEntityDelegator();
> setupServiceDispatcher();
> }
>
> private void setupServiceDispatcher() {
>        if(this.dispatcher == null){
>            dispatcher = new GenericDispatcher("default", this.delegator);
>            assertNotNull("Error creating dispatcher",this.dispatcher);
>        }
>  }
>
> private void setupEntityDelegator()
> {
> try {
> if(this.delegator == null ) {
> this.delegator = GenericDelegator.getGenericDelegator("default");
> assertNotNull(this.delegator);
> }
> } catch(Exception e) {
> Debug.logError("Error creating delegator", module);
> e.printStackTrace();
> }
> }
>
>
>
> public void testFirstService(){
> obj = new HashMap();
> obj.put("username","Sujit");
> try{
> Map serviceResult = dispatcher.runSync("display_name", obj);
> //System.out.println("This is the user
> name:"+(String)serviceResult.get("username"));
> assertEquals("Sujit",(String)serviceResult.get("username"));
>  }catch(Exception e){
>  e.printStackTrace();
>  }
>  }
>
> public static  Test suite()
> {
> TestSuite suite=new TestSuite();
> suite.addTest(new GreetTest("testFirstService"));
> return suite;
> }
> public static void main(String[] args)
> {  junit.textui.TestRunner.run(GreetTest.class);
> System.exit(0);
>
> }
> }
>
>
> By the way I am using Eclipse 3.1 . When I run the test I get one lengthy
> error on my console which is :
>
> 2007-11-21 10:09:09,130 (main)
> [GenericDelegator.java:getGenericDelegator:124 :INFO ] :: Creating new
> delegator [default] (main)
>
> 2007-11-21 10:09:09,209 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
> :: No ofbiz.home property set in environment
>
> 2007-11-21 10:09:09,217 (main) [EntityConfigUtil.java::91  :ERROR] ::
> ---- exception report
> ----------------------------------------------------------
> Error loading entity config XML file entityengine.xml
> Exception: org.ofbiz.entity.GenericEntityConfException
> Message: Could not get entity engine XML root element (ERROR: could not find
> the [entityengine.xml] XML file on the classpath)
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.entity.GenericEntityConfException: Could not get entity engine XML
> root element (ERROR: could not find the [entityengine.xml] XML file on the
> classpath)
> org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:75)
> org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
> in2m.GreetNormal.(GreetNormal.java:18)
> in2m.GreetNormal.main(GreetNormal.java:27)
> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
> [entityengine.xml] XML file on the classpath
> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
> org.ofbiz.entity.config.EntityConfigUtil.getXmlRootElement(EntityConfigUtil.java:73)
> org.ofbiz.entity.config.EntityConfigUtil.(EntityConfigUtil.java:89)
> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:89)
> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
> in2m.GreetNormal.(GreetNormal.java:18)
> in2m.GreetNormal.main(GreetNormal.java:27)
> --------------------------------------------------------------------------------
>
>
> 2007-11-21 10:09:09,218 (main)
> [GenericDelegator.java:getGenericDelegator:129 :ERROR] ::
> ---- exception report
> ----------------------------------------------------------
> Error creating delegator
> Exception: org.ofbiz.entity.GenericEntityConfException
> Message: Could not find a delegator with the name default
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.entity.GenericEntityConfException: Could not find a delegator with
> the name default
> org.ofbiz.entity.model.ModelReader.getModelReader(ModelReader.java:92)
> org.ofbiz.entity.GenericDelegator.(GenericDelegator.java:151)
> org.ofbiz.entity.GenericDelegator.getGenericDelegator(GenericDelegator.java:127)
> in2m.GreetNormal.(GreetNormal.java:18)
> in2m.GreetNormal.main(GreetNormal.java:27)
> --------------------------------------------------------------------------------
>
>
> 2007-11-21 10:09:09,219 (main)
> [GenericDelegator.java:getGenericDelegator:134 :ERROR] :: Could not create
> delegator with name default, constructor failed (got null value) not sure
> why/how.
>
> 2007-11-21 10:09:09,357 (main) [ServiceDispatcher.java::81  :INFO ] ::
> [ServiceDispatcher] : Creating new instance.
>
> 2007-11-21 10:09:09,384 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
> :: No ofbiz.home property set in environment
>
> 2007-11-21 10:09:09,385 (main) [ServiceGroupReader.java:readConfig:50
> :ERROR] ::
> ---- exception report
> ----------------------------------------------------------
> Error getting Service Engine XML root element
> Exception: org.ofbiz.base.config.GenericConfigException
> Message: ERROR: could not find the [serviceengine.xml] XML file on the
> classpath
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
> [serviceengine.xml] XML file on the classpath
> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
> org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
> org.ofbiz.service.group.ServiceGroupReader.readConfig(ServiceGroupReader.java:48)
> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:83)
> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
> org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
> in2m.GreetNormal.(GreetNormal.java:19)
> in2m.GreetNormal.main(GreetNormal.java:27)
> --------------------------------------------------------------------------------
>
>
> 2007-11-21 10:09:09,391 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
> :: No ofbiz.home property set in environment
>
> 2007-11-21 10:09:09,392 (main) [ServiceEcaUtil.java:readConfig:64  :ERROR]
> ::
> ---- exception report
> ----------------------------------------------------------
> Error getting Service Engine XML root element
> Exception: org.ofbiz.base.config.GenericConfigException
> Message: ERROR: could not find the [serviceengine.xml] XML file on the
> classpath
> ---- stack trace
> ---------------------------------------------------------------
> org.ofbiz.base.config.GenericConfigException: ERROR: could not find the
> [serviceengine.xml] XML file on the classpath
> org.ofbiz.base.config.ResourceLoader.getXmlDocument(ResourceLoader.java:107)
> org.ofbiz.base.config.ResourceLoader.getXmlRootElement(ResourceLoader.java:84)
> org.ofbiz.service.config.ServiceConfigUtil.getXmlRootElement(ServiceConfigUtil.java:44)
> org.ofbiz.service.eca.ServiceEcaUtil.readConfig(ServiceEcaUtil.java:62)
> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:84)
> org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
> org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
> org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
> in2m.GreetNormal.(GreetNormal.java:19)
> in2m.GreetNormal.main(GreetNormal.java:27)
> --------------------------------------------------------------------------------
>
>
> 2007-11-21 10:09:09,425 (main) [UtilURL.java:fromOfbizHomePath:110 :WARN ]
> :: No ofbiz.home property set in environment
>
> Exception in thread "main" java.lang.NullPointerException
> at org.ofbiz.service.job.JobManager.(JobManager.java:74)
> at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:101)
> at org.ofbiz.service.ServiceDispatcher.(ServiceDispatcher.java:117)
> at
> org.ofbiz.service.ServiceDispatcher.getInstance(ServiceDispatcher.java:151)
> at org.ofbiz.service.GenericDispatcher.init(GenericDispatcher.java:72)
> at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:49)
> at org.ofbiz.service.GenericDispatcher.(GenericDispatcher.java:37)
> at in2m.GreetNormal.(GreetNormal.java:19)
> at in2m.GreetNormal.main(GreetNormal.java:27)
>
>
> Just to inform you I am troubleshooting for the last 2 days. I hope the
> information provided is sufficient enough.
> Thanks is advance.
>
> --
> View this message in context:
> http://www.nabble.com/Service-cannot-be-called-tf4848069.html#a13871108
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>