Author: ningjiang
Date: Sun Aug 12 07:35:17 2007
New Revision: 565076

URL: http://svn.apache.org/viewvc?view=rev&rev=565076
Log:
CXF-902 resolved the ClassCastException in CXFServlet.loadSpringBus when spring 
context initalization fails

Added:
    
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java
   (with props)
    
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring-error.xml
   (with props)
    
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/web-spring-error.xml
   (with props)
Modified:
    
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java

Modified: 
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java?view=diff&rev=565076&r1=565075&r2=565076
==============================================================================
--- 
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
 (original)
+++ 
incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/CXFServlet.java
 Sun Aug 12 07:35:17 2007
@@ -138,8 +138,15 @@
 
         // Spring 2.0
         if (ctx == null) {
-            ctx = (ApplicationContext)svCtx
+            Object ctxObject = svCtx
                 
.getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
+            if (ctxObject instanceof ApplicationContext) {
+                ctx = (ApplicationContext) ctxObject;
+            } else {
+                // it should be the runtime exception
+                Exception ex = (Exception) ctxObject;
+                throw new ServletException(ex);
+            }                   
         }
         
         // This constructor works whether there is a context or not

Added: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java?view=auto&rev=565076
==============================================================================
--- 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java
 (added)
+++ 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java
 Sun Aug 12 07:35:17 2007
@@ -0,0 +1,59 @@
+/**
+ * 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.cxf.systest.servlet;
+
+import com.meterware.servletunit.ServletRunner;
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusException;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ErrorContextSerletTest extends AbstractServletTest {
+    @Override
+    protected String getConfiguration() {
+        return "/org/apache/cxf/systest/servlet/web-spring-error.xml";
+    }
+
+    @Override
+    protected Bus createBus() throws BusException {
+        // don't set up the bus, let the servlet do it
+        return null;
+    }
+    
+    @Before
+    public void setUp() throws Exception {
+        // do nothing here
+             
+    } 
+    
+    @Test
+    public void testInvoke() {
+        try {
+            sr = new ServletRunner(getResourceAsStream(getConfiguration()), 
CONTEXT);
+            sr.newClient().getResponse(CONTEXT_URL + "/services");
+            // there expect a class not found exception
+            fail("we expect a CannotLoadBeanClassException here");
+        } catch (Exception ex) {
+            assertTrue("we expect a CannotLoadBeanClassException here",
+                      ex instanceof 
org.springframework.beans.factory.CannotLoadBeanClassException);
+        } 
+    }
+
+
+}

Propchange: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/ErrorContextSerletTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring-error.xml
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring-error.xml?view=auto&rev=565076
==============================================================================
--- 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring-error.xml
 (added)
+++ 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring-error.xml
 Sun Aug 12 07:35:17 2007
@@ -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:jaxws="http://cxf.apache.org/jaxws";
+      xsi:schemaLocation="
+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 resource="classpath:META-INF/cxf/cxf.xml"/>
+  <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
+  <import resource="classpath:META-INF/cxf/cxf-extension-http-binding.xml"/>
+  <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+  
+  
+  <bean id="greeterServerFactory"
+    class="org.apache.cxf.jaxws.JaxWsServerFactoryBean123" 
init-method="create">
+    <property name="serviceClass" 
value="org.apache.hello_world_soap_http.GreeterImpl" />
+    <property name="serviceBean">
+      <bean class="org.apache.hello_world_soap_http.GreeterImpl"/>
+    </property>
+    <property name="address" value="/services/Greeter"/>
+    <property name="bus" ref="cxf"/>
+    <property name="bindingId" value="http://apache.org/cxf/binding/http"/>
+  </bean>
+  
+   
+  
+</beans>

Propchange: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring-error.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring-error.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/spring-error.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/web-spring-error.xml
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/web-spring-error.xml?view=auto&rev=565076
==============================================================================
--- 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/web-spring-error.xml
 (added)
+++ 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/web-spring-error.xml
 Sun Aug 12 07:35:17 2007
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+    "http://java.sun.com/dtd/web-app_2_3.dtd";>
+
+<!--
+       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.
+-->
+
+<web-app>
+       <context-param>
+               <param-name>contextConfigLocation</param-name>
+               <param-value>
+                       
classpath:org/apache/cxf/systest/servlet/spring-error.xml
+               </param-value>
+       </context-param>
+
+       <listener>
+               <listener-class>
+                       org.springframework.web.context.ContextLoaderListener
+               </listener-class>
+       </listener>
+       
+       <servlet>
+               <servlet-name>CXFServlet</servlet-name>
+               <display-name>CXF Servlet</display-name>
+               <servlet-class>
+                       org.apache.cxf.transport.servlet.CXFServlet
+               </servlet-class>
+               <load-on-startup>1</load-on-startup>
+       </servlet>
+
+       <servlet-mapping>
+               <servlet-name>CXFServlet</servlet-name>
+               <url-pattern>/*</url-pattern>
+       </servlet-mapping>
+
+
+</web-app>
\ No newline at end of file

Propchange: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/web-spring-error.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/web-spring-error.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/servlet/web-spring-error.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to