use of java.net.CookieHandler in project robovm by robovm.
the class HttpEngine method prepareRawRequestHeaders.
/**
* Populates requestHeaders with defaults and cookies.
*
* <p>This client doesn't specify a default {@code Accept} header because it
* doesn't know what content types the application is interested in.
*/
private void prepareRawRequestHeaders() throws IOException {
requestHeaders.getHeaders().setRequestLine(getRequestLine());
if (requestHeaders.getUserAgent() == null) {
requestHeaders.setUserAgent(getDefaultUserAgent());
}
if (requestHeaders.getHost() == null) {
requestHeaders.setHost(getOriginAddress(policy.getURL()));
}
if ((connection == null || connection.getHttpMinorVersion() != 0) && requestHeaders.getConnection() == null) {
requestHeaders.setConnection("Keep-Alive");
}
if (requestHeaders.getAcceptEncoding() == null) {
transparentGzip = true;
requestHeaders.setAcceptEncoding("gzip");
}
if (hasRequestBody() && requestHeaders.getContentType() == null) {
requestHeaders.setContentType("application/x-www-form-urlencoded");
}
long ifModifiedSince = policy.getIfModifiedSince();
if (ifModifiedSince != 0) {
requestHeaders.setIfModifiedSince(new Date(ifModifiedSince));
}
CookieHandler cookieHandler = client.getCookieHandler();
if (cookieHandler != null) {
requestHeaders.addCookies(cookieHandler.get(uri, requestHeaders.getHeaders().toMultimap(false)));
}
}
use of java.net.CookieHandler in project robovm by robovm.
the class OldCookieHandlerTest method test_get_put.
public void test_get_put() {
MockCookieHandler mch = new MockCookieHandler();
CookieHandler defaultHandler = CookieHandler.getDefault();
CookieHandler.setDefault(mch);
class TestThread extends Thread {
public void run() {
try {
URL url = new URL(link);
URLConnection conn = url.openConnection();
conn.getContent();
url = new URL(link);
conn = url.openConnection();
conn.getContent();
completedSuccessfully = true;
} catch (Exception e) {
e.printStackTrace();
}
}
}
try {
TestThread thread = new TestThread();
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
fail("InterruptedException was thrown.");
}
assertTrue(isGetCalled);
assertTrue(isPutCalled);
assertTrue(completedSuccessfully);
} finally {
CookieHandler.setDefault(defaultHandler);
}
}
use of java.net.CookieHandler in project phonegap-facebook-plugin by Wizcorp.
the class HttpEngine method prepareRawRequestHeaders.
/**
* Populates requestHeaders with defaults and cookies.
*
* <p>This client doesn't specify a default {@code Accept} header because it
* doesn't know what content types the application is interested in.
*/
private void prepareRawRequestHeaders() throws IOException {
requestHeaders.getHeaders().setRequestLine(getRequestLine());
if (requestHeaders.getUserAgent() == null) {
requestHeaders.setUserAgent(getDefaultUserAgent());
}
if (requestHeaders.getHost() == null) {
requestHeaders.setHost(getOriginAddress(policy.getURL()));
}
if ((connection == null || connection.getHttpMinorVersion() != 0) && requestHeaders.getConnection() == null) {
requestHeaders.setConnection("Keep-Alive");
}
if (requestHeaders.getAcceptEncoding() == null) {
transparentGzip = true;
requestHeaders.setAcceptEncoding("gzip");
}
if (hasRequestBody() && requestHeaders.getContentType() == null) {
requestHeaders.setContentType("application/x-www-form-urlencoded");
}
long ifModifiedSince = policy.getIfModifiedSince();
if (ifModifiedSince != 0) {
requestHeaders.setIfModifiedSince(new Date(ifModifiedSince));
}
CookieHandler cookieHandler = policy.cookieHandler;
if (cookieHandler != null) {
requestHeaders.addCookies(cookieHandler.get(uri, requestHeaders.getHeaders().toMultimap(false)));
}
}
use of java.net.CookieHandler in project LeafPic by HoraApps.
the class PlayerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(org.horaapps.leafpic.R.layout.activity_player);
FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root);
findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggleControlsVisibility();
}
});
root.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
}
});
root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));
shutterView = findViewById(org.horaapps.leafpic.R.id.shutter);
videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame);
surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view);
surfaceView.getHolder().addCallback(this);
mediaController = new CustomMediaController(this, this);
mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor);
mediaController.setAnchorView(root);
//mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
initUI();
CookieHandler currentHandler = CookieHandler.getDefault();
if (currentHandler != defaultCookieManager)
CookieHandler.setDefault(defaultCookieManager);
audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
audioCapabilitiesReceiver.register();
}
use of java.net.CookieHandler in project okhttp by square.
the class CookiesTest method cookieHandlerLikeAndroid.
@Test
public void cookieHandlerLikeAndroid() throws Exception {
final MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse());
server.start();
final HttpUrl serverUrl = urlWithIpAddress(server, "/");
CookieHandler androidCookieHandler = new CookieHandler() {
@Override
public Map<String, List<String>> get(URI uri, Map<String, List<String>> map) throws IOException {
return Collections.singletonMap("Cookie", Collections.singletonList("$Version=\"1\"; " + "a=\"android\";$Path=\"/\";$Domain=\"" + serverUrl.host() + "\"; " + "b=\"banana\";$Path=\"/\";$Domain=\"" + serverUrl.host() + "\""));
}
@Override
public void put(URI uri, Map<String, List<String>> map) throws IOException {
}
};
client = client.newBuilder().cookieJar(new JavaNetCookieJar(androidCookieHandler)).build();
get(serverUrl);
RecordedRequest request = server.takeRequest();
assertEquals("a=android; b=banana", request.getHeader("Cookie"));
}
Aggregations