1 24 package org.ofbiz.minilang.method.callops; 25 26 import java.util.HashMap ; 27 import java.util.Locale ; 28 import java.util.Map ; 29 30 import org.ofbiz.base.util.Debug; 31 import org.ofbiz.entity.GenericValue; 32 import org.ofbiz.minilang.SimpleMethod; 33 import org.ofbiz.minilang.method.ContextAccessor; 34 import org.ofbiz.minilang.method.MethodContext; 35 import org.ofbiz.minilang.method.MethodOperation; 36 import org.ofbiz.service.GenericServiceException; 37 import org.w3c.dom.Element ; 38 39 47 public class CallServiceAsynch extends MethodOperation { 48 49 public static final String module = CallServiceAsynch.class.getName(); 50 51 String serviceName; 52 ContextAccessor inMapAcsr; 53 String includeUserLoginStr; 54 55 public CallServiceAsynch(Element element, SimpleMethod simpleMethod) { 56 super(element, simpleMethod); 57 serviceName = element.getAttribute("service-name"); 58 inMapAcsr = new ContextAccessor(element.getAttribute("in-map-name")); 59 includeUserLoginStr = element.getAttribute("include-user-login"); 60 } 61 62 public boolean exec(MethodContext methodContext) { 63 String serviceName = methodContext.expandString(this.serviceName); 64 boolean includeUserLogin = !"false".equals(methodContext.expandString(includeUserLoginStr)); 65 66 Map inMap = null; 67 if (inMapAcsr.isEmpty()) { 68 inMap = new HashMap (); 69 } else { 70 inMap = (Map ) inMapAcsr.get(methodContext); 71 if (inMap == null) { 72 inMap = new HashMap (); 73 inMapAcsr.put(methodContext, inMap); 74 } 75 } 76 77 if (includeUserLogin) { 79 GenericValue userLogin = methodContext.getUserLogin(); 80 81 if (userLogin != null) 82 inMap.put("userLogin", userLogin); 83 } 84 85 Locale locale = methodContext.getLocale(); 87 if (locale != null) { 88 inMap.put("locale", locale); 89 } 90 91 try { 93 methodContext.getDispatcher().runAsync(serviceName, inMap); 94 } catch (GenericServiceException e) { 95 Debug.logError(e, module); 96 String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem invoking the " + serviceName + " service: " + e.getMessage() + "]"; 97 98 if (methodContext.getMethodType() == MethodContext.EVENT) { 99 methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); 100 methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); 101 } else if (methodContext.getMethodType() == MethodContext.SERVICE) { 102 methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); 103 methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); 104 } 105 return false; 106 } 107 108 return true; 109 } 110 111 public String rawString() { 112 return "<call-service-asynch/>"; 114 } 115 public String expandedString(MethodContext methodContext) { 116 return this.rawString(); 118 } 119 } 120 | Popular Tags |