use of java.net.CookieManager in project jetty.project by eclipse.
the class CookieTest method testViaCookieManager.
@Test
public void testViaCookieManager() throws Exception {
// Setup client
CookieManager cookieMgr = new CookieManager();
client.setCookieStore(cookieMgr.getCookieStore());
HttpCookie cookie = new HttpCookie("hello", "world");
cookie.setPath("/");
cookie.setVersion(0);
cookie.setMaxAge(100000);
cookieMgr.getCookieStore().add(server.getWsUri(), cookie);
cookie = new HttpCookie("foo", "bar is the word");
cookie.setPath("/");
cookie.setMaxAge(100000);
cookieMgr.getCookieStore().add(server.getWsUri(), cookie);
// Client connects
CookieTrackingSocket clientSocket = new CookieTrackingSocket();
Future<Session> clientConnectFuture = client.connect(clientSocket, server.getWsUri());
// Server accepts connect
IBlockheadServerConnection serverConn = server.accept();
// client confirms upgrade and receipt of frame
String serverCookies = confirmClientUpgradeAndCookies(clientSocket, clientConnectFuture, serverConn);
assertThat("Cookies seen at server side", serverCookies, containsString("hello=world"));
assertThat("Cookies seen at server side", serverCookies, containsString("foo=bar is the word"));
}
use of java.net.CookieManager in project Synthese_2BIN by TheYoungSensei.
the class LoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// Set up the login form.
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
populateAutoComplete();
mPasswordView = (EditText) findViewById(R.id.password);
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == R.id.login || id == EditorInfo.IME_NULL) {
attemptLogin();
return true;
}
return false;
}
});
Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
mLoginFormView = findViewById(R.id.login_form);
mProgressView = findViewById(R.id.login_progress);
}
use of java.net.CookieManager in project jdk8u_jdk by JetBrains.
the class NullUriCookieTest method checkCookieNullUri.
static void checkCookieNullUri() throws Exception {
//get a cookie store implementation and add a cookie to the store with null URI
CookieStore cookieStore = (new CookieManager()).getCookieStore();
//Check if removeAll() retrurns false on an empty CookieStore
if (cookieStore.removeAll()) {
fail = true;
}
checkFail("removeAll on empty store should return false");
HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
cookie.setDomain("foo.com");
cookieStore.add(null, cookie);
//Retrieve added cookie
URI uri = new URI("http://foo.com");
List<HttpCookie> addedCookieList = cookieStore.get(uri);
//Verify CookieStore behaves well
if (addedCookieList.size() != 1) {
fail = true;
}
checkFail("Abnormal size of cookie jar");
for (HttpCookie chip : addedCookieList) {
if (!chip.equals(cookie)) {
fail = true;
}
}
checkFail("Cookie not retrieved from Cookie Jar");
boolean ret = cookieStore.remove(null, cookie);
if (!ret) {
fail = true;
}
checkFail("Abnormal removal behaviour from Cookie Jar");
}
use of java.net.CookieManager in project jdk8u_jdk by JetBrains.
the class HttpOnly method populateCookieStore.
void populateCookieStore(URI uri) throws IOException {
CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cm);
Map<String, List<String>> header = new HashMap<>();
List<String> values = new ArrayList<>();
values.add("JSESSIONID=" + SESSION_ID + "; version=1; Path=" + URI_PATH + "; HttpOnly");
values.add("CUSTOMER=WILE_E_COYOTE; version=1; Path=" + URI_PATH);
header.put("Set-Cookie", values);
cm.put(uri, header);
}
use of java.net.CookieManager in project robovm by robovm.
the class CookiesTest method testCookieStoreRemoveRequiresUri.
public void testCookieStoreRemoveRequiresUri() throws URISyntaxException {
CookieStore cookieStore = new CookieManager().getCookieStore();
HttpCookie cookieA = new HttpCookie("a", "android");
cookieStore.add(new URI("http://android.com/source/"), cookieA);
assertFalse(// RI6 fails this
"Expected remove() to take the cookie URI into account.", cookieStore.remove(new URI("http://code.google.com/"), cookieA));
assertEquals(Arrays.asList(cookieA), cookieStore.getCookies());
}
Aggregations