You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by er...@apache.org on 2010/06/29 20:43:57 UTC
svn commit: r959071 - in /ofbiz/trunk: ./ framework/base/lib/
framework/service/config/ framework/service/dtd/
framework/service/servicedef/ framework/service/src/org/ofbiz/service/config/
framework/service/src/org/ofbiz/service/engine/ framework/servi...
Author: erwan
Date: Tue Jun 29 18:43:56 2010
New Revision: 959071
URL: http://svn.apache.org/viewvc?rev=959071&view=rev
Log:
OFBIZ-3798 Add xml-rpc engine on serviceengine - (https://issues.apache.org/jira/browse/OFBIZ-3798)
A patch from Nicolas Malin - adding a generic service to call xml-rpc server. The goal is to have a technical interface to make calls directly from mini-lang.
Added:
ofbiz/trunk/framework/base/lib/xmlrpc-client-3.0.jar (with props)
ofbiz/trunk/framework/base/lib/xmlrpc-common-3.0.jar (with props)
ofbiz/trunk/framework/base/lib/xmlrpc-server-3.0.jar (with props)
ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/XMLRPCClientEngine.java (with props)
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/AbstractXmlRpcTestCase.java (with props)
ofbiz/trunk/framework/service/src/org/ofbiz/service/test/XmlRpcTests.java (with props)
ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/
ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/AliasSupportedTransportFactory.java (with props)
ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/XmlRpcClient.java (with props)
Removed:
ofbiz/trunk/framework/webapp/lib/xmlrpc-client-3.0.jar
ofbiz/trunk/framework/webapp/lib/xmlrpc-common-3.0.jar
ofbiz/trunk/framework/webapp/lib/xmlrpc-server-3.0.jar
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/AbstractXmlRpcTestCase.java
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/test/XmlRpcTests.java
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/xmlrpc/AliasSupportedTransportFactory.java
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/xmlrpc/XmlRpcClient.java
Modified:
ofbiz/trunk/.classpath
ofbiz/trunk/LICENSE
ofbiz/trunk/framework/service/config/serviceengine.xml
ofbiz/trunk/framework/service/dtd/service-config.xsd
ofbiz/trunk/framework/service/servicedef/services_test_se.xml
ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java
ofbiz/trunk/framework/service/testdef/servicetests.xml
Modified: ofbiz/trunk/.classpath
URL: http://svn.apache.org/viewvc/ofbiz/trunk/.classpath?rev=959071&r1=959070&r2=959071&view=diff
==============================================================================
--- ofbiz/trunk/.classpath (original)
+++ ofbiz/trunk/.classpath Tue Jun 29 18:43:56 2010
@@ -46,6 +46,9 @@
<classpathentry kind="lib" path="framework/base/lib/xml-apis-2.9.1.jar"/>
<classpathentry kind="lib" path="framework/base/lib/xml-apis-ext-1.3.04.jar"/>
<classpathentry kind="lib" path="framework/base/lib/xmlgraphics-commons-1.3.1.jar"/>
+ <classpathentry kind="lib" path="framework/base/lib/xmlrpc-client-3.0.jar"/>
+ <classpathentry kind="lib" path="framework/base/lib/xmlrpc-common-3.0.jar"/>
+ <classpathentry kind="lib" path="framework/base/lib/xmlrpc-server-3.0.jar"/>
<classpathentry kind="lib" path="framework/base/lib/xstream-1.3.1.jar"/>
<classpathentry kind="lib" path="framework/base/lib/xpp3_min-1.1.4c.jar"/>
<classpathentry kind="lib" path="framework/base/lib/commons/commons-beanutils-1.7.0.jar"/>
@@ -146,9 +149,6 @@
<classpathentry kind="lib" path="framework/webapp/lib/velocity-1.6.1.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/ws-commons-java5-1.0.1.jar"/>
<classpathentry kind="lib" path="framework/webapp/lib/ws-commons-util-1.0.1.jar"/>
- <classpathentry kind="lib" path="framework/webapp/lib/xmlrpc-client-3.0.jar"/>
- <classpathentry kind="lib" path="framework/webapp/lib/xmlrpc-common-3.0.jar"/>
- <classpathentry kind="lib" path="framework/webapp/lib/xmlrpc-server-3.0.jar"/>
<classpathentry kind="lib" path="framework/base/lib/webslinger-base-invoker-20091211-3897-7ab22baea4b6.jar"/>
<classpathentry kind="lib" path="framework/webslinger/lib/webslinger-20091211-3897-7ab22baea4b6.jar"/>
<classpathentry kind="lib" path="framework/webslinger/lib/webslinger-base-cache-20091211-3897-7ab22baea4b6.jar"/>
Modified: ofbiz/trunk/LICENSE
URL: http://svn.apache.org/viewvc/ofbiz/trunk/LICENSE?rev=959071&r1=959070&r2=959071&view=diff
==============================================================================
--- ofbiz/trunk/LICENSE (original)
+++ ofbiz/trunk/LICENSE Tue Jun 29 18:43:56 2010
@@ -65,6 +65,9 @@ ofbiz/trunk/framework/base/lib/j2eespecs
ofbiz/trunk/framework/base/lib/scripting/bsf-2.4.0.jar
ofbiz/trunk/framework/base/lib/scripting/jakarta-oro-2.0.8.jar
ofbiz/trunk/framework/base/lib/scripting/groovy-all-1.7.3.jar
+ofbiz/trunk/framework/base/lib/xmlrpc-client-3.0.jar
+ofbiz/trunk/framework/base/lib/xmlrpc-common-3.0.jar
+ofbiz/trunk/framework/base/lib/xmlrpc-server-3.0.jar
ofbiz/trunk/framework/catalina/lib/tomcat-6.0.26-catalina-ha.jar
ofbiz/trunk/framework/catalina/lib/tomcat-6.0.26-catalina-tribes.jar
ofbiz/trunk/framework/catalina/lib/tomcat-6.0.26-catalina.jar
@@ -104,9 +107,6 @@ ofbiz/trunk/framework/webapp/lib/ezmorph
ofbiz/trunk/framework/webapp/lib/rome-0.9.jar
ofbiz/trunk/framework/webapp/lib/serializer-2.7.0.jar
ofbiz/trunk/framework/webapp/lib/xalan-2.7.1.jar
-ofbiz/trunk/framework/webapp/lib/xmlrpc-client-3.0.jar
-ofbiz/trunk/framework/webapp/lib/xmlrpc-common-3.0.jar
-ofbiz/trunk/framework/webapp/lib/xmlrpc-server-3.0.jar
ofbiz/trunk/framework/webapp/lib/ws-commons-java5-1.0.1.jar
ofbiz/trunk/framework/webapp/lib/ws-commons-util-1.0.1.jar
ofbiz/trunk/framework/geronimo/lib/geronimo-connector-2.1.1.jar
Added: ofbiz/trunk/framework/base/lib/xmlrpc-client-3.0.jar
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/lib/xmlrpc-client-3.0.jar?rev=959071&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ofbiz/trunk/framework/base/lib/xmlrpc-client-3.0.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: ofbiz/trunk/framework/base/lib/xmlrpc-common-3.0.jar
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/lib/xmlrpc-common-3.0.jar?rev=959071&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ofbiz/trunk/framework/base/lib/xmlrpc-common-3.0.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: ofbiz/trunk/framework/base/lib/xmlrpc-server-3.0.jar
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/lib/xmlrpc-server-3.0.jar?rev=959071&view=auto
==============================================================================
Binary file - no diff available.
Propchange: ofbiz/trunk/framework/base/lib/xmlrpc-server-3.0.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: ofbiz/trunk/framework/service/config/serviceengine.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/config/serviceengine.xml?rev=959071&r1=959070&r2=959071&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/config/serviceengine.xml (original)
+++ ofbiz/trunk/framework/service/config/serviceengine.xml Tue Jun 29 18:43:56 2010
@@ -58,7 +58,11 @@ under the License.
<engine name="ofbiz-workflow" class="org.ofbiz.workflow.WorkflowEngine"/>
<engine name="workflow" class="org.ofbiz.shark.service.SharkServiceEngine"/>
<engine name="webslinger-server" class="org.ofbiz.webslinger.WebslingerServerEngine"/>
-
+ <engine name="xml-rpc-local" class="org.ofbiz.service.engine.XMLRPCClientEngine">
+ <parameter name="url" value="http://localhost:8080/webtools/control/xmlrpc"/>
+ <parameter name="login" value="admin"/>
+ <parameter name="password" value="ofbiz"/>
+ </engine>
<service-location name="main-rmi" location="rmi://localhost:1099/RMIDispatcher"/>
<service-location name="main-http" location="http://localhost:8080/webtools/control/httpService"/>
Modified: ofbiz/trunk/framework/service/dtd/service-config.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/dtd/service-config.xsd?rev=959071&r1=959070&r2=959071&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/dtd/service-config.xsd (original)
+++ ofbiz/trunk/framework/service/dtd/service-config.xsd Tue Jun 29 18:43:56 2010
@@ -92,9 +92,26 @@ under the License.
</xs:attributeGroup>
<xs:element name="engine">
<xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" maxOccurs="unbounded" ref="parameter"/>
+ </xs:sequence>
<xs:attributeGroup ref="attlist.engine"/>
</xs:complexType>
</xs:element>
+ <xs:element name="parameter">
+ <xs:annotation>
+ <xs:documentation>
+ Technical parameters use by engine
+ </xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:attributeGroup ref="attlist.parameter"/>
+ </xs:complexType>
+ </xs:element>
+ <xs:attributeGroup name="attlist.parameter">
+ <xs:attribute type="xs:string" name="name" use="required"/>
+ <xs:attribute type="xs:string" name="value" use="required"/>
+ </xs:attributeGroup>
<xs:attributeGroup name="attlist.engine">
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:string" name="class" use="required"/>
Modified: ofbiz/trunk/framework/service/servicedef/services_test_se.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/servicedef/services_test_se.xml?rev=959071&r1=959070&r2=959071&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/servicedef/services_test_se.xml (original)
+++ ofbiz/trunk/framework/service/servicedef/services_test_se.xml Tue Jun 29 18:43:56 2010
@@ -83,4 +83,19 @@ under the License.
<service name="testServiceEcaGlobalEventExecOnRollback" engine="java" auth="false"
location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceEcaGlobalEventExecOnRollback">
</service>
+
+ <!-- Call xml rpc from engine -->
+ <service name="testXmlRpcAdd" engine="java" auth="false" location="org.ofbiz.service.test.XmlRpcTests" invoke="testXmlRpcAdd" export="true">
+ <attribute name="num1" mode="IN" type="Integer"/>
+ <attribute name="num2" mode="IN" type="Integer"/>
+ <attribute name="resulting" mode="OUT" type="Integer"/>
+ </service>
+ <service name="testXmlRpcLocalEngine" engine="xml-rpc-local" auth="false" invoke="testXmlRpcAdd">
+ <attribute name="num1" mode="IN" type="Integer"/>
+ <attribute name="num2" mode="IN" type="Integer"/>
+ <attribute name="resulting" mode="OUT" type="Integer"/>
+ </service>
+ <service name="testXmlRpcClientAdd" engine="java" auth="false" location="org.ofbiz.service.test.XmlRpcTests" invoke="testXmlRpcClientAdd">
+ <implements service="testServiceInterface"/>
+ </service>
</services>
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java?rev=959071&r1=959070&r2=959071&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java Tue Jun 29 18:43:56 2010
@@ -31,6 +31,8 @@ import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.cache.UtilCache;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
/**
* Misc. utility method for dealing with the serviceengine.xml file
@@ -144,6 +146,32 @@ public class ServiceConfigUtil implement
return null;
}
+
+ public static String getEngineParameter(String engineName, String name) throws GenericConfigException {
+ Element root = ServiceConfigUtil.getXmlRootElement();
+ Node node = root.getFirstChild();
+
+ if (node != null) {
+ do {
+ if (node.getNodeType() == Node.ELEMENT_NODE && "engine".equals(node.getLocalName())) {
+ Element engine = (Element) node;
+ if (engineName.equals(engine.getAttribute("name"))) {
+ NodeList params = engine.getElementsByTagName("parameter");
+ if (params.getLength() > 0) {
+ for (int index = 0; index < params.getLength(); index++) {
+ Element param = (Element) params.item(index);
+ if (param != null && name.equals(param.getAttribute("name"))) {
+ return (String) param.getAttribute("value");
+ }
+ }
+ }
+ }
+ }
+ } while ((node = node.getNextSibling()) != null);
+ }
+ return null;
+ }
+
public static class NotificationGroup implements Serializable {
protected Notification notification;
protected List<Notify> notify;
Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/XMLRPCClientEngine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/XMLRPCClientEngine.java?rev=959071&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/XMLRPCClientEngine.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/XMLRPCClientEngine.java Tue Jun 29 18:43:56 2010
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.service.engine;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.ofbiz.base.config.GenericConfigException;
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.ModelParam;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.service.ServiceDispatcher;
+import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.service.config.ServiceConfigUtil;
+import org.ofbiz.service.xmlrpc.XmlRpcClient;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Engine For XML RPC CLient Configuration management
+ */
+public class XMLRPCClientEngine extends GenericAsyncEngine {
+
+ public static final String module = XMLRPCClientEngine.class.getName();
+
+ public XMLRPCClientEngine(ServiceDispatcher dispatcher) {
+ super(dispatcher);
+ }
+
+ /**
+ * @see org.ofbiz.service.engine.GenericEngine#runSyncIgnore(java.lang.String, org.ofbiz.service.ModelService, java.util.Map)
+ */
+ @Override
+ public void runSyncIgnore(String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException {
+ runSync(localName, modelService, context);
+ }
+
+ /**
+ * @see org.ofbiz.service.engine.GenericEngine#runSync(java.lang.String, org.ofbiz.service.ModelService, java.util.Map)
+ */
+ @Override
+ public Map<String, Object> runSync(String localName, ModelService modelService, Map<String, Object> context) throws GenericServiceException {
+ Map<String, Object> result = serviceInvoker(modelService, context);
+
+ if (result == null)
+ throw new GenericServiceException("Service did not return expected result");
+ return result;
+ }
+
+ /*
+ * Invoke the remote XMLRPC SERVICE : This engine convert all value in IN mode to one struct.
+ */
+ private Map<String, Object> serviceInvoker(ModelService modelService, Map<String, Object> context) throws GenericServiceException {
+ if (modelService.location == null || modelService.invoke == null)
+ throw new GenericServiceException("Cannot locate service to invoke");
+
+ XmlRpcClientConfigImpl config = null;
+ XmlRpcClient client = null;
+ String serviceName = modelService.invoke;
+ String engine = modelService.engineName;
+ String url = null;
+ String login = null;
+ String password = null;
+ String keyStoreComponent = null;
+ String keyStoreName = null;
+ String keyAlias = null;
+ try {
+ url = ServiceConfigUtil.getEngineParameter(engine, "url");
+ login = ServiceConfigUtil.getEngineParameter(engine, "login");
+ password = ServiceConfigUtil.getEngineParameter(engine, "password");
+ keyStoreComponent = ServiceConfigUtil.getEngineParameter(engine, "keyStoreComponent");
+ keyStoreName = ServiceConfigUtil.getEngineParameter(engine, "keyStoreName");
+ keyAlias = ServiceConfigUtil.getEngineParameter(engine, "keyAlias");
+ config = new XmlRpcClientConfigImpl();
+ config.setBasicUserName(login);
+ config.setBasicPassword(password);
+ config.setServerURL(new URL(url));
+ }catch (MalformedURLException e) {
+ throw new GenericServiceException("Cannot invoke service : engine parameters are not correct");
+ }
+ catch (GenericConfigException e) {
+ throw new GenericServiceException("Cannot invoke service : engine parameters are not correct");
+ }
+ if(UtilValidate.isNotEmpty(keyStoreComponent) && UtilValidate.isNotEmpty(keyStoreName) && UtilValidate.isNotEmpty(keyAlias)){
+ client = new XmlRpcClient(config, keyStoreComponent, keyStoreName, keyAlias);
+ }
+ else{
+ client = new XmlRpcClient(config);
+ }
+ List<ModelParam> inModelParamList = modelService.getInModelParamList();
+
+ if (Debug.infoOn()) {
+ Debug.logInfo("[XMLRPCClientEngine.invoke] : Parameter length - " + inModelParamList.size(), module);
+ for (ModelParam p: inModelParamList) {
+ Debug.logInfo("[XMLRPCClientEngine.invoke} : Parameter: " + p.name + " (" + p.mode + ")", module);
+ }
+ }
+
+ Map<String, Object> result = null;
+ Map<String, Object> params = FastMap.newInstance();
+ for (ModelParam modelParam: modelService.getModelParamList()) {
+ // don't include OUT parameters in this list, only IN and INOUT
+ if ("OUT".equals(modelParam.mode) || modelParam.internal) continue;
+
+ Object paramValue = context.get(modelParam.name);
+ if (paramValue != null) {
+ params.put(modelParam.name, paramValue);
+ }
+ }
+
+ List<Map<String,Object>> listParams = UtilMisc.toList(params);
+ try{
+ result = UtilGenerics.cast(client.execute(serviceName, listParams.toArray()));
+ }catch (XmlRpcException e) {
+ result = ServiceUtil.returnError(e.getLocalizedMessage());
+ }
+ return result;
+ }
+}
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/XMLRPCClientEngine.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/XMLRPCClientEngine.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/engine/XMLRPCClientEngine.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/AbstractXmlRpcTestCase.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/test/AbstractXmlRpcTestCase.java?rev=959071&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/test/AbstractXmlRpcTestCase.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/test/AbstractXmlRpcTestCase.java Tue Jun 29 18:43:56 2010
@@ -0,0 +1,75 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+package org.ofbiz.service.test;
+
+import junit.framework.TestCase;
+import org.ofbiz.service.xmlrpc.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * AbstractXmlRpcTestCase
+ */
+public class AbstractXmlRpcTestCase extends TestCase {
+
+ public static final String module = AbstractXmlRpcTestCase.class.getName();
+
+ protected String keyStoreComponent;
+ protected String keyStoreName;
+ protected String keyAlias;
+
+ public AbstractXmlRpcTestCase(String name, String keyStoreComponent, String keyStoreName, String keyAlias) {
+ super(name);
+ this.keyStoreComponent = keyStoreComponent;
+ this.keyStoreName = keyStoreName;
+ this.keyAlias = keyAlias;
+ }
+
+ public AbstractXmlRpcTestCase(String name) {
+ super(name);
+ this.keyStoreComponent = null;
+ this.keyStoreName = null;
+ this.keyAlias = null;
+ }
+
+
+ public org.apache.xmlrpc.client.XmlRpcClient getRpcClient(String url) throws MalformedURLException {
+ return getRpcClient(url, null, null);
+ }
+
+ public org.apache.xmlrpc.client.XmlRpcClient getRpcClient(String url, String login, String password) throws MalformedURLException {
+ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
+ config.setServerURL(new URL(url));
+ if (login != null) {
+ config.setBasicUserName(login);
+ }
+ if (password != null) {
+ config.setBasicPassword(password);
+ }
+
+ if (keyStoreComponent != null && keyStoreName != null && keyAlias != null) {
+ return new XmlRpcClient(config, keyStoreComponent, keyStoreName, keyAlias);
+ } else {
+ return new XmlRpcClient(config);
+ }
+ }
+}
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/AbstractXmlRpcTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/AbstractXmlRpcTestCase.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/AbstractXmlRpcTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/XmlRpcTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/test/XmlRpcTests.java?rev=959071&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/test/XmlRpcTests.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/test/XmlRpcTests.java Tue Jun 29 18:43:56 2010
@@ -0,0 +1,94 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+package org.ofbiz.service.test;
+
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.ofbiz.base.util.UtilGenerics;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.ServiceUtil;
+
+import java.util.Map;
+
+/**
+ * XmlRpcTests
+ */
+public class XmlRpcTests extends AbstractXmlRpcTestCase {
+
+ public static final String module = XmlRpcTests.class.getName();
+ public static final String url = "http://localhost:8080/webtools/control/xmlrpc";
+
+ public XmlRpcTests(String name) {
+ super(name);
+ }
+
+ /**
+ * Test Xml Rpc by java class call with a Object List
+ * @throws Exception
+ */
+ public void testXmlRpcRequest() throws Exception {
+ XmlRpcClient client = this.getRpcClient(url, "admin", "ofbiz");
+ Object[] params = new Object[] { 55.00, "message from xml-rpc client" };
+ Map<String, Object> result = UtilGenerics.cast(client.execute("testScv", params));
+ assertEquals("XML-RPC Service result success", "service done", result.get("resp"));
+ }
+
+ /**
+ * Service to receive information from xml-rpc call
+ */
+ public static Map<String, Object> testXmlRpcAdd(DispatchContext dctx, Map<String, ?> context) {
+ Map<String, Object> response = ServiceUtil.returnSuccess();
+ Integer num1 = (Integer) context.get("num1");
+ Integer num2 = (Integer) context.get("num2");
+ if (UtilValidate.isEmpty(num1) || UtilValidate.isEmpty(num2)) {
+ return ServiceUtil.returnError("missing parameters");
+ }
+ Integer res = num1 + num2;
+ response.put("resulting", res);
+ return response;
+ }
+
+ /**
+ * Service to send information to xml-rpc service
+ */
+ public static Map<String, Object> testXmlRpcClientAdd(DispatchContext dctx, Map<String, ?> context) {
+ Map<String, Object> result = null;
+ Integer num1 = 125;
+ Integer num2 = 365;
+ try {
+ Map<String, Object> localMap = dctx.makeValidContext("testXmlRpcLocalEngine", "IN", context);
+ localMap.put("num1", num1);
+ localMap.put("num2", num2);
+ result = dctx.getDispatcher().runSync("testXmlRpcLocalEngine", localMap);
+ }
+ catch (GenericServiceException e) {
+ return ServiceUtil.returnError(e.getLocalizedMessage());
+ }
+ if (ServiceUtil.isError(result)) return result;
+ Integer res = (Integer) result.get("resulting");
+ if (res == (num1 + num2)) {
+ result = ServiceUtil.returnSuccess("adding integer 125 to 365 yields " + res);
+ } else {
+ result = ServiceUtil.returnError("calcul is wrong ! Why ?");
+ }
+ return result;
+ }
+}
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/XmlRpcTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/XmlRpcTests.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/XmlRpcTests.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/AliasSupportedTransportFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/AliasSupportedTransportFactory.java?rev=959071&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/AliasSupportedTransportFactory.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/AliasSupportedTransportFactory.java Tue Jun 29 18:43:56 2010
@@ -0,0 +1,142 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+package org.ofbiz.service.xmlrpc;
+
+import org.apache.xmlrpc.client.XmlRpcClientException;
+import org.apache.xmlrpc.client.XmlRpcHttpClientConfig;
+import org.apache.xmlrpc.client.XmlRpcHttpTransport;
+import org.apache.xmlrpc.client.XmlRpcTransport;
+import org.apache.xmlrpc.client.XmlRpcTransportFactoryImpl;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.util.HttpUtil;
+import org.apache.xmlrpc.common.XmlRpcStreamRequestConfig;
+import org.ofbiz.base.util.SSLUtil;
+import org.ofbiz.base.util.GeneralException;
+import org.xml.sax.SAXException;
+
+import javax.net.ssl.HttpsURLConnection;
+import java.security.KeyStore;
+import java.security.GeneralSecurityException;
+import java.net.URLConnection;
+import java.net.URL;
+import java.net.HttpURLConnection;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * AliasSupportedTransportFactory
+ */
+public class AliasSupportedTransportFactory extends XmlRpcTransportFactoryImpl {
+
+ private final AliasSupportedTransport transport;
+
+ public AliasSupportedTransportFactory(org.apache.xmlrpc.client.XmlRpcClient client, KeyStore ks, String password, String alias) {
+ super(client);
+ transport = new AliasSupportedTransport(client, ks, password, alias);
+ }
+
+ public XmlRpcTransport getTransport() {
+ return transport;
+ }
+
+ class AliasSupportedTransport extends XmlRpcHttpTransport {
+
+ protected static final String userAgent = USER_AGENT + " (Sun HTTP Transport)";
+ private URLConnection con;
+ private String password;
+ private String alias;
+ private KeyStore ks;
+
+ protected AliasSupportedTransport(org.apache.xmlrpc.client.XmlRpcClient client, KeyStore ks, String password, String alias) {
+ super(client, userAgent);
+ this.password = password;
+ this.alias = alias;
+ this.ks = ks;
+ }
+
+ @Override
+ public Object sendRequest(XmlRpcRequest req) throws XmlRpcException {
+ XmlRpcHttpClientConfig config = (XmlRpcHttpClientConfig) req.getConfig();
+ URL serverUrl = config.getServerURL();
+ if (serverUrl == null) {
+ throw new XmlRpcException("Invalid server URL");
+ }
+
+ try {
+ con = openConnection(serverUrl);
+ con.setUseCaches(false);
+ con.setDoInput(true);
+ con.setDoOutput(true);
+ } catch (IOException e) {
+ throw new XmlRpcException("Failed to create URLConnection: " + e.getMessage(), e);
+ }
+ return super.sendRequest(req);
+ }
+
+ protected URLConnection openConnection(URL url) throws IOException {
+ URLConnection con = url.openConnection();
+ if ("HTTPS".equalsIgnoreCase(url.getProtocol())) {
+ HttpsURLConnection scon = (HttpsURLConnection) con;
+ try {
+ scon.setSSLSocketFactory(SSLUtil.getSSLSocketFactory(ks, password, alias));
+ scon.setHostnameVerifier(SSLUtil.getHostnameVerifier(SSLUtil.HOSTCERT_MIN_CHECK));
+ } catch (GeneralException e) {
+ throw new IOException(e.getMessage());
+ } catch (GeneralSecurityException e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ return con;
+ }
+
+ @Override
+ protected void setRequestHeader(String header, String value) {
+ con.setRequestProperty(header, value);
+ }
+
+ @Override
+ protected void close() throws XmlRpcClientException {
+ if (con instanceof HttpURLConnection) {
+ ((HttpURLConnection) con).disconnect();
+ }
+ }
+
+ @Override
+ protected boolean isResponseGzipCompressed(XmlRpcStreamRequestConfig config) {
+ return HttpUtil.isUsingGzipEncoding(con.getHeaderField("Content-Encoding"));
+ }
+
+ @Override
+ protected InputStream getInputStream() throws XmlRpcException {
+ try {
+ return con.getInputStream();
+ } catch (IOException e) {
+ throw new XmlRpcException("Failed to create input stream: " + e.getMessage(), e);
+ }
+ }
+
+ @Override
+ protected void writeRequest(ReqWriter pWriter) throws IOException, XmlRpcException, SAXException {
+ pWriter.write(con.getOutputStream());
+ }
+ }
+}
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/AliasSupportedTransportFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/AliasSupportedTransportFactory.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/AliasSupportedTransportFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/XmlRpcClient.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/XmlRpcClient.java?rev=959071&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/XmlRpcClient.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/XmlRpcClient.java Tue Jun 29 18:43:56 2010
@@ -0,0 +1,69 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+package org.ofbiz.service.xmlrpc;
+
+import org.apache.xmlrpc.client.XmlRpcClientConfig;
+import org.apache.xmlrpc.client.XmlRpcTransportFactory;
+import org.ofbiz.base.component.ComponentConfig;
+import org.ofbiz.base.util.KeyStoreUtil;
+import org.ofbiz.base.util.Debug;
+
+import java.security.KeyStore;
+
+/**
+ * XmlRpcClient
+ */
+public class XmlRpcClient extends org.apache.xmlrpc.client.XmlRpcClient {
+
+ public static final String module = XmlRpcClient.class.getName();
+
+ protected String keyStoreComponent;
+ protected String keyStoreName;
+ protected String keyAlias;
+
+ public XmlRpcClient(XmlRpcClientConfig config, String keyStoreComponent, String keyStoreName, String keyAlias) {
+ this(config);
+ this.keyStoreComponent = keyStoreComponent;
+ this.keyStoreName = keyStoreName;
+ this.keyAlias = keyAlias;
+ this.setTransportFactory(this.getClientTransportFactory());
+ }
+
+ public XmlRpcClient(XmlRpcClientConfig config) {
+ super();
+ this.setConfig(config);
+ }
+
+ public XmlRpcTransportFactory getClientTransportFactory() {
+ if (keyStoreComponent == null || keyStoreName == null || keyAlias == null) {
+ return this.getTransportFactory();
+ }
+
+ ComponentConfig.KeystoreInfo ks = ComponentConfig.getKeystoreInfo(keyStoreComponent, keyStoreName);
+ KeyStore keyStore = null;
+ try {
+ keyStore = KeyStoreUtil.getStore(ks.createResourceHandler().getURL(), ks.getPassword(), ks.getType());
+ } catch (Exception e) {
+ Debug.logError(e, "Unable to load keystore: " + keyStoreName, module);
+ }
+
+ return new AliasSupportedTransportFactory(this, keyStore, ks.getPassword(), keyAlias);
+ }
+}
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/XmlRpcClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/XmlRpcClient.java
------------------------------------------------------------------------------
svn:keywords = "Date Rev Author URL Id"
Propchange: ofbiz/trunk/framework/service/src/org/ofbiz/service/xmlrpc/XmlRpcClient.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: ofbiz/trunk/framework/service/testdef/servicetests.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/testdef/servicetests.xml?rev=959071&r1=959070&r2=959071&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/testdef/servicetests.xml (original)
+++ ofbiz/trunk/framework/service/testdef/servicetests.xml Tue Jun 29 18:43:56 2010
@@ -65,4 +65,11 @@ under the License.
<test-case case-name="service-eca-global-event-exec-assert-data">
<entity-xml action="assert" entity-xml-url="component://service/testdef/data/ServiceEcaGlobalEventAssertData.xml"/>
</test-case>
+
+ <test-case case-name="service-xml-rpc">
+ <junit-test-suite class-name="org.ofbiz.service.test.XmlRpcTests"/>
+ </test-case>
+ <test-case case-name="service-xml-rpc-local-engine">
+ <service-test service-name="testXmlRpcClientAdd"/>
+ </test-case>
</test-suite>