Author: ningjiang
Date: Fri Apr 29 03:53:08 2011
New Revision: 1097680
URL: http://svn.apache.org/viewvc?rev=1097680&view=rev
Log:
CAMEL-3879 Fixed the tests which are running with CXF 2.4.0
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/MessageDataFormatFeature.java
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/SpringBusFactoryBeans.xml
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/MessageDataFormatFeature.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/MessageDataFormatFeature.java?rev=1097680&r1=1097679&r2=1097680&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/MessageDataFormatFeature.java
(original)
+++
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/MessageDataFormatFeature.java
Fri Apr 29 03:53:08 2011
@@ -17,11 +17,17 @@
package org.apache.camel.component.cxf.feature;
+import java.util.List;
+
import
org.apache.camel.component.cxf.interceptors.RawMessageContentRedirectInterceptor;
+import org.apache.camel.util.ObjectHelper;
import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Message;
import org.apache.cxf.phase.Phase;
+import org.apache.cxf.version.Version;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -65,9 +71,18 @@ public class MessageDataFormatFeature ex
public void initialize(Server server, Bus bus) {
// currently we do not filter the bus
// remove the interceptors
+
+ // Find the WSDLGetInterceptor
+ Interceptor<? extends Message> wsdlGetInterceptor =
getInterceptorByName(server.getEndpoint().getInInterceptors(),
"org.apache.cxf.frontend.WSDLGetInterceptor");
+
removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getInInterceptors(),
REMAINING_IN_PHASES);
removeInterceptorWhichIsOutThePhases(server.getEndpoint().getInInterceptors(),
REMAINING_IN_PHASES);
+ // For CXF 2.4.x we need to add the WSDLGetInterceptor back
+ if (wsdlGetInterceptor != null) {
+ server.getEndpoint().getInInterceptors().add(wsdlGetInterceptor);
+ }
+
// Do not using the binding interceptor any more
server.getEndpoint().getBinding().getInInterceptors().clear();
@@ -83,5 +98,14 @@ public class MessageDataFormatFeature ex
protected Logger getLogger() {
return LOG;
}
+
+ private Interceptor<? extends Message>
getInterceptorByName(List<Interceptor<? extends Message>> interceptors, String
name) {
+ for (Interceptor<? extends Message> interceptor : interceptors) {
+ if (name.equals(interceptor.getClass().getName())) {
+ return interceptor;
+ }
+ }
+ return null;
+ }
}
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java?rev=1097680&r1=1097679&r2=1097680&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java
(original)
+++
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBean.java
Fri Apr 29 03:53:08 2011
@@ -28,7 +28,12 @@ import org.springframework.context.Appli
* without needing to import bunch of CXF packages in OSGi bundle, as the
SpringBusFactory
* will try to load the bus extensions with the CXF bundle classloader.
* You can set the CXF extensions files with ; as the separator to create a
bus.
- */
+ *
+ * NOTE: when you set the includeDefaultBus value to be false, you should
aware that the CXF bus
+ * will automatically load all the extension in CXF 2.4.x by default.
+ * You can still specify the spring extension file in the cfgFiles list and it
will override
+ * the extensions which is load by CXF bus.
+ */
public class SpringBusFactoryBean implements SmartFactoryBean {
private String[] cfgFiles;
private boolean includeDefaultBus;
Modified:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java?rev=1097680&r1=1097679&r2=1097680&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java
(original)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfGreeterMessageRouterTest.java
Fri Apr 29 03:53:08 2011
@@ -18,6 +18,7 @@
package org.apache.camel.component.cxf;
import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
@@ -38,6 +39,5 @@ public class CxfGreeterMessageRouterTest
protected ClassPathXmlApplicationContext createApplicationContext() {
return new
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/GreeterEndpointBeans.xml");
}
-
-
+
}
Modified:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java?rev=1097680&r1=1097679&r2=1097680&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
(original)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/cxfbean/CxfBeanTest.java
Fri Apr 29 03:53:08 2011
@@ -29,6 +29,7 @@ import org.apache.camel.wsdl_first.Perso
import org.apache.camel.wsdl_first.PersonService;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
@@ -82,68 +83,62 @@ public class CxfBeanTest extends Abstrac
assertTrue(testedEndpointWithProviders);
}
+ private void invokeRsService(String getUrl, String expected) throws
Exception {
+ HttpGet get = new HttpGet(getUrl);
+ get.addHeader("Accept" , "application/json");
+ HttpClient httpclient = new DefaultHttpClient();
+
+ try {
+ HttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals(expected,
+ EntityUtils.toString(response.getEntity()));
+ } finally {
+ httpclient.getConnectionManager().shutdown();
+ }
+ }
+
@Test
public void testGetConsumer() throws Exception {
- URL url = new
URL("http://localhost:9000/customerservice/customers/123");
-
- InputStream in = url.openStream();
- assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
CxfUtils.getStringFromInputStream(in));
-
- // START SNIPPET: clientInvocation
- url = new
URL("http://localhost:9000/customerservice/orders/223/products/323");
- in = url.openStream();
- assertEquals("{\"Product\":{\"description\":\"product
323\",\"id\":323}}", CxfUtils.getStringFromInputStream(in));
- // END SNIPPET: clientInvocation
+ invokeRsService("http://localhost:9000/customerservice/customers/123",
+ "{\"Customer\":{\"id\":123,\"name\":\"John\"}}");
+
+
invokeRsService("http://localhost:9000/customerservice/orders/223/products/323",
+ "{\"Product\":{\"description\":\"product
323\",\"id\":323}}");
+
+
}
@Test
public void testGetConsumerWithQueryParam() throws Exception {
- URL url = new
URL("http://localhost:9000/customerservice/customers?id=123");
-
- try {
- InputStream in = url.openStream();
- assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
CxfUtils.getStringFromInputStream(in));
- } catch (Exception ex) {
- Thread.sleep(3000000);
- }
+
invokeRsService("http://localhost:9000/customerservice/customers?id=123",
+ "{\"Customer\":{\"id\":123,\"name\":\"John\"}}");
+
}
@Test
public void testGetConsumerAfterReStartCamelContext() throws Exception {
- URL url = new
URL("http://localhost:9000/customerservice/customers/123");
-
- InputStream in = url.openStream();
- assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
CxfUtils.getStringFromInputStream(in));
- in.close();
+ invokeRsService("http://localhost:9000/customerservice/customers/123",
+ "{\"Customer\":{\"id\":123,\"name\":\"John\"}}");
camelContext.stop();
camelContext.start();
- url = new
URL("http://localhost:9000/customerservice/orders/223/products/323");
- in = url.openStream();
-
- assertEquals("{\"Product\":{\"description\":\"product
323\",\"id\":323}}",
- CxfUtils.getStringFromInputStream(in));
- in.close();
+
invokeRsService("http://localhost:9000/customerservice/orders/223/products/323",
+ "{\"Product\":{\"description\":\"product
323\",\"id\":323}}");
+
}
@Test
public void testGetConsumerAfterResumingCamelContext() throws Exception {
- URL url = new
URL("http://localhost:9000/customerservice/customers/123");
-
- InputStream in = url.openStream();
- assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
CxfUtils.getStringFromInputStream(in));
- in.close();
-
+ invokeRsService("http://localhost:9000/customerservice/customers/123",
+ "{\"Customer\":{\"id\":123,\"name\":\"John\"}}");
+
camelContext.suspend();
camelContext.resume();
- url = new
URL("http://localhost:9000/customerservice/orders/223/products/323");
- in = url.openStream();
-
- assertEquals("{\"Product\":{\"description\":\"product
323\",\"id\":323}}",
- CxfUtils.getStringFromInputStream(in));
- in.close();
+
invokeRsService("http://localhost:9000/customerservice/orders/223/products/323",
+ "{\"Product\":{\"description\":\"product
323\",\"id\":323}}");
}
@Test
Modified:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java?rev=1097680&r1=1097679&r2=1097680&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
(original)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsConsumerTest.java
Fri Apr 29 03:53:08 2011
@@ -18,7 +18,6 @@ package org.apache.camel.component.cxf.j
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URL;
import javax.ws.rs.WebApplicationException;
@@ -32,10 +31,10 @@ import org.apache.camel.builder.NoErrorH
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.CxfConstants;
import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
-import org.apache.camel.component.cxf.util.CxfUtils;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
@@ -100,11 +99,19 @@ public class CxfRsConsumerTest extends C
@Test
public void testGetCustomer() throws Exception {
- URL url = new
URL("http://localhost:9000/rest/customerservice/customers/126");
+ HttpGet get = new
HttpGet("http://localhost:9000/rest/customerservice/customers/126");
+ get.addHeader("Accept" , "application/json");
+ HttpClient httpclient = new DefaultHttpClient();
- InputStream in = url.openStream();
- assertEquals("{\"Customer\":{\"id\":126,\"name\":\"Willem\"}}",
CxfUtils.getStringFromInputStream(in));
-
+ try {
+ HttpResponse response = httpclient.execute(get);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ assertEquals("{\"Customer\":{\"id\":126,\"name\":\"Willem\"}}",
+ EntityUtils.toString(response.getEntity()));
+ } finally {
+ httpclient.getConnectionManager().shutdown();
+ }
+
}
@Test
Modified:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java?rev=1097680&r1=1097679&r2=1097680&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java
(original)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/SpringBusFactoryBeanTest.java
Fri Apr 29 03:53:08 2011
@@ -18,6 +18,8 @@ package org.apache.camel.component.cxf.s
import org.apache.camel.component.cxf.transport.CamelTransportFactory;
import org.apache.cxf.Bus;
+import org.apache.cxf.binding.soap.SoapBindingFactory;
+import org.apache.cxf.version.Version;
import org.junit.Test;
public class SpringBusFactoryBeanTest extends AbstractSpringBeanTestSupport {
@@ -29,15 +31,20 @@ public class SpringBusFactoryBeanTest ex
@Test
public void getTheBusInstance() {
- Bus bus = (Bus)ctx.getBean("cxf");
+ Bus bus = (Bus)ctx.getBean("cxfBus");
assertNotNull("The bus should not be null", bus);
- CamelTransportFactory factory =
bus.getExtension(CamelTransportFactory.class);
- assertNull("You should find the factory here", factory);
+ if (!Version.getCurrentVersion().startsWith("2.4")) {
+ // This test just for the CXF 2.3.x, we skip this test with CXF
2.4.x
+ CamelTransportFactory factory =
bus.getExtension(CamelTransportFactory.class);
+ assertNull("You should not find the factory here", factory);
+ }
bus = (Bus)ctx.getBean("myBus");
assertNotNull("The bus should not be null", bus);
- factory = bus.getExtension(CamelTransportFactory.class);
+ CamelTransportFactory factory =
bus.getExtension(CamelTransportFactory.class);
assertNotNull("You should find the factory here", factory);
+ SoapBindingFactory soapBindingFactory =
bus.getExtension(SoapBindingFactory.class);
+ assertNotNull("You should find the factory here", soapBindingFactory);
}
}
Modified:
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/SpringBusFactoryBeans.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/SpringBusFactoryBeans.xml?rev=1097680&r1=1097679&r2=1097680&view=diff
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/SpringBusFactoryBeans.xml
(original)
+++
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/SpringBusFactoryBeans.xml
Fri Apr 29 03:53:08 2011
@@ -23,13 +23,13 @@
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
">
- <bean id="cxf"
class="org.apache.camel.component.cxf.spring.SpringBusFactoryBean">
+ <bean id="cxfBus"
class="org.apache.camel.component.cxf.spring.SpringBusFactoryBean">
<property name="cfgFiles"
value="META-INF/cxf/cxf.xml;META-INF/cxf/cxf-extension-soap.xml;META-INF/cxf/cxf-extension-http-jetty.xml"
/>
<property name="includeDefaultBus" value="false" />
</bean>
<bean id="myBus"
class="org.apache.camel.component.cxf.spring.SpringBusFactoryBean">
- <property name="cfgFiles"
value="META-INF/cxf/cxf-extension-soap.xml;META-INF/cxf/cxf-extension-http-jetty.xml"
/>
+ <property name="cfgFiles" value="META-INF/cxf/cxf-extension-soap.xml" />
<property name="includeDefaultBus" value="true" />
</bean>