Author: bimargulies
Date: Sat Oct 17 00:34:22 2009
New Revision: 826145
URL: http://svn.apache.org/viewvc?rev=826145&view=rev
Log:
Start to implement CXF-1355.
Added:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsWebServicePublisherBeanPostProcessor.java
(contents, props changed)
- copied, changed from r826144,
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/Jsr181HandlerMapping.java
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/BeanPostProcessorTest.java
(with props)
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/IWebServiceRUs.java
(with props)
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/WebServiceRUs.java
(with props)
cxf/trunk/systests/jaxws/src/test/resources/org/
cxf/trunk/systests/jaxws/src/test/resources/org/apache/
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/context.xml
(with props)
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/customized-context.xml
(with props)
Removed:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/Jsr181HandlerMapping.java
Copied:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsWebServicePublisherBeanPostProcessor.java
(from r826144,
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/Jsr181HandlerMapping.java)
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsWebServicePublisherBeanPostProcessor.java?p2=cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsWebServicePublisherBeanPostProcessor.java&p1=cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/Jsr181HandlerMapping.java&r1=826144&r2=826145&rev=826145&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/Jsr181HandlerMapping.java
(original)
+++
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsWebServicePublisherBeanPostProcessor.java
Sat Oct 17 00:34:22 2009
@@ -19,7 +19,6 @@
package org.apache.cxf.jaxws.spring;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Logger;
@@ -31,12 +30,14 @@
import javax.servlet.http.HttpServletResponse;
import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ClassHelper;
import org.apache.cxf.databinding.DataBinding;
-import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
@@ -60,24 +61,27 @@
* and then creates a URL under /services/ based on the service name.
Properties of the bean
* permit you to configure this; if you set prototypeServiceFactoryBeanName,
the code
* will fetch that bean. It must be a prototype, since service factory object
can't be used
- * for more than one endpoint. Similiarly, prototypeDataBindingBeanName can be
used to
+ * for more than one endpoint. Similarly, prototypeDataBindingBeanName can be
used to
* control the data binding.
*
* Note that this class uses {...@link
org.apache.cxf.transport.servlet#CXFServlet} from the
- * cxf-rt-transports-http-jetty library, which is not part of the standard
dependencies of the JAX-WS front
+ * cxf-rt-transports-http-jetty library, which is not part of
+ * the standard dependencies of the JAX-WS front
* end.
*
+ * If you use this processor in an environment with no servlet, it will still
launch the
+ * endpoints using the embedded CXF server.
+ *
*/
-public class Jsr181HandlerMapping extends AbstractUrlHandlerMapping implements
BeanPostProcessor,
+public class JaxWsWebServicePublisherBeanPostProcessor
+ extends AbstractUrlHandlerMapping implements BeanPostProcessor,
ServletConfigAware, BeanFactoryAware {
- private static final Logger LOG =
LogUtils.getL7dLogger(Jsr181HandlerMapping.class);
+ private static final Logger LOG =
LogUtils.getL7dLogger(JaxWsWebServicePublisherBeanPostProcessor.class);
- private static final String CXF_SERVLET_CLASS_NAME =
"org.apache.cxf.transport.servlet";
- private static final String AOP_UTILS_CLASS_NAME =
"org.springframework.aop.support.AopUtils";
+ private static final String CXF_SERVLET_CLASS_NAME =
"org.apache.cxf.transport.servlet.CXFServlet";
private Class<?> servletClass;
private Method servletGetBusMethod;
- private Method aopUtilsGetTargetClassMethod;
private String urlPrefix = "/services/";
private Servlet shadowCxfServlet;
@@ -85,7 +89,8 @@
private String prototypeServiceFactoryBeanName;
private BeanFactory beanFactory;
- public Jsr181HandlerMapping() throws SecurityException,
NoSuchMethodException, ClassNotFoundException {
+ public JaxWsWebServicePublisherBeanPostProcessor() throws
SecurityException,
+ NoSuchMethodException, ClassNotFoundException {
try {
servletClass = ClassLoaderUtils.loadClass(CXF_SERVLET_CLASS_NAME,
getClass());
} catch (ClassNotFoundException e) {
@@ -94,18 +99,14 @@
throw e;
}
servletGetBusMethod = servletClass.getMethod("getBus");
- try {
- Class<?> aopUtilsClass =
ClassLoaderUtils.loadClass(AOP_UTILS_CLASS_NAME, getClass());
- aopUtilsGetTargetClassMethod =
aopUtilsClass.getMethod("getTargetClass", Object.class);
- } catch (Exception e) {
- Message message = new Message("AOP_GET_TARGET_CLASS_MISSING", LOG);
- LOG.severe(message.toString());
-
- }
}
private Bus getServletBus() {
try {
+ if (shadowCxfServlet == null) {
+ // no servlet going on. Just launch.
+ return BusFactory.getDefaultBus(true);
+ }
return (Bus) servletGetBusMethod.invoke(shadowCxfServlet);
} catch (Exception e) {
// CXF internally inconsistent?
@@ -126,23 +127,8 @@
return bean;
}
- private Class<?> aopUtilsGetTargetClass(Object possiblyProxiedObject) {
- if (aopUtilsGetTargetClassMethod != null && possiblyProxiedObject !=
null) {
- try {
- return (Class<?>)aopUtilsGetTargetClassMethod.invoke(null,
possiblyProxiedObject);
- } catch (IllegalArgumentException e) {
- return possiblyProxiedObject.getClass();
- } catch (IllegalAccessException e) {
- return possiblyProxiedObject.getClass();
- } catch (InvocationTargetException e) {
- return possiblyProxiedObject.getClass();
- }
- }
- return possiblyProxiedObject.getClass();
- }
-
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
- Class<?> clazz = aopUtilsGetTargetClass(bean);
+ Class<?> clazz = ClassHelper.getRealClass(bean);
if (clazz.isAnnotationPresent(WebService.class)) {
WebService ws = (WebService)clazz.getAnnotation(WebService.class);
@@ -180,9 +166,9 @@
serviceFactory = new JaxWsServiceFactoryBean();
}
- ServerFactoryBean serverFactoryBean = new ServerFactoryBean();
+ JaxWsServerFactoryBean serverFactoryBean = new
JaxWsServerFactoryBean();
serverFactoryBean.setServiceBean(implementor);
- serverFactoryBean.setServiceClass(aopUtilsGetTargetClass(implementor));
+
serverFactoryBean.setServiceClass(ClassHelper.getRealClass(implementor));
serverFactoryBean.setAddress(url);
DataBinding dataBinding = null;
@@ -206,7 +192,6 @@
}
public void setServletConfig(ServletConfig servletConfig) {
-
try {
shadowCxfServlet = (Servlet)servletClass.newInstance();
} catch (InstantiationException e) {
@@ -267,16 +252,4 @@
public void setPrototypeDataBindingBeanName(String
prototypeDataBindingBeanName) {
this.prototypeDataBindingBeanName = prototypeDataBindingBeanName;
}
-
- /**
- * For unit testing ONLY. Disable use of Spring-AOP method to unwrap
target classes, to
- * ensure that this code works when AOP is not there.
- * @param b
- */
- public void setSimulateNoAopForUnitTest(boolean b) {
- if (b) {
- aopUtilsGetTargetClassMethod = null;
- }
- }
-
}
Propchange:
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/JaxWsWebServicePublisherBeanPostProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/BeanPostProcessorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/BeanPostProcessorTest.java?rev=826145&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/BeanPostProcessorTest.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/BeanPostProcessorTest.java
Sat Oct 17 00:34:22 2009
@@ -0,0 +1,53 @@
+/**
+ * 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.jaxws.beanpostprocessor;
+
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.test.AbstractCXFSpringTest;
+
+import org.junit.Test;
+
+/**
+ * The majority of this test happens when the context is loaded.
+ */
+public class BeanPostProcessorTest extends AbstractCXFSpringTest {
+
+ @Test
+ public void verifyServices() throws Exception {
+ JaxWsClientFactoryBean cf = new JaxWsClientFactoryBean();
+ cf.setAddress("local://services/Alger");
+ cf.setServiceClass(IWebServiceRUs.class);
+ Client client = cf.create();
+ String response = (String)client.invoke("consultTheOracle")[0];
+ assertEquals("All your bases belong to us.", response);
+ Service service = WebServiceRUs.getService();
+ assertEquals(JAXBDataBinding.class,
service.getDataBinding().getClass());
+ }
+
+ @Override
+ protected String[] getConfigLocations() {
+ return new String[]
{"/org/apache/cxf/systest/jaxws/beanpostprocessor/context.xml" };
+ }
+
+
+}
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/BeanPostProcessorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/IWebServiceRUs.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/IWebServiceRUs.java?rev=826145&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/IWebServiceRUs.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/IWebServiceRUs.java
Sat Oct 17 00:34:22 2009
@@ -0,0 +1,29 @@
+/**
+ * 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.jaxws.beanpostprocessor;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+...@webservice
+public interface IWebServiceRUs {
+ @WebMethod
+ String consultTheOracle();
+}
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/IWebServiceRUs.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/WebServiceRUs.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/WebServiceRUs.java?rev=826145&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/WebServiceRUs.java
(added)
+++
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/WebServiceRUs.java
Sat Oct 17 00:34:22 2009
@@ -0,0 +1,61 @@
+/**
+ * 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.jaxws.beanpostprocessor;
+
+import javax.annotation.Resource;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.apache.cxf.jaxws.context.WrappedMessageContext;
+import org.apache.cxf.service.Service;
+
+/**
+ * a web service that can be launched and spoken to by the test.
+ */
+...@webservice(name = "Horatio", serviceName = "Alger",
+ endpointInterface =
"org.apache.cxf.systest.jaxws.beanpostprocessor.IWebServiceRUs")
+public class WebServiceRUs implements IWebServiceRUs {
+
+ private static org.apache.cxf.service.Service service;
+
+ @Resource
+ WebServiceContext injectedContext;
+
+ private void noteService() {
+ MessageContext ctx = injectedContext.getMessageContext();
+ WrappedMessageContext wmc = (WrappedMessageContext) ctx;
+ org.apache.cxf.message.Message msg = wmc.getWrappedMessage();
+ service = msg.getExchange().get(Service.class);
+ }
+
+ @WebMethod(exclude = true)
+ public static Service getService() {
+ return service;
+ }
+
+ /** {...@inheritdoc}*/
+ @WebMethod
+ public String consultTheOracle() {
+ noteService();
+ return "All your bases belong to us.";
+ }
+}
Propchange:
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/beanpostprocessor/WebServiceRUs.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/context.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/context.xml?rev=826145&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/context.xml
(added)
+++
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/context.xml
Sat Oct 17 00:34:22 2009
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.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-jaxws.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-local.xml" />
+
+<!-- This test is not run with a servlet container. It tests non-servlet
publication. -->
+<bean id="servicebean"
class="org.apache.cxf.systest.jaxws.beanpostprocessor.WebServiceRUs"/>
+
+<bean id="postprocess"
class="org.apache.cxf.jaxws.spring.JaxWsWebServicePublisherBeanPostProcessor">
+ <property name='urlPrefix' value='local://services/' />
+</bean>
+</beans>
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/customized-context.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/customized-context.xml?rev=826145&view=auto
==============================================================================
---
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/customized-context.xml
(added)
+++
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/customized-context.xml
Sat Oct 17 00:34:22 2009
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.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-jaxws.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-local.xml" />
+
+<!-- This test is not run with a servlet container. It tests non-servlet
publication. -->
+<bean id="servicebean"
class="org.apache.cxf.systest.jaxws.beanpostprocessor.WebServiceRUs"/>
+
+<bean id="dataBinding"
class="org.apache.cxf.aegis.databinding.AegisDatabinding" scope='prototype'/>
+
+<bean id="postprocess"
class="org.apache.cxf.jaxws.spring.JaxWsWebServicePublisherBeanPostProcessor">
+ <property name='urlPrefix' value='local://services/' />
+ <property name='prototypeDataBindingBeanName' value="dataBinding"/>
+</bean>
+</beans>
\ No newline at end of file
Propchange:
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/customized-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/jaxws/src/test/resources/org/apache/cxf/systest/jaxws/beanpostprocessor/customized-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml