camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1408301 - in /camel/trunk/components/camel-xmlrpc/src: main/java/org/apache/camel/component/xmlrpc/ main/java/org/apache/camel/component/xmlrpc/converter/ main/resources/META-INF/services/org/apache/camel/ test/java/org/apache/camel/compon...
Date Mon, 12 Nov 2012 14:25:48 GMT
Author: ningjiang
Date: Mon Nov 12 14:25:47 2012
New Revision: 1408301

URL: http://svn.apache.org/viewvc?rev=1408301&view=rev
Log:
CAMEL-5776 Added XmlRpcRequestConverter

Added:
    camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcRequestImpl.java
    camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/converter/
    camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverter.java
    camel/trunk/components/camel-xmlrpc/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
    camel/trunk/components/camel-xmlrpc/src/test/java/org/apache/camel/component/xmlrpc/converter/
    camel/trunk/components/camel-xmlrpc/src/test/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverterTest.java
Modified:
    camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcConstants.java

Modified: camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcConstants.java?rev=1408301&r1=1408300&r2=1408301&view=diff
==============================================================================
--- camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcConstants.java
(original)
+++ camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcConstants.java
Mon Nov 12 14:25:47 2012
@@ -18,6 +18,9 @@ package org.apache.camel.component.xmlrp
 
 public final class XmlRpcConstants {
     public static final String OPERATION_NAME = "CamelXmlRpcOperationName";
+    public static final String ERROR_CODE = "CamelXmlRpcErrorCode";
+    public static final String ERROR_MESSAGE = "CamelXmlRpcErrorMessage";
+    
     private XmlRpcConstants() {
         //Utils class
     }

Added: camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcRequestImpl.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcRequestImpl.java?rev=1408301&view=auto
==============================================================================
--- camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcRequestImpl.java
(added)
+++ camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcRequestImpl.java
Mon Nov 12 14:25:47 2012
@@ -0,0 +1,59 @@
+/**
+ * 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.apache.camel.component.xmlrpc;
+
+import java.util.List;
+
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.XmlRpcRequestConfig;
+
+public class XmlRpcRequestImpl implements XmlRpcRequest {
+    private static final Object[] ZERO_PARAMS = new Object[0];
+    private final String methodName;
+    private final Object[] params;
+    
+    public XmlRpcRequestImpl(String pMethodName, Object[] pParams) {
+        methodName = pMethodName;
+        if (methodName == null) {
+            throw new NullPointerException("The method name must not be null.");
+        }
+        params = pParams == null ? ZERO_PARAMS : pParams;
+    }
+    
+    public XmlRpcRequestImpl(String pMethodName, List<?> pParams) {
+        this(pMethodName, pParams == null ? null : pParams.toArray());
+    }
+
+    // we don't want to use the config here
+    public XmlRpcRequestConfig getConfig() {
+        return null;
+    }
+
+    public String getMethodName() {
+        return methodName;
+    }
+
+    public int getParameterCount() {
+        return params.length;
+    }
+
+    public Object getParameter(int pIndex) {
+        return params[pIndex];
+    }
+   
+
+}

Added: camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverter.java?rev=1408301&view=auto
==============================================================================
--- camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverter.java
(added)
+++ camel/trunk/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverter.java
Mon Nov 12 14:25:47 2012
@@ -0,0 +1,56 @@
+/**
+ * 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.apache.camel.component.xmlrpc.converter;
+
+import java.util.List;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.xmlrpc.XmlRpcConstants;
+import org.apache.camel.component.xmlrpc.XmlRpcRequestImpl;
+import org.apache.xmlrpc.XmlRpcRequest;
+
+@Converter
+public final class XmlRpcConverter {
+    
+    private XmlRpcConverter() {
+        //Helper class
+    }
+    
+    @Converter
+    public static XmlRpcRequest toXmlRpcRequest(final Object[] parameters, Exchange exchange)
{
+        // get the message operation name
+        String operationName = exchange.getIn().getHeader(XmlRpcConstants.OPERATION_NAME,
String.class);
+        
+        // create the request object here
+        XmlRpcRequest request = new XmlRpcRequestImpl(operationName, parameters);
+        
+        return request;
+    }
+    
+    @Converter
+    public static XmlRpcRequest toXmlRpcRequest(final List<?> parameters, Exchange
exchange) {
+        // get the message operation name
+        String operationName = exchange.getIn().getHeader(XmlRpcConstants.OPERATION_NAME,
String.class);
+        
+        // create the request object here
+        XmlRpcRequest request = new XmlRpcRequestImpl(operationName, parameters);
+        
+        return request;
+    }
+
+}

Added: camel/trunk/components/camel-xmlrpc/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmlrpc/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=1408301&view=auto
==============================================================================
--- camel/trunk/components/camel-xmlrpc/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
(added)
+++ camel/trunk/components/camel-xmlrpc/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
Mon Nov 12 14:25:47 2012
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.component.xmlrpc.converter.XmlRpcConverter

Added: camel/trunk/components/camel-xmlrpc/src/test/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmlrpc/src/test/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverterTest.java?rev=1408301&view=auto
==============================================================================
--- camel/trunk/components/camel-xmlrpc/src/test/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverterTest.java
(added)
+++ camel/trunk/components/camel-xmlrpc/src/test/java/org/apache/camel/component/xmlrpc/converter/XmlRpcConverterTest.java
Mon Nov 12 14:25:47 2012
@@ -0,0 +1,56 @@
+/**
+ * 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.apache.camel.component.xmlrpc.converter;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.TypeConversionException;
+import org.apache.camel.component.xmlrpc.XmlRpcConstants;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class XmlRpcConverterTest extends Assert {
+    
+    @Test
+    public void testToXmlRpcRequest() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setHeader(XmlRpcConstants.OPERATION_NAME, "greet");
+        exchange.getIn().setBody(new Object[] {"me", "you"});
+        XmlRpcRequest request = exchange.getIn().getBody(XmlRpcRequest.class);
+        
+        assertNotNull("The request should not be null", request);
+        assertEquals("Get a wrong operation name", "greet", request.getMethodName());
+        assertEquals("Get a wrong parameter size", 2, request.getParameterCount());
+        assertEquals("Get a worng parameter", "you", request.getParameter(1));
+    }
+    
+    @Test(expected = TypeConversionException.class)
+    public void testToXmlRpcRequestWithoutOperationName() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        Exchange exchange = new DefaultExchange(context);
+        
+        exchange.getIn().setBody(new Object[] {"me", "you"});
+        exchange.getIn().getBody(XmlRpcRequest.class);
+        fail("Expect the exception is throw");
+        
+    }
+
+}



Mime
View raw message