Author: ningjiang
Date: Sun Oct 28 03:54:23 2012
New Revision: 1402926
URL: http://svn.apache.org/viewvc?rev=1402926&view=rev
Log:
Added an unit test to show how to setup the cxf client timeout in the message
header
Added:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMessageHeaderTimeoutTest.java
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfMessageHeaderTimeOutContext.xml
Added:
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMessageHeaderTimeoutTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMessageHeaderTimeoutTest.java?rev=1402926&view=auto
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMessageHeaderTimeoutTest.java
(added)
+++
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMessageHeaderTimeoutTest.java
Sun Oct 28 03:54:23 2012
@@ -0,0 +1,95 @@
+/**
+ * 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.SocketTimeoutException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.hello_world_soap_http.Greeter;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfMessageHeaderTimeoutTest extends CamelSpringTestSupport {
+ protected static final String GREET_ME_OPERATION = "greetMe";
+ protected static final String TEST_MESSAGE = "Hello World!";
+ protected static final String SERVER_ADDRESS = "http://localhost:" +
CXFTestSupport.getPort1() + "/CxfMessageHeaderTimeoutTest/SoapContext/SoapPort";
+
+ @Override
+ public boolean isCreateCamelContextPerClass() {
+ return true;
+ }
+
+
+ @BeforeClass
+ public static void startService() {
+ Greeter implementor = new GreeterImplWithSleep();
+ Endpoint.publish(SERVER_ADDRESS, implementor);
+ }
+
+ @Test
+ public void testInvokingJaxWsServerWithCxfEndpoint() throws Exception {
+ sendTimeOutMessage("cxf://bean:springEndpoint");
+ }
+
+ protected void sendTimeOutMessage(String endpointUri) throws Exception {
+ Exchange reply = sendJaxWsMessage(endpointUri);
+ Exception e = reply.getException();
+ assertNotNull("We should get the exception cause here", e);
+ assertTrue("We should get the socket time out exception here", e
instanceof SocketTimeoutException);
+ }
+
+ protected Exchange sendJaxWsMessage(String endpointUri) throws
InterruptedException {
+ Exchange exchange = template.send(endpointUri, new Processor() {
+ public void process(final Exchange exchange) {
+ final List<String> params = new ArrayList<String>();
+ params.add(TEST_MESSAGE);
+ exchange.getIn().setBody(params);
+ exchange.getIn().setHeader(CxfConstants.OPERATION_NAME,
GREET_ME_OPERATION);
+ // setup the receive timeout dynamically
+ Map<String, Object> requestContext = new HashMap<String,
Object>();
+ HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
+ clientPolicy.setReceiveTimeout(100);
+ requestContext.put(HTTPClientPolicy.class.getName(),
clientPolicy);
+ exchange.getIn().setBody(params);
+ exchange.getIn().setHeader(Client.REQUEST_CONTEXT ,
requestContext);
+
+ }
+ });
+ return exchange;
+ }
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ // we can put the http conduit configuration here
+ return new
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/cxfMessageHeaderTimeOutContext.xml");
+ }
+
+
+}
Added:
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfMessageHeaderTimeOutContext.xml
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfMessageHeaderTimeOutContext.xml?rev=1402926&view=auto
==============================================================================
---
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfMessageHeaderTimeOutContext.xml
(added)
+++
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfMessageHeaderTimeOutContext.xml
Sun Oct 28 03:54:23 2012
@@ -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://camel.apache.org/schema/cxf"
+ xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd
+ http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+ <import resource="classpath:META-INF/cxf/cxf.xml"/>
+
+
+ <cxf:cxfEndpoint id="springEndpoint"
address="http://localhost:${CXFTestSupport.port1}/CxfMessageHeaderTimeoutTest/SoapContext/SoapPort"
+ serviceClass="org.apache.hello_world_soap_http.Greeter"/>
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"
errorHandlerRef="noErrorHandler">
+ <route errorHandlerRef="noErrorHandler">
+ <from uri="direct:start"/>
+ <to uri="cxf:bean:springEndpoint"/>
+ </route>
+ </camelContext>
+
+ <bean id="noErrorHandler"
class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
+
+</beans>
\ No newline at end of file