Author: ningjiang
Date: Mon Jun 9 21:15:03 2008
New Revision: 665971
URL: http://svn.apache.org/viewvc?rev=665971&view=rev
Log:
Added unitest to show how to work with the camel-cxf endpoint's Holders message
in processor
Added:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstProcessorTest.java
(with props)
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonProcessor.java
(with props)
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstProcessor.xml
(with props)
Modified:
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonImpl.java
Modified:
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java?rev=665971&r1=665970&r2=665971&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
(original)
+++
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CamelInvoker.java
Mon Jun 9 21:15:03 2008
@@ -182,7 +182,7 @@
if (result != null) {
if (result instanceof MessageContentsList || result instanceof
List || result.getClass().isArray()) {
return result;
- } else {
+ } else { // if the result is the single object
MessageContentsList resList = new MessageContentsList();
resList.add(result);
return resList;
Added:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstProcessorTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstProcessorTest.java?rev=665971&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstProcessorTest.java
(added)
+++
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstProcessorTest.java
Mon Jun 9 21:15:03 2008
@@ -0,0 +1,44 @@
+/**
+ * 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.Endpoint;
+import javax.xml.ws.Holder;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.SpringTestSupport;
+import org.apache.camel.wsdl_first.Person;
+import org.apache.camel.wsdl_first.PersonImpl;
+import org.apache.camel.wsdl_first.PersonService;
+import org.apache.camel.wsdl_first.UnknownPersonFault;
+import org.apache.cxf.endpoint.ServerImpl;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfWsdlFirstProcessorTest extends CxfWsdlFirstTest {
+
+
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/WsdlFirstProcessor.xml");
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstProcessorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstProcessorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstTest.java?rev=665971&r1=665970&r2=665971&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstTest.java
(original)
+++
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfWsdlFirstTest.java
Mon Jun 9 21:15:03 2008
@@ -28,6 +28,7 @@
import org.apache.camel.wsdl_first.Person;
import org.apache.camel.wsdl_first.PersonImpl;
import org.apache.camel.wsdl_first.PersonService;
+import org.apache.camel.wsdl_first.UnknownPersonFault;
import org.apache.cxf.endpoint.ServerImpl;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
@@ -80,13 +81,21 @@
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();
- ClientProxy.getClient(client).getOutInterceptors().add(new
LoggingOutInterceptor());
Holder<String> personId = new Holder<String>();
- personId.value = "world";
+ 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);
+
+ 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
+ fault.printStackTrace();
+ }
}
Modified:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonImpl.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonImpl.java?rev=665971&r1=665970&r2=665971&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonImpl.java
(original)
+++
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonImpl.java
Mon Jun 9 21:15:03 2008
@@ -26,12 +26,11 @@
public void getPerson(Holder<String> personId, Holder<String> ssn,
Holder<String> name) throws UnknownPersonFault {
- //System.out.println("the server is invoked ");
if (personId.value == null || personId.value.length() == 0) {
org.apache.camel.wsdl_first.types.UnknownPersonFault
fault = new
org.apache.camel.wsdl_first.types.UnknownPersonFault();
fault.setPersonId(personId.value);
- throw new UnknownPersonFault(null, fault);
+ throw new UnknownPersonFault("Get the null value of person name",
fault);
}
name.value = "Bonjour";
ssn.value = "000-000-0000";
Added:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonProcessor.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonProcessor.java?rev=665971&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonProcessor.java
(added)
+++
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonProcessor.java
Mon Jun 9 21:15:03 2008
@@ -0,0 +1,57 @@
+/**
+ * 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.wsdl_first;
+
+import javax.xml.ws.Holder;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.wsdl_first.types.GetPersonResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.message.MessageContentsList;
+
+public class PersonProcessor implements Processor {
+
+ private static final transient Log LOG =
LogFactory.getLog(PersonProcessor.class);
+
+ public void process(Exchange exchange) throws Exception {
+ LOG.info("processing exchange in camel");
+
+ MessageContentsList msgList =
(MessageContentsList)exchange.getIn().getBody();
+ Holder<String> personId = (Holder<String>)msgList.get(0);
+ Holder<String> ssn = (Holder<String>)msgList.get(1);
+ Holder<String> name = (Holder<String>)msgList.get(2);
+
+ if (personId.value == null || personId.value.length() == 0) {
+ // only wrote the rubbish above to get into this section
+ LOG.info("person id 123, so throwing exception");
+ org.apache.camel.wsdl_first.types.UnknownPersonFault personFault =
+ new org.apache.camel.wsdl_first.types.UnknownPersonFault();
+ personFault.setPersonId("");
+ org.apache.camel.wsdl_first.UnknownPersonFault fault =
+ new org.apache.camel.wsdl_first.UnknownPersonFault("Get the
null value of person name", personFault);
+ exchange.getFault().setBody(fault);
+ }
+
+ name.value = "Bonjour";
+ ssn.value = "123";
+ LOG.info("setting Bonjour as the response");
+ exchange.getOut().setBody(new Object[] {null, personId, ssn, name});
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/wsdl_first/PersonProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstProcessor.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstProcessor.xml?rev=665971&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstProcessor.xml
(added)
+++
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstProcessor.xml
Mon Jun 9 21:15:03 2008
@@ -0,0 +1,46 @@
+<?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://activemq.apache.org/camel/schema/cxfEndpoint"
+ xmlns:camel="http://activemq.apache.org/camel/schema/spring"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://activemq.apache.org/camel/schema/cxfEndpoint
http://activemq.apache.org/camel/schema/cxf/cxfEndpoint.xsd
+ http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/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"
+ xmlns:person="http://camel.apache.org/wsdl-first"/>
+
+ <bean id="personProcessor"
class="org.apache.camel.wsdl_first.PersonProcessor"/>
+
+ <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="cxf:bean:routerEndpoint?dataFormat=POJO"/>
+ <process ref= "personProcessor"/>
+ </route>
+
+ </camelContext>
+
+
+</beans>
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstProcessor.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstProcessor.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/WsdlFirstProcessor.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml