You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/03/27 21:42:30 UTC
svn commit: r523051 -
/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/XmlRpcEventHandler.java
Author: jaz
Date: Tue Mar 27 12:42:29 2007
New Revision: 523051
URL: http://svn.apache.org/viewvc?view=rev&rev=523051
Log:
XML-RPC now will accept un-named services parmeters in order which they appear in the servicedef
Modified:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/XmlRpcEventHandler.java
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/XmlRpcEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/XmlRpcEventHandler.java?view=diff&rev=523051&r1=523050&r2=523051
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/XmlRpcEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/XmlRpcEventHandler.java Tue Mar 27 12:42:29 2007
@@ -39,6 +39,8 @@
import java.io.OutputStream;
import java.io.IOException;
import java.util.Map;
+import java.util.Locale;
+import java.util.Iterator;
import javolution.util.FastMap;
@@ -150,12 +152,7 @@
String serviceName = xmlRpcReq.getMethodName();
// prepare the context -- single parameter type struct (map)
- Map context;
- if (xmlRpcReq.getParameterCount() == 0) {
- context = FastMap.newInstance();
- } else {
- context = (Map) xmlRpcReq.getParameter(0);
- }
+ Map context = this.getContext(xmlRpcReq, serviceName);
// add in auth parameters
XmlRpcHttpRequestConfig config = (XmlRpcHttpRequestConfig) xmlRpcReq.getConfig();
@@ -166,6 +163,9 @@
context.put("login.password", password);
}
+ // add the locale to the context
+ context.put("locale", Locale.getDefault());
+
// invoke the service
Map resp;
try {
@@ -178,6 +178,53 @@
}
return resp;
+ }
+
+ protected Map getContext(XmlRpcRequest xmlRpcReq, String serviceName) throws XmlRpcException {
+ ModelService model;
+ try {
+ model = dispatcher.getDispatchContext().getModelService(serviceName);
+ } catch (GenericServiceException e) {
+ throw new XmlRpcException(e.getMessage(), e);
+ }
+
+ // context placeholder
+ Map context = FastMap.newInstance();
+
+ if (model != null) {
+ int parameterCount = xmlRpcReq.getParameterCount();
+
+ // more than one parameter; use list notation based on service def order
+ if (parameterCount > 1) {
+ int x = 0;
+ Iterator i = model.getInParamNames().iterator();
+ while (i.hasNext()) {
+ String name = (String) i.next();
+ context.put(name, xmlRpcReq.getParameter(x));
+ x++;
+
+ if (x == parameterCount) {
+ break;
+ }
+ }
+
+ // only one parameter; if its a map use it as the context; otherwise make sure the service takes one param
+ } else if (parameterCount == 1) {
+ Object param = xmlRpcReq.getParameter(0);
+ if (param instanceof Map) {
+ context = (Map) param;
+ } else {
+ if (model.getDefinedInCount() == 1) {
+ String paramName = (String) model.getInParamNames().iterator().next();
+ context.put(paramName, xmlRpcReq.getParameter(0));
+ } else {
+ throw new XmlRpcException("More than one parameter defined on service; cannot call via RPC with parameter list");
+ }
+ }
+ }
+ }
+
+ return context;
}
}