0

How to call Event(Simple Method) for Ofbiz Service that written in Java.

is there a way? I am using rest api to Create Employee in ofbiz, i created a wrapper for rest and from rest controller I am calling services of my own and from there calling ofbiz services, but Some creation processes had written in simple methods.

How can I call these events that written in simple methods from Service?

Krishna
  • 353
  • 2
  • 15
  • Do you want to call an event written in Simple method or a service written in simple method? Please give me an example of the simple method you want to call. – Michael Brohl Jan 19 '17 at 17:20
  • I want to call event written in simple method from a service written in java – Krishna Jan 20 '17 at 09:09

2 Answers2

0

To call a simple method we should have two object

  1. dispatach context object
  2. map context

we can get dispatch contex object by

GenericDispatcher dispatcher = (GenericDispatcher)request.getAttribute("dispatcher");
DispatchContext dctx =  dispatcher.getDispatchContext();

In Java method/event, any service can be invoked by

GenericDispatcher dispatcher = (GenericDispatcher) request.getAttribute("dispatcher");
dispatcher.runSync("SERVICE_NAME", context);

context is map of required IN/IN-OUT parameters to service.This parameters cn be found in webtool > Service Engine > click on SERVICE_NAME

remember this

  1. runSync —which runs a service synchronously and returns the result as a map.
  2. runSyncIgnore —which runs a service synchronously and ignores the result.Nothing is passed back.
  3. runAsync —which runs a service asynchronously. Again, nothing is passed back.
naib khan
  • 928
  • 9
  • 16
0

Calling Simple Method from Java Service or Event

SimpleMethod.runSimpleEvent("Simple method file Location", "methodName", request, response);

To Get Request & Response Object From Service you have to pass those object as service parameter, like

<attribute name="request" mode="IN" type="javax.servlet.http.HttpServletRequest"/>
<attribute name="response" mode="IN" type="javax.servlet.http.HttpServletResponse"/>

// Retrieving Request & Response object from context paramters 
HttpServletRequest request = (HttpServletRequest) context.get("request");
HttpServletResponse response = (HttpServletResponse) context.get("response");

// For this you can refer payPalProcessor service definition...
ms74
  • 77
  • 1
  • 14