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 2014/02/14 08:35:03 UTC
git commit: CAMEL-7194 Added features option to the cxfrs endpoint
Updated Branches:
refs/heads/camel-2.12.x aad59d74f -> 2f8e1ff72
CAMEL-7194 Added features option to the cxfrs endpoint
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2f8e1ff7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2f8e1ff7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2f8e1ff7
Branch: refs/heads/camel-2.12.x
Commit: 2f8e1ff72e1e921a2074e55eb4e6b3919053b324
Parents: aad59d7
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Feb 13 14:35:24 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Feb 14 15:27:40 2014 +0800
----------------------------------------------------------------------
.../component/cxf/jaxrs/CxfRsEndpoint.java | 72 ++++++++------------
.../cxf/jaxrs/CxfRsSpringEndpoint.java | 12 ----
.../component/cxf/jaxrs/CxfRsProducerTest.java | 43 ++++++++++--
.../component/cxf/jaxrs/CxfRsSpringProducer.xml | 7 ++
.../CxfRsSpringProducerAddressOverride.xml | 7 ++
5 files changed, 83 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2f8e1ff7/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
index 0b4c816..9cb0b1d 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsEndpoint.java
@@ -39,6 +39,8 @@ import org.apache.camel.spi.HeaderFilterStrategyAware;
import org.apache.camel.util.ObjectHelper;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.util.ModCountCopyOnWriteArrayList;
+import org.apache.cxf.feature.Feature;
import org.apache.cxf.feature.LoggingFeature;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
@@ -89,6 +91,8 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
private boolean isSetDefaultBus;
+ private List<Feature> features = new ModCountCopyOnWriteArrayList<Feature>();
+
@Deprecated
@@ -188,6 +192,16 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
}
sfb.setResourceClasses(res);
}
+ // let customer to override the default setting of provider
+ if (!getProviders().isEmpty()) {
+ sfb.setProviders(getProviders());
+ }
+ // setup the features
+ if (!getFeatures().isEmpty()) {
+ for (Feature feature: getFeatures()) {
+ sfb.getFeatures().add(feature);
+ }
+ }
sfb.setStart(false);
}
@@ -200,6 +214,14 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
cfb.setResourceClass(getResourceClasses().get(0));
cfb.getServiceFactory().setResourceClasses(getResourceClasses());
}
+ // let customer to override the default setting of provider
+ if (!getProviders().isEmpty()) {
+ cfb.setProviders(getProviders());
+ }
+ // setup the features
+ if (!getFeatures().isEmpty()) {
+ cfb.setFeatures(getFeatures());
+ }
if (isLoggingFeatureEnabled()) {
if (getLoggingSizeLimit() > 0) {
cfb.getFeatures().add(new LoggingFeature(getLoggingSizeLimit()));
@@ -238,29 +260,8 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
public JAXRSServerFactoryBean createJAXRSServerFactoryBean() {
-
JAXRSServerFactoryBean answer = newJAXRSServerFactoryBean();
setupJAXRSServerFactoryBean(answer);
- // let customer to override the default setting of provider
- if (!getProviders().isEmpty()) {
- answer.setProviders(getProviders());
- }
- if (schemaLocations != null) {
- answer.setSchemaLocations(schemaLocations);
- }
- if (isLoggingFeatureEnabled()) {
- if (getLoggingSizeLimit() > 0) {
- answer.getFeatures().add(new LoggingFeature(getLoggingSizeLimit()));
- } else {
- answer.getFeatures().add(new LoggingFeature());
- }
- }
- if (this.isSkipFaultLogging()) {
- if (answer.getProperties() == null) {
- answer.setProperties(new HashMap<String, Object>());
- }
- answer.getProperties().put(FaultListener.class.getName(), new NullFaultListener());
- }
return answer;
}
@@ -270,29 +271,8 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
}
public JAXRSClientFactoryBean createJAXRSClientFactoryBean(String address) {
-
JAXRSClientFactoryBean answer = newJAXRSClientFactoryBean();
setupJAXRSClientFactoryBean(answer, address);
- // let customer to override the default setting of provider
- if (!getProviders().isEmpty()) {
- answer.setProviders(getProviders());
- }
- if (schemaLocations != null) {
- answer.setSchemaLocations(schemaLocations);
- }
- if (isLoggingFeatureEnabled()) {
- if (getLoggingSizeLimit() > 0) {
- answer.getFeatures().add(new LoggingFeature(getLoggingSizeLimit()));
- } else {
- answer.getFeatures().add(new LoggingFeature());
- }
- }
- if (this.isSkipFaultLogging()) {
- if (answer.getProperties() == null) {
- answer.setProperties(new HashMap<String, Object>());
- }
- answer.getProperties().put(FaultListener.class.getName(), new NullFaultListener());
- }
return answer;
}
@@ -413,6 +393,14 @@ public class CxfRsEndpoint extends DefaultEndpoint implements HeaderFilterStrate
return schemaLocations;
}
+ public List<Feature> getFeatures() {
+ return features;
+ }
+
+ public void setFeatures(List<Feature> features) {
+ this.features = features;
+ }
+
/**
* See documentation of {@link BindingStyle}.
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/2f8e1ff7/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java
index 1738215..fa96d3c 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsSpringEndpoint.java
@@ -53,18 +53,6 @@ public class CxfRsSpringEndpoint extends CxfRsEndpoint implements BeanIdAware {
}
@Override
- protected void setupJAXRSServerFactoryBean(JAXRSServerFactoryBean sfb) {
- // Do nothing here
- }
-
- @Override
- protected void setupJAXRSClientFactoryBean(JAXRSClientFactoryBean cfb, String address) {
- cfb.setAddress(address);
- // Need to enable the option of ThreadSafe
- cfb.setThreadSafe(true);
- }
-
- @Override
protected JAXRSServerFactoryBean newJAXRSServerFactoryBean() {
checkBeanType(bean, JAXRSServerFactoryBean.class);
return (JAXRSServerFactoryBean)bean;
http://git-wip-us.apache.org/repos/asf/camel/blob/2f8e1ff7/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
index 546f074..8eb6d0d 100644
--- a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
+++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducerTest.java
@@ -33,6 +33,11 @@ import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.apache.camel.component.cxf.jaxrs.testbean.Customer;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.apache.camel.util.CastUtils;
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.feature.Feature;
+import org.apache.cxf.interceptor.InterceptorProvider;
import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -70,7 +75,7 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
}
@Test
- public void testGetCostumerWithClientProxyAPI() {
+ public void testGetCustomerWithClientProxyAPI() {
// START SNIPPET: ProxyExample
Exchange exchange = template.send("direct://proxy", new Processor() {
public void process(Exchange exchange) throws Exception {
@@ -101,7 +106,7 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
}
@Test
- public void testGetCostumersWithClientProxyAPI() {
+ public void testGetCustomersWithClientProxyAPI() {
Exchange exchange = template.send("direct://proxy", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
@@ -127,7 +132,7 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
}
@Test
- public void testGetCostumerWithHttpCentralClientAPI() {
+ public void testGetCustomerWithHttpCentralClientAPI() {
// START SNIPPET: HttpExample
Exchange exchange = template.send("direct://http", new Processor() {
public void process(Exchange exchange) throws Exception {
@@ -188,7 +193,7 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
}
@Test
- public void testGetCustumerWithCxfRsEndpoint() {
+ public void testGetCustomerWithCxfRsEndpoint() {
Exchange exchange
= template.send("cxfrs://http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/?httpClientAPI=true", new Processor() {
public void process(Exchange exchange) throws Exception {
@@ -376,5 +381,35 @@ public class CxfRsProducerTest extends CamelSpringTestSupport {
assertNotNull(response);
assertTrue(response.endsWith("<name>Donald Duck</name></Customer>"));
}
+
+ static class TestFeature implements Feature {
+ boolean initialized;
+ @Override
+ public void initialize(InterceptorProvider interceptorProvider, Bus bus) {
+ initialized = true;
+ }
+ @Override
+ public void initialize(Client client, Bus bus) {
+ //Do nothing
+ }
+ @Override
+ public void initialize(Server server, Bus bus) {
+ //Do nothing
+ }
+ @Override
+ public void initialize(Bus bus) {
+ //Do nothing
+ }
+ };
+
+ @Test
+ public void testProducerWithFeature() {
+ TestFeature feature = context().getRegistry().lookupByNameAndType("testFeature", TestFeature.class);
+
+ template.requestBodyAndHeader("cxfrs:http://localhost:" + getPort1() + "/" + getClass().getSimpleName() + "/customerservice/customers/123?features=#myFeatures",
+ null, Exchange.HTTP_METHOD, "GET", String.class);
+
+ assertTrue("The feature should be initialized", feature.initialized);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f8e1ff7/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
index 4500667..6f8add8 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducer.xml
@@ -19,8 +19,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
@@ -59,5 +61,10 @@
</camelContext>
<bean id="myProcessor" class="org.apache.camel.component.cxf.jaxrs.CxfRsProducerTest$JettyProcessor"/>
+ <bean id ="testFeature" class="org.apache.camel.component.cxf.jaxrs.CxfRsProducerTest$TestFeature" />
+
+ <util:list id="myFeatures" >
+ <ref bean="testFeature"/>
+ </util:list>
</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/2f8e1ff7/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducerAddressOverride.xml
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducerAddressOverride.xml b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducerAddressOverride.xml
index f13cd8a..e346ab7 100644
--- a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducerAddressOverride.xml
+++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/jaxrs/CxfRsSpringProducerAddressOverride.xml
@@ -19,8 +19,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
@@ -59,5 +61,10 @@
</camelContext>
<bean id="myProcessor" class="org.apache.camel.component.cxf.jaxrs.CxfRsProducerTest$JettyProcessor"/>
+ <bean id ="testFeature" class="org.apache.camel.component.cxf.jaxrs.CxfRsProducerTest$TestFeature" />
+
+ <util:list id="myFeatures" >
+ <ref bean="testFeature"/>
+ </util:list>
</beans>