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