1

I am using OfBiz 16.11.03 and try to implement some new services. Every service setup up with engine="entity-auto" works just fine. However, when I try to create a service with engine="java" during runtime, it fails locating the implementing class. Here's what I did: In hot-deploy folder, I have an ofbiz-component.xml specyfying

<service-resource type="model" loader="main" location="servicedef/services.xml"/>

In that services.xml in the folder servicedef, I have created a new service

<service name="getSomething" engine="java" 
            location="com.mycompany.myapp.services.SomeServices"
            invoke="getSomething"> 
         ... attributes and description
</service>            

Now, to implement the service, I create the implementing class under src/main/java/com/mycompany/myapp/services/SomeServices.java, where I implement

public static Map<String, Object> getSomething(DispatchContext dctx, 
                     Map<String, ? extends Object> context) {
    ....
}

To test the service, I open WebTools -> ServiceEngine -> run Service and enter "getSomething" as a service name, pool is left empty. I reach the form where I can input my IN parameters and try to run the service. An exception is thrown like

org.apache.ofbiz.service.GenericServiceException: 
Cannot find service [getSomething] location class (com.mycompany.myapp.services.SomeServices)

Of course, the plugin was created with gradlew createPlugin -PpluginId=myplugin, moved to hot-deploy and the corresponding entry was removed from the component-load.xml in specialpurpose, so the dispatcher exists.

Is there something missing?

UPDATE: It appeared that the ofbiz library was not set in the classpath of my application accordingly. I fixed it by adding <classpath type="jar" location="build/libs/*"/> to it (full ofbiz-component.xml see below). Now, SomeServices.class is put in the ofbiz.jar root, instead of com/mycompany/myapp/services/SomeServices.class. I can access the service by locating it at "SomeServices" in the service definition in services.xml, but I think there is some piece missing that puts SomeServices into the right folder...

Update #2: The IDE did not put the class SomeServices.java into the right package. Adding package com.mycompany.myapp.services; to the class fixed the problem.

Here is my ofbiz-component.xml:

<?xml version="1.0" encoding="UTF-8"?>

<!-- place the config directory on the classpath to access configuration files -->
<classpath type="dir" location="config"/>
<classpath type="dir" location="dtd"/>
<classpath type="jar" location="build/libs/*"/>

<!-- entity resources: model(s), eca(s), group, and data definitions -->
<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
<!-- <entity-resource type="eca" reader-name="main" loader="main" location="entitydef/eecas.xml"/> -->
<entity-resource type="data" reader-name="seed" loader="main" location="data/MyappTypeData.xml"/>
<entity-resource type="data" reader-name="seed" loader="main" location="data/MyappSecurityPermissionSeedData.xml"/>
<entity-resource type="data" reader-name="demo" loader="main" location="data/MyappSecurityGroupDemoData.xml"/>
<entity-resource type="data" reader-name="demo" loader="main" location="data/MyappDemoData.xml"/>

<!-- service resources: model(s), eca(s) and group definitions -->
<service-resource type="model" loader="main" location="servicedef/services.xml"/>
<!--
<service-resource type="eca" loader="main" location="servicedef/secas.xml"/>
<service-resource type="group" loader="main" location="servicedef/groups.xml"/>
-->


<test-suite loader="main" location="testdef/MyappTests.xml"/>

<!-- web applications; will be mounted when using the embedded container -->
<webapp name="myapp"
    title="Myapp"
    server="default-server"
    location="webapp/myapp"
    base-permission="OFBTOOLS,MYAPP"
    mount-point="/myapp"/>

sarathas
  • 25
  • 6

0 Answers0