You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/12/11 20:27:21 UTC
svn commit: r1420346 - in /cxf/dosgi/trunk/dsw/cxf-dsw/src:
main/java/org/apache/cxf/dosgi/dsw/
main/java/org/apache/cxf/dosgi/dsw/handlers/
main/java/org/apache/cxf/dosgi/dsw/qos/
main/java/org/apache/cxf/dosgi/dsw/service/ main/java/org/apache/cxf/do...
Author: dkulp
Date: Tue Dec 11 19:27:18 2012
New Revision: 1420346
URL: http://svn.apache.org/viewvc?rev=1420346&view=rev
Log:
Start of cleanup of cxf-dsw, mostly whitespace/indent related
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/UtilsTest.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/Activator.java Tue Dec 11 19:27:18 2012
@@ -115,7 +115,7 @@ public class Activator implements Manage
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- public synchronized void updated(Dictionary config) throws ConfigurationException {
+ public synchronized void updated(Dictionary config) throws ConfigurationException {
if (rsaFactoryReg != null) {
try {
stop(bc);
@@ -124,13 +124,13 @@ public class Activator implements Manage
}
}
if (config != null) {
- HashMap<String, Object> configMap = getMapFromDictionary(config);
+ Map<String, Object> configMap = getMapFromDictionary(config);
start(bc, configMap);
}
}
- private HashMap<String, Object> getMapFromDictionary(Dictionary<String, Object> config) {
- HashMap<String, Object> configMap = new HashMap<String, Object>();
+ private Map<String, Object> getMapFromDictionary(Dictionary<String, Object> config) {
+ Map<String, Object> configMap = new HashMap<String, Object>();
if (config == null) {
return configMap;
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/AbstractPojoConfigurationTypeHandler.java Tue Dec 11 19:27:18 2012
@@ -1,21 +1,21 @@
/**
- * 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.
- */
+ * 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;
import java.lang.reflect.Proxy;
@@ -50,54 +50,54 @@ public abstract class AbstractPojoConfig
protected BundleContext bundleContext;
protected IntentManager intentManager;
protected HttpServiceManager httpServiceManager;
-
- public AbstractPojoConfigurationTypeHandler(BundleContext dswBC,
- IntentManager intentManager,
+
+ public AbstractPojoConfigurationTypeHandler(BundleContext dswBC, IntentManager intentManager,
HttpServiceManager httpServiceManager) {
this.bundleContext = dswBC;
this.intentManager = intentManager;
this.httpServiceManager = httpServiceManager;
}
-
+
protected Object getProxy(Object serviceProxy, Class<?> iType) {
return Proxy.newProxyInstance(iType.getClassLoader(), new Class[] {
iType
}, new ServiceInvocationHandler(serviceProxy, iType));
}
- protected Map<String, Object> createEndpointProps(Map<String, Object> sd, Class<?> iClass, String[] importedConfigs,
- String address, String[] intents) {
+ protected Map<String, Object> createEndpointProps(Map<String, Object> sd, Class<?> iClass,
+ String[] importedConfigs, String address, String[] intents) {
Map<String, Object> props = new HashMap<String, Object>();
copyEndpointProperties(sd, props);
- String[] sa = new String[] {iClass.getName()};
+ String[] sa = new String[] {
+ iClass.getName()
+ };
String pkg = iClass.getPackage().getName();
-
+
props.remove(org.osgi.framework.Constants.SERVICE_ID);
props.put(org.osgi.framework.Constants.OBJECTCLASS, sa);
- props.put(RemoteConstants.ENDPOINT_SERVICE_ID, sd.get(org.osgi.framework.Constants.SERVICE_ID));
+ props.put(RemoteConstants.ENDPOINT_SERVICE_ID, sd.get(org.osgi.framework.Constants.SERVICE_ID));
props.put(RemoteConstants.ENDPOINT_FRAMEWORK_UUID, OsgiUtils.getUUID(bundleContext));
props.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, importedConfigs);
- props.put(RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + pkg,
- OsgiUtils.getVersion(iClass, bundleContext));
+ props.put(RemoteConstants.ENDPOINT_PACKAGE_VERSION_ + pkg, OsgiUtils.getVersion(iClass, bundleContext));
for (String configurationType : importedConfigs) {
- if(Constants.WS_CONFIG_TYPE.equals(configurationType))
+ if (Constants.WS_CONFIG_TYPE.equals(configurationType)) {
props.put(Constants.WS_ADDRESS_PROPERTY, address);
- else if(Constants.RS_CONFIG_TYPE.equals(configurationType))
+ } else if (Constants.RS_CONFIG_TYPE.equals(configurationType)) {
props.put(Constants.RS_ADDRESS_PROPERTY, address);
- else if(Constants.WS_CONFIG_TYPE_OLD.equals(configurationType)){
+ } else if (Constants.WS_CONFIG_TYPE_OLD.equals(configurationType)) {
props.put(Constants.WS_ADDRESS_PROPERTY_OLD, address);
props.put(Constants.WS_ADDRESS_PROPERTY, address);
}
}
-
+
{
String[] allIntents = IntentUtils.mergeArrays(intents, IntentUtils.getInetntsImplementedByTheService(sd));
props.put(RemoteConstants.SERVICE_INTENTS, allIntents);
}
-
+
props.put(RemoteConstants.ENDPOINT_ID, address);
return props;
@@ -107,92 +107,90 @@ public abstract class AbstractPojoConfig
Set<Map.Entry<String, Object>> keys = sd.entrySet();
for (Map.Entry<String, Object> entry : keys) {
try {
- String skey = (String)entry.getKey();
- if (!skey.startsWith("."))
+ String skey = entry.getKey();
+ if (!skey.startsWith(".")) {
endpointProps.put(skey, entry.getValue());
+ }
} catch (ClassCastException e) {
LOG.warn("ServiceProperties Map contained non String key. Skipped " + entry + " "
- + e.getLocalizedMessage());
+ + e.getLocalizedMessage());
+ }
+ }
+ }
+
+ protected void setWsdlProperties(ServerFactoryBean factory, BundleContext callingContext, Map<String, Object> sd,
+ boolean wsdlType) {
+ String location = OsgiUtils.getProperty(sd, wsdlType ? Constants.WSDL_LOCATION : Constants.WS_WSDL_LOCATION);
+ if (location != null) {
+ URL wsdlURL = callingContext.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 setClientWsdlProperties(ClientFactoryBean factory, BundleContext dswContext, Map<String, Object> sd,
+ boolean wsdlType) {
+ String location = OsgiUtils.getProperty(sd, wsdlType ? Constants.WSDL_LOCATION : Constants.WS_WSDL_LOCATION);
+ if (location != null) {
+ URL wsdlURL = dswContext.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) {
- String location = OsgiUtils.getProperty(sd, wsdlType ? Constants.WSDL_LOCATION : Constants.WS_WSDL_LOCATION);
- if (location != null) {
- URL wsdlURL = callingContext.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 setClientWsdlProperties(ClientFactoryBean factory, BundleContext dswContext,
- Map<String, Object> sd, boolean wsdlType) {
- String location = OsgiUtils.getProperty(sd, wsdlType ? Constants.WSDL_LOCATION : Constants.WS_WSDL_LOCATION);
- if (location != null) {
- URL wsdlURL = dswContext.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 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));
+ 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();
+ 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);
+ String portName = OsgiUtils.getProperty(sd, propName);
if (portName == null) {
- return null;
+ return null;
}
return new QName(ns, portName);
}
-
+
protected String getClientAddress(Map<String, Object> sd, Class<?> iClass) {
- return OsgiUtils.getFirstNonEmptyStringProperty(sd,
- RemoteConstants.ENDPOINT_ID,
- Constants.WS_ADDRESS_PROPERTY,
- Constants.WS_ADDRESS_PROPERTY,
- Constants.WS_ADDRESS_PROPERTY_OLD,
- Constants.RS_ADDRESS_PROPERTY);
+ return OsgiUtils.getFirstNonEmptyStringProperty(sd, RemoteConstants.ENDPOINT_ID, Constants.WS_ADDRESS_PROPERTY,
+ Constants.WS_ADDRESS_PROPERTY,
+ Constants.WS_ADDRESS_PROPERTY_OLD,
+ Constants.RS_ADDRESS_PROPERTY);
}
protected String getServerAddress(Map<String, Object> sd, Class<?> iClass) {
@@ -203,9 +201,9 @@ public abstract class AbstractPojoConfig
LOG.error(e.getMessage(), e);
return null;
}
- return (address == null) ? httpServiceManager.getDefaultAddress(iClass) : address;
+ return address == null ? httpServiceManager.getDefaultAddress(iClass) : address;
}
-
+
protected final ExportResult createServerFromFactory(ServerFactoryBean factory, Map<String, Object> endpointProps) {
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
@@ -219,8 +217,8 @@ public abstract class AbstractPojoConfig
}
}
- protected static void addWsInterceptorsFeaturesProps(
- AbstractEndpointFactory factory, BundleContext callingContext, Map<String, Object> sd) {
+ 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);
@@ -228,9 +226,9 @@ public abstract class AbstractPojoConfig
addFeatures(factory, callingContext, sd, Constants.WS_FEATURES_PROP_KEY);
addContextProperties(factory, callingContext, sd, Constants.WS_CONTEXT_PROPS_PROP_KEY);
}
-
- static void addRsInterceptorsFeaturesProps(
- AbstractEndpointFactory factory, BundleContext callingContext, Map<String, Object> sd) {
+
+ 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);
@@ -239,16 +237,16 @@ public abstract class AbstractPojoConfig
addContextProperties(factory, callingContext, sd, Constants.RS_CONTEXT_PROPS_PROP_KEY);
}
- private static void addInterceptors(AbstractEndpointFactory factory, BundleContext callingContext,
- Map<String, Object> sd, String propName) {
+ private static void addInterceptors(AbstractEndpointFactory factory, BundleContext callingContext,
+ Map<String, Object> sd, String propName) {
- List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName);
+ List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName);
boolean in = propName.contains("in.interceptors");
boolean out = propName.contains("out.interceptors");
boolean in_fault = propName.contains("in.fault.interceptors");
boolean out_fault = propName.contains("out.fault.interceptors");
for (int i = 0; i < providers.size(); i++) {
- Interceptor<?> interceptor = (Interceptor<?>)providers.get(i);
+ Interceptor<?> interceptor = (Interceptor<?>)providers.get(i);
if (in) {
factory.getInInterceptors().add(interceptor);
} else if (out) {
@@ -260,18 +258,18 @@ public abstract class AbstractPojoConfig
}
}
}
-
- private static void addFeatures(AbstractEndpointFactory factory, BundleContext callingContext,
- Map<String, Object> sd, String propName) {
- List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName);
+ private static void addFeatures(AbstractEndpointFactory factory, BundleContext callingContext,
+ Map<String, Object> sd, String propName) {
+
+ List<Object> providers = ClassUtils.loadProviderClasses(callingContext, sd, propName);
if (providers.size() > 0) {
factory.getFeatures().addAll(CastUtils.cast(providers, AbstractFeature.class));
}
}
-
- private static void addContextProperties(AbstractEndpointFactory factory, BundleContext callingContext,
- Map<String, Object> sd, String propName) {
+
+ private static void addContextProperties(AbstractEndpointFactory factory, BundleContext callingContext,
+ Map<String, Object> sd, String propName) {
@SuppressWarnings("unchecked")
Map<String, Object> props = (Map<String, Object>)sd.get(propName);
if (props != null) {
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContext.java Tue Dec 11 19:27:18 2012
@@ -42,79 +42,79 @@ import org.slf4j.LoggerFactory;
* security by delegating to a {@link FilterChain} based on the set of {@link Filter}s registered with a
* {@link #FILTER_PROP} property.
* </p>
- *
* <p>
* If the {@link BundleContext} contains a {@link #FILTER_REQUIRED_PROP} property with value "true", requests will not
* be allowed until at least one {@link Filter} with a {@link #FILTER_PROP} property is registered.
* </p>
*/
public class SecurityDelegatingHttpContext implements HttpContext {
- private static final Logger LOG = LoggerFactory.getLogger(SecurityDelegatingHttpContext.class);
- public static final String FILTER_PROP = "org.apache.cxf.httpservice.filter";
- public static final String FILTER_REQUIRED_PROP = "org.apache.cxf.httpservice.requirefilter";
- private static final String FILTER_FILTER = "(" + FILTER_PROP + "=*)";
-
- BundleContext bundleContext;
- HttpContext delegate;
- boolean requireFilter;
-
- public SecurityDelegatingHttpContext(BundleContext bundleContext, HttpContext delegate) {
- this.bundleContext = bundleContext;
- this.delegate = delegate;
- requireFilter = Boolean.TRUE.toString().equalsIgnoreCase(bundleContext.getProperty(FILTER_REQUIRED_PROP));
- }
-
- public String getMimeType(String name) {
- return delegate.getMimeType(name);
- }
-
- public URL getResource(String name) {
- return delegate.getResource(name);
- }
-
- public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
- ServiceReference[] refs;
- try {
- refs = bundleContext.getServiceReferences(Filter.class.getName(), FILTER_FILTER);
- } catch (InvalidSyntaxException e) {
- LOG.warn(e.getMessage(), e);
- return false;
- }
- if (refs == null || refs.length == 0) {
- LOG.info("No filter registered.");
- return !requireFilter;
- }
- Filter[] filters = new Filter[refs.length];
- for (int i = 0; i < refs.length; i++)
- filters[i] = (Filter) bundleContext.getService(refs[i]);
- try {
- new Chain(filters).doFilter(request, response);
- return !response.isCommitted();
- } catch (ServletException e) {
- LOG.warn(e.getMessage(), e);
- return false;
+ public static final String FILTER_PROP = "org.apache.cxf.httpservice.filter";
+ public static final String FILTER_REQUIRED_PROP = "org.apache.cxf.httpservice.requirefilter";
+ private static final Logger LOG = LoggerFactory.getLogger(SecurityDelegatingHttpContext.class);
+ private static final String FILTER_FILTER = "(" + FILTER_PROP + "=*)";
+
+ BundleContext bundleContext;
+ HttpContext delegate;
+ boolean requireFilter;
+
+ public SecurityDelegatingHttpContext(BundleContext bundleContext, HttpContext delegate) {
+ this.bundleContext = bundleContext;
+ this.delegate = delegate;
+ requireFilter = Boolean.TRUE.toString().equalsIgnoreCase(bundleContext.getProperty(FILTER_REQUIRED_PROP));
+ }
+
+ public String getMimeType(String name) {
+ return delegate.getMimeType(name);
+ }
+
+ public URL getResource(String name) {
+ return delegate.getResource(name);
+ }
+
+ public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ ServiceReference[] refs;
+ try {
+ refs = bundleContext.getServiceReferences(Filter.class.getName(), FILTER_FILTER);
+ } catch (InvalidSyntaxException e) {
+ LOG.warn(e.getMessage(), e);
+ return false;
+ }
+ if (refs == null || refs.length == 0) {
+ LOG.info("No filter registered.");
+ return !requireFilter;
+ }
+ Filter[] filters = new Filter[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ filters[i] = (Filter)bundleContext.getService(refs[i]);
+ }
+ try {
+ new Chain(filters).doFilter(request, response);
+ return !response.isCommitted();
+ } catch (ServletException e) {
+ LOG.warn(e.getMessage(), e);
+ return false;
+ }
}
- }
}
/**
* A {@link FilterChain} composed of {@link Filter}s with the
*/
class Chain implements FilterChain {
- private static final Logger LOG = LoggerFactory.getLogger(Chain.class);
+ private static final Logger LOG = LoggerFactory.getLogger(Chain.class);
- int current = 0;
- Filter[] filters;
+ int current = 0;
+ Filter[] filters;
+
+ Chain(Filter[] filters) {
+ this.filters = filters;
+ }
- Chain(Filter[] filters) {
- this.filters = filters;
- }
-
- public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
- if (current < filters.length && !response.isCommitted()) {
- Filter filter = filters[current++];
- LOG.info("doFilter() on {}", filter);
- filter.doFilter(request, response, this);
+ public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
+ if (current < filters.length && !response.isCommitted()) {
+ Filter filter = filters[current++];
+ LOG.info("doFilter() on {}", filter);
+ filter.doFilter(request, response, this);
+ }
}
- }
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/WsdlConfigurationTypeHandler.java Tue Dec 11 19:27:18 2012
@@ -108,17 +108,17 @@ public class WsdlConfigurationTypeHandle
Class<?> iClass,
Object serviceBean) {
- String location = OsgiUtils.getProperty(sd, Constants.WSDL_LOCATION);
- if (location == null) {
- throw new RuntimeException("WSDL location property is unavailable");
- }
+ String location = OsgiUtils.getProperty(sd, Constants.WSDL_LOCATION);
+ if (location == null) {
+ throw new RuntimeException("WSDL location property is unavailable");
+ }
URL wsdlURL = dswContext.getBundle().getResource(location);
if (wsdlURL == null) {
throw new RuntimeException("WSDL resource at " + location + " is unavailable");
- }
+ }
- String address = getServerAddress(sd, iClass);
- String contextRoot = httpServiceManager.getServletContextRoot(sd, iClass);
+ String address = getServerAddress(sd, iClass);
+ String contextRoot = httpServiceManager.getServletContextRoot(sd, iClass);
if (address == null && contextRoot == null) {
throw new RuntimeException("Remote address is unavailable");
}
@@ -143,7 +143,9 @@ public class WsdlConfigurationTypeHandle
String[] intents = intentManager.applyIntents(factory.getFeatures(), factory, sd);
// The properties for the EndpointDescription
- Map<String, Object> endpointProps = createEndpointProps(sd, iClass, new String[]{Constants.WS_CONFIG_TYPE}, address,intents);
+ Map<String, Object> endpointProps = createEndpointProps(sd, iClass,
+ new String[]{Constants.WS_CONFIG_TYPE},
+ address, intents);
return createServerFromFactory(factory, endpointProps);
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/qos/DefaultIntentMapFactory.java Tue Dec 11 19:27:18 2012
@@ -29,7 +29,7 @@ import org.apache.cxf.feature.LoggingFea
public class DefaultIntentMapFactory {
public Map<String, Object> create() {
- Map<String,Object> intentMap = new HashMap<String, Object>();
+ Map<String, Object> intentMap = new HashMap<String, Object>();
intentMap.put("logging", getLoggingFeature());
Object soap11 = getSoapBinding(Soap11.getInstance());
intentMap.put("SOAP", soap11);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/EventAdminHelper.java Tue Dec 11 19:27:18 2012
@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
public class EventAdminHelper {
- private final static Logger LOG = LoggerFactory.getLogger(EventAdminHelper.class);
+ private static final Logger LOG = LoggerFactory.getLogger(EventAdminHelper.class);
private BundleContext bctx;
@@ -43,7 +43,7 @@ public class EventAdminHelper {
}
@SuppressWarnings("rawtypes")
- private Event createEvent(Properties props, String type) {
+ private Event createEvent(Properties props, String type) {
String topic = "org/osgi/service/remoteserviceadmin/" + type;
props.put("bundle", bctx.getBundle());
@@ -54,11 +54,11 @@ public class EventAdminHelper {
String version = (String)bctx.getBundle().getHeaders().get("Bundle-Version");
Version v;
- if(version!=null)
+ if (version != null) {
v = new Version(version);
- else
+ } else {
v = Version.emptyVersion;
-
+ }
setIfNotNull(props, "bundle.version", v);
return new Event(topic, (Dictionary)props);
@@ -104,9 +104,10 @@ public class EventAdminHelper {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- private void setIfNotNull(Dictionary props, String key, Object o) {
- if (o != null)
+ private void setIfNotNull(Dictionary props, String key, Object o) {
+ if (o != null) {
props.put(key, o);
+ }
}
private EventAdmin[] getEventAdmins() {
@@ -117,8 +118,9 @@ public class EventAdminHelper {
LOG.error("Failed to get EventAdmin: " + e.getMessage(), e);
}
- if (refs == null)
+ if (refs == null) {
return null;
+ }
EventAdmin[] eas = new EventAdmin[refs.length];
for (int x = 0; x < refs.length; ++x) {
@@ -130,7 +132,7 @@ public class EventAdminHelper {
return eas;
}
- static String remoteServiceAdminEventTypeToString(int type){
+ static String remoteServiceAdminEventTypeToString(int type) {
switch (type) {
case RemoteServiceAdminEvent.EXPORT_ERROR:
return "EXPORT_ERROR";
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java Tue Dec 11 19:27:18 2012
@@ -41,10 +41,10 @@ public class ExportRegistrationImpl impl
private static final Logger LOG = LoggerFactory.getLogger(ExportRegistrationImpl.class);
private Server server;
- private boolean closed = false;
- private Throwable exception = null;
+ private boolean closed;
+ private Throwable exception;
- private ExportRegistrationImpl parent = null;
+ private ExportRegistrationImpl parent;
private volatile int instanceCount = 1;
private RemoteServiceAdminCore rsaCore;
@@ -61,28 +61,31 @@ public class ExportRegistrationImpl impl
rsaCore = parent.getRsaCore();
parent.instanceAdded();
}
+ public ExportRegistrationImpl(ServiceReference sref,
+ EndpointDescription endpoint,
+ RemoteServiceAdminCore remoteServiceAdminCore) {
+ exportReference = new ExportReferenceImpl(sref, endpoint);
+ parent = this;
+ rsaCore = remoteServiceAdminCore;
+ }
private void instanceAdded() {
++instanceCount;
}
- public ExportRegistrationImpl(ServiceReference sref, EndpointDescription endpoint, RemoteServiceAdminCore remoteServiceAdminCore) {
- exportReference = new ExportReferenceImpl(sref, endpoint);
- parent = this;
- rsaCore = remoteServiceAdminCore;
- }
public synchronized void close() {
- if (closed)
+ if (closed) {
return;
+ }
closed = true;
rsaCore.removeExportRegistration(this);
parent.instanceClosed();
if (server != null) {
- server.stop();
- server = null;
+ server.stop();
+ server = null;
}
exportReference.close();
}
@@ -106,10 +109,7 @@ public class ExportRegistrationImpl impl
}
public Throwable getException() {
- if (!closed)
- return exception;
- else
- return null;
+ return closed ? null : exception;
}
@Override
@@ -126,11 +126,11 @@ public class ExportRegistrationImpl impl
if (endpointDescription == null) {
r += "---> NULL <---- \n";
} else {
- Set<Map.Entry<String,Object>> props = endpointDescription.getProperties().entrySet();
- for (Map.Entry<String,Object> entry : props) {
+ Set<Map.Entry<String, Object>> props = endpointDescription.getProperties().entrySet();
+ for (Map.Entry<String, Object> entry : props) {
Object value = entry.getValue();
- r += entry.getKey() + " => " +
- (value instanceof Object[] ? Arrays.toString((Object []) value) : value) + "\n";
+ r += entry.getKey() + " => "
+ + (value instanceof Object[] ? Arrays.toString((Object []) value) : value) + "\n";
}
}
return r;
@@ -149,7 +149,7 @@ public class ExportRegistrationImpl impl
}
public ExportReference getExportReference() {
- return exportReference;
+ return exportReference;
}
/**
@@ -159,13 +159,13 @@ public class ExportRegistrationImpl impl
public void startServiceTracker(BundleContext bctx) {
// only the parent should do this
- if(parent!=this){
+ if (parent != this) {
parent.startServiceTracker(bctx);
return;
}
// do it only once
- if(serviceTracker!=null){
+ if (serviceTracker != null) {
return;
}
@@ -174,19 +174,21 @@ public class ExportRegistrationImpl impl
try {
f = bctx.createFilter("(" + Constants.SERVICE_ID + "=" + sid + ")");
} catch (InvalidSyntaxException e) {
- LOG.warn("Service tracker could not be started. The service will not be automatically unexported " + e.getMessage(), e);
+ LOG.warn("Service tracker could not be started. The service will not be automatically unexported "
+ + e.getMessage(), e);
return;
}
serviceTracker = new ServiceTracker(bctx, f, new ServiceTrackerCustomizer() {
public void removedService(ServiceReference sr, Object s) {
- LOG.info("Service ["+sid+"] has been unregistered: Removing service export");
+ LOG.info("Service [" + sid + "] has been unregistered: Removing service export");
close();
}
public void modifiedService(ServiceReference sr, Object s) {
// FIXME:
- LOG.warn("Service modifications after the service is exported are currently not supported. The export is not modified!");
+ LOG.warn("Service modifications after the service is exported are "
+ + "currently not supported. The export is not modified!");
}
public Object addingService(ServiceReference sr) {
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/ClassUtils.java Tue Dec 11 19:27:18 2012
@@ -1,21 +1,21 @@
/**
- * 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.
- */
+ * 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.util;
import java.util.ArrayList;
@@ -29,14 +29,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class ClassUtils {
- private static final Logger LOG = LoggerFactory.getLogger(ClassUtils.class);
-
- private ClassUtils() {}
-
+ private static final Logger LOG = LoggerFactory.getLogger(ClassUtils.class);
+
+ private ClassUtils() {
+ }
+
public static Class<?> getInterfaceClass(Object service, String interfaceName) {
return getInterfaceClass(service.getClass(), interfaceName);
}
-
+
private static Class<?> getInterfaceClass(Class<?> serviceClass, String interfaceName) {
for (Class<?> iClass : serviceClass.getInterfaces()) {
if (iClass.getName().equals(interfaceName)) {
@@ -47,19 +48,19 @@ public final class ClassUtils {
return intf;
}
}
-
+
if (serviceClass.getName().equals(interfaceName)) {
return serviceClass;
}
-
+
Class<?> interfaceOnProxiedClass = getInterfaceClassOnSuperClasses(serviceClass, interfaceName);
- if (interfaceOnProxiedClass != null){
- return interfaceOnProxiedClass;
+ if (interfaceOnProxiedClass != null) {
+ return interfaceOnProxiedClass;
}
-
+
return null;
- }
-
+ }
+
/**
* <pre>
*
@@ -73,34 +74,34 @@ public final class ClassUtils {
* @param interfaceName
* @return
*/
- private static Class<?> getInterfaceClassOnSuperClasses(Class<?> serviceClass, String interfaceName){
+ private static Class<?> getInterfaceClassOnSuperClasses(Class<?> serviceClass, String interfaceName) {
Class<?> superClass = serviceClass.getSuperclass();
- if (superClass != null){
- for (Class<?> iClass : superClass.getInterfaces()) {
- if (iClass.getName().equals(interfaceName)) {
- return iClass;
- }
- Class<?> intf = getInterfaceClass(iClass, interfaceName);
- if (intf != null) {
- return intf;
- }
- }
- Class<?> foundOnSuperclass = getInterfaceClassOnSuperClasses(superClass, interfaceName);
- if (foundOnSuperclass != null){
- return foundOnSuperclass;
- }
- }
- return null;
+ if (superClass != null) {
+ for (Class<?> iClass : superClass.getInterfaces()) {
+ if (iClass.getName().equals(interfaceName)) {
+ return iClass;
+ }
+ Class<?> intf = getInterfaceClass(iClass, interfaceName);
+ if (intf != null) {
+ return intf;
+ }
+ }
+ Class<?> foundOnSuperclass = getInterfaceClassOnSuperClasses(superClass, interfaceName);
+ if (foundOnSuperclass != null) {
+ return foundOnSuperclass;
+ }
+ }
+ return null;
}
-
+
@SuppressWarnings("rawtypes")
- public static List<Object> loadProviderClasses(BundleContext callingContext, Map sd, String propName) {
-
- Object serviceProviders = sd.get(propName);
+ public static List<Object> loadProviderClasses(BundleContext callingContext, Map sd, String propName) {
+
+ Object serviceProviders = sd.get(propName);
if (serviceProviders != null) {
if (serviceProviders.getClass().isArray()) {
if (serviceProviders.getClass().getComponentType() == String.class) {
- return loadProviders(callingContext, (String[])serviceProviders);
+ return loadProviders(callingContext, (String[])serviceProviders);
} else {
return Arrays.asList((Object[])serviceProviders);
}
@@ -108,16 +109,15 @@ public final class ClassUtils {
String[] classNames = serviceProviders.toString().split(",");
return loadProviders(callingContext, classNames);
} else {
- return Arrays.asList(serviceProviders);
+ return Arrays.asList(serviceProviders);
}
} else {
- return Collections.emptyList();
+ return Collections.emptyList();
}
}
-
- private static List<Object> loadProviders(BundleContext callingContext,
- String[] classNames) {
- List<Object> providers = new ArrayList<Object>();
+
+ private static List<Object> loadProviders(BundleContext callingContext, String[] classNames) {
+ List<Object> providers = new ArrayList<Object>();
for (String className : classNames) {
try {
String realName = className.trim();
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/util/OsgiUtils.java Tue Dec 11 19:27:18 2012
@@ -200,11 +200,11 @@ public final class OsgiUtils {
LOG.info("exportService called with additional properties map that contained illegal key: "
+ key + " The key is ignored");
continue;
- }else if(keysLowerCase.containsKey(key)){
+ } else if(keysLowerCase.containsKey(key)) {
String origKey = keysLowerCase.get(key);
serviceProperties.put(origKey, e.getValue());
LOG.debug("Overwriting property [{}] with value [{}]", origKey, e.getValue());
- }else{
+ } else {
serviceProperties.put(e.getKey(), e.getValue());
keysLowerCase.put(e.getKey().toString().toLowerCase(), e.getKey().toString());
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/HttpServiceManagerTest.java Tue Dec 11 19:27:18 2012
@@ -106,7 +106,7 @@ public class HttpServiceManagerTest exte
@SuppressWarnings("rawtypes")
public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context)
- throws ServletException, NamespaceException {
+ throws ServletException, NamespaceException {
Assert.assertEquals("/myService", alias);
servlet.init(config);
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/handlers/SecurityDelegatingHttpContextTest.java Tue Dec 11 19:27:18 2012
@@ -20,197 +20,224 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
+
public class SecurityDelegatingHttpContextTest extends TestCase {
- protected HttpContext defaultHttpContext;
- protected SecurityDelegatingHttpContext httpContext;
- protected CommitResponseFilter commitFilter;
- protected DoNothingFilter doNothingFilter;
- protected AccessDeniedFilter accessDeniedFilter;
- protected String mimeType;
- protected URL url; // does not need to exist
-
- public void setUp() throws Exception {
- mimeType = "text/xml";
- url = new URL("file:test.xml"); // does not need to exist
-
- // Sample filters
- commitFilter = new CommitResponseFilter();
- doNothingFilter = new DoNothingFilter();
- accessDeniedFilter = new AccessDeniedFilter();
-
- // Mock up the default http context
- defaultHttpContext = EasyMock.createNiceMock(HttpContext.class);
- EasyMock.expect(defaultHttpContext.getMimeType((String)EasyMock.anyObject())).andReturn(mimeType);
- EasyMock.expect(defaultHttpContext.getResource((String)EasyMock.anyObject())).andReturn(url);
- EasyMock.replay(defaultHttpContext);
- }
-
- public void testFilterRequired() throws Exception {
- // Mock up the service references
- ServiceReference[] serviceReferences = new ServiceReference[] {};
-
- // Mock up the bundle context
- BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.expect(bundleContext.getServiceReferences(Filter.class.getName(),
- "(org.apache.cxf.httpservice.filter=true)")).andReturn(serviceReferences);
- EasyMock.replay(bundleContext);
-
- // Set up the secure http context
- httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
- httpContext.requireFilter = true;
-
- // Ensure that the httpContext doesn't allow the request to be processed, since there are no registered servlet filters
- HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
- EasyMock.replay(request);
- HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
- EasyMock.replay(response);
- boolean requestAllowed = httpContext.handleSecurity(request, response);
- Assert.assertFalse(requestAllowed);
-
- // Ensure that the httpContext returns true if there is no requirement for registered servlet filters
- httpContext.requireFilter = false;
- requestAllowed = httpContext.handleSecurity(request, response);
- Assert.assertTrue(requestAllowed);
- }
-
- public void testSingleCommitFilter() throws Exception {
- // Mock up the service references
- ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
- EasyMock.replay(filterReference);
- ServiceReference[] serviceReferences = new ServiceReference[] {filterReference};
-
- // Mock up the bundle context
- BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
- .andReturn(serviceReferences);
- EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter);
- EasyMock.replay(bundleContext);
-
- // Set up the secure http context
- httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
-
- // Ensure that the httpContext returns false, since the filter has committed the response
- HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
- EasyMock.replay(request);
- HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
- EasyMock.expect(response.isCommitted()).andReturn(false); // the first call checks to see whether to invoke the filter
- EasyMock.expect(response.isCommitted()).andReturn(true); // the second is called to determine the handleSecurity return value
- EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out));
- EasyMock.replay(response);
- Assert.assertFalse(httpContext.handleSecurity(request, response));
-
- // Ensure that the appropriate filters were called
- Assert.assertTrue(commitFilter.called);
- Assert.assertFalse(doNothingFilter.called);
- Assert.assertFalse(accessDeniedFilter.called);
- }
-
- public void testFilterChain() throws Exception {
- // Mock up the service references
- ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
- EasyMock.replay(filterReference);
- ServiceReference[] serviceReferences = new ServiceReference[] {filterReference, filterReference};
-
- // Mock up the bundle context
- BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
- .andReturn(serviceReferences);
- EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter);
- EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter);
- EasyMock.replay(bundleContext);
-
- // Set up the secure http context
- httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
-
- // Ensure that the httpContext returns false, since the filter has committed the response
- HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
- EasyMock.replay(request);
- HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
- EasyMock.expect(response.isCommitted()).andReturn(false); // doNothingFilter should not commit the response
- EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out));
- EasyMock.expect(response.isCommitted()).andReturn(false);
- EasyMock.expect(response.isCommitted()).andReturn(true); // the commit filter indicating that it committed the response
- EasyMock.replay(response);
- Assert.assertFalse(httpContext.handleSecurity(request, response));
-
- // Ensure that the appropriate filters were called
- Assert.assertTrue(doNothingFilter.called);
- Assert.assertTrue(commitFilter.called);
- Assert.assertFalse(accessDeniedFilter.called);
- }
-
- public void testAllowRequest() throws Exception {
- // Mock up the service references
- ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
- EasyMock.replay(filterReference);
- ServiceReference[] serviceReferences = new ServiceReference[] {filterReference};
-
- // Mock up the bundle context
- BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
- .andReturn(serviceReferences);
- EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter);
- EasyMock.replay(bundleContext);
-
- // Set up the secure http context
- httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
-
- // Ensure that the httpContext returns true, since the filter has not committed the response
- HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
- EasyMock.replay(request);
- HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
- EasyMock.expect(response.isCommitted()).andReturn(false);
- EasyMock.replay(response);
- Assert.assertTrue(httpContext.handleSecurity(request, response));
-
- // Ensure that the appropriate filters were called
- Assert.assertTrue(doNothingFilter.called);
- Assert.assertFalse(commitFilter.called);
- Assert.assertFalse(accessDeniedFilter.called);
- }
-
- public void testDelegation() throws Exception {
- BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
- EasyMock.replay(bundleContext);
-
- // Set up the secure http context
- httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
-
- // Ensure that it delegates non-security calls to the wrapped implementation (in this case, the mock)
- Assert.assertEquals(mimeType, httpContext.getMimeType(""));
- Assert.assertEquals(url, httpContext.getResource(""));
- }
+ protected HttpContext defaultHttpContext;
+ protected SecurityDelegatingHttpContext httpContext;
+ protected CommitResponseFilter commitFilter;
+ protected DoNothingFilter doNothingFilter;
+ protected AccessDeniedFilter accessDeniedFilter;
+ protected String mimeType;
+ protected URL url; // does not need to exist
+
+ public void setUp() throws Exception {
+ mimeType = "text/xml";
+ url = new URL("file:test.xml"); // does not need to exist
+
+ // Sample filters
+ commitFilter = new CommitResponseFilter();
+ doNothingFilter = new DoNothingFilter();
+ accessDeniedFilter = new AccessDeniedFilter();
+
+ // Mock up the default http context
+ defaultHttpContext = EasyMock.createNiceMock(HttpContext.class);
+ EasyMock.expect(defaultHttpContext.getMimeType((String)EasyMock.anyObject())).andReturn(mimeType);
+ EasyMock.expect(defaultHttpContext.getResource((String)EasyMock.anyObject())).andReturn(url);
+ EasyMock.replay(defaultHttpContext);
+ }
+
+ public void testFilterRequired() throws Exception {
+ // Mock up the service references
+ ServiceReference[] serviceReferences = new ServiceReference[] {};
+
+ // Mock up the bundle context
+ BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+ EasyMock.expect(bundleContext.getServiceReferences(Filter.class.getName(),
+ "(org.apache.cxf.httpservice.filter=true)"))
+ .andReturn(serviceReferences);
+ EasyMock.replay(bundleContext);
+
+ // Set up the secure http context
+ httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+ httpContext.requireFilter = true;
+
+ // Ensure that the httpContext doesn't allow the request to be processed, since there are no registered servlet
+ // filters
+ HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+ EasyMock.replay(request);
+ HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+ EasyMock.replay(response);
+ boolean requestAllowed = httpContext.handleSecurity(request, response);
+ Assert.assertFalse(requestAllowed);
+
+ // Ensure that the httpContext returns true if there is no requirement for registered servlet filters
+ httpContext.requireFilter = false;
+ requestAllowed = httpContext.handleSecurity(request, response);
+ Assert.assertTrue(requestAllowed);
+ }
+
+ public void testSingleCommitFilter() throws Exception {
+ // Mock up the service references
+ ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(filterReference);
+ ServiceReference[] serviceReferences = new ServiceReference[] {
+ filterReference
+ };
+
+ // Mock up the bundle context
+ BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+ EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
+ .andReturn(serviceReferences);
+ EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter);
+ EasyMock.replay(bundleContext);
+
+ // Set up the secure http context
+ httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+
+ // Ensure that the httpContext returns false, since the filter has committed the response
+ HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+ EasyMock.replay(request);
+ HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+ EasyMock.expect(response.isCommitted()).andReturn(false); // the first call checks to see whether to invoke the
+ // filter
+ EasyMock.expect(response.isCommitted()).andReturn(true); // the second is called to determine the handleSecurity
+ // return value
+ EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out));
+ EasyMock.replay(response);
+ Assert.assertFalse(httpContext.handleSecurity(request, response));
+
+ // Ensure that the appropriate filters were called
+ Assert.assertTrue(commitFilter.called);
+ Assert.assertFalse(doNothingFilter.called);
+ Assert.assertFalse(accessDeniedFilter.called);
+ }
+
+ public void testFilterChain() throws Exception {
+ // Mock up the service references
+ ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(filterReference);
+ ServiceReference[] serviceReferences = new ServiceReference[] {
+ filterReference, filterReference
+ };
+
+ // Mock up the bundle context
+ BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+ EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
+ .andReturn(serviceReferences);
+ EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter);
+ EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(commitFilter);
+ EasyMock.replay(bundleContext);
+
+ // Set up the secure http context
+ httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+
+ // Ensure that the httpContext returns false, since the filter has committed the response
+ HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+ EasyMock.replay(request);
+ HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+ EasyMock.expect(response.isCommitted()).andReturn(false); // doNothingFilter should not commit the response
+ EasyMock.expect(response.getWriter()).andReturn(new PrintWriter(System.out));
+ EasyMock.expect(response.isCommitted()).andReturn(false);
+ EasyMock.expect(response.isCommitted()).andReturn(true); // the commit filter indicating that it committed the
+ // response
+ EasyMock.replay(response);
+ Assert.assertFalse(httpContext.handleSecurity(request, response));
+
+ // Ensure that the appropriate filters were called
+ Assert.assertTrue(doNothingFilter.called);
+ Assert.assertTrue(commitFilter.called);
+ Assert.assertFalse(accessDeniedFilter.called);
+ }
+
+ public void testAllowRequest() throws Exception {
+ // Mock up the service references
+ ServiceReference filterReference = EasyMock.createNiceMock(ServiceReference.class);
+ EasyMock.replay(filterReference);
+ ServiceReference[] serviceReferences = new ServiceReference[] {
+ filterReference
+ };
+
+ // Mock up the bundle context
+ BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+ EasyMock.expect(bundleContext.getServiceReferences((String)EasyMock.anyObject(), (String)EasyMock.anyObject()))
+ .andReturn(serviceReferences);
+ EasyMock.expect(bundleContext.getService((ServiceReference)EasyMock.anyObject())).andReturn(doNothingFilter);
+ EasyMock.replay(bundleContext);
+
+ // Set up the secure http context
+ httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+
+ // Ensure that the httpContext returns true, since the filter has not committed the response
+ HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
+ EasyMock.replay(request);
+ HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class);
+ EasyMock.expect(response.isCommitted()).andReturn(false);
+ EasyMock.replay(response);
+ Assert.assertTrue(httpContext.handleSecurity(request, response));
+
+ // Ensure that the appropriate filters were called
+ Assert.assertTrue(doNothingFilter.called);
+ Assert.assertFalse(commitFilter.called);
+ Assert.assertFalse(accessDeniedFilter.called);
+ }
+
+ public void testDelegation() throws Exception {
+ BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
+ EasyMock.replay(bundleContext);
+
+ // Set up the secure http context
+ httpContext = new SecurityDelegatingHttpContext(bundleContext, defaultHttpContext);
+
+ // Ensure that it delegates non-security calls to the wrapped implementation (in this case, the mock)
+ Assert.assertEquals(mimeType, httpContext.getMimeType(""));
+ Assert.assertEquals(url, httpContext.getResource(""));
+ }
}
class CommitResponseFilter implements Filter {
- public boolean called = false;
- public void init(FilterConfig filterConfig) throws ServletException {}
- public void destroy() {}
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
- throws java.io.IOException ,javax.servlet.ServletException {
- called = true;
- response.getWriter().write("committing the response");
- };
+ public boolean called = false;
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void destroy() {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws java.io.IOException, javax.servlet.ServletException {
+ called = true;
+ response.getWriter().write("committing the response");
+ };
}
class DoNothingFilter implements Filter {
- boolean called = false;
- public void init(FilterConfig filterConfig) throws ServletException {}
- public void destroy() {}
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
- throws java.io.IOException ,javax.servlet.ServletException {
- called = true;
- chain.doFilter(request, response);
- };
+ boolean called = false;
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void destroy() {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws java.io.IOException, javax.servlet.ServletException {
+ called = true;
+ chain.doFilter(request, response);
+ };
}
class AccessDeniedFilter implements Filter {
- boolean called = false;
- public void init(FilterConfig filterConfig) throws ServletException {}
- public void destroy() {}
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
- throws java.io.IOException ,javax.servlet.ServletException {
- called = true;
- ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN);
- };
+ boolean called = false;
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void destroy() {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws java.io.IOException, javax.servlet.ServletException {
+ called = true;
+ ((HttpServletResponse)response).sendError(HttpServletResponse.SC_FORBIDDEN);
+ };
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/UtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/UtilsTest.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/UtilsTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/service/UtilsTest.java Tue Dec 11 19:27:18 2012
@@ -34,14 +34,14 @@ import org.osgi.framework.Constants;
public class UtilsTest {
- @Test
- public void testSplitString() {
- String[] values = Utils.normalizeStringPlus("1, 2");
- assertEquals(2, values.length);
- assertEquals(values[0], "1");
- assertEquals(values[1], "2");
- }
-
+ @Test
+ public void testSplitString() {
+ String[] values = Utils.normalizeStringPlus("1, 2");
+ assertEquals(2, values.length);
+ assertEquals(values[0], "1");
+ assertEquals(values[1], "2");
+ }
+
@Test
public void testNormalizeStringPlus() {
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java?rev=1420346&r1=1420345&r2=1420346&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/ClassUtilsTest.java Tue Dec 11 19:27:18 2012
@@ -36,22 +36,27 @@ public class ClassUtilsTest extends Test
}
public void testGetInterfaceClassFromSubclass() {
- assertEquals(Map.class, ClassUtils.getInterfaceClass(new MySubclassFour(), "java.util.Map"));
- assertNull(ClassUtils.getInterfaceClass(new MySubclassFour(), "java.util.UnknownType"));
+ assertEquals(Map.class, ClassUtils.getInterfaceClass(new MySubclassFour(), "java.util.Map"));
+ assertNull(ClassUtils.getInterfaceClass(new MySubclassFour(), "java.util.UnknownType"));
}
@SuppressWarnings({ "serial", "rawtypes" })
- private static class MyMapSubclass extends HashMap{}
+ private static class MyMapSubclass extends HashMap {
+ }
@SuppressWarnings("serial")
- static class MySubclassOne extends MyMapSubclass{}
+ static class MySubclassOne extends MyMapSubclass {
+ }
@SuppressWarnings("serial")
- static class MySubclassTwo extends MySubclassOne{}
+ static class MySubclassTwo extends MySubclassOne {
+ }
@SuppressWarnings("serial")
- static class MySubclassThree extends MySubclassTwo{}
+ static class MySubclassThree extends MySubclassTwo {
+ }
@SuppressWarnings("serial")
- static class MySubclassFour extends MySubclassThree{}
+ static class MySubclassFour extends MySubclassThree {
+ }
}