You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2011/02/15 09:45:37 UTC

svn commit: r1070807 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/model/ components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/

Author: ningjiang
Date: Tue Feb 15 08:45:37 2011
New Revision: 1070807

URL: http://svn.apache.org/viewvc?rev=1070807&view=rev
Log:
CAMEL-3668 Add setFaultBody spring DSL

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetFaultBodyDefinition.java   (with props)
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java   (with props)
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml   (with props)

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetFaultBodyDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetFaultBodyDefinition.java?rev=1070807&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetFaultBodyDefinition.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetFaultBodyDefinition.java Tue Feb 15 08:45:37 2011
@@ -0,0 +1,64 @@
+/**
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.Expression;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.ProcessorBuilder;
+import org.apache.camel.processor.SetBodyProcessor;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * Represents an XML <setFaultBody/> element.
+ */
+@XmlRootElement(name = "setFaultBody")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class SetFaultBodyDefinition extends ExpressionNode {
+
+    public SetFaultBodyDefinition() {
+    }
+
+    public SetFaultBodyDefinition(Expression expression) {
+        super(expression);
+    }
+
+    @Override
+    public String toString() {
+        return "SetFaultBody[" + getExpression() + "]";
+    }
+
+    @Override
+    public String getShortName() {
+        return "setFaultBody";
+    }
+
+    @Override
+    public String getLabel() {
+        return "setFaultBody[" + getExpression() + "]";
+    }
+
+    @Override
+    public Processor createProcessor(RouteContext routeContext) throws Exception {
+        Expression expr = getExpression().createExpression(routeContext);
+        return ProcessorBuilder.setFaultBody(expr);
+    }
+    
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetFaultBodyDefinition.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/SetFaultBodyDefinition.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java?rev=1070807&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java Tue Feb 15 08:45:37 2011
@@ -0,0 +1,96 @@
+/**
+ * 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.cxf;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.cxf.Bus;
+import org.apache.cxf.binding.soap.SoapFault;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfSpringCustomizedExceptionTest extends CamelTestSupport  {
+    private static final String EXCEPTION_MESSAGE = "This is an exception test message";
+    private static final String DETAIL_TEXT = "This is a detail text node";
+    private static final SoapFault SOAP_FAULT;
+    private AbstractXmlApplicationContext applicationContext;
+   
+    static {
+        // START SNIPPET: FaultDefine
+        SOAP_FAULT = new SoapFault(EXCEPTION_MESSAGE, SoapFault.FAULT_CODE_CLIENT);
+        Element detail = SOAP_FAULT.getOrCreateDetail();
+        Document doc = detail.getOwnerDocument();
+        Text tn = doc.createTextNode(DETAIL_TEXT);
+        detail.appendChild(tn);
+        // END SNIPPET: FaultDefine
+    }    
+   
+    
+    @Before
+    public void setUp() throws Exception {
+        applicationContext = createApplicationContext();
+        super.setUp();
+        assertNotNull("Should have created a valid spring context", applicationContext);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (applicationContext != null) {
+            applicationContext.destroy();
+        }
+        super.tearDown();
+    }
+    
+    @Test
+    public void testInvokingServiceFromCamel() throws Exception {
+        try {
+            template.sendBodyAndHeader("direct:start", ExchangePattern.InOut, "hello world" , CxfConstants.OPERATION_NAME, "echo");
+        } catch (Exception ex) {
+            Throwable result = ex.getCause();
+            assertTrue("Exception is not instance of SoapFault", result instanceof SoapFault);
+            assertEquals("Expect to get right detail message", DETAIL_TEXT, ((SoapFault)result).getDetail().getTextContent());
+            assertEquals("Expect to get right fault-code", "{http://schemas.xmlsoap.org/soap/envelope/}Client", ((SoapFault)result).getFaultCode().toString());
+        }
+        
+    }
+    
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml");
+    }
+    
+    public static class SOAPFaultFactory {
+        public SoapFault getSoapFault() {
+            return SOAP_FAULT;
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfSpringCustomizedExceptionTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml?rev=1070807&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml Tue Feb 15 08:45:37 2011
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+   
+   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="direct:start" />
+      <to uri="cxf://http://localhost:9002/router?serviceClass=org.apache.camel.component.cxf.HelloService"/>
+    </route>
+    <route>
+      <from uri="cxf://http://localhost:9002/router?serviceClass=org.apache.camel.component.cxf.HelloService"/>
+      <setFaultBody>
+      	<method beanType="org.apache.camel.component.cxf.CxfSpringCustomizedExceptionTest$SOAPFaultFactory"/>
+      </setFaultBody>
+      <!-- Need to add output endpoint to get route loaded -->
+      <to uri="log:mylog"/>
+    </route>
+   </camelContext>
+
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfCustomizedExceptionContext.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml