You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/05/13 12:03:18 UTC

svn commit: r774271 - in /servicemix/components/bindings/servicemix-cxf-bc/trunk/src: main/java/org/apache/servicemix/cxfbc/ test/java/org/apache/servicemix/cxfbc/ test/resources/org/apache/servicemix/cxfbc/secondSU/

Author: ffang
Date: Wed May 13 10:03:18 2009
New Revision: 774271

URL: http://svn.apache.org/viewvc?rev=774271&view=rev
Log:
[SMXCOMP-539]add test to verify the PIC of cxf bc su will always use its own classloader even use same jetty port with other SU

Added:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ClassloaderCampareInterceptor.java   (with props)
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcSUClassloaderTest.java   (with props)
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/calculator.wsdl   (with props)
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/xbean.xml   (with props)
Modified:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java?rev=774271&r1=774270&r2=774271&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java Wed May 13 10:03:18 2009
@@ -619,6 +619,7 @@
         }
       
         public void onMessage(Message m) {
+            m.put("suClassloader", suClassLoader);
             ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
             if (oldCl != suClassLoader) {
                 try {

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ClassloaderCampareInterceptor.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ClassloaderCampareInterceptor.java?rev=774271&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ClassloaderCampareInterceptor.java (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ClassloaderCampareInterceptor.java Wed May 13 10:03:18 2009
@@ -0,0 +1,37 @@
+/*
+ * 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.servicemix.cxfbc;
+
+import org.apache.cxf.binding.jbi.JBIFault;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class ClassloaderCampareInterceptor extends AbstractPhaseInterceptor {
+
+    public ClassloaderCampareInterceptor() {
+        super(Phase.PRE_INVOKE);
+    }
+
+    public void handleMessage(Message message) throws Fault {
+        if (Thread.currentThread().getContextClassLoader() != message.get("suClassloader")) {
+            throw new JBIFault("not use the SU's classloader");
+        }
+    }
+
+}

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ClassloaderCampareInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/ClassloaderCampareInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcSUClassloaderTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcSUClassloaderTest.java?rev=774271&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcSUClassloaderTest.java (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcSUClassloaderTest.java Wed May 13 10:03:18 2009
@@ -0,0 +1,106 @@
+/*
+ * 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.servicemix.cxfbc;
+
+import java.io.File;
+import java.net.URL;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.calculator.CalculatorPortType;
+import org.apache.cxf.calculator.CalculatorService;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class CxfBcSUClassloaderTest extends SpringTestSupport {
+    
+    private static final Logger LOG = LogUtils.getL7dLogger(CxfBcSUClassloaderTest.class);
+    private CxfBcComponent component;
+   
+    
+    public void setUp() throws Exception {
+        super.setUp();
+        LOG.info("setUp is invoked");
+        component = new CxfBcComponent();
+        jbi.activateComponent(component, "CxfBcComponent");
+        //Deploy second cxf bc consumer SU
+        component.getServiceUnitManager().deploy("secondSU", getServiceUnitPath("secondSU"));
+        component.getServiceUnitManager().init("secondSU", getServiceUnitPath("secondSU"));
+        component.getServiceUnitManager().start("secondSU");
+    }
+    
+        
+    public void tearDown() throws Exception {
+        component.getServiceUnitManager().stop("secondSU");
+        component.getServiceUnitManager().shutDown("secondSU");
+        component.getServiceUnitManager().undeploy("secondSU", getServiceUnitPath("secondSU"));
+    }
+
+    public void testSUClassLoader() throws Exception {
+        URL wsdl = getClass().getResource("/wsdl/calculator.wsdl");
+        assertNotNull(wsdl);
+        CalculatorService service = new CalculatorService(wsdl, new QName(
+                "http://apache.org/cxf/calculator", "CalculatorService"));
+        CalculatorPortType port = service.getCalculatorPort();
+        ClientProxy.getClient(port).getInFaultInterceptors().add(new LoggingInInterceptor());
+        ClientProxy.getClient(port).getInInterceptors().add(new LoggingInInterceptor());
+        int ret = port.add(1, 2);
+        assertEquals(ret, 3);
+        
+        wsdl = getClass().getClassLoader().getResource("org/apache/servicemix/cxfbc/secondSU/calculator.wsdl");
+        assertNotNull(wsdl);
+        service = new CalculatorService(wsdl, new QName(
+                "http://apache.org/cxf/calculator", "CalculatorSecondService"));
+        port = service.getCalculatorPort();
+        ClientProxy.getClient(port).getInFaultInterceptors().add(new LoggingInInterceptor());
+        ClientProxy.getClient(port).getInInterceptors().add(new LoggingInInterceptor());
+        try {
+            ret = port.add(1, 2);
+            assertEquals(ret, 3);
+        } catch (Exception e) {
+            fail();
+        }
+    }
+    
+    @Override
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        // load cxf se and bc from spring config file
+        return new ClassPathXmlApplicationContext(
+                "org/apache/servicemix/cxfbc/xbean.xml");
+    }
+    
+    protected AbstractXmlApplicationContext createBeanFactory(String beanFile) {
+        //load cxf se and bc from specified spring config file
+        return new ClassPathXmlApplicationContext(
+            beanFile);
+    }
+    
+    protected String getServiceUnitPath(String name) {
+        URL url = getClass().getClassLoader().getResource("org/apache/servicemix/cxfbc/" + name + "/xbean.xml");
+        File path = new File(url.getFile());
+        path = path.getParentFile();
+        System.out.println("the absolutepath is " + path.getAbsolutePath());
+        return path.getAbsolutePath();
+    }
+
+}

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcSUClassloaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/java/org/apache/servicemix/cxfbc/CxfBcSUClassloaderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/calculator.wsdl
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/calculator.wsdl?rev=774271&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/calculator.wsdl (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/calculator.wsdl Wed May 13 10:03:18 2009
@@ -0,0 +1,94 @@
+<?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.
+-->
+
+<definitions name="Calculator"  
+	     targetNamespace="http://apache.org/cxf/calculator"
+	     xmlns:tns="http://apache.org/cxf/calculator"
+	     xmlns="http://schemas.xmlsoap.org/wsdl/" 
+	     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+	     xmlns:x1="http://apache.org/cxf/calculator/types"
+	     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
+    <types>
+	<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" 
+		    elementFormDefault="qualified" 
+		    targetNamespace="http://apache.org/cxf/calculator/types">
+
+	    <complexType name="addNumbersResponse">
+		<sequence>
+		    <element name="return" type="xsd:int" />
+		</sequence>
+	    </complexType>
+	    <element name="addNumbersResponse" type="x1:addNumbersResponse" />
+
+	    <complexType name="addNumbers">
+		<sequence>
+		    <element name="arg0" type="xsd:int" />
+		    <element name="arg1" type="xsd:int" />
+		</sequence>
+	    </complexType>
+	    <element name="add" type="x1:addNumbers" />
+
+	    <element name="CalculatorFault" type="x1:CalculatorFault" />
+	    <complexType name="CalculatorFault">
+		<sequence>
+		    <element name="faultInfo" type="xsd:string" />
+		    <element name="message" type="xsd:string" />
+		</sequence>
+	    </complexType>
+	</xsd:schema>
+    </types>
+    <message name="add">
+	<part name="parameters" element="x1:add" />
+    </message>
+    <message name="addNumbersResponse">
+	<part name="result" element="x1:addNumbersResponse" />
+    </message>
+    <message name="addNumbersFault">
+	<part name="CalculatorFault" element="x1:CalculatorFault" />
+    </message>
+    <portType name="CalculatorPortType">
+	<operation name="add">
+	    <input message="tns:add"/>
+	    <output message="tns:addNumbersResponse"/>
+	    <fault name="addNumbersFault" message="tns:addNumbersFault"/>
+	</operation>
+    </portType>
+
+    <binding name="CalculatorBinding" type="tns:CalculatorPortType">
+	<soap12:binding transport="http://www.w3.org/2003/05/soap/bindings/HTTP/" style="document" />
+	<operation name="add">
+	    <soap12:operation soapAction="" />
+	    <input>
+		<soap12:body use="literal" />
+	    </input>
+	    <output>
+		<soap12:body use="literal" />
+	    </output>
+	    <fault name="addNumbersFault">
+		<soap12:fault name="addNumbersFault" use="literal" />
+	    </fault>
+	</operation>
+    </binding>
+    <service name="CalculatorSecondService">
+	<port name="CalculatorPort" binding="tns:CalculatorBinding">
+	    <soap12:address location="http://localhost:9000/CalculatorSecondService/SoapPort" />
+	</port>
+    </service>
+</definitions>

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/calculator.wsdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/calculator.wsdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/calculator.wsdl
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/xbean.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/xbean.xml?rev=774271&view=auto
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/xbean.xml (added)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/xbean.xml Wed May 13 10:03:18 2009
@@ -0,0 +1,48 @@
+<?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:sm="http://servicemix.apache.org/config/1.0"
+       xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0"
+       xmlns:cxfbc="http://servicemix.apache.org/cxfbc/1.0"
+       xmlns:test="urn:test"
+       xmlns:calculator="http://apache.org/cxf/calculator">
+  
+    
+      <cxfbc:consumer wsdl="classpath:calculator.wsdl"
+                      targetEndpoint="CalculatorPort"
+                      targetService="calculator:CalculatorService"
+                      targetInterface="calculator:CalculatorPortType"
+                      >
+        <cxfbc:inInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+          <bean class="org.apache.servicemix.cxfbc.ClassloaderCampareInterceptor"/>
+        </cxfbc:inInterceptors>
+        <cxfbc:outInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfbc:outInterceptors>
+        <cxfbc:inFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+        </cxfbc:inFaultInterceptors>
+        <cxfbc:outFaultInterceptors>
+          <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+        </cxfbc:outFaultInterceptors>
+      </cxfbc:consumer>
+    
+  
+</beans>

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/xbean.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/xbean.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/secondSU/xbean.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml