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 2010/08/03 15:53:07 UTC
svn commit: r981882 - in /camel/trunk/components/camel-cxf/src:
main/java/org/apache/camel/component/cxf/CxfConsumer.java
test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadFaultMessageTest.java
Author: ningjiang
Date: Tue Aug 3 13:53:07 2010
New Revision: 981882
URL: http://svn.apache.org/viewvc?rev=981882&view=rev
Log:
CAMEL-3022 camel-cxf consumer should support to take the fault message
Added:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadFaultMessageTest.java (with props)
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java?rev=981882&r1=981881&r2=981882&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java Tue Aug 3 13:53:07 2010
@@ -92,14 +92,17 @@ public class CxfConsumer extends Default
Map<String, Object> context = new HashMap<String, Object>();
binding.extractJaxWsContext(cxfExchange, context);
// send Camel exchange to the target processor
- LOG.trace("Processing +++ START +++");
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Processing +++ START +++");
+ }
try {
getProcessor().process(camelExchange);
} catch (Exception e) {
throw new Fault(e);
}
- LOG.trace("Processing +++ END +++");
-
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Processing +++ END +++");
+ }
checkFailure(camelExchange);
// bind the Camel response into a CXF response
@@ -120,8 +123,11 @@ public class CxfConsumer extends Default
if (camelExchange.isFailed()) {
// either Fault or Exception
Throwable t = (camelExchange.hasOut() && camelExchange.getOut().isFault())
- ? (Throwable)camelExchange.getOut().getBody() : camelExchange.getException();
- throw (t instanceof Fault) ? (Fault)t : new Fault(t);
+ ? camelExchange.getOut().getBody(Throwable.class) : camelExchange.getException();
+ // There is no exception and the Fault message is set to the out message
+ if (t != null) {
+ throw (t instanceof Fault) ? (Fault)t : new Fault(t);
+ }
}
}
Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadFaultMessageTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadFaultMessageTest.java?rev=981882&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadFaultMessageTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadFaultMessageTest.java Tue Aug 3 13:53:07 2010
@@ -0,0 +1,60 @@
+/**
+ * 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 java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.w3c.dom.Element;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.cxf.binding.soap.SoapHeader;
+import org.apache.cxf.helpers.DOMUtils;
+
+
+// SET the fault message directly on the out message
+public class CxfConsumerPayLoadFaultMessageTest extends CxfConsumerPayloadFaultTest {
+
+ protected static final String FAULTS = "<soap:Fault xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><faultcode>soap:Server</faultcode>"
+ + "<faultstring>Get the null value of person name</faultstring>"
+ + "<detail><UnknownPersonFault xmlns=\"http://camel.apache.org/wsdl-first/types\"><personId /></UnknownPersonFault></detail></soap:Fault>";
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from(FROM_URI).process(new Processor() {
+ public void process(final Exchange exchange) throws Exception {
+ Element details = DOMUtils.readXml(new StringReader(FAULTS)).getDocumentElement();
+ List<Element> outElements = new ArrayList<Element>();
+ outElements.add(details);
+ CxfPayload<SoapHeader> responsePayload = new CxfPayload<SoapHeader>(null, outElements);
+ exchange.getOut().setBody(responsePayload);
+ exchange.getOut().setFault(true);
+ }
+ });
+
+ }
+ };
+ }
+
+}
+
+
Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadFaultMessageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayLoadFaultMessageTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date