fix: korrekt registrering av cookie jar
This commit is contained in:
parent
8196e3318e
commit
b24e090471
|
@ -4,12 +4,12 @@ import com.facebook.react.ReactActivity;
|
|||
|
||||
public class MainActivity extends ReactActivity {
|
||||
|
||||
/**
|
||||
* Returns the name of the main component registered from JavaScript. This is used to schedule
|
||||
* rendering of the component.
|
||||
*/
|
||||
@Override
|
||||
protected String getMainComponentName() {
|
||||
return "app";
|
||||
}
|
||||
/**
|
||||
* Returns the name of the main component registered from JavaScript. This is used to schedule
|
||||
* rendering of the component.
|
||||
*/
|
||||
@Override
|
||||
protected String getMainComponentName() {
|
||||
return "app";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,92 +10,95 @@ import com.facebook.react.ReactNativeHost;
|
|||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.modules.network.OkHttpClientFactory;
|
||||
import com.facebook.react.modules.network.OkHttpClientProvider;
|
||||
import com.facebook.react.modules.network.ReactCookieJarContainer;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.CookieManager;
|
||||
import java.net.CookieHandler;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class MainApplication extends Application implements ReactApplication {
|
||||
private final ReactNativeHost mReactNativeHost =
|
||||
new ReactNativeHost(this) {
|
||||
@Override
|
||||
public boolean getUseDeveloperSupport() {
|
||||
return BuildConfig.DEBUG;
|
||||
}
|
||||
private final ReactNativeHost mReactNativeHost =
|
||||
new ReactNativeHost(this) {
|
||||
@Override
|
||||
public boolean getUseDeveloperSupport() {
|
||||
return BuildConfig.DEBUG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ReactPackage> getPackages() {
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
List<ReactPackage> packages = new PackageList(this).getPackages();
|
||||
// Packages that cannot be autolinked yet can be added manually here, for example:
|
||||
// packages.add(new MyReactNativePackage());
|
||||
return packages;
|
||||
}
|
||||
@Override
|
||||
protected List<ReactPackage> getPackages() {
|
||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||
List<ReactPackage> packages = new PackageList(this).getPackages();
|
||||
// Packages that cannot be autolinked yet can be added manually here, for example:
|
||||
// packages.add(new MyReactNativePackage());
|
||||
return packages;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getJSMainModuleName() {
|
||||
return "index";
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected String getJSMainModuleName() {
|
||||
return "index";
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public ReactNativeHost getReactNativeHost() {
|
||||
return mReactNativeHost;
|
||||
}
|
||||
@Override
|
||||
public ReactNativeHost getReactNativeHost() {
|
||||
return mReactNativeHost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
SoLoader.init(this, /* native exopackage */ false);
|
||||
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
SoLoader.init(this, /* native exopackage */ false);
|
||||
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
||||
|
||||
ReactInstanceManager mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
|
||||
mReactInstanceManager.addReactInstanceEventListener(reactContext -> {
|
||||
OkHttpClientProvider.setOkHttpClientFactory(new OkHttpClientFactory() {
|
||||
@Override
|
||||
public OkHttpClient createNewNetworkModuleClient() {
|
||||
return OkHttpClientProvider.createClientBuilder(reactContext)
|
||||
.cookieJar(new SkolplattformenCookieJar(new CookieManager()))
|
||||
.build();
|
||||
}
|
||||
ReactInstanceManager mReactInstanceManager = getReactNativeHost().getReactInstanceManager();
|
||||
mReactInstanceManager.addReactInstanceEventListener(reactContext -> {
|
||||
OkHttpClientProvider.setOkHttpClientFactory(new OkHttpClientFactory() {
|
||||
@Override
|
||||
public OkHttpClient createNewNetworkModuleClient() {
|
||||
ReactCookieJarContainer reactCookieJarContainer = new ReactCookieJarContainer();
|
||||
reactCookieJarContainer.setCookieJar(new SkolplattformenCookieJar(CookieHandler.getDefault()));
|
||||
return OkHttpClientProvider.createClientBuilder(reactContext)
|
||||
.cookieJar(reactCookieJarContainer)
|
||||
.build();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
|
||||
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
||||
*
|
||||
* @param context
|
||||
* @param reactInstanceManager
|
||||
*/
|
||||
private static void initializeFlipper(
|
||||
Context context, ReactInstanceManager reactInstanceManager) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
try {
|
||||
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
|
||||
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
|
||||
*
|
||||
* @param context
|
||||
* @param reactInstanceManager
|
||||
*/
|
||||
private static void initializeFlipper(
|
||||
Context context, ReactInstanceManager reactInstanceManager) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
try {
|
||||
/*
|
||||
We use reflection here to pick up the class that initializes Flipper,
|
||||
since Flipper library is not available in release mode
|
||||
*/
|
||||
Class<?> aClass = Class.forName("com.app.ReactNativeFlipper");
|
||||
aClass
|
||||
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
|
||||
.invoke(null, context, reactInstanceManager);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Class<?> aClass = Class.forName("com.app.ReactNativeFlipper");
|
||||
aClass
|
||||
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
|
||||
.invoke(null, context, reactInstanceManager);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ import static okhttp3.internal.Util.trimSubstring;
|
|||
import static okhttp3.internal.platform.Platform.WARN;
|
||||
|
||||
public final class SkolplattformenCookieJar implements CookieJar {
|
||||
public static final String HEADER_COOKIE_2 = "Cookie2";
|
||||
public static final String HEADER_COOKIE = "Cookie";
|
||||
public static final String HEADER_SET_COOKIE = "Set-Cookie";
|
||||
private final CookieHandler cookieHandler;
|
||||
public static final String HEADER_COOKIE_2 = "Cookie2";
|
||||
public static final String HEADER_COOKIE = "Cookie";
|
||||
public static final String HEADER_SET_COOKIE = "Set-Cookie";
|
||||
private final CookieHandler cookieHandler;
|
||||
|
||||
public SkolplattformenCookieJar(CookieHandler cookieHandler) {
|
||||
this.cookieHandler = cookieHandler;
|
||||
|
|
Loading…
Reference in New Issue