protected void tryInjectMessageContext(Object handler) { Method m = null; try { m = handler.getClass().getMethod("setMessageContext", new Class[]{MessageContext.class}); } catch (Throwable t) { return; } try { InjectionUtils.injectThroughMethod(handler, m, mc); } catch (Throwable t) { LOG.warning("Message context can not be injected into " + handler.getClass().getName() + " : " + t.getMessage()); } }
protected void tryInjectMessageContext(Object handler) { Method m = null; try { m = handler.getClass().getMethod("setMessageContext", new Class[]{MessageContext.class}); } catch (Throwable t) { return; } try { InjectionUtils.injectThroughMethod(handler, m, mc); } catch (Throwable t) { LOG.warning("Message context can not be injected into " + handler.getClass().getName() + " : " + t.getMessage()); } }
protected void tryInjectMessageContext(Object handler) { Method m = null; try { m = handler.getClass().getMethod("setMessageContext", new Class[]{MessageContext.class}); } catch (Throwable t) { return; } try { InjectionUtils.injectThroughMethod(handler, m, mc); } catch (Throwable t) { LOG.warning("Message context can not be injected into " + handler.getClass().getName() + " : " + t.getMessage()); } }
private void injectProperties(Object instance, Map<String, List<String>> props) { if (props == null || props.isEmpty()) { return; } Method[] methods = instance.getClass().getMethods(); Map<String, Method> methodsMap = new HashMap<>(); for (Method m : methods) { methodsMap.put(m.getName(), m); } for (Map.Entry<String, List<String>> entry : props.entrySet()) { Method m = methodsMap.get("set" + Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1)); if (m != null) { Class<?> type = m.getParameterTypes()[0]; Object value; if (InjectionUtils.isPrimitive(type)) { value = PrimitiveUtils.read(entry.getValue().get(0), type); } else { value = entry.getValue(); } InjectionUtils.injectThroughMethod(instance, m, value); } } }
private void injectProperties(Object instance, Map<String, List<String>> props) { if (props == null || props.isEmpty()) { return; } Method[] methods = instance.getClass().getMethods(); Map<String, Method> methodsMap = new HashMap<String, Method>(); for (Method m : methods) { methodsMap.put(m.getName(), m); } for (Map.Entry<String, List<String>> entry : props.entrySet()) { Method m = methodsMap.get("set" + Character.toUpperCase(entry.getKey().charAt(0)) + entry.getKey().substring(1)); if (m != null) { Class<?> type = m.getParameterTypes()[0]; Object value; if (InjectionUtils.isPrimitive(type)) { value = PrimitiveUtils.read(entry.getValue().get(0), type); } else { value = entry.getValue(); } InjectionUtils.injectThroughMethod(instance, m, value); } } }
public static void injectThroughMethod(Object requestObject, Method method, Object parameterValue, Message inMessage) { try { Method methodToInvoke = checkProxy(method, requestObject); methodToInvoke.invoke(requestObject, new Object[]{parameterValue}); } catch (IllegalAccessException ex) { reportServerError("METHOD_ACCESS_FAILURE", method.getName()); } catch (InvocationTargetException ex) { LOG.log(Level.SEVERE, ex.getCause().getMessage(), ex); Response r = JAXRSUtils.convertFaultToResponse(ex.getCause(), inMessage); if (r != null) { inMessage.getExchange().put(Response.class, r); throw new WebApplicationException(); } reportServerError("METHOD_ACCESS_FAILURE", method.getName()); } catch (Exception ex) { reportServerError("METHOD_INJECTION_FAILURE", method.getName()); } }
@SuppressWarnings("unchecked") public static void injectContextMethods(Object requestObject, AbstractResourceInfo cri, Message message) { for (Map.Entry<Class<?>, Method> entry : cri.getContextMethods().entrySet()) { Method method = entry.getValue(); if (VALUE_CONTEXTS.contains(method.getParameterTypes()[0].getName()) && cri.isSingleton()) { continue; } Object o = JAXRSUtils.createContextValue(message, method.getGenericParameterTypes()[0], entry.getKey()); if (o != null) { if (!cri.isSingleton()) { InjectionUtils.injectThroughMethod(requestObject, method, o, message); } else { ThreadLocalProxy<Object> proxy = (ThreadLocalProxy<Object>)cri.getContextSetterProxy(method); if (proxy != null) { proxy.set(o); } } } } }
public static void injectThroughMethod(Object requestObject, Method method, Object parameterValue, Message inMessage) { try { Method methodToInvoke = checkProxy(method, requestObject); methodToInvoke.invoke(requestObject, new Object[]{parameterValue}); } catch (IllegalAccessException ex) { reportServerError("METHOD_ACCESS_FAILURE", method.getName()); } catch (InvocationTargetException ex) { Response r = JAXRSUtils.convertFaultToResponse(ex.getCause(), inMessage); if (r != null) { inMessage.getExchange().put(Response.class, r); throw new WebApplicationException(); } reportServerError("METHOD_ACCESS_FAILURE", method.getName()); } catch (Exception ex) { reportServerError("METHOD_INJECTION_FAILURE", method.getName()); } }
private static ThreadLocalProxy<?> getMethodThreadLocalProxy(Method m, Object provider) { if (provider != null) { Object proxy = null; synchronized (provider) { try { proxy = InjectionUtils.extractFromMethod(provider, InjectionUtils.getGetterFromSetter(m), false); } catch (Throwable t) { // continue } if (!(proxy instanceof ThreadLocalProxy)) { proxy = InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]); InjectionUtils.injectThroughMethod(provider, m, proxy); } } return (ThreadLocalProxy<?>)proxy; } return InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]); }
private static ThreadLocalProxy<?> getMethodThreadLocalProxy(Method m, Object provider) { if (provider != null) { Object proxy = null; synchronized (provider) { try { proxy = InjectionUtils.extractFromMethod(provider, InjectionUtils.getGetterFromSetter(m), false); } catch (Throwable t) { // continue } if (!(proxy instanceof ThreadLocalProxy)) { proxy = InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]); InjectionUtils.injectThroughMethod(provider, m, proxy); } } return (ThreadLocalProxy<?>)proxy; } else { return InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]); } }
@SuppressWarnings("unchecked") public static void injectContextMethods(Object requestObject, AbstractResourceInfo cri, Message message) { for (Map.Entry<Class<?>, Method> entry : cri.getContextMethods().entrySet()) { Method method = entry.getValue(); if (method.getParameterTypes()[0] == Application.class && cri.isSingleton()) { continue; } Object o = JAXRSUtils.createContextValue(message, method.getGenericParameterTypes()[0], entry.getKey()); if (o != null) { if (!cri.isSingleton()) { InjectionUtils.injectThroughMethod(requestObject, method, o, message); } else { ThreadLocalProxy<Object> proxy = (ThreadLocalProxy<Object>)cri.getContextSetterProxy(method); if (proxy != null) { proxy.set(o); } } } } }
InjectionUtils.injectThroughMethod(bean, (Method) setter, paramValue); } else { InjectionUtils.injectFieldValue((Field) setter, bean, paramValue);
protected void injectApplicationIntoFeature(Feature feature) { if (application != null) { AbstractResourceInfo info = new AbstractResourceInfo(feature.getClass(), ClassHelper.getRealClass(feature), true, true, getBus()) { @Override public boolean isSingleton() { return false; } }; Method contextMethod = info.getContextMethods().get(Application.class); if (contextMethod != null) { InjectionUtils.injectThroughMethod(feature, contextMethod, application.getProvider()); return; } for (Field contextField : info.getContextFields()) { if (Application.class == contextField.getType()) { InjectionUtils.injectContextField(info, contextField, feature, application.getProvider()); break; } } } }
InjectionUtils.injectThroughMethod(bean, (Method) setter, paramValue); } else { InjectionUtils.injectFieldValue((Field) setter, bean, paramValue);
ori); InjectionUtils.injectThroughMethod(requestObject, m, o, message);
ori); InjectionUtils.injectThroughMethod(requestObject, m, o, message);
InjectionUtils.injectThroughMethod(instance, method, value);
InjectionUtils.injectThroughMethod(instance, method, value);