protected void addListener(AbstractApplicationContext wac) { try { //spring 2 vs spring 3 return type is different Method m = wac.getClass().getMethod("getApplicationListeners"); Collection<Object> c = CastUtils.cast((Collection<?>)ReflectionUtil .setAccessible(m).invoke(wac)); c.add(this); } catch (Throwable t) { //ignore. } }
if (JavaUtils.isJava9Compatible()) { try { Method m = ReflectionUtil.getMethod(Authenticator.class, "getDefault"); wrapped = (Authenticator)m.invoke(null); } catch (Exception e) { for (final Field f : ReflectionUtil.getDeclaredFields(Authenticator.class)) { if (f.getType().equals(Authenticator.class)) { ReflectionUtil.setAccessible(f); try { wrapped = (Authenticator)f.get(null); if (JavaUtils.isJava9Compatible()) { Class<?> methodHandles = Class.forName("java.lang.invoke.MethodHandles"); Method m = ReflectionUtil.getMethod(methodHandles, "lookup"); Object lookup = m.invoke(null); m = ReflectionUtil.getMethod(lookup.getClass(), "findClass", String.class); try { cls = (Class<?>)m.invoke(lookup, "org.apache.cxf.transport.http.ReferencingAuthenticator"); } catch (InvocationTargetException e) { m = ReflectionUtil.getMethod(lookup.getClass(), "defineClass", byte[].class); cls = (Class<?>)m.invoke(lookup, b); Method m = ReflectionUtil.getDeclaredMethod(ClassLoader.class, "defineClass", String.class, byte[].class, Integer.TYPE, Integer.TYPE); ReflectionUtil.setAccessible(m).invoke(loader, ReferencingAuthenticator.class.getName(),
private ServiceImpl findDelegate() { for (Field f : ReflectionUtil.getDeclaredFields(Service.class)) { if (ServiceDelegate.class.equals(f.getType())) { ServiceDelegate del = ReflectionUtil.accessDeclaredField(f, this, ServiceDelegate.class); if (del instanceof ServiceImpl) { return (ServiceImpl)del; } throw new WebServiceException("Delegate of class " + del.getClass() + " is not a CXF delegate. " + " Check the classpath to make sure CXF is loaded first."); } } throw new WebServiceException("Could not find CXF service delegate"); }
private OutputStream connectAndGetOutputStream(Boolean b) throws IOException { OutputStream cout = null; if (b != null && b) { String method = connection.getRequestMethod(); connection.connect(); try { java.lang.reflect.Field f = ReflectionUtil.getDeclaredField(HttpURLConnection.class, "method"); ReflectionUtil.setAccessible(f).set(connection, "POST"); cout = connection.getOutputStream(); ReflectionUtil.setAccessible(f).set(connection, method); } catch (Throwable t) { logStackTrace(t); } } else { cout = connection.getOutputStream(); } return cout; } protected void setupWrappedStream() throws IOException {
public JAXWSProviderMethodDispatcher(JaxWsImplementorInfo implInfo) { try { invoke = ReflectionUtil.getMethod(implInfo.getImplementorClass(), "invoke", new Class[] {implInfo.getProviderParameterType()}); ReflectionUtil.setAccessible(invoke); } catch (Exception e1) { //fall back to the raw Provider provided invoke method try { invoke = Provider.class.getMethod("invoke", new Class[] {Object.class}); } catch (Exception e) { throw new ServiceConstructionException(e); } } }
static Class<?> getClassForMetaData(BlueprintContainer container, ComponentMetadata cmd) { Class<?> cls = null; if (cmd instanceof BeanMetadata) { BeanMetadata bm = (BeanMetadata)cmd; if (bm instanceof ExtendedBeanMetadata) { cls = ((ExtendedBeanMetadata)bm).getRuntimeClass(); } if (cls == null && bm.getClassName() != null) { try { Method m = ReflectionUtil.findMethod(container.getClass(), "loadClass", String.class); cls = (Class<?>)ReflectionUtil.setAccessible(m).invoke(container, bm.getClassName()); } catch (Exception e) { //ignore } } } return cls; } private Class<?> getClassForMetaData(ComponentMetadata cmd) {
private void processFields(AnnotationVisitor visitor, Class<? extends Object> targetClass) { if (targetClass.getSuperclass() != null) { processFields(visitor, targetClass.getSuperclass()); } for (Field element : ReflectionUtil.getDeclaredFields(targetClass)) { for (Class<? extends Annotation> clz : annotationTypes) { Annotation ann = element.getAnnotation(clz); if (ann != null) { visitor.visitField(element, ann); } } } }
private void processMethods(AnnotationVisitor visitor, Class<? extends Object> targetClass) { if (targetClass.getSuperclass() != null) { processMethods(visitor, targetClass.getSuperclass()); } for (Method element : ReflectionUtil.getDeclaredMethods(targetClass)) { for (Class<? extends Annotation> clz : annotationTypes) { Annotation ann = element.getAnnotation(clz); if (ann != null) { visitor.visitMethod(element, ann); } } } }
Field[] fields = ReflectionUtil.getDeclaredFields(cls); for (Field f : fields) { if (isFieldAccepted(f, accessType)) { Method[] methods = ReflectionUtil.getDeclaredMethods(cls); for (Method m : methods) { if (isMethodAccepted(m, accessType)) {
public static Class<?> getValidClass(Class<?> cls) { if (cls.isEnum()) { return cls; } if (cls.isArray()) { return cls; } if (cls == Object.class || cls == String.class || "javax.xml.ws.Holder".equals(cls.getName())) { cls = null; } else if (cls.isPrimitive() || cls.isAnnotation()) { cls = null; } else if (cls.isInterface()) { return cls; } if (cls != null) { if (cls.getName().equals("javax.xml.ws.wsaddressing.W3CEndpointReference")) { return cls; } Constructor<?> cons = ReflectionUtil.getDeclaredConstructor(cls); if (cons == null) { cons = ReflectionUtil.getConstructor(cls); } if (cons == null) { cls = null; } } return cls; }
public T run() { Field f = getDeclaredField(cls, fieldName); boolean b = f.isAccessible(); try { f.setAccessible(true); return responseClass.cast(f.get(o)); } catch (SecurityException | IllegalAccessException e) { return null; } finally { f.setAccessible(b); } } });
protected boolean getValuesFromBeanParamField(Object bean, Field f, Class<? extends Annotation> annClass, Map<String, BeanPair> values) { boolean jaxrsParamAnnAvailable = false; Annotation fieldAnnotation = f.getAnnotation(annClass); if (fieldAnnotation != null) { jaxrsParamAnnAvailable = true; Object value = ReflectionUtil.accessDeclaredField(f, bean, Object.class); if (value != null) { String annotationValue = AnnotationUtils.getAnnotationValue(fieldAnnotation); values.put(annotationValue, new BeanPair(value, f.getAnnotations())); } } return jaxrsParamAnnAvailable; }
Method m = findMethod(cs, name, params); if (m != null && Modifier.isPublic(m.getModifiers())) { return m; Method m = findMethod(cls.getSuperclass(), name, params); if (m == null) { try {
if (b) { try { java.lang.reflect.Field f = ReflectionUtil.getDeclaredField(HttpURLConnection.class, "method"); if (connection instanceof HttpsURLConnection) { try { java.lang.reflect.Field f2 = ReflectionUtil.getDeclaredField(connection.getClass(), "delegate"); Object c = ReflectionUtil.setAccessible(f2).get(connection); if (c instanceof HttpURLConnection) { ReflectionUtil.setAccessible(f).set(c, httpRequestMethod); f2 = ReflectionUtil.getDeclaredField(c.getClass(), "httpsURLConnection"); HttpsURLConnection c2 = (HttpsURLConnection)ReflectionUtil.setAccessible(f2) .get(c); ReflectionUtil.setAccessible(f).set(c2, httpRequestMethod); } catch (Throwable t) { ReflectionUtil.setAccessible(f).set(connection, httpRequestMethod); message.put(HTTPURL_CONNECTION_METHOD_REFLECTION, true); } catch (Throwable t) {
static Class<?> getClassForMetaData(BlueprintContainer container, ComponentMetadata cmd) { Class<?> cls = null; if (cmd instanceof BeanMetadata) { BeanMetadata bm = (BeanMetadata)cmd; if (bm instanceof ExtendedBeanMetadata) { cls = ((ExtendedBeanMetadata)bm).getRuntimeClass(); } if (cls == null && bm.getClassName() != null) { try { Method m = ReflectionUtil.findMethod(container.getClass(), "loadClass", String.class); cls = (Class<?>)ReflectionUtil.setAccessible(m).invoke(container, bm.getClassName()); } catch (Exception e) { //ignore } } } return cls; } private Class<?> getClassForMetaData(ComponentMetadata cmd) {
public JAXWSProviderMethodDispatcher(JaxWsImplementorInfo implInfo) { try { invoke = ReflectionUtil.getMethod(implInfo.getImplementorClass(), "invoke", new Class[] {implInfo.getProviderParameterType()}); ReflectionUtil.setAccessible(invoke); } catch (Exception e1) { //fall back to the raw Provider provided invoke method try { invoke = Provider.class.getMethod("invoke", new Class[] {Object.class}); } catch (Exception e) { throw new ServiceConstructionException(e); } } }
private void processFields(AnnotationVisitor visitor, Class<? extends Object> targetClass) { if (targetClass.getSuperclass() != null) { processFields(visitor, targetClass.getSuperclass()); } for (Field element : ReflectionUtil.getDeclaredFields(targetClass)) { for (Class<? extends Annotation> clz : annotationTypes) { Annotation ann = element.getAnnotation(clz); if (ann != null) { visitor.visitField(element, ann); } } } }
private void processMethods(AnnotationVisitor visitor, Class<? extends Object> targetClass) { if (targetClass.getSuperclass() != null) { processMethods(visitor, targetClass.getSuperclass()); } for (Method element : ReflectionUtil.getDeclaredMethods(targetClass)) { for (Class<? extends Annotation> clz : annotationTypes) { Annotation ann = element.getAnnotation(clz); if (ann != null) { visitor.visitMethod(element, ann); } } } }
public static Class<?> getValidClass(Class<?> cls) { if (cls.isEnum()) { return cls; } if (cls.isArray()) { return cls; } if (cls == Object.class || cls == String.class || "javax.xml.ws.Holder".equals(cls.getName())) { cls = null; } else if (cls.isPrimitive() || cls.isAnnotation()) { cls = null; } else if (cls.isInterface()) { return cls; } if (cls != null) { if ("javax.xml.ws.wsaddressing.W3CEndpointReference".equals(cls.getName())) { return cls; } Constructor<?> cons = ReflectionUtil.getDeclaredConstructor(cls); if (cons == null) { cons = ReflectionUtil.getConstructor(cls); } if (cons == null) { cls = null; } } return cls; }
public T run() { Field f = getDeclaredField(cls, fieldName); boolean b = f.isAccessible(); try { f.setAccessible(true); return responseClass.cast(f.get(o)); } catch (SecurityException | IllegalAccessException e) { return null; } finally { f.setAccessible(b); } } });