Skip to content
Permalink
Browse files
[CXF-5542] Minor updates
git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1565616 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sergey Beryozkin committed Feb 7, 2014
1 parent fc6fb5c commit 4e8e5f292895681a97a762cf55f5bc9cbd17b9a2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 38 deletions.
@@ -130,7 +130,6 @@ private void findContextFields(Class<?> cls, Object provider) {
}

private static ThreadLocalProxy<?> getFieldThreadLocalProxy(Field f, Object provider) {
ThreadLocalProxy<?> defaultValue = InjectionUtils.createThreadLocalProxy(f.getType());
if (provider != null) {
Object proxy = null;
synchronized (provider) {
@@ -140,18 +139,17 @@ private static ThreadLocalProxy<?> getFieldThreadLocalProxy(Field f, Object prov
// continue
}
if (!(proxy instanceof ThreadLocalProxy)) {
proxy = defaultValue;
proxy = InjectionUtils.createThreadLocalProxy(f.getType());
InjectionUtils.injectFieldValue(f, provider, proxy);
}
}
return (ThreadLocalProxy<?>)proxy;
} else {
return defaultValue;
return InjectionUtils.createThreadLocalProxy(f.getType());
}
}

private static ThreadLocalProxy<?> getMethodThreadLocalProxy(Method m, Object provider) {
ThreadLocalProxy<?> defaultValue = InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]);
if (provider != null) {
Object proxy = null;
synchronized (provider) {
@@ -163,24 +161,27 @@ private static ThreadLocalProxy<?> getMethodThreadLocalProxy(Method m, Object pr
// continue
}
if (!(proxy instanceof ThreadLocalProxy)) {
proxy = defaultValue;
proxy = InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]);
InjectionUtils.injectThroughMethod(provider, m, proxy);
}
}
return (ThreadLocalProxy<?>)proxy;
} else {
return defaultValue;
return InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]);
}
}

@SuppressWarnings("unchecked")
private <T> Map<Class<?>, Map<T, ThreadLocalProxy<?>>> getProxyMap(Class<T> keyCls, String prop, boolean create) {
Object property = bus.getProperty(prop);
if (property == null && create) {
Map<Class<?>, Map<T, ThreadLocalProxy<?>>> map
= new ConcurrentHashMap<Class<?>, Map<T, ThreadLocalProxy<?>>>(2);
bus.setProperty(prop, map);
property = map;
Object property = null;
synchronized (bus) {
property = bus.getProperty(prop);
if (property == null && create) {
Map<Class<?>, Map<T, ThreadLocalProxy<?>>> map
= new ConcurrentHashMap<Class<?>, Map<T, ThreadLocalProxy<?>>>(2);
bus.setProperty(prop, map);
property = map;
}
}
return (Map<Class<?>, Map<T, ThreadLocalProxy<?>>>)property;
}
@@ -321,8 +322,9 @@ private <T> void clearProxies(Map<Class<?>, Map<T, ThreadLocalProxy<?>>> tlps) {
}

private Map<Class<?>, List<Field>> addContextField(Map<Class<?>, List<Field>> theFields, Field f) {

theFields = theFields == null ? new HashMap<Class<?>, List<Field>>() : theFields;
if (theFields == null) {
theFields = new HashMap<Class<?>, List<Field>>();
}

List<Field> fields = theFields.get(serviceClass);
if (fields == null) {
@@ -335,12 +337,13 @@ private Map<Class<?>, List<Field>> addContextField(Map<Class<?>, List<Field>> th
return theFields;
}

private <T, V> void addToMap(Map<Class<?>, Map<T, V>> theFields,
T f, V proxy) {
Map<T, V> proxies = theFields.get(serviceClass);
private <T, V> void addToMap(Map<Class<?>, Map<T, V>> proxyMap,
T f,
V proxy) {
Map<T, V> proxies = proxyMap.get(serviceClass);
if (proxies == null) {
proxies = new HashMap<T, V>();
theFields.put(serviceClass, proxies);
proxyMap.put(serviceClass, proxies);
}
if (!proxies.containsKey(f)) {
proxies.put(f, proxy);
@@ -992,37 +992,35 @@ public static void injectContextProxiesAndApplication(AbstractResourceInfo cri,
if (!cri.contextsAvailable() || !cri.isSingleton()) {
return;
}

for (Map.Entry<Class<?>, Method> entry : cri.getContextMethods().entrySet()) {
Method method = entry.getValue();
Object value = method.getParameterTypes()[0] == Application.class
? app : cri.getContextSetterProxy(method);
try {
synchronized (instance) {
synchronized (instance) {
for (Map.Entry<Class<?>, Method> entry : cri.getContextMethods().entrySet()) {
Method method = entry.getValue();
Object value = method.getParameterTypes()[0] == Application.class
? app : cri.getContextSetterProxy(method);
try {
if (value == InjectionUtils.extractFromMethod(instance,
getGetterFromSetter(method),
false)) {
continue;
}

} catch (Throwable t) {
// continue
}
} catch (Throwable t) {
// continue
InjectionUtils.injectThroughMethod(instance, method, value);
}
InjectionUtils.injectThroughMethod(instance, method, value);
}

for (Field f : cri.getContextFields()) {
Object value = f.getType() == Application.class ? app : cri.getContextFieldProxy(f);
try {
synchronized (instance) {

for (Field f : cri.getContextFields()) {
Object value = f.getType() == Application.class ? app : cri.getContextFieldProxy(f);
try {
if (value == InjectionUtils.extractFieldValue(f, instance)) {
continue;
}
} catch (Throwable t) {
// continue
}
} catch (Throwable t) {
// continue
InjectionUtils.injectFieldValue(f, instance, value);
}
InjectionUtils.injectFieldValue(f, instance, value);
}
}

@@ -79,12 +79,13 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
<ref bean="gBookStore2"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jackson"/>
<ref bean="jackson2"/>
<ref bean="jaxb"/>
</jaxrs:providers>
</jaxrs:server>

<bean id="jackson" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
<bean id="jackson2" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
<bean id="jaxb" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="unmarshallAsJaxbElement" value="true"/>
<property name="marshallAsJaxbElement" value="true"/>

0 comments on commit 4e8e5f2

Please sign in to comment.