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 {
try { Field f = ReflectionUtil.getDeclaredField(loader.getClass(), "acc"); ReflectionUtil.setAccessible(f).set(loader, null); } catch (Throwable t) {
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); f2 = ReflectionUtil.getDeclaredField(c.getClass(), "httpsURLConnection"); HttpsURLConnection c2 = (HttpsURLConnection)ReflectionUtil.setAccessible(f2) .get(c);
try { Field f = ReflectionUtil.getDeclaredField(loader.getClass(), "acc"); ReflectionUtil.setAccessible(f).set(loader, null); } catch (Throwable t) {
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); } } });
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); } } });
public static Field getDeclaredField(Class<?> cls, String fieldName) { if (cls == null || cls == Object.class) { return null; } Field f = ReflectionUtil.getDeclaredField(cls, fieldName); if (f != null) { return f; } return getDeclaredField(cls.getSuperclass(), fieldName); }
private static Field getField(Class<?> cls, String name) { if (cls == null) { return null; } try { Field f = ReflectionUtil.getDeclaredField(cls, name); if (f == null) { f = getField(cls.getSuperclass(), name); } return f; } catch (Exception ex) { return getField(cls.getSuperclass(), name); } }
private static Field getField(Class<?> cls, String name) { if (cls == null) { return null; } try { Field f = ReflectionUtil.getDeclaredField(cls, name); if (f == null) { f = getField(cls.getSuperclass(), name); } return f; } catch (Exception ex) { return getField(cls.getSuperclass(), name); } }
private void dump(final LogFacade log, final ServerProviderFactory spf, final String description, final String fieldName) { final Field field = ReflectionUtil.getDeclaredField(ProviderFactory.class, fieldName); if (!field.isAccessible()) { field.setAccessible(true); } try { final Collection<ProviderInfo<?>> providers = Collection.class.cast(field.get(spf)); log.info(" " + description); providers.stream().map(ProviderInfo::getProvider).forEach(o -> { try { log.info(" - " + o); } catch (final RuntimeException re) { // no-op: maybe cdi context is not active } }); } catch (IllegalAccessException e) { // ignore, not that a big deal } } }
private void dump(final LogFacade log, final ServerProviderFactory spf, final String description, final String fieldName) { final Field field = ReflectionUtil.getDeclaredField(ProviderFactory.class, fieldName); if (!field.isAccessible()) { field.setAccessible(true); } try { final Collection<ProviderInfo<?>> providers = Collection.class.cast(field.get(spf)); log.info(" " + description); providers.stream().map(ProviderInfo::getProvider).forEach(o -> { try { log.info(" - " + o); } catch (final RuntimeException re) { // no-op: maybe cdi context is not active } }); } catch (IllegalAccessException e) { // ignore, not that a big deal } } }
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 {
Field f = ReflectionUtil.getDeclaredField(c.getClass(), "mNamespaces"); ReflectionUtil.setAccessible(f); String[] ns = (String[])f.get(c); Field f = ReflectionUtil.getDeclaredField(c.getClass(), "fNamespaceContext"); ReflectionUtil.setAccessible(f); Object c2 = f.get(c);
private static Object createEscapeHandler(Class<?> cls, String simpleClassName) { try { String postFix = getPostfix(cls); if (postFix == null) { LOG.log(Level.WARNING, "Failed to create" + simpleClassName + " for unknown jaxb class:" + cls); return null; } Class<?> handlerClass = ClassLoaderUtils.loadClass("com.sun.xml" + postFix + ".bind.marshaller." + simpleClassName, cls); Class<?> handlerInterface = ClassLoaderUtils .loadClass("com.sun.xml" + postFix + ".bind.marshaller.CharacterEscapeHandler", cls); Object targetHandler = ReflectionUtil.getDeclaredField(handlerClass, "theInstance").get(null); return ProxyHelper.getProxy(cls.getClassLoader(), new Class[] {handlerInterface}, new EscapeHandlerInvocationHandler(targetHandler)); } catch (Exception e) { if ("NoEscapeHandler".equals(simpleClassName)) { //this class doesn't exist in JAXB 2.2 so expected LOG.log(Level.FINER, "Failed to create " + simpleClassName); } else { LOG.log(Level.INFO, "Failed to create " + simpleClassName); } } return null; }
private static Object createEscapeHandler(Class<?> cls, String simpleClassName) { try { String postFix = getPostfix(cls); if (postFix == null) { LOG.log(Level.WARNING, "Failed to create" + simpleClassName + " for unknown jaxb class:" + cls); return null; } Class<?> handlerClass = ClassLoaderUtils.loadClass("com.sun.xml" + postFix + ".bind.marshaller." + simpleClassName, cls); Class<?> handlerInterface = ClassLoaderUtils .loadClass("com.sun.xml" + postFix + ".bind.marshaller.CharacterEscapeHandler", cls); Object targetHandler = ReflectionUtil.getDeclaredField(handlerClass, "theInstance").get(null); return ProxyHelper.getProxy(cls.getClassLoader(), new Class[] {handlerInterface}, new EscapeHandlerInvocationHandler(targetHandler)); } catch (Exception e) { if ("NoEscapeHandler".equals(simpleClassName)) { //this class doesn't exist in JAXB 2.2 so expected LOG.log(Level.FINER, "Failed to create " + simpleClassName); } else { LOG.log(Level.INFO, "Failed to create " + simpleClassName); } } return null; }
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); f2 = ReflectionUtil.getDeclaredField(c.getClass(), "httpsURLConnection"); HttpsURLConnection c2 = (HttpsURLConnection)ReflectionUtil.setAccessible(f2) .get(c);
Field fn = ReflectionUtil.getDeclaredField(cls, q.getLocalPart()); if (fn != null) { ReflectionUtil.setAccessible(fn);