Updated Branches:
  refs/heads/camel-2.11.x 2cdf2e780 -> 0136e11c8

fix test failures with latest CXF


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0136e11c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0136e11c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0136e11c

Branch: refs/heads/camel-2.11.x
Commit: 0136e11c869b1d77584d328d2304874c7e773d0e
Parents: 2cdf2e7
Author: Daniel Kulp <[email protected]>
Authored: Mon Feb 10 11:27:49 2014 -0500
Committer: Daniel Kulp <[email protected]>
Committed: Mon Feb 10 11:27:49 2014 -0500

----------------------------------------------------------------------
 .../cxf/feature/PayLoadDataFormatFeature.java   |   3 -
 .../cxf/feature/RAWDataFormatFeature.java       |   9 +-
 .../RawMessageWSDLGetInterceptor.java           | 121 +++++++++++++++++++
 .../RawMessageWSDLGetOutInterceptor.java        |  69 +++++++++++
 .../cxf/AbstractCXFGreeterRouterTest.java       |   6 +-
 5 files changed, 197 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0136e11c/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java
index e9efdd4..dabde13 100644
--- 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java
@@ -16,8 +16,6 @@
  */
 package org.apache.camel.component.cxf.feature;
 
-import java.util.ArrayList;
-import java.util.Collection;
 import javax.xml.transform.Source;
 import javax.xml.transform.dom.DOMSource;
 
@@ -29,7 +27,6 @@ import org.apache.cxf.binding.soap.SoapBinding;
 import org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.Server;
-import org.apache.cxf.interceptor.ClientFaultConverter;
 import org.apache.cxf.jaxws.interceptors.HolderInInterceptor;
 import org.apache.cxf.jaxws.interceptors.HolderOutInterceptor;
 import org.apache.cxf.service.model.BindingMessageInfo;

http://git-wip-us.apache.org/repos/asf/camel/blob/0136e11c/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/RAWDataFormatFeature.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/RAWDataFormatFeature.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/RAWDataFormatFeature.java
index 276cd2b..b609719 100644
--- 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/RAWDataFormatFeature.java
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/RAWDataFormatFeature.java
@@ -18,10 +18,10 @@
 package org.apache.camel.component.cxf.feature;
 
 import 
org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor;
+import 
org.apache.camel.component.cxf.interceptors.RawMessageWSDLGetInterceptor;
 import org.apache.cxf.Bus;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.Server;
-import org.apache.cxf.frontend.WSDLGetInterceptor;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.slf4j.Logger;
@@ -69,10 +69,7 @@ public class RAWDataFormatFeature extends 
AbstractDataFormatFeature {
     public void initialize(Server server, Bus bus) {
         // currently we do not filter the bus
         // remove the interceptors
-        
-        // keep the WSDLGetInterceptor
-        getInInterceptorNames().add(WSDLGetInterceptor.class.getName());
-        
+                
         
removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getInInterceptors(),
 REMAINING_IN_PHASES, getInInterceptorNames());
         
removeInterceptorWhichIsOutThePhases(server.getEndpoint().getInInterceptors(), 
REMAINING_IN_PHASES, getInInterceptorNames());
 
@@ -90,6 +87,8 @@ public class RAWDataFormatFeature extends 
AbstractDataFormatFeature {
         server.getEndpoint().getBinding().getOutInterceptors().clear();
         server.getEndpoint().getOutInterceptors().add(new 
RawMessageContentRedirectInterceptor());
         
+        // setup the RawMessageWSDLGetInterceptor
+        
server.getEndpoint().getInInterceptors().add(RawMessageWSDLGetInterceptor.INSTANCE);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/0136e11c/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageWSDLGetInterceptor.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageWSDLGetInterceptor.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageWSDLGetInterceptor.java
new file mode 100644
index 0000000..e102971
--- /dev/null
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageWSDLGetInterceptor.java
@@ -0,0 +1,121 @@
+/**
+ * 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.interceptors;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.binding.soap.interceptor.EndpointSelectionInterceptor;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.common.util.UrlUtils;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.frontend.WSDLGetUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.OutgoingChainInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.EndpointInfo;
+
+
+/**
+ * Just copy the from WSDLGetInterceptor to provide backward compatible 
support for 2.7.x
+ */
+public class RawMessageWSDLGetInterceptor extends 
AbstractPhaseInterceptor<Message> {
+    public static final RawMessageWSDLGetInterceptor INSTANCE = new 
RawMessageWSDLGetInterceptor();
+    public static final String DOCUMENT_HOLDER = 
RawMessageWSDLGetInterceptor.class.getName() + ".documentHolder";
+
+    public RawMessageWSDLGetInterceptor() {
+        super(Phase.READ);
+        getAfter().add(EndpointSelectionInterceptor.class.getName());
+    }
+
+    public void handleMessage(Message message) throws Fault {
+        String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
+        String query = (String)message.get(Message.QUERY_STRING);
+
+        if (!"GET".equals(method) || StringUtils.isEmpty(query)) {
+            return;
+        }
+
+        String baseUri = (String)message.get(Message.REQUEST_URL);
+        String ctx = (String)message.get(Message.PATH_INFO);
+
+        Map<String, String> map = UrlUtils.parseQueryString(query);
+        if (isRecognizedQuery(map, baseUri, ctx, 
message.getExchange().getEndpoint().getEndpointInfo())) {
+            Document doc = getDocument(message, baseUri, map, ctx);
+
+            Endpoint e = message.getExchange().get(Endpoint.class);
+            Message mout = new MessageImpl();
+            mout.setExchange(message.getExchange());
+            mout = e.getBinding().createMessage(mout);
+            
mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
+            message.getExchange().setOutMessage(mout);
+
+            mout.put(DOCUMENT_HOLDER, doc);
+
+            Iterator<Interceptor<? extends Message>> iterator = 
mout.getInterceptorChain().iterator();
+            while (iterator.hasNext()) {
+                Interceptor<? extends Message> inInterceptor = iterator.next();
+                if (inInterceptor instanceof AbstractPhaseInterceptor) {
+                    AbstractPhaseInterceptor<?> interceptor = 
(AbstractPhaseInterceptor<?>)inInterceptor;
+                    if (interceptor.getPhase().equals(Phase.PREPARE_SEND)
+                        || interceptor.getPhase().equals(Phase.PRE_STREAM)) {
+                        // just make sure we keep the right interceptors
+                        continue;
+                    }
+                }
+                mout.getInterceptorChain().remove(inInterceptor);
+            }
+
+            // notice this is being added after the purge above, don't swap 
the order!
+            
mout.getInterceptorChain().add(RawMessageWSDLGetOutInterceptor.INSTANCE);
+
+            // skip the service executor and goto the end of the chain.
+            message.getInterceptorChain().doInterceptStartingAt(
+                    message,
+                    OutgoingChainInterceptor.class.getName());
+        }
+    }
+
+    private Document getDocument(Message message, String base, Map<String, 
String> params, String ctxUri) {
+        // cannot have two wsdl's being generated for the same endpoint at the 
same
+        // time as the addresses may get mixed up
+        // For WSDL's the WSDLWriter does not share any state between 
documents.
+        // For XSD's, the WSDLGetUtils makes a copy of any XSD schema 
documents before updating
+        // any addresses and returning them, so for both WSDL and XSD this is 
the only part that needs
+        // to be synchronized.
+        synchronized (message.getExchange().getEndpoint()) {
+            return new WSDLGetUtils().getDocument(message, base, params, 
ctxUri,
+                    message.getExchange().getEndpoint().getEndpointInfo());
+        }
+    }
+
+    private boolean isRecognizedQuery(Map<String, String> map, String baseUri, 
String ctx,
+                                      EndpointInfo endpointInfo) {
+
+        if (map.containsKey("wsdl") || map.containsKey("xsd")) {
+            return true;
+        }
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0136e11c/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageWSDLGetOutInterceptor.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageWSDLGetOutInterceptor.java
 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageWSDLGetOutInterceptor.java
new file mode 100644
index 0000000..2d7c963
--- /dev/null
+++ 
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/RawMessageWSDLGetOutInterceptor.java
@@ -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.apache.camel.component.cxf.interceptors;
+
+import java.io.OutputStream;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Document;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.StaxUtils;
+
+
+public class RawMessageWSDLGetOutInterceptor extends 
AbstractPhaseInterceptor<Message> {
+    public static final RawMessageWSDLGetOutInterceptor INSTANCE = new 
RawMessageWSDLGetOutInterceptor();
+
+    public RawMessageWSDLGetOutInterceptor() {
+        super(Phase.PRE_STREAM);
+    }
+
+    public void handleMessage(Message message) throws Fault {
+
+        Document doc = 
(Document)message.get(RawMessageWSDLGetInterceptor.DOCUMENT_HOLDER);
+        if (doc == null) {
+            return;
+        }
+        message.remove(RawMessageWSDLGetInterceptor.DOCUMENT_HOLDER);
+
+        OutputStream out = message.getContent(OutputStream.class);
+
+        String enc = null;
+        try {
+            enc = doc.getXmlEncoding();
+        } catch (Exception ex) {
+            //ignore - not dom level 3
+        }
+        if (enc == null) {
+            enc = "utf-8";
+        }
+
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out, enc);
+        try {
+            StaxUtils.writeNode(doc, writer, true);
+            writer.flush();
+        } catch (XMLStreamException e) {
+            throw new Fault(e);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/0136e11c/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/AbstractCXFGreeterRouterTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/AbstractCXFGreeterRouterTest.java
 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/AbstractCXFGreeterRouterTest.java
index 7b3b92c..39f3283 100644
--- 
a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/AbstractCXFGreeterRouterTest.java
+++ 
b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/AbstractCXFGreeterRouterTest.java
@@ -118,9 +118,9 @@ public abstract class AbstractCXFGreeterRouterTest extends 
CamelTestSupport {
     
     @Test
     public void testPublishEndpointUrl() throws Exception {
-        String response = template.requestBody("http://localhost:"; + 
getPort2() + "/" + getClass().getSimpleName()
-                                               + "/CamelContext/RouterPort/"
-            + getClass().getSimpleName() + "?wsdl", null, String.class);
+        String url = "http://localhost:"; + getPort2() + "/" + 
getClass().getSimpleName()
+            + "/CamelContext/RouterPort?wsdl";
+        String response = template.requestBody(url, null, String.class);
         assertTrue("Can't find the right service location.", 
response.indexOf("http://www.simple.com/services/test";) > 0);
     }
     

Reply via email to