You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by wt...@apache.org on 2009/03/12 19:04:29 UTC
svn commit: r752956 - in /camel/trunk/components/camel-cxf/src:
main/java/org/apache/camel/component/cxf/
main/java/org/apache/camel/component/cxf/feature/
main/java/org/apache/camel/component/cxf/interceptors/
test/java/org/apache/camel/component/cxf/...
Author: wtam
Date: Thu Mar 12 18:04:28 2009
New Revision: 752956
URL: http://svn.apache.org/viewvc?rev=752956&view=rev
Log:
[CAMEL-1454] CXF component running in Payload mode does not work with Holders
Added:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstPayloadModeTest.java (with props)
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml (with props)
Modified:
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/AbstractMessageInInterceptor.java
camel/trunk/components/camel-cxf/src/test/resources/logging.properties
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java?rev=752956&r1=752955&r2=752956&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java Thu Mar 12 18:04:28 2009
@@ -34,6 +34,7 @@
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.context.WrappedMessageContext;
import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
import org.apache.cxf.service.model.BindingOperationInfo;
/**
@@ -78,7 +79,7 @@
CxfBinding binding = endpoint.getCxfBinding();
// create invocation context
- Map<String, Object> requestContext = new WrappedMessageContext(
+ WrappedMessageContext requestContext = new WrappedMessageContext(
new HashMap<String, Object>(), null, Scope.APPLICATION);
Map<String, Object> responseContext = new HashMap<String, Object>();
@@ -125,10 +126,14 @@
}
}
+ // Remove protocol headers from scopes. Otherwise, response headers can be
+ // overwritten by request headers when SOAPHandlerInterceptor tries to create
+ // a wrapped message context by the copyScoped() method.
+ requestContext.getScopes().remove(Message.PROTOCOL_HEADERS);
+
Map<String, Object> invocationContext = new HashMap<String, Object>();
invocationContext.put(Client.RESPONSE_CONTEXT, responseContext);
- invocationContext.put(Client.REQUEST_CONTEXT,
- ((WrappedMessageContext)requestContext).getWrappedMap());
+ invocationContext.put(Client.REQUEST_CONTEXT, requestContext.getWrappedMap());
// send the CXF request
client.invoke(boi, getParams(endpoint, camelExchange),
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java?rev=752956&r1=752955&r2=752956&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/feature/PayLoadDataFormatFeature.java Thu Mar 12 18:04:28 2009
@@ -36,11 +36,17 @@
public class PayLoadDataFormatFeature extends AbstractDataFormatFeature {
private static final Logger LOG = LogUtils.getL7dLogger(PayLoadDataFormatFeature.class);
// filter the unused phase
- private static final String[] REMOVING_IN_PHASES = {Phase.UNMARSHAL, Phase.PRE_LOGICAL,
- Phase.PRE_LOGICAL_ENDING, Phase.POST_LOGICAL, Phase.POST_LOGICAL_ENDING };
-
- private static final String[] REMOVING_OUT_PHASES = {Phase.MARSHAL, Phase.MARSHAL_ENDING,
- Phase.PRE_LOGICAL, Phase.PRE_LOGICAL_ENDING, Phase.POST_LOGICAL, Phase.POST_LOGICAL_ENDING };
+
+ // PRE_INVOKE needs to be removed. Otherwise, HolderInInterceptor will interfere us
+ private static final String[] REMOVING_IN_PHASES = {
+ Phase.UNMARSHAL, Phase.PRE_LOGICAL, Phase.PRE_LOGICAL_ENDING, Phase.POST_LOGICAL,
+ Phase.POST_LOGICAL_ENDING, Phase.PRE_INVOKE
+ };
+
+ private static final String[] REMOVING_OUT_PHASES = {
+ Phase.MARSHAL, Phase.MARSHAL_ENDING, Phase.PRE_LOGICAL, Phase.PRE_LOGICAL_ENDING, Phase.POST_LOGICAL,
+ Phase.POST_LOGICAL_ENDING
+ };
@Override
public void initialize(Client client, Bus bus) {
Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/AbstractMessageInInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/AbstractMessageInInterceptor.java?rev=752956&r1=752955&r2=752956&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/AbstractMessageInInterceptor.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/AbstractMessageInInterceptor.java Thu Mar 12 18:04:28 2009
@@ -78,14 +78,18 @@
Element payloadEl = (Element)document.getChildNodes().item(0);
Exchange ex = message.getExchange();
+
+ // make sure BindingInfo put in the exchange
+ BindingInfo bi = ex.get(BindingInfo.class);
+ if (bi == null) {
+ Endpoint ep = ex.get(Endpoint.class);
+ bi = ep.getEndpointInfo().getBinding();
+ ex.put(BindingInfo.class, bi);
+ }
+
BindingOperationInfo boi = ex.get(BindingOperationInfo.class);
if (boi == null) {
- BindingInfo bi = ex.get(BindingInfo.class);
- if (bi == null) {
- Endpoint ep = ex.get(Endpoint.class);
- bi = ep.getEndpointInfo().getBinding();
- ex.put(BindingInfo.class, bi);
- }
+
// handling inbound message
if (logger.isLoggable(Level.INFO)) {
logger.info("AbstractRoutingMessageInInterceptor Infer BindingOperationInfo.");
Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstPayloadModeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstPayloadModeTest.java?rev=752956&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstPayloadModeTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstPayloadModeTest.java Thu Mar 12 18:04:28 2009
@@ -0,0 +1,94 @@
+/**
+ * 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.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Holder;
+
+import org.apache.camel.wsdl_first.JaxwsTestHandler;
+import org.apache.camel.wsdl_first.Person;
+import org.apache.camel.wsdl_first.PersonService;
+import org.apache.camel.wsdl_first.UnknownPersonFault;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfWsdlFirstPayloadModeTest extends CxfWsdlFirstTest {
+
+
+ @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml");
+ }
+
+ @Override
+ public void testInvokingServiceFromCXFClient() throws Exception {
+
+ JaxwsTestHandler fromHandler = getMandatoryBean(JaxwsTestHandler.class, "fromEndpointJaxwsHandler");
+ fromHandler.reset();
+
+ JaxwsTestHandler toHandler = getMandatoryBean(JaxwsTestHandler.class, "toEndpointJaxwsHandler");
+ toHandler.reset();
+
+ URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
+ PersonService ss = new PersonService(wsdlURL, new QName("http://camel.apache.org/wsdl-first", "PersonService"));
+ Person client = ss.getSoap();
+ Holder<String> personId = new Holder<String>();
+ personId.value = "hello";
+ Holder<String> ssn = new Holder<String>();
+ Holder<String> name = new Holder<String>();
+
+ client.getPerson(personId, ssn, name);
+ assertEquals("we should get the right answer from router", "Bonjour", name.value);
+
+ Throwable t = null;
+ personId.value = "";
+ try {
+ client.getPerson(personId, ssn, name);
+ fail("We expect to get the UnknowPersonFault here");
+ } catch (UnknownPersonFault fault) {
+ // We expect to get fault here
+ t = fault;
+ }
+
+ assertTrue(t instanceof UnknownPersonFault);
+
+ // Note: Since unmarshal phase has been removed in PAYLOAD mode,
+ // it is not able to validate against the schema.
+ personId.value = "Invoking getPerson with invalid length string, expecting exception...xxxxxxxxx";
+ client.getPerson(personId, ssn, name);
+
+ verifyJaxwsHandlers(fromHandler, toHandler);
+ }
+
+ @Override
+ public void testInvokingServiceWithCamelProducer() throws Exception {
+ // this test does not apply to PAYLOAD mode
+ }
+
+ @Override
+ protected void verifyJaxwsHandlers(JaxwsTestHandler fromHandler, JaxwsTestHandler toHandler) {
+ assertEquals(1, fromHandler.getFaultCount());
+ assertEquals(5, fromHandler.getMessageCount());
+ assertEquals(8, toHandler.getGetHeadersCount());
+ assertEquals(10, toHandler.getMessageCount());
+ assertEquals(6, toHandler.getFaultCount());
+
+ }
+
+
+}
Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstPayloadModeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstPayloadModeTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: camel/trunk/components/camel-cxf/src/test/resources/logging.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/logging.properties?rev=752956&r1=752955&r2=752956&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/logging.properties (original)
+++ camel/trunk/components/camel-cxf/src/test/resources/logging.properties Thu Mar 12 18:04:28 2009
@@ -55,12 +55,12 @@
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = %h/java%u.log
-java.util.logging.FileHandler.limit = 50000
+java.util.logging.FileHandler.limit = 5000000
java.util.logging.FileHandler.count = 1
-java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
+java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
# Limit the message that are printed on the console to INFO and above.
-java.util.logging.ConsoleHandler.level = WARNING
+java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
@@ -72,3 +72,4 @@
# For example, set the com.xyz.foo logger to only log SEVERE
# messages:
#com.xyz.foo.level = SEVERE
+org.apache.cxf.level = FINEST
Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml?rev=752956&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml Thu Mar 12 18:04:28 2009
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/cxf"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+ <cxf:cxfEndpoint id="routerEndpoint"
+ address="http://localhost:8092/PersonService/" serviceClass="org.apache.camel.wsdl_first.Person"
+ endpointName="person:soap" serviceName="person:PersonService" wsdlURL="person.wsdl"
+ xmlns:person="http://camel.apache.org/wsdl-first">
+ <cxf:properties>
+ <entry key="schema-validation-enabled" value="true" />
+ </cxf:properties>
+ <cxf:handlers>
+ <ref bean="fromEndpointJaxwsHandler" />
+ </cxf:handlers>
+ <cxf:inInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
+ </cxf:inInterceptors>
+ <cxf:outInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
+ </cxf:outInterceptors>
+ </cxf:cxfEndpoint>
+
+ <cxf:cxfEndpoint id="serviceEndpoint"
+ address="http://localhost:9000/PersonService/" serviceClass="org.apache.camel.wsdl_first.Person"
+ endpointName="person:soap" serviceName="person:PersonService"
+ xmlns:person="http://camel.apache.org/wsdl-first">
+ <cxf:handlers>
+ <ref bean="toEndpointJaxwsHandler" />
+ </cxf:handlers>
+ <cxf:inInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingInInterceptor" />
+ </cxf:inInterceptors>
+ <cxf:outInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
+ </cxf:outInterceptors>
+ </cxf:cxfEndpoint>
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="cxf:bean:routerEndpoint?dataFormat=PAYLOAD" />
+ <to uri="cxf:bean:serviceEndpoint?dataFormat=PAYLOAD" />
+ </route>
+ </camelContext>
+ <bean id="fromEndpointJaxwsHandler" class="org.apache.camel.wsdl_first.JaxwsTestHandler" />
+ <bean id="toEndpointJaxwsHandler" class="org.apache.camel.wsdl_first.JaxwsTestHandler" />
+</beans>
\ No newline at end of file
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstBeansPayloadMode.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml