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/27 03:34:06 UTC
svn commit: r758990 - in /camel/trunk/components/camel-cxf/src/test:
java/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest.java
resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml
Author: wtam
Date: Fri Mar 27 02:34:05 2009
New Revision: 758990
URL: http://svn.apache.org/viewvc?rev=758990&view=rev
Log:
Add a test for [CAMEL-1351]
Added:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest.java (with props)
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml (with props)
Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest.java?rev=758990&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest.java Fri Mar 27 02:34:05 2009
@@ -0,0 +1,126 @@
+/**
+ * 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.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.camel.CamelContext;
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.frontend.ClientFactoryBean;
+import org.apache.cxf.frontend.ClientProxyFactoryBean;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+/**
+ *
+ * @version $Revision$
+ */
+@ContextConfiguration
+public class LoggingInterceptorInMessageModeTest extends AbstractJUnit38SpringContextTests {
+
+ protected static final String ROUTER_ADDRESS = "http://localhost:9000/router";
+ protected static final String SERVICE_ADDRESS = "http://localhost:9002/helloworld";
+
+ @Autowired
+ protected CamelContext context;
+
+ protected Server server;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ startService();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+
+ if (server != null) {
+ server.stop();
+ server = null;
+ }
+
+ super.tearDown();
+ }
+
+ protected void startService() {
+ //start a service
+ ServerFactoryBean svrBean = new ServerFactoryBean();
+
+ svrBean.setAddress(SERVICE_ADDRESS);
+ svrBean.setServiceClass(HelloService.class);
+ svrBean.setServiceBean(new HelloServiceImpl());
+
+ server = svrBean.create();
+ server.start();
+ }
+
+ public void testInvokingServiceFromCXFClient() throws Exception {
+
+ LoggingOutInterceptor logInterceptor = null;
+
+ for (Interceptor<?> interceptor
+ : context.getEndpoint("cxf:bean:serviceEndpoint", CxfSpringEndpoint.class).getBean()
+ .getOutInterceptors()) {
+ if (interceptor instanceof LoggingOutInterceptor) {
+ logInterceptor = LoggingOutInterceptor.class.cast(interceptor);
+ break;
+ }
+ }
+
+ assertNotNull(logInterceptor);
+ // StringPrintWriter writer = new StringPrintWriter();
+ // Unfortunately, LoggingOutInterceptor does not have a setter for writer so
+ // we can't capture the output to verify.
+ // logInterceptor.setPrintWriter(writer);
+
+ ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
+ ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
+ clientBean.setAddress(ROUTER_ADDRESS);
+ clientBean.setServiceClass(HelloService.class);
+
+ HelloService client = (HelloService) proxyFactory.create();
+
+ String result = client.echo("hello world");
+ assertEquals("we should get the right answer from router", result, "echo hello world");
+ //assertTrue(writer.getString().indexOf("hello world") > 0);
+
+ }
+
+ @SuppressWarnings("unused")
+ private final class StringPrintWriter extends PrintWriter {
+ private StringPrintWriter() {
+ super(new StringWriter());
+ }
+
+ private StringPrintWriter(int initialSize) {
+ super(new StringWriter(initialSize));
+ }
+
+ private String getString() {
+ flush();
+ return ((StringWriter) out).toString();
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml?rev=758990&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml Fri Mar 27 02:34:05 2009
@@ -0,0 +1,51 @@
+<?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"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.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
+ ">
+
+ <bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor">
+ <constructor-arg value="user-stream"/>
+ </bean>
+
+ <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9000/router"
+ serviceClass="org.apache.camel.component.cxf.HelloService">
+ <cxf:properties>
+ <entry key="dataFormat" value="MESSAGE"/>
+ </cxf:properties>
+ </cxf:cxfEndpoint>
+
+ <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9002/helloworld"
+ serviceClass="org.apache.camel.component.cxf.HelloService">
+ <cxf:outInterceptors>
+ <ref bean="loggingOutInterceptor"/>
+ </cxf:outInterceptors>
+ <cxf:properties>
+ <entry key="dataFormat" value="MESSAGE"/>
+ </cxf:properties>
+ </cxf:cxfEndpoint>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="cxf:bean:routerEndpoint" />
+ <to uri="cxf:bean:serviceEndpoint" />
+ </route>
+ </camelContext>
+</beans>
\ No newline at end of file
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/LoggingInterceptorInMessageModeTest-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml