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 2013/06/17 09:41:14 UTC

git commit: Added an integration test for testing CXF_MESSAGE dataformat

Updated Branches:
  refs/heads/master 107e3a4ed -> d4aa9aece


Added an integration test for testing CXF_MESSAGE dataformat


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d4aa9aec
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d4aa9aec
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d4aa9aec

Branch: refs/heads/master
Commit: d4aa9aecefa340e953069a62a907ee1949f3012f
Parents: 107e3a4
Author: Willem Jiang <ni...@apache.org>
Authored: Mon Jun 17 15:35:01 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Mon Jun 17 15:36:57 2013 +0800

----------------------------------------------------------------------
 .../component/cxf/converter/CxfConverter.java   |  9 ++
 .../itest/security/CXFMessageProcessor.java     | 46 ++++++++++
 .../security/GreeterClientCxfMessageTest.java   |  8 ++
 .../camel/itest/security/GreeterClientTest.java |  2 +
 .../itest/security/CxfMessageCamelContext.xml   | 92 ++++++++++++++++++++
 5 files changed, 157 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d4aa9aec/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
index 512223e..c8e15f4 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/converter/CxfConverter.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.cxf.converter;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -23,6 +24,7 @@ import java.util.Collection;
 
 import javax.ws.rs.core.Response;
 import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPMessage;
 
@@ -95,6 +97,13 @@ public final class CxfConverter {
     }
     
     @Converter
+    public static SOAPMessage StringToSoapMessage(final String string, Exchange exchange) throws SOAPException, IOException {
+        InputStream is = new ByteArrayInputStream(string.getBytes(IOHelper.getCharsetName(exchange)));
+        SOAPMessage message = MessageFactory.newInstance().createMessage(null, is);
+        return message;
+    }
+    
+    @Converter
     public static DataFormat toDataFormat(final String name) {
         return DataFormat.valueOf(name.toUpperCase());
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/d4aa9aec/tests/camel-itest/src/test/java/org/apache/camel/itest/security/CXFMessageProcessor.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/CXFMessageProcessor.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/CXFMessageProcessor.java
new file mode 100644
index 0000000..538d1b4
--- /dev/null
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/CXFMessageProcessor.java
@@ -0,0 +1,46 @@
+/**
+ * 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.itest.security;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+
+import static org.junit.Assert.assertTrue;
+
+public class CXFMessageProcessor implements Processor {
+    static final String RESPONSE = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+        + "<soap:Body><greetMeResponse xmlns=\"http://apache.org/hello_world_soap_http/types\">"
+        + "<responseType> Hello CXF</responseType></greetMeResponse></soap:Body></soap:Envelope>";
+
+    public void process(Exchange exchange) throws Exception {
+        // just print out the request message
+        Message in = exchange.getIn();
+        String request = in.getBody(String.class);
+        // just make sure the request is greetme
+        assertTrue("It should be GreetMe request.", request.indexOf("<greetMe") > 0);
+        InputStream is = new ByteArrayInputStream(RESPONSE.getBytes());
+        SOAPMessage message = MessageFactory.newInstance().createMessage(null, is);
+        exchange.getOut().setBody(message);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d4aa9aec/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientCxfMessageTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientCxfMessageTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientCxfMessageTest.java
new file mode 100644
index 0000000..8aba72d
--- /dev/null
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientCxfMessageTest.java
@@ -0,0 +1,8 @@
+package org.apache.camel.itest.security;
+
+import org.springframework.test.context.ContextConfiguration;
+
+@ContextConfiguration(locations = {"CxfMessageCamelContext.xml"})
+public class GreeterClientCxfMessageTest extends GreeterClientTest {
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d4aa9aec/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java
index dca7a9f..6229c98 100644
--- a/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/security/GreeterClientTest.java
@@ -82,7 +82,9 @@ public class GreeterClientTest extends AbstractJUnit4SpringContextTests {
 
     @Test
     public void testServiceWithValidateUser() throws Exception {
+        
         String response = sendMessageWithUsernameToken("jim", "jimspassword", "CXF");
+        
         assertEquals(" Hello CXF", response);
 
         try {

http://git-wip-us.apache.org/repos/asf/camel/blob/d4aa9aec/tests/camel-itest/src/test/resources/org/apache/camel/itest/security/CxfMessageCamelContext.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/security/CxfMessageCamelContext.xml b/tests/camel-itest/src/test/resources/org/apache/camel/itest/security/CxfMessageCamelContext.xml
new file mode 100644
index 0000000..b58f273
--- /dev/null
+++ b/tests/camel-itest/src/test/resources/org/apache/camel/itest/security/CxfMessageCamelContext.xml
@@ -0,0 +1,92 @@
+<?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:cxf="http://camel.apache.org/schema/cxf"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        
+    xsi:schemaLocation="http://camel.apache.org/schema/cxf
+        http://camel.apache.org/schema/cxf/camel-cxf.xsd
+        http://camel.apache.org/schema/spring-security
+        http://camel.apache.org/schema/spring-security/camel-spring-security.xsd
+        http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd
+        http://cxf.apache.org/jaxws                                     
+        http://cxf.apache.org/schemas/jaxws.xsd">
+        
+    <!-- import the spring security configuration  -->
+    <import resource="classpath:org/apache/camel/itest/security/commonSecurity.xml"/>
+
+    <authorizationPolicy id="admin" access="ROLE_ADMIN"
+                         authenticationAdapter="myAuthenticationAdapter"
+                         authenticationManager="authenticationManager"
+                         accessDecisionManager="accessDecisionManager"
+                         xmlns="http://camel.apache.org/schema/spring-security"/>
+      
+    <bean id="myAuthenticationAdapter"  class="org.apache.camel.itest.security.MyAuthenticationAdapter"/>
+    <bean id="cxfMessageProcessor" class="org.apache.camel.itest.security.CXFMessageProcessor"/>
+
+    <camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/spring">
+        <route>
+            <from uri="cxf:bean:UsernameTokenEndpoint?dataFormat=CXF_MESSAGE" />
+            <!-- The exchange should be authenticated with the role of ADMIN before it is send to myProcessor -->
+            <policy ref="admin">
+                <process ref="cxfMessageProcessor"/>
+            </policy>
+        </route>
+    </camelContext>
+
+    <!--    
+         UsernameToken endpoint definition    
+         This endpoint is configured to read the username and password tokens    
+         and validate them using a password callback handler.    
+    -->
+    <cxf:cxfEndpoint
+        id="UsernameTokenEndpoint"
+        wsdlURL="wsdl/hello_world.wsdl"
+    	serviceClass="org.apache.hello_world_soap_http.Greeter"
+    	endpointName="s:SoapOverHttp"
+    	serviceName="s:SOAPService"
+    	xmlns:s="http://apache.org/hello_world_soap_http"
+        address="http://localhost:9000/SoapContext/SoapPort"
+        loggingFeatureEnabled="true"        
+        >
+        <cxf:inInterceptors>
+            <ref bean="UsernameToken_Request"/>
+        </cxf:inInterceptors>
+    </cxf:cxfEndpoint>
+
+    <!--    
+         WSS4JInInterceptor for UsernameTokenEndpoint above    
+    -->
+    <bean 
+        id="UsernameToken_Request"
+        class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"
+        >
+        <constructor-arg>
+            <map>
+                <entry key="action" value="UsernameToken"/> 
+                <entry key="passwordType" value="PasswordText"/>
+                <entry key="passwordCallbackClass" value="org.apache.camel.itest.security.KeystorePasswordCallback"/> 
+            </map>
+        </constructor-arg>
+    </bean>
+    
+</beans>