How to return error from OFBiz service

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

How to return error from OFBiz service

debmalya.biswas
I am using a seca to validate a field's value from the database. If the field value doesn't match with required string it will return error with some string using ServiceUtil.returnError(String);

When using ServiceUtil.returnError("Some error messages."). OFBiz show the error message

The Following Errors Occurred:

Error calling event: org.ofbiz.webapp.event.EventHandlerException: Service invocation error (No transaction manager or invalid status)

But however it will log the message correctly in log file.
Message: Error in Service [checkProduct]: Not my product

I want to show only the error message string which I pass in the ServiceUtil.returnError method. How should I achieve that? Am I missing something? The sample code is below:

Service eca:

<eca service="createProduct" event="commit">
    <action mode="sync" service="checkProduct"/>
</eca>

service_validator:

<service name="checkProduct" engine="java" location="mypackage.validation.ValidationServices"
         invoke="checkProduct" auth="true">
        <description></description>
        <attribute name="productId" mode="IN" type="String"/>
</service>

ValidationServices.java:

public static Map<String, Object> checkProduct(DispatchContext dctx, Map<String, ?> context) {
    String productId = (String) context.get("productId");
    if (productId.equals("Not my product")); {
        ServiceUtil.returnError("Not my product");
    }
    ServiceUtil.returnSuccess();
}