Skip to content
Permalink
Browse files
[DOSGI-242] Prepare split of jaxws and jaxrs support
  • Loading branch information
cschneider committed Jul 4, 2016
1 parent 951f7c8 commit ccf5a7a73be73c8549c2e199ac104b2d81f7260c
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 160 deletions.
@@ -2,5 +2,6 @@ Import-Package: javax.servlet;version='[2,4)', javax.servlet.http;version='[2,4)
Export-Package: \
org.apache.cxf.dosgi.common.httpservice,\
org.apache.cxf.dosgi.common.util,\
org.apache.cxf.dosgi.common.intent
org.apache.cxf.dosgi.common.intent,\
org.apache.cxf.dosgi.common.proxy

@@ -44,30 +44,14 @@
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-databinding-aegis</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_${servlet.version}_spec</artifactId>
@@ -0,0 +1,32 @@
/**
* 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.dosgi.common.proxy;

import java.lang.reflect.Proxy;

public final class ProxyFactory {
private ProxyFactory() {
}

public static Object create(Object serviceProxy, Class<?> iType) {
return Proxy.newProxyInstance(iType.getClassLoader(), new Class[] {
iType
}, new ServiceInvocationHandler(serviceProxy, iType));
}
}
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.dosgi.dsw.handlers.pojo;
package org.apache.cxf.dosgi.common.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -40,10 +40,12 @@ public class ServiceInvocationHandler implements InvocationHandler {
private Map<Method, List<Class<?>>> exceptionsMap = new HashMap<Method, List<Class<?>>>();
private Object serviceObject;

public ServiceInvocationHandler(Object serviceObject, Class<?> iType) {
ServiceInvocationHandler(Object serviceObject, Class<?> iType) {
this.serviceObject = serviceObject;
introspectType(iType);
}



public Object invoke(Object proxy, final Method m, Object[] params) throws Throwable {
if (OBJECT_METHODS.contains(m)) {
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.dosgi.dsw.handlers;
package org.apache.cxf.dosgi.common.proxy;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@@ -26,8 +26,6 @@
import java.util.List;
import java.util.Map;

import org.apache.cxf.dosgi.dsw.handlers.pojo.ServiceInvocationHandler;

import junit.framework.TestCase;

public class ServiceInvocationHandlerTest extends TestCase {
@@ -18,35 +18,24 @@
*/
package org.apache.cxf.dosgi.dsw.handlers.pojo;

import java.lang.reflect.Proxy;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;

import org.apache.aries.rsa.spi.DistributionProvider;
import org.apache.aries.rsa.spi.Endpoint;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.common.util.PackageUtils;
import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager;
import org.apache.cxf.dosgi.common.intent.IntentManager;
import org.apache.cxf.dosgi.common.util.ClassUtils;
import org.apache.cxf.dosgi.common.util.OsgiUtils;
import org.apache.cxf.dosgi.common.util.ServerWrapper;
import org.apache.cxf.dosgi.common.util.StringPlus;
import org.apache.cxf.dosgi.dsw.osgi.Constants;
import org.apache.cxf.endpoint.AbstractEndpointFactory;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory;
import org.apache.cxf.frontend.ClientFactoryBean;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.interceptor.Interceptor;
import org.osgi.framework.BundleContext;
import org.osgi.service.remoteserviceadmin.EndpointDescription;
import org.osgi.service.remoteserviceadmin.RemoteConstants;
@@ -63,12 +52,6 @@ public AbstractPojoConfigurationTypeHandler(BundleContext dswBC, IntentManager i
this.httpServiceManager = httpServiceManager;
}

protected Object getProxy(Object serviceProxy, Class<?> iType) {
return Proxy.newProxyInstance(iType.getClassLoader(), new Class[] {
iType
}, new ServiceInvocationHandler(serviceProxy, iType));
}

protected EndpointDescription createEndpointDesc(Map<String, Object> props,
String[] importedConfigs,
String address,
@@ -77,8 +60,6 @@ protected EndpointDescription createEndpointDesc(Map<String, Object> props,
for (String configurationType : importedConfigs) {
if (Constants.WS_CONFIG_TYPE.equals(configurationType)) {
props.put(Constants.WS_ADDRESS_PROPERTY, address);
} else if (Constants.RS_CONFIG_TYPE.equals(configurationType)) {
props.put(Constants.RS_ADDRESS_PROPERTY, address);
} else if (Constants.WS_CONFIG_TYPE_OLD.equals(configurationType)) {
props.put(Constants.WS_ADDRESS_PROPERTY_OLD, address);
props.put(Constants.WS_ADDRESS_PROPERTY, address);
@@ -110,62 +91,6 @@ public static String[] mergeArrays(String[] a1, String[] a2) {
return list.toArray(new String[list.size()]);
}

protected void setCommonWsdlProperties(AbstractWSDLBasedEndpointFactory factory, BundleContext context,
Map<String, Object> sd, boolean wsdlType) {
String location = OsgiUtils.getProperty(sd, wsdlType ? Constants.WSDL_LOCATION : Constants.WS_WSDL_LOCATION);
if (location != null) {
URL wsdlURL = context.getBundle().getResource(location);
if (wsdlURL != null) {
factory.setWsdlURL(wsdlURL.toString());
}
QName serviceName = getServiceQName(null, sd,
wsdlType ? Constants.WSDL_SERVICE_NAMESPACE : Constants.WS_WSDL_SERVICE_NAMESPACE,
wsdlType ? Constants.WSDL_SERVICE_NAME : Constants.WS_WSDL_SERVICE_NAME);
if (serviceName != null) {
factory.setServiceName(serviceName);
QName portName = getPortQName(serviceName.getNamespaceURI(), sd,
wsdlType ? Constants.WSDL_PORT_NAME : Constants.WS_WSDL_PORT_NAME);
if (portName != null) {
factory.setEndpointName(portName);
}
}
}
}

protected void setWsdlProperties(ServerFactoryBean factory, BundleContext callingContext, Map<String, Object> sd,
boolean wsdlType) {
setCommonWsdlProperties(factory, callingContext, sd, wsdlType);
}

protected void setClientWsdlProperties(ClientFactoryBean factory, BundleContext dswContext, Map<String, Object> sd,
boolean wsdlType) {
setCommonWsdlProperties(factory, dswContext, sd, wsdlType);
}

protected static QName getServiceQName(Class<?> iClass, Map<String, Object> sd, String nsPropName,
String namePropName) {
String serviceNs = OsgiUtils.getProperty(sd, nsPropName);
String serviceName = OsgiUtils.getProperty(sd, namePropName);
if (iClass == null && (serviceNs == null || serviceName == null)) {
return null;
}
if (serviceNs == null) {
serviceNs = PackageUtils.getNamespace(PackageUtils.getPackageName(iClass));
}
if (serviceName == null) {
serviceName = iClass.getSimpleName();
}
return new QName(serviceNs, serviceName);
}

protected static QName getPortQName(String ns, Map<String, Object> sd, String propName) {
String portName = OsgiUtils.getProperty(sd, propName);
if (portName == null) {
return null;
}
return new QName(ns, portName);
}

protected String getClientAddress(Map<String, Object> sd) {
return OsgiUtils.getFirstNonEmptyStringProperty(sd, RemoteConstants.ENDPOINT_ID,
Constants.WS_ADDRESS_PROPERTY,
@@ -185,7 +110,6 @@ public String getServletContextRoot(Map<String, Object> sd) {
Constants.WSDL_HTTP_SERVICE_CONTEXT,
Constants.RS_HTTP_SERVICE_CONTEXT);
}


protected Bus createBus(Long sid, BundleContext callingContext, String contextRoot) {
Bus bus = BusFactory.newInstance().createBus();
@@ -208,53 +132,14 @@ protected Endpoint createServerFromFactory(ServerFactoryBean factory, EndpointDe

protected static void addWsInterceptorsFeaturesProps(AbstractEndpointFactory factory, BundleContext callingContext,
Map<String, Object> sd) {
addInterceptors(factory, callingContext, sd, Constants.WS_IN_INTERCEPTORS_PROP_KEY);
addInterceptors(factory, callingContext, sd, Constants.WS_OUT_INTERCEPTORS_PROP_KEY);
addInterceptors(factory, callingContext, sd, Constants.WS_OUT_FAULT_INTERCEPTORS_PROP_KEY);
addInterceptors(factory, callingContext, sd, Constants.WS_IN_FAULT_INTERCEPTORS_PROP_KEY);
addFeatures(factory, callingContext, sd, Constants.WS_FEATURES_PROP_KEY);
InterceptorSupport.addInterceptors(factory, callingContext, sd, Constants.WS_IN_INTERCEPTORS_PROP_KEY);
InterceptorSupport.addInterceptors(factory, callingContext, sd, Constants.WS_OUT_INTERCEPTORS_PROP_KEY);
InterceptorSupport.addInterceptors(factory, callingContext, sd, Constants.WS_OUT_FAULT_INTERCEPTORS_PROP_KEY);
InterceptorSupport.addInterceptors(factory, callingContext, sd, Constants.WS_IN_FAULT_INTERCEPTORS_PROP_KEY);
InterceptorSupport.addFeatures(factory, callingContext, sd, Constants.WS_FEATURES_PROP_KEY);
addContextProperties(factory, sd, Constants.WS_CONTEXT_PROPS_PROP_KEY);
}

protected static void addRsInterceptorsFeaturesProps(AbstractEndpointFactory factory, BundleContext callingContext,
Map<String, Object> sd) {
addInterceptors(factory, callingContext, sd, Constants.RS_IN_INTERCEPTORS_PROP_KEY);
addInterceptors(factory, callingContext, sd, Constants.RS_OUT_INTERCEPTORS_PROP_KEY);
addInterceptors(factory, callingContext, sd, Constants.RS_OUT_FAULT_INTERCEPTORS_PROP_KEY);
addInterceptors(factory, callingContext, sd, Constants.RS_IN_FAULT_INTERCEPTORS_PROP_KEY);
addFeatures(factory, callingContext, sd, Constants.RS_FEATURES_PROP_KEY);
addContextProperties(factory, sd, Constants.RS_CONTEXT_PROPS_PROP_KEY);
}

private static void addInterceptors(AbstractEndpointFactory factory, BundleContext callingContext,
Map<String, Object> sd, String propName) {
List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName);
boolean in = propName.contains("in.interceptors");
boolean out = propName.contains("out.interceptors");
boolean inFault = propName.contains("in.fault.interceptors");
boolean outFault = propName.contains("out.fault.interceptors");
for (Object provider : providers) {
Interceptor<?> interceptor = (Interceptor<?>) provider;
if (in) {
factory.getInInterceptors().add(interceptor);
} else if (out) {
factory.getOutInterceptors().add(interceptor);
} else if (inFault) {
factory.getInFaultInterceptors().add(interceptor);
} else if (outFault) {
factory.getOutFaultInterceptors().add(interceptor);
}
}
}

private static void addFeatures(AbstractEndpointFactory factory, BundleContext callingContext,
Map<String, Object> sd, String propName) {
List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName);
if (!providers.isEmpty()) {
factory.getFeatures().addAll(CastUtils.cast(providers, AbstractFeature.class));
}
}

private static void addContextProperties(AbstractEndpointFactory factory, Map<String, Object> sd, String propName) {
@SuppressWarnings("unchecked")
Map<String, Object> props = (Map<String, Object>)sd.get(propName);
@@ -0,0 +1,63 @@
/**
* 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.dosgi.dsw.handlers.pojo;

import java.util.List;
import java.util.Map;

import org.apache.cxf.dosgi.common.util.ClassUtils;
import org.apache.cxf.endpoint.AbstractEndpointFactory;
import org.apache.cxf.feature.AbstractFeature;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.interceptor.Interceptor;
import org.osgi.framework.BundleContext;

public final class InterceptorSupport {
private InterceptorSupport() {
}

public static void addInterceptors(AbstractEndpointFactory factory, BundleContext callingContext,
Map<String, Object> sd, String propName) {
List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName);
boolean in = propName.contains("in.interceptors");
boolean out = propName.contains("out.interceptors");
boolean inFault = propName.contains("in.fault.interceptors");
boolean outFault = propName.contains("out.fault.interceptors");
for (Object provider : providers) {
Interceptor<?> interceptor = (Interceptor<?>) provider;
if (in) {
factory.getInInterceptors().add(interceptor);
} else if (out) {
factory.getOutInterceptors().add(interceptor);
} else if (inFault) {
factory.getInFaultInterceptors().add(interceptor);
} else if (outFault) {
factory.getOutFaultInterceptors().add(interceptor);
}
}
}

public static void addFeatures(AbstractEndpointFactory factory, BundleContext callingContext,
Map<String, Object> sd, String propName) {
List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName);
if (!providers.isEmpty()) {
factory.getFeatures().addAll(CastUtils.cast(providers, AbstractFeature.class));
}
}
}
@@ -29,6 +29,7 @@
import org.apache.cxf.databinding.DataBinding;
import org.apache.cxf.dosgi.common.httpservice.HttpServiceManager;
import org.apache.cxf.dosgi.common.intent.IntentManager;
import org.apache.cxf.dosgi.common.proxy.ProxyFactory;
import org.apache.cxf.dosgi.dsw.osgi.Constants;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.frontend.ServerFactoryBean;
@@ -78,12 +79,12 @@ public Object importEndpoint(ClassLoader consumerLoader,
factory.setServiceClass(iClass);
factory.setAddress(address);
addWsInterceptorsFeaturesProps(factory.getClientFactoryBean(), consumerContext, sd);
setClientWsdlProperties(factory.getClientFactoryBean(), bundleContext, sd, false);
WsdlSupport.setWsdlProperties(factory.getClientFactoryBean(), bundleContext, sd, false);

intentManager.applyIntents(factory.getFeatures(), factory.getClientFactoryBean(), sd);

Thread.currentThread().setContextClassLoader(ClientProxyFactoryBean.class.getClassLoader());
return getProxy(factory.create(), iClass);
return ProxyFactory.create(factory.create(), iClass);
} catch (Exception e) {
LOG.warn("proxy creation failed", e);
} finally {
@@ -111,7 +112,7 @@ public Endpoint exportService(Object serviceO,

factory.setServiceBean(serviceO);
addWsInterceptorsFeaturesProps(factory, serviceContext, endpointProps);
setWsdlProperties(factory, serviceContext, endpointProps, false);
WsdlSupport.setWsdlProperties(factory, serviceContext, endpointProps, false);
String[] intents = intentManager.applyIntents(factory.getFeatures(), factory, endpointProps);

String completeEndpointAddress = httpServiceManager.getAbsoluteAddress(contextRoot, address);

0 comments on commit ccf5a7a

Please sign in to comment.