Author: dkulp
Date: Fri Aug 17 14:02:37 2007
New Revision: 567144
URL: http://svn.apache.org/viewvc?view=rev&rev=567144
Log:
Add ability to inject Bus into things with @Resource
Add ResourceResolver that wraps the Spring ApplicationContext so spring beans
can be injected into handlers and such
Added:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
(with props)
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/resource/ResourceManagerImpl.java
incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/resource/ResourceManagerImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/resource/ResourceManagerImpl.java?view=diff&rev=567144&r1=567143&r2=567144
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/resource/ResourceManagerImpl.java
(original)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/resource/ResourceManagerImpl.java
Fri Aug 17 14:02:37 2007
@@ -26,13 +26,15 @@
import javax.annotation.Resource;
import org.apache.cxf.Bus;
+import org.apache.cxf.extension.BusExtension;
import org.apache.cxf.resource.DefaultResourceManager;
+import org.apache.cxf.resource.ObjectTypeResolver;
import org.apache.cxf.resource.PropertiesResolver;
import org.apache.cxf.resource.ResourceManager;
import org.apache.cxf.resource.ResourceResolver;
-public class ResourceManagerImpl extends DefaultResourceManager {
+public class ResourceManagerImpl extends DefaultResourceManager implements
BusExtension {
private Bus bus;
@@ -57,9 +59,15 @@
@PostConstruct
public void register() {
- if (null != bus) {
+ super.addResourceResolver(new ObjectTypeResolver(bus));
+ if (null != bus && bus.getExtension(ResourceManager.class) != this) {
bus.setExtension(this, ResourceManager.class);
}
}
+
+ public Class<?> getRegistrationType() {
+ return ResourceManager.class;
+ }
+
}
Added:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java?view=auto&rev=567144
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
(added)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
Fri Aug 17 14:02:37 2007
@@ -0,0 +1,67 @@
+/**
+ * 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.bus.spring;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.cxf.resource.ResourceResolver;
+
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.core.io.Resource;
+
+
+public class BusApplicationContextResourceResolver
+ implements ResourceResolver, ApplicationContextAware {
+
+ ApplicationContext context;
+
+ public BusApplicationContextResourceResolver() {
+ }
+
+
+ public InputStream getAsStream(String name) {
+ Resource r = context.getResource(name);
+ if (r != null && r.exists()) {
+ try {
+ return r.getInputStream();
+ } catch (IOException e) {
+ //ignore and return null
+ }
+ }
+ return null;
+ }
+
+ public <T> T resolve(String resourceName, Class<T> resourceType) {
+ try {
+ return resourceType.cast(context.getBean(resourceName,
resourceType));
+ } catch (NoSuchBeanDefinitionException def) {
+ return null;
+ }
+ }
+
+
+ public void setApplicationContext(ApplicationContext arg0) throws
BeansException {
+ context = arg0;
+ }
+
+}
Propchange:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContextResourceResolver.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml?view=diff&rev=567144&r1=567143&r2=567144
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
(original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml Fri Aug
17 14:02:37 2007
@@ -32,6 +32,7 @@
<list>
<bean class="org.apache.cxf.resource.ClasspathResolver"/>
<bean class="org.apache.cxf.resource.ClassLoaderResolver"/>
+ <bean
class="org.apache.cxf.bus.spring.BusApplicationContextResourceResolver"/>
</list>
</constructor-arg>
<property name="bus" ref="cxf"/>
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java?view=diff&rev=567144&r1=567143&r2=567144
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/handlers/TestSOAPHandler.java
Fri Aug 17 14:02:37 2007
@@ -23,6 +23,8 @@
import java.util.Set;
import java.util.StringTokenizer;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPException;
@@ -35,9 +37,13 @@
import javax.xml.ws.handler.soap.SOAPMessageContext;
import javax.xml.ws.soap.SOAPFaultException;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
+
+import org.apache.cxf.Bus;
+
//import org.apache.handler_test.PingException;
/**
@@ -52,6 +58,13 @@
public class TestSOAPHandler<T extends SOAPMessageContext> extends
TestHandlerBase
implements SOAPHandler<T> {
+
+
+ @Resource
+ Bus bus;
+ @Resource(name = "org.apache.cxf.wsdl.WSDLManager")
+ org.apache.cxf.wsdl.WSDLManager manager;
+
public TestSOAPHandler() {
this(true);
}
@@ -60,6 +73,17 @@
super(serverSide);
}
+
+ @PostConstruct
+ public void initPost() {
+ if (bus == null) {
+ throw new RuntimeException("No BUS");
+ }
+ if (manager == null) {
+ throw new RuntimeException("No WSDL Manager");
+ }
+ }
+
// Implementation of javax.xml.ws.handler.soap.SOAPHandler
public final Set<QName> getHeaders() {