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/11/11 11:03:39 UTC
svn commit: r1200795 - in
/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf:
CxfBlueprintEndpoint.java CxfEndpoint.java
feature/AbstractDataFormatFeature.java feature/MessageDataFormatFeature.java
Author: ningjiang
Date: Fri Nov 11 10:03:39 2011
New Revision: 1200795
URL: http://svn.apache.org/viewvc?rev=1200795&view=rev
Log:
CAMEL-4646 MessageDataFormatFeature should keep the interceptors which are set to cxfEndpoint
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/AbstractDataFormatFeature.java
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/MessageDataFormatFeature.java
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java?rev=1200795&r1=1200794&r2=1200795&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBlueprintEndpoint.java Fri Nov 11 10:03:39 2011
@@ -63,38 +63,6 @@ public class CxfBlueprintEndpoint extend
}
}
- /**
- * Create a CXF server factory bean
- */
- ServerFactoryBean createServerFactoryBean() throws Exception {
-
- Class<?> cls = null;
- if (getDataFormat() == DataFormat.POJO || getServiceClass() != null) {
- // get service class
- ObjectHelper.notNull(getServiceClass(), CxfConstants.SERVICE_CLASS);
- cls = getServiceClass();
- }
-
- // create server factory bean
- // Shouldn't use CxfEndpointUtils.getServerFactoryBean(cls) as it is for
- // CxfSoapComponent
- ServerFactoryBean answer = null;
-
- if (cls == null) {
- checkName(getPortName(), " endpoint/port name");
- checkName(getServiceName(), " service name");
- answer = new ServerFactoryBean(new WSDLServiceFactoryBean());
- } else if (CxfEndpointUtils.hasWebServiceAnnotation(cls)) {
- answer = new JaxWsServerFactoryBean();
- } else {
- answer = new ServerFactoryBean();
- }
- // setup server factory bean
- setupServerFactoryBean(answer, cls);
-
- return answer;
- }
-
public BlueprintContainer getBlueprintContainer() {
return blueprintContainer;
}
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=1200795&r1=1200794&r2=1200795&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java Fri Nov 11 10:03:39 2011
@@ -258,7 +258,10 @@ public class CxfEndpoint extends Default
if (getDataFormat() == DataFormat.PAYLOAD) {
sfb.getFeatures().add(new PayLoadDataFormatFeature(allowStreaming));
} else if (getDataFormat() == DataFormat.MESSAGE) {
- sfb.getFeatures().add(new MessageDataFormatFeature());
+ MessageDataFormatFeature feature = new MessageDataFormatFeature();
+ feature.addInIntercepters(getInInterceptors());
+ feature.addOutInterceptors(getOutInterceptors());
+ sfb.getFeatures().add(feature);
}
} else {
LOG.debug("Ignore DataFormat mode {} since SEI class is annotated with WebServiceProvider", getDataFormat());
@@ -413,7 +416,10 @@ public class CxfEndpoint extends Default
// apply feature here
if (getDataFormat() == DataFormat.MESSAGE) {
- factoryBean.getFeatures().add(new MessageDataFormatFeature());
+ MessageDataFormatFeature feature = new MessageDataFormatFeature();
+ feature.addInIntercepters(getInInterceptors());
+ feature.addOutInterceptors(getOutInterceptors());
+ factoryBean.getFeatures().add(feature);
} else if (getDataFormat() == DataFormat.PAYLOAD) {
factoryBean.getFeatures().add(new PayLoadDataFormatFeature(allowStreaming));
factoryBean.setDataBinding(new HybridSourceDataBinding());
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/AbstractDataFormatFeature.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/AbstractDataFormatFeature.java?rev=1200795&r1=1200794&r2=1200795&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/AbstractDataFormatFeature.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/AbstractDataFormatFeature.java Fri Nov 11 10:03:39 2011
@@ -18,7 +18,9 @@
package org.apache.camel.component.cxf.feature;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.interceptor.Interceptor;
@@ -31,24 +33,46 @@ import org.slf4j.Logger;
*/
public abstract class AbstractDataFormatFeature extends AbstractFeature {
+ // The interceptors which need to be keeped
+ protected Set<String> inInterceptorNames = new HashSet<String>();
+ protected Set<String> outInterceptorNames = new HashSet<String>();
protected abstract Logger getLogger();
+ @Deprecated
+ // It will be removed in Camel 3.0
protected void removeInterceptorWhichIsInThePhases(List<Interceptor<? extends Message>> interceptors, String[] phaseNames) {
+ removeInterceptorWhichIsInThePhases(interceptors, phaseNames, null);
+ }
+
+ protected void removeInterceptorWhichIsInThePhases(List<Interceptor<? extends Message>> interceptors, String[] phaseNames, Set<String> needToBeKept) {
for (Interceptor i : interceptors) {
if (i instanceof PhaseInterceptor) {
PhaseInterceptor p = (PhaseInterceptor) i;
for (String phaseName : phaseNames) {
if (p.getPhase().equals(phaseName)) {
- getLogger().info("removing the interceptor " + p);
- interceptors.remove(p);
- break;
+ // To support the old API
+ if (needToBeKept == null) {
+ getLogger().info("removing the interceptor " + p);
+ interceptors.remove(p);
+ break;
+ } else if (!needToBeKept.contains(p.getClass().getName())) {
+ getLogger().info("removing the interceptor " + p);
+ interceptors.remove(p);
+ break;
+ }
}
}
}
}
}
-
+
+ @Deprecated
+ // It will be removed in Camel 3.0
protected void removeInterceptorWhichIsOutThePhases(List<Interceptor<? extends Message>> interceptors, String[] phaseNames) {
+ removeInterceptorWhichIsOutThePhases(interceptors, phaseNames, null);
+ }
+
+ protected void removeInterceptorWhichIsOutThePhases(List<Interceptor<? extends Message>> interceptors, String[] phaseNames, Set<String> needToBeKept) {
for (Interceptor i : interceptors) {
boolean outside = false;
if (i instanceof PhaseInterceptor) {
@@ -60,8 +84,14 @@ public abstract class AbstractDataFormat
}
}
if (!outside) {
- getLogger().info("removing the interceptor " + p);
- interceptors.remove(p);
+ // To support the old API
+ if (needToBeKept == null) {
+ getLogger().info("removing the interceptor " + p);
+ interceptors.remove(p);
+ } else if (!needToBeKept.contains(p.getClass().getName())) {
+ getLogger().info("removing the interceptor " + p);
+ interceptors.remove(p);
+ }
}
}
}
@@ -84,4 +114,24 @@ public abstract class AbstractDataFormat
}
}
}
+
+ public void addInIntercepters(List<Interceptor<? extends Message>> interceptors) {
+ for (Interceptor interceptor : interceptors) {
+ inInterceptorNames.add(interceptor.getClass().getName());
+ }
+ }
+
+ public void addOutInterceptors(List<Interceptor<? extends Message>> interceptors) {
+ for (Interceptor interceptor : interceptors) {
+ outInterceptorNames.add(interceptor.getClass().getName());
+ }
+ }
+
+ public Set<String> getInInterceptorNames() {
+ return inInterceptorNames;
+ }
+
+ public Set<String> getOutInterceptorNames() {
+ return outInterceptorNames;
+ }
}
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=1200795&r1=1200794&r2=1200795&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 Nov 11 10:03:39 2011
@@ -23,6 +23,7 @@ import org.apache.camel.component.cxf.in
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.Interceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.message.Message;
@@ -56,20 +57,16 @@ public class MessageDataFormatFeature ex
@Override
public void initialize(Client client, Bus bus) {
//check if there is logging interceptor
-
- removeInterceptorWhichIsOutThePhases(client.getInInterceptors(), REMAINING_IN_PHASES);
- removeInterceptorWhichIsOutThePhases(client.getEndpoint().getInInterceptors(), REMAINING_IN_PHASES);
+ removeInterceptorWhichIsOutThePhases(client.getInInterceptors(), REMAINING_IN_PHASES, getInInterceptorNames());
+ removeInterceptorWhichIsOutThePhases(client.getEndpoint().getInInterceptors(), REMAINING_IN_PHASES, getInInterceptorNames());
client.getEndpoint().getBinding().getInInterceptors().clear();
//we need to keep the LoggingOutputInterceptor
- Interceptor<? extends Message> loggingOutputInterceptor = getLoggingOutInterceptor(client);
- removeInterceptorWhichIsOutThePhases(client.getOutInterceptors(), REMAINING_OUT_PHASES);
- removeInterceptorWhichIsOutThePhases(client.getEndpoint().getOutInterceptors(), REMAINING_OUT_PHASES);
+ getOutInterceptorNames().add(LoggingOutInterceptor.class.getName());
+ removeInterceptorWhichIsOutThePhases(client.getOutInterceptors(), REMAINING_OUT_PHASES, getOutInterceptorNames());
+ removeInterceptorWhichIsOutThePhases(client.getEndpoint().getOutInterceptors(), REMAINING_OUT_PHASES, getOutInterceptorNames());
client.getEndpoint().getBinding().getOutInterceptors().clear();
client.getEndpoint().getOutInterceptors().add(new RawMessageContentRedirectInterceptor());
- if (loggingOutputInterceptor != null) {
- client.getEndpoint().getOutInterceptors().add(loggingOutputInterceptor);
- }
}
@Override
@@ -77,63 +74,32 @@ public class MessageDataFormatFeature ex
// 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");
+ // keep the WSDLGetInterceptor
+ getInInterceptorNames().add(WSDLGetInterceptor.class.getName());
- removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getInInterceptors(), REMAINING_IN_PHASES);
- removeInterceptorWhichIsOutThePhases(server.getEndpoint().getInInterceptors(), REMAINING_IN_PHASES);
+ removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getInInterceptors(), REMAINING_IN_PHASES, getInInterceptorNames());
+ removeInterceptorWhichIsOutThePhases(server.getEndpoint().getInInterceptors(), REMAINING_IN_PHASES, getInInterceptorNames());
- // For CXF 2.4.x we need to add the WSDLGetInterceptor back
- if (wsdlGetInterceptor != null) {
- server.getEndpoint().getInInterceptors().add(wsdlGetInterceptor);
- }
//we need to keep the LoggingOutputInterceptor
- Interceptor<? extends Message> loggingOutputInterceptor = getLoggingOutInterceptor(server);
+ getOutInterceptorNames().add(LoggingOutInterceptor.class.getName());
// Do not using the binding interceptor any more
server.getEndpoint().getBinding().getInInterceptors().clear();
- removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getOutInterceptors(), REMAINING_OUT_PHASES);
- removeInterceptorWhichIsOutThePhases(server.getEndpoint().getOutInterceptors(), REMAINING_OUT_PHASES);
+ removeInterceptorWhichIsOutThePhases(server.getEndpoint().getService().getOutInterceptors(), REMAINING_OUT_PHASES, getOutInterceptorNames());
+ removeInterceptorWhichIsOutThePhases(server.getEndpoint().getOutInterceptors(), REMAINING_OUT_PHASES, getOutInterceptorNames());
// Do not use the binding interceptor any more
server.getEndpoint().getBinding().getOutInterceptors().clear();
server.getEndpoint().getOutInterceptors().add(new RawMessageContentRedirectInterceptor());
- if (loggingOutputInterceptor != null) {
- server.getEndpoint().getOutInterceptors().add(loggingOutputInterceptor);
- }
}
@Override
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;
- }
-
- protected Interceptor<? extends Message> getLoggingOutInterceptor(Client client) {
- Interceptor<? extends Message> result = getInterceptorByName(client.getOutInterceptors(), LoggingOutInterceptor.class.getName());
- if (result == null) {
- result = getInterceptorByName(client.getEndpoint().getOutInterceptors(), LoggingOutInterceptor.class.getName());
- }
- return result;
- }
-
- protected Interceptor<? extends Message> getLoggingOutInterceptor(Server server) {
- Interceptor<? extends Message> result = getInterceptorByName(server.getEndpoint().getOutInterceptors(), LoggingOutInterceptor.class.getName());
- if (result == null) {
- result = getInterceptorByName(server.getEndpoint().getService().getOutInterceptors(), LoggingOutInterceptor.class.getName());
- }
- return result;
- }
+
}