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 2007/05/24 21:01:39 UTC
svn commit: r541388 - in /incubator/cxf/trunk:
common/common/src/main/java/org/apache/cxf/common/util/
rt/core/src/main/java/org/apache/cxf/wsdl11/
rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/
rt/frontend/jaxws/src/main/java/org/apache/cxf/jax...
Author: dkulp
Date: Thu May 24 12:01:36 2007
New Revision: 541388
URL: http://svn.apache.org/viewvc?view=rev&rev=541388
Log:
Update WSDLManger to cache things better
Add more debugging code to JaxWsServiceFactory to help debug some Geronimo issues
Added:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java (with props)
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/WeakIdentityHashMap.java (with props)
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java?view=auto&rev=541388
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java (added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java Thu May 24 12:01:36 2007
@@ -0,0 +1,134 @@
+/**
+ * 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.common.util;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+
+/**
+ * Implements a useful caching map. It weakly references the keys,
+ * but strongly references the data. It works a log like the WeakHashMap,
+ * in that when the keys are garbage collected, the data is removed from
+ * the map.
+ *
+ * The main difference is that keys used for lookups don't have to be "=="
+ * the same to maintain the data in the cache. Basically, lookups in this
+ * map use a ".equals" compare, but the keys are then stored with a "=="
+ * compare so if the original key is garbage collected, the other keys that
+ * may reference the data keep the data in the cache.
+ *
+ * <b>
+ * Note that this implementation is not synchronized.
+ * </b>
+ */
+public class CacheMap<K, V> implements Map<K, V> {
+ Map<K, V> mainDataMap = new WeakHashMap<K, V>();
+ Map<K, V> extraKeyMap = new WeakIdentityHashMap<K, V>();
+
+ public void clear() {
+ mainDataMap.clear();
+ extraKeyMap.clear();
+ }
+
+ private void updateMainDataMap() {
+ //if the singleton in the mainDataMap has been garbage collected,
+ //we'll copy another version of it from the extraKeyMap
+ for (K o : extraKeyMap.keySet()) {
+ if (!mainDataMap.containsKey(o)) {
+ mainDataMap.put(o, extraKeyMap.get(o));
+ }
+ }
+ }
+
+ public boolean containsKey(Object key) {
+ if (!mainDataMap.containsKey(key)) {
+ updateMainDataMap();
+ return mainDataMap.containsKey(key);
+ }
+ return true;
+ }
+
+ public boolean containsValue(Object value) {
+ return mainDataMap.containsValue(value)
+ || extraKeyMap.containsValue(value);
+ }
+
+ public Set<java.util.Map.Entry<K, V>> entrySet() {
+ updateMainDataMap();
+ return mainDataMap.entrySet();
+ }
+
+ @SuppressWarnings("unchecked")
+ public V get(Object key) {
+ V val = mainDataMap.get(key);
+ if (val == null) {
+ updateMainDataMap();
+ val = mainDataMap.get(val);
+ }
+ if (val != null) {
+ extraKeyMap.put((K)key, val);
+ }
+ return val;
+ }
+
+ public boolean isEmpty() {
+ return mainDataMap.isEmpty() && extraKeyMap.isEmpty();
+ }
+
+ public Set<K> keySet() {
+ updateMainDataMap();
+ return mainDataMap.keySet();
+ }
+
+ public V put(K key, V value) {
+ V v = mainDataMap.put(key, value);
+ V v2 = extraKeyMap.put(key, value);
+ return v == null ? v2 : v;
+ }
+
+ public void putAll(Map<? extends K, ? extends V> t) {
+ for (Map.Entry<? extends K, ? extends V> ent : t.entrySet()) {
+ put(ent.getKey(), ent.getValue());
+ }
+ }
+
+ public V remove(Object key) {
+ V v = mainDataMap.remove(key);
+ V v2 = extraKeyMap.remove(key);
+ return v == null ? v2 : v;
+ }
+
+ public int size() {
+ updateMainDataMap();
+ return mainDataMap.size();
+ }
+
+ public Collection<V> values() {
+ updateMainDataMap();
+ return mainDataMap.values();
+ }
+
+ public String toString() {
+ updateMainDataMap();
+ return mainDataMap.toString();
+ }
+}
Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/CacheMap.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/WeakIdentityHashMap.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/WeakIdentityHashMap.java?view=auto&rev=541388
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/WeakIdentityHashMap.java (added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/WeakIdentityHashMap.java Thu May 24 12:01:36 2007
@@ -0,0 +1,172 @@
+/**
+ * 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.common.util;
+
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.WeakReference;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * Implements a combination of WeakHashMap and IdentityHashMap.
+ * Useful for caches that need to key off of a == comparison
+ * instead of a .equals.
+ *
+ * <b>
+ * This class is not a general-purpose Map implementation! While
+ * this class implements the Map interface, it intentionally violates
+ * Map's general contract, which mandates the use of the equals method
+ * when comparing objects. This class is designed for use only in the
+ * rare cases wherein reference-equality semantics are required.
+ *
+ * Note that this implementation is not synchronized.
+ * </b>
+ */
+public class WeakIdentityHashMap<K, V> implements Map<K, V> {
+ private final ReferenceQueue<K> queue = new ReferenceQueue<K>();
+ private Map<IdentityWeakReference, V> backingStore = new HashMap<IdentityWeakReference, V>();
+
+
+ public WeakIdentityHashMap() {
+ }
+
+
+ public void clear() {
+ backingStore.clear();
+ reap();
+ }
+
+ public boolean containsKey(Object key) {
+ reap();
+ return backingStore.containsKey(new IdentityWeakReference(key));
+ }
+
+ public boolean containsValue(Object value) {
+ reap();
+ return backingStore.containsValue(value);
+ }
+
+ public Set<Map.Entry<K, V>> entrySet() {
+ reap();
+ Set<Map.Entry<K, V>> ret = new HashSet<Map.Entry<K, V>>();
+ for (Map.Entry<IdentityWeakReference, V> ref : backingStore.entrySet()) {
+ final K key = ref.getKey().get();
+ final V value = ref.getValue();
+ Map.Entry<K, V> entry = new Map.Entry<K, V>() {
+ public K getKey() {
+ return key;
+ }
+ public V getValue() {
+ return value;
+ }
+ public V setValue(V value) {
+ throw new UnsupportedOperationException();
+ }
+ };
+ ret.add(entry);
+ }
+ return Collections.unmodifiableSet(ret);
+ }
+ public Set<K> keySet() {
+ reap();
+ Set<K> ret = new HashSet<K>();
+ for (IdentityWeakReference ref : backingStore.keySet()) {
+ ret.add(ref.get());
+ }
+ return Collections.unmodifiableSet(ret);
+ }
+
+ public boolean equals(Object o) {
+ return backingStore.equals(((WeakIdentityHashMap)o).backingStore);
+ }
+
+ public V get(Object key) {
+ reap();
+ return backingStore.get(new IdentityWeakReference(key));
+ }
+ public V put(K key, V value) {
+ reap();
+ return backingStore.put(new IdentityWeakReference(key), value);
+ }
+
+ public int hashCode() {
+ reap();
+ return backingStore.hashCode();
+ }
+ public boolean isEmpty() {
+ reap();
+ return backingStore.isEmpty();
+ }
+ public void putAll(Map t) {
+ throw new UnsupportedOperationException();
+ }
+ public V remove(Object key) {
+ reap();
+ return backingStore.remove(new IdentityWeakReference(key));
+ }
+ public int size() {
+ reap();
+ return backingStore.size();
+ }
+ public Collection<V> values() {
+ reap();
+ return backingStore.values();
+ }
+
+ private synchronized void reap() {
+ Object zombie = queue.poll();
+
+ while (zombie != null) {
+ IdentityWeakReference victim = (IdentityWeakReference)zombie;
+ backingStore.remove(victim);
+ zombie = queue.poll();
+ }
+ }
+
+ class IdentityWeakReference extends WeakReference<K> {
+ int hash;
+
+ @SuppressWarnings("unchecked")
+ IdentityWeakReference(Object obj) {
+ super((K)obj, queue);
+ hash = System.identityHashCode(obj);
+ }
+
+ public int hashCode() {
+ return hash;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ IdentityWeakReference ref = (IdentityWeakReference)o;
+ if (this.get() == ref.get()) {
+ return true;
+ }
+ return false;
+ }
+ }
+}
+
Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/WeakIdentityHashMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/WeakIdentityHashMap.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java?view=diff&rev=541388&r1=541387&r2=541388
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLManagerImpl.java Thu May 24 12:01:36 2007
@@ -46,8 +46,8 @@
import org.apache.cxf.catalog.CatalogWSDLLocator;
import org.apache.cxf.catalog.OASISCatalogManager;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.CacheMap;
import org.apache.cxf.common.util.PropertiesLoaderUtils;
-import org.apache.cxf.common.util.TwoStageMap;
import org.apache.cxf.wsdl.JAXBExtensionHelper;
import org.apache.cxf.wsdl.WSDLConstants;
import org.apache.cxf.wsdl.WSDLManager;
@@ -65,7 +65,7 @@
final ExtensionRegistry registry;
final WSDLFactory factory;
- final TwoStageMap<Object, Definition> definitionsMap;
+ final Map<Object, Definition> definitionsMap;
private Bus bus;
public WSDLManagerImpl() throws BusException {
@@ -78,7 +78,7 @@
} catch (WSDLException e) {
throw new BusException(e);
}
- definitionsMap = new TwoStageMap<Object, Definition>();
+ definitionsMap = new CacheMap<Object, Definition>();
registerInitialExtensions();
}
@@ -99,9 +99,12 @@
return factory;
}
- public Map<Object, Definition> getDefinitions() {
- return Collections.unmodifiableMap(definitionsMap);
+ public Map<Object, Definition> getDefinitions() {
+ synchronized (definitionsMap) {
+ return Collections.unmodifiableMap(definitionsMap);
+ }
}
+
/*
* (non-Javadoc)
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=541388&r1=541387&r2=541388
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java Thu May 24 12:01:36 2007
@@ -116,7 +116,7 @@
bus = b;
implementor = i;
this.bindingUri = bindingUri;
- wsdlLocation = wsdl;
+ wsdlLocation = wsdl == null ? null : new String(wsdl);
serverFactory = new JaxWsServerFactoryBean();
doInit = true;
@@ -312,7 +312,12 @@
}
configureObject(endpoint.getService());
- configureObject(endpoint);
+ configureObject(endpoint);
+
+ if (getWsdlLocation() == null) {
+ //hold onto the wsdl location so cache won't clear till we go away
+ setWsdlLocation(serverFactory.getWsdlURL());
+ }
}
return (ServerImpl) server;
}
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java?view=diff&rev=541388&r1=541387&r2=541388
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java Thu May 24 12:01:36 2007
@@ -19,6 +19,7 @@
package org.apache.cxf.jaxws;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
@@ -79,7 +80,7 @@
private static final ResourceBundle BUNDLE = LOG.getResourceBundle();
private Bus bus;
- private URL wsdlURL;
+ private String wsdlURL;
private HandlerResolver handlerResolver;
private final Collection<QName> ports = new HashSet<QName>();
@@ -90,7 +91,7 @@
public ServiceImpl(Bus b, URL url, QName name, Class<?> cls) {
bus = b;
- wsdlURL = url;
+ wsdlURL = url == null ? null : url.toString();
this.serviceName = name;
clazz = cls;
@@ -263,7 +264,11 @@
}
public URL getWSDLDocumentLocation() {
- return wsdlURL;
+ try {
+ return new URL(wsdlURL);
+ } catch (MalformedURLException e) {
+ throw new WebServiceException(e);
+ }
}
public void setExecutor(Executor e) {
@@ -292,7 +297,7 @@
proxyFac.setServiceName(serviceName);
if (wsdlURL != null) {
- proxyFac.setWsdlURL(wsdlURL.toString());
+ proxyFac.setWsdlURL(wsdlURL);
}
if (portName == null) {
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?view=diff&rev=541388&r1=541387&r2=541388
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java Thu May 24 12:01:36 2007
@@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.logging.Logger;
import javax.wsdl.Operation;
import javax.xml.namespace.QName;
@@ -37,6 +38,8 @@
import org.apache.cxf.binding.soap.model.SoapBindingInfo;
import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.databinding.source.SourceDataBinding;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.endpoint.EndpointException;
@@ -68,6 +71,7 @@
* @see org.apache.cxf.jaxws.JaxWsServerFactoryBean
*/
public class JaxWsServiceFactoryBean extends AbstractJaxWsServiceFactoryBean {
+ private static final Logger LOG = LogUtils.getL7dLogger(JaxWsServiceFactoryBean.class);
private AbstractServiceConfiguration jaxWsConfiguration;
@@ -375,17 +379,35 @@
if (isIn && !isOut) {
QName name = getInPartName(o, method, i);
part = o.getInput().getMessagePart(name);
+ if (part == null) {
+ throw new ServiceConstructionException(
+ new Message("COULD_NOT_FIND_PART", LOG,
+ name,
+ o.getInput().getMessagePartsMap().keySet().toString()));
+ }
initializeParameter(part, paramType, genericType);
part.setIndex(i);
} else if (!isIn && isOut) {
QName name = getOutPartName(o, method, i);
part = o.getOutput().getMessagePart(name);
+ if (part == null) {
+ throw new ServiceConstructionException(
+ new Message("COULD_NOT_FIND_PART", LOG,
+ name,
+ o.getInput().getMessagePartsMap().keySet().toString()));
+ }
part.setProperty(ReflectionServiceFactoryBean.MODE_OUT, Boolean.TRUE);
initializeParameter(part, paramType, genericType);
part.setIndex(i);
} else if (isIn && isOut) {
QName name = getInPartName(o, method, i);
part = o.getInput().getMessagePart(name);
+ if (part == null) {
+ throw new ServiceConstructionException(
+ new Message("COULD_NOT_FIND_PART", LOG,
+ name,
+ o.getInput().getMessagePartsMap().keySet().toString()));
+ }
part.setProperty(ReflectionServiceFactoryBean.MODE_INOUT, Boolean.TRUE);
initializeParameter(part, paramType, genericType);
part.setIndex(i);
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties?view=diff&rev=541388&r1=541387&r2=541388
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/Messages.properties Thu May 24 12:01:36 2007
@@ -24,3 +24,4 @@
ILLEGAL_ATTRIBUTE_IN_SEI_ANNOTATION_EXC = Attributes portName, serviceName and endpointInterface are not allowed in the @WebService annotation of an SEI.
MALFORMED_URL_IN_WEBSERVICE_ANNOTATION_EXC = Malformed url in @WwebService annotation attribute wsdlLocation.
LOAD_WSDL_EXC = Could not load WSDL from URL {0}.
+COULD_NOT_FIND_PART = Could not find a message part matching name {0}. Possible values are {1}.
Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?view=diff&rev=541388&r1=541387&r2=541388
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java Thu May 24 12:01:36 2007
@@ -1272,6 +1272,9 @@
for (AbstractServiceConfiguration c : serviceConfigurations) {
wsdlURL = c.getWsdlURL();
if (wsdlURL != null) {
+ //create a unique string so if its an interned string (like
+ //from an annotation), caches will clear
+ wsdlURL = new String(wsdlURL);
break;
}
}
@@ -1280,7 +1283,9 @@
}
public void setWsdlURL(String wsdlURL) {
- this.wsdlURL = wsdlURL;
+ //create a unique string so if its an interned string (like
+ //from an annotation), caches will clear
+ this.wsdlURL = new String(wsdlURL);
}
public void setWsdlURL(URL wsdlURL) {