Example usage for org.apache.commons.httpclient Cookie Cookie

List of usage examples for org.apache.commons.httpclient Cookie Cookie

Introduction

In this page you can find the example usage for org.apache.commons.httpclient Cookie Cookie.

Prototype

public Cookie() 

Source Link

Usage

From source file:com.intuit.tank.http.BaseResponseTest.java

/**
 * Run the void logResponse() method test.
 * //from   ww w  .  ja  v a 2s .  c o m
 * @throws Exception
 * 
 * @generatedBy CodePro at 12/16/14 3:57 PM
 */
@Test
public void testLogResponse_8() throws Exception {
    BinaryResponse fixture = new BinaryResponse();
    fixture.responseTime = 1L;
    fixture.cookiesByDomain = new HashMap();
    fixture.httpCode = 1;
    fixture.response = "";
    fixture.responseByteArray = new byte[] {};
    fixture.cookies = new Cookie[] { new Cookie() };
    fixture.rspMessage = "";
    fixture.headers = new HashMap();
    fixture.responseLogMsg = "";

    fixture.logResponse();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.NoClassDefFoundError: Could not initialize class com.intuit.tank.http.binary.BinaryResponse
}

From source file:nl.nn.adapterframework.util.SsoUtil.java

public static void addSsoCredential(HttpMethod method, HttpState state, String defaultForwardHost) {
    try {/*from ww  w  .j  av  a  2  s .  com*/
        String name = SsoUtil.getSsoTokenName();
        String value = SsoUtil.getSsoToken();
        if (StringUtils.isEmpty(value)) {
            if (log.isDebugEnabled())
                log.debug("no value for SsoCredential [" + name + "]");
        } else {
            if (log.isDebugEnabled())
                log.debug("constructing SsoCredentialCookie [" + name + "]");
            Cookie ssoCookie = new Cookie();
            ssoCookie.setName(name);

            ssoCookie.setValue(value);
            String forwardHost;
            try {
                URI uri = method.getURI();
                forwardHost = uri.getHost();
                if (StringUtils.isEmpty(forwardHost)) {
                    if (log.isDebugEnabled())
                        log.debug("did not find host from URI [" + uri.getURI() + "], will use default ["
                                + defaultForwardHost + "] for SSO credential cookie");
                    forwardHost = defaultForwardHost;
                }
            } catch (Throwable t) {
                log.warn("could not extract host from URI", t);
                forwardHost = defaultForwardHost;
            }
            ssoCookie.setDomain(forwardHost);
            // path must have a value, otherwise cookie is not appended to request
            ssoCookie.setPath("/");
            if (log.isDebugEnabled())
                log.debug("set SSOcookie attributes: domain [" + ssoCookie.getDomain() + "] path ["
                        + ssoCookie.getPath() + "]");
            state.addCookie(ssoCookie);
        }

    } catch (Exception e) {
        log.warn("could not obtain SsoToken: " + e.getMessage());
    }
}

From source file:org.fao.geonet.csw.common.requests.CatalogRequest.java

public CatalogRequest(ServiceContext context, String host, int port, String protocol) {
    this.host = host;
    this.port = port;
    this.protocol = protocol;

    setMethod(Method.POST);/*ww w.j av a  2s  .  co  m*/
    Cookie cookie = new Cookie();
    HttpState state = new HttpState();
    state.addCookie(cookie);
    client.setState(state);
    client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

    if (context != null)
        Lib.net.setupProxy(context, client);
}

From source file:org.mule.transport.http.CookieHelperTestCase.java

@Test
public void testAsArrayOfCookies_CookiesInArray() throws Exception {
    Cookie[] cookiesObject = new Cookie[] { new Cookie() };
    assertSame(cookiesObject, CookieHelper.asArrayOfCookies(cookiesObject));

    Cookie[] emptyArray = CookieHelper.asArrayOfCookies(null);
    assertNotNull("A null cookiesObject should return a non null array", emptyArray);
    assertEquals(0, emptyArray.length);//from ww w.j av  a2  s . c o  m
}

From source file:org.mule.transport.http.CookieWrapper.java

public Cookie createCookie() throws ParseException {
    Cookie cookie = new Cookie();
    cookie.setName(getName());//  ww  w .j ava 2 s. c om
    cookie.setValue(getValue());
    cookie.setDomain(domain);
    cookie.setPath(path);

    if (expiryDate != null) {
        cookie.setExpiryDate(formatExpiryDate(expiryDate));
    }

    if (maxAge != null && expiryDate == null) {
        cookie.setExpiryDate(new Date(System.currentTimeMillis() + Integer.valueOf(maxAge) * 1000L));
    }

    if (secure != null) {
        cookie.setSecure(Boolean.valueOf(secure));
    }
    if (version != null) {
        cookie.setVersion(Integer.valueOf(version));
    }

    return cookie;
}

From source file:org.wso2.appserver.integration.tests.session.persistence.WSAS2060SessionPersistenceTestCase.java

@Test(groups = "wso2.as", description = "Check if Session Webapp is available")
public void testSessionWebappAvailable() throws Exception {
    GetMethod httpGet = null;/*from w  ww . j a  v a 2s.c  o  m*/
    GetMethod httpGetFabIcon = null;
    boolean isSecondSession = false;
    try {
        httpGet = new GetMethod(endpoint);
        int statusCode = httpClient.executeMethod(httpGet);
        ++sessionCount;
        assertTrue(HttpStatus.SC_OK == statusCode,
                "Session example webapp is not available for Tenant: " + userMode);

        HttpClient httpClientFabIcon = new HttpClient();
        httpGetFabIcon = new GetMethod(SERVER_URL + "/" + "favicon.ico");
        statusCode = httpClientFabIcon.executeMethod(httpGetFabIcon);
        Cookie cookie = null;
        if (HttpStatus.SC_METHOD_NOT_ALLOWED == statusCode) {
            Cookie[] cookiesFabIcon = httpClientFabIcon.getState().getCookies();
            if (cookiesFabIcon.length > 0) {
                cookie = cookiesFabIcon[0];
                isSecondSession = true;
            }
        }

        if (!isSecondSession) {
            cookie = new Cookie();
            cookie.setDomain(asServer.getInstance().getHosts().get("default"));
            cookie.setPath("/");
            cookie.setName("JSESSIONID");
            cookie.setValue("C0FCA53EBF7F09D24E2B430847214934");
        }

        httpClient.getState().addCookie(cookie);
    } finally {
        if (httpGet != null) {
            httpGet.releaseConnection();
        }
        if (httpGetFabIcon != null) {
            httpGetFabIcon.releaseConnection();
        }
    }
}

From source file:org.zaproxy.zap.network.ZapCookieSpecUnitTest.java

@Test(expected = IllegalArgumentException.class)
public void shouldThrowWhenValidatingWithNullHost() throws MalformedCookieException {
    // Given//w  ww.  ja  va2  s  . c  o  m
    CookieSpec cookieSpec = createCookieSpec();
    String host = null;
    // When
    cookieSpec.validate(host, PORT, PATH, SECURE, new Cookie());
    // Then = IllegalArgumentException.
}

From source file:org.zaproxy.zap.network.ZapCookieSpecUnitTest.java

@Test(expected = IllegalArgumentException.class)
public void shouldThrowWhenValidatingWithEmptyHost() throws MalformedCookieException {
    // Given/*from   w w w  .  j a  v  a  2  s .c o  m*/
    CookieSpec cookieSpec = createCookieSpec();
    String host = "";
    // When
    cookieSpec.validate(host, PORT, PATH, SECURE, new Cookie());
    // Then = IllegalArgumentException.
}

From source file:org.zaproxy.zap.network.ZapCookieSpecUnitTest.java

@Test(expected = IllegalArgumentException.class)
public void shouldThrowWhenValidatingWithNegativePort() throws MalformedCookieException {
    // Given//from  www  .j a v a  2 s  .c o m
    CookieSpec cookieSpec = createCookieSpec();
    int port = -1;
    // When
    cookieSpec.validate(HOST, port, PATH, SECURE, new Cookie());
    // Then = IllegalArgumentException.
}

From source file:org.zaproxy.zap.network.ZapCookieSpecUnitTest.java

@Test(expected = IllegalArgumentException.class)
public void shouldThrowWhenValidatingWithNullPath() throws MalformedCookieException {
    // Given/*from w  ww.  jav a2s .  co m*/
    CookieSpec cookieSpec = createCookieSpec();
    String path = null;
    // When
    cookieSpec.validate(HOST, PORT, path, SECURE, new Cookie());
    // Then = IllegalArgumentException.
}