Search in sources :

Example 1 with CookieManager

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"));
}
Also used : IBlockheadServerConnection(org.eclipse.jetty.websocket.common.test.IBlockheadServerConnection) Matchers.containsString(org.hamcrest.Matchers.containsString) HttpCookie(java.net.HttpCookie) CookieManager(java.net.CookieManager) Session(org.eclipse.jetty.websocket.api.Session) Test(org.junit.Test)

Example 2 with CookieManager

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);
}
Also used : KeyEvent(android.view.KeyEvent) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) CookieManager(java.net.CookieManager)

Example 3 with CookieManager

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");
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) URI(java.net.URI) CookieManager(java.net.CookieManager)

Example 4 with CookieManager

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CookieManager(java.net.CookieManager)

Example 5 with CookieManager

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());
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) URI(java.net.URI) CookieManager(java.net.CookieManager)

Aggregations

CookieManager (java.net.CookieManager)162 URI (java.net.URI)89 HttpCookie (java.net.HttpCookie)82 CookieStore (java.net.CookieStore)49 MockResponse (com.google.mockwebserver.MockResponse)20 List (java.util.List)20 ArrayList (java.util.ArrayList)18 MockWebServer (com.google.mockwebserver.MockWebServer)15 IOException (java.io.IOException)13 HashMap (java.util.HashMap)12 Test (org.junit.jupiter.api.Test)12 Test (org.junit.Test)11 RecordedRequest (com.google.mockwebserver.RecordedRequest)8 MockResponse (mockwebserver3.MockResponse)8 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 RecordedRequest (mockwebserver3.RecordedRequest)5 JavaNetCookieJar (okhttp3.JavaNetCookieJar)4