當前位置: 首頁>>代碼示例>>Java>>正文


Java Cookie類代碼示例

本文整理匯總了Java中javax.ws.rs.core.Cookie的典型用法代碼示例。如果您正苦於以下問題:Java Cookie類的具體用法?Java Cookie怎麽用?Java Cookie使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Cookie類屬於javax.ws.rs.core包,在下文中一共展示了Cookie類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: provideValue

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
@Override
public Object provideValue(Parameter parameter, ContainerRequestContext requestContext, ObjectMapper objectMapper) {
	Object returnValue;
	String cookieName = parameter.getAnnotation(CookieParam.class).value();
	Cookie cookie = requestContext.getCookies().get(cookieName);
	if (cookie == null) {
		return null;
	} else {
		if (Cookie.class.isAssignableFrom(parameter.getType())) {
			returnValue = cookie;
		} else if (String.class.isAssignableFrom(parameter.getType())) {
			returnValue = cookie.getValue();
		} else {
			try {
				returnValue = objectMapper.readValue(cookie.getValue(), parameter.getType());
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
		}
	}

	return returnValue;
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:24,代碼來源:CookieParamProvider.java

示例2: putResource

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
public <I> void putResource(String resourcePath, final I input, Cookie cookie) throws Exception {
    Response response = null;
    try {
        final Invocation.Builder requestBuilder = getRequestBuilder(resourcePath);
        response = requestBuilder.async().put(Entity.entity(input, this.mediaType), new InvocationLogCallback())
                .get(REQUEST_THREAD_TIMEOUT, TimeUnit.MILLISECONDS);
        Response.Status status = Response.Status.fromStatusCode(response.getStatus());

        if (status == Response.Status.OK || status == Response.Status.NO_CONTENT) {
            this.lastRequestHeaders = response.getHeaders();
        } else {
            throw new ClientResponseNotOkException();
        }
    } catch (Exception ex) {
        RestClientException restClientException = createRestClientException("PUT", this.webTarget.getUri() + "/"
                + resourcePath, input, response, ex);
        log.debug("Error invoking putResource", restClientException);

        throw restClientException;
    }
}
 
開發者ID:opensecuritycontroller,項目名稱:osc-core,代碼行數:22,代碼來源:RestBaseClient.java

示例3: testUserWithoutPassword

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
@Test
public void testUserWithoutPassword() throws IOException {
    final User user = new User();
    user.setName("Example 2");
    user.setEmail("[email protected]");
    user.setRoles("user");

    Cookie cookie = null;

    try (MinijaxRequestContext ctx = createRequestContext()) {
        ctx.get(Dao.class).create(user);
        cookie = ctx.get(Security.class).loginAs(user);
    }

    final Form form = new Form();
    form.param("csrf", cookie.getValue());
    form.param("oldPassword", "my-old-password");
    form.param("newPassword", "my-new-password");
    form.param("confirmNewPassword", "my-new-password");

    final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
    assertNotNull(r);
    assertEquals(400, r.getStatus());
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:25,代碼來源:ChangePasswordTest.java

示例4: testIncorrectOldPassword

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
@Test
public void testIncorrectOldPassword() throws IOException {
    final User user = new User();
    user.setName("Example 3");
    user.setEmail("[email protected]");
    user.setRoles("user");
    user.setPassword("my-old-password");

    Cookie cookie = null;

    try (MinijaxRequestContext ctx = createRequestContext()) {
        ctx.get(Dao.class).create(user);
        cookie = ctx.get(Security.class).loginAs(user);
    }

    final Form form = new Form();
    form.param("csrf", cookie.getValue());
    form.param("oldPassword", "wrong-old-password");
    form.param("newPassword", "my-new-password");
    form.param("confirmNewPassword", "my-new-password");

    final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
    assertNotNull(r);
    assertEquals(400, r.getStatus());
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:26,代碼來源:ChangePasswordTest.java

示例5: testMismatchedPasswords

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
@Test
public void testMismatchedPasswords() throws IOException {
    final User user = new User();
    user.setName("Example 4");
    user.setEmail("[email protected]");
    user.setRoles("user");
    user.setPassword("my-old-password");

    Cookie cookie = null;

    try (MinijaxRequestContext ctx = createRequestContext()) {
        ctx.get(Dao.class).create(user);
        cookie = ctx.get(Security.class).loginAs(user);
    }

    final Form form = new Form();
    form.param("csrf", cookie.getValue());
    form.param("oldPassword", "my-old-password");
    form.param("newPassword", "my-new-password");
    form.param("confirmNewPassword", "different-password");

    final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
    assertNotNull(r);
    assertEquals(400, r.getStatus());
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:26,代碼來源:ChangePasswordTest.java

示例6: testPasswordTooShort

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
@Test
public void testPasswordTooShort() throws IOException {
    final User user = new User();
    user.setName("Example 5");
    user.setEmail("[email protected]");
    user.setRoles("user");
    user.setPassword("my-old-password");

    Cookie cookie = null;

    try (MinijaxRequestContext ctx = createRequestContext()) {
        ctx.get(Dao.class).create(user);
        cookie = ctx.get(Security.class).loginAs(user);
    }

    final Form form = new Form();
    form.param("csrf", cookie.getValue());
    form.param("oldPassword", "my-old-password");
    form.param("newPassword", "foo");
    form.param("confirmNewPassword", "foo");

    final Response r = target("/changepassword").request().cookie(cookie).post(Entity.form(form));
    assertNotNull(r);
    assertEquals(400, r.getStatus());
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:26,代碼來源:ChangePasswordTest.java

示例7: createHeaderDelegate

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public <T> HeaderDelegate<T> createHeaderDelegate(final Class<T> type) {
    if (type == MediaType.class) {
        return (HeaderDelegate<T>) MEDIA_TYPE_DELEGATE;
    }
    if (type == Cookie.class) {
        return (HeaderDelegate<T>) COOKIE_DELEGATE;
    }
    if (type == NewCookie.class) {
        return (HeaderDelegate<T>) NEW_COOKIE_DELEGATE;
    }
    if (type == CacheControl.class) {
        return (HeaderDelegate<T>) CACHE_CONTROL_DELEGATE;
    }
    throw new IllegalArgumentException("Unrecognized header delegate: " + type);
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:18,代碼來源:MinijaxRuntimeDelegate.java

示例8: apply

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
@Override
public Response apply(ContainerRequestContext arg0) {
    SwaggerSpecFilter filter = FilterFactory.getFilter();
    if (filter != null) {

        Map<String, Cookie> cookiesvalue = arg0.getCookies();
        Map<String, String> cookies = new HashMap<>();
        if (cookiesvalue != null) {
            for (String key : cookiesvalue.keySet()) {
                cookies.put(key, cookiesvalue.get(key).getValue());
            }
        }

        MultivaluedMap<String, String> headers = arg0.getHeaders();
        return Response.ok().entity(new VendorSpecFilter().filter(getSwagger(), filter, null, cookies, headers)).build();
    }
    return Response.ok().entity(getSwagger()).build();
}
 
開發者ID:groovylabs,項目名稱:lyre,代碼行數:19,代碼來源:SwaggerInflector.java

示例9: getClientByIdTest

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
/**
 * Prueba para consultar un Client
 *
 * @generated
 */
@Test
public void getClientByIdTest() {
    Cookie cookieSessionId = login(username, password);

    ClientDTO clientTest = target
        .path(oraculo.get(0).getId().toString())
        .request().cookie(cookieSessionId).get(ClientDTO.class);
    
    Assert.assertEquals(clientTest.getId(), oraculo.get(0).getId());
    Assert.assertEquals(clientTest.getName(), oraculo.get(0).getName());
    Assert.assertEquals(clientTest.getMiddleName(), oraculo.get(0).getMiddleName());
    Assert.assertEquals(clientTest.getLastName(), oraculo.get(0).getLastName());
    Assert.assertEquals(clientTest.getEmail(), oraculo.get(0).getEmail());
    Assert.assertEquals(clientTest.getPhoneNumber(), oraculo.get(0).getPhoneNumber());
    Assert.assertEquals(clientTest.getAddress(), oraculo.get(0).getAddress());
    Assert.assertEquals(clientTest.getPhoto(), oraculo.get(0).getPhoto());
}
 
開發者ID:Uniandes-MISO4203-backup,項目名稱:turism-201620-2,代碼行數:23,代碼來源:ClientTest.java

示例10: getPaymentMethodByIdTest

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
/**
 * Prueba para consultar un PaymentMethod
 *
 * @generated
 */
@Test
public void getPaymentMethodByIdTest() {
    Cookie cookieSessionId = login(username, password);

    PaymentMethodDTO paymentMethodTest = target
            .path(ORACULO.get(0).getId().toString())
            .request().cookie(cookieSessionId).get(PaymentMethodDTO.class);

    Assert.assertEquals(paymentMethodTest.getId(), ORACULO.get(0).getId());
    Assert.assertEquals(paymentMethodTest.getName(), ORACULO.get(0).getName());
    Assert.assertEquals(paymentMethodTest.getCardType(), ORACULO.get(0).getCardType());
    Assert.assertEquals(paymentMethodTest.getCardNumber(), ORACULO.get(0).getCardNumber());
    Assert.assertEquals(paymentMethodTest.getSecurityCode(), ORACULO.get(0).getSecurityCode());
    Assert.assertEquals(paymentMethodTest.getExpirationMonth(), ORACULO.get(0).getExpirationMonth());
    Assert.assertEquals(paymentMethodTest.getExpirationYear(), ORACULO.get(0).getExpirationYear());
}
 
開發者ID:Uniandes-MISO4203-backup,項目名稱:turism-201620-2,代碼行數:22,代碼來源:PaymentMethodTest.java

示例11: updateProductTest

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
/**
 * Prueba para actualizar un Product
 *
 * @generated
 */
@Test
public void updateProductTest() throws IOException {
    Cookie cookieSessionId = login(username, password);
    ProductDTO product = new ProductDTO(oraculo.get(0));

    ProductDTO productChanged = factory.manufacturePojo(ProductDTO.class);

    product.setName(productChanged.getName());
    product.setPrice(productChanged.getPrice());

    Response response = target
        .path(product.getId().toString())
        .request().cookie(cookieSessionId)
        .put(Entity.entity(product, MediaType.APPLICATION_JSON));

    ProductDTO productTest = (ProductDTO) response.readEntity(ProductDTO.class);

    Assert.assertEquals(Ok, response.getStatus());
    Assert.assertEquals(product.getName(), productTest.getName());
    Assert.assertEquals(product.getPrice(), productTest.getPrice());
}
 
開發者ID:Uniandes-MISO4203-backup,項目名稱:turism-201620-2,代碼行數:27,代碼來源:ProductTest.java

示例12: updateItemTest

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
/**
 * Prueba para actualizar un Item
 *
 * @generated
 */
@Test
public void updateItemTest() throws IOException {
    Cookie cookieSessionId = login(username, password);
    ItemDTO item = new ItemDTO(oraculo.get(0));

    ItemDTO itemChanged = factory.manufacturePojo(ItemDTO.class);

    item.setName(itemChanged.getName());
    item.setQty(itemChanged.getQty());

    Response response = target
        .path(item.getId().toString())
        .request().cookie(cookieSessionId)
        .put(Entity.entity(item, MediaType.APPLICATION_JSON));

    ItemDTO itemTest = (ItemDTO) response.readEntity(ItemDTO.class);

    Assert.assertEquals(Ok, response.getStatus());
    Assert.assertEquals(item.getName(), itemTest.getName());
    Assert.assertEquals(item.getQty(), itemTest.getQty());
}
 
開發者ID:Uniandes-MISO4203-backup,項目名稱:turism-201620-2,代碼行數:27,代碼來源:ItemTest.java

示例13: updateCategoryTest

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
/**
 * Prueba para actualizar un Category
 *
 * @generated
 */
@Test
public void updateCategoryTest() throws IOException {
    Cookie cookieSessionId = login(username, password);
    CategoryDTO category = new CategoryDTO(oraculo.get(0));

    CategoryDTO categoryChanged = factory.manufacturePojo(CategoryDTO.class);

    category.setName(categoryChanged.getName());

    Response response = target
        .path(category.getId().toString())
        .request().cookie(cookieSessionId)
        .put(Entity.entity(category, MediaType.APPLICATION_JSON));

    CategoryDTO categoryTest = (CategoryDTO) response.readEntity(CategoryDTO.class);

    Assert.assertEquals(Ok, response.getStatus());
    Assert.assertEquals(category.getName(), categoryTest.getName());
}
 
開發者ID:Uniandes-MISO4203-backup,項目名稱:turism-201620-2,代碼行數:25,代碼來源:CategoryTest.java

示例14: updateTripTest

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
/**
 * Prueba para actualizar un Trip
 *
 * @generated
 */
@Test
public void updateTripTest() throws IOException {
    Cookie cookieSessionId = login(username, password);
    TripDTO trip = new TripDTO(oraculo.get(0));

    TripDTO tripChanged = factory.manufacturePojo(TripDTO.class);

    trip.setName(tripChanged.getName());
    trip.setImage(tripChanged.getImage());
    trip.setPrice(tripChanged.getPrice());

    Response response = target
        .path(trip.getId().toString())
        .request().cookie(cookieSessionId)
        .put(Entity.entity(trip, MediaType.APPLICATION_JSON));

    TripDTO tripTest = (TripDTO) response.readEntity(TripDTO.class);

    Assert.assertEquals(Ok, response.getStatus());
    Assert.assertEquals(trip.getName(), tripTest.getName());
    Assert.assertEquals(trip.getImage(), tripTest.getImage());
    Assert.assertEquals(trip.getPrice(), tripTest.getPrice());
}
 
開發者ID:Uniandes-MISO4203-backup,項目名稱:turism-201620-2,代碼行數:29,代碼來源:TripTest.java

示例15: updateAgencyTest

import javax.ws.rs.core.Cookie; //導入依賴的package包/類
/**
 * Prueba para actualizar un Agency
 *
 * @generated
 */
@Test
public void updateAgencyTest() throws IOException {
    Cookie cookieSessionId = login(username, password);
    AgencyDTO agency = new AgencyDTO(oraculo.get(0));

    AgencyDTO agencyChanged = factory.manufacturePojo(AgencyDTO.class);

    agency.setName(agencyChanged.getName());

    Response response = target
        .path(agency.getId().toString())
        .request().cookie(cookieSessionId)
        .put(Entity.entity(agency, MediaType.APPLICATION_JSON));

    AgencyDTO agencyTest = (AgencyDTO) response.readEntity(AgencyDTO.class);

    Assert.assertEquals(Ok, response.getStatus());
    Assert.assertEquals(agency.getName(), agencyTest.getName());
}
 
開發者ID:Uniandes-MISO4203-backup,項目名稱:turism-201620-2,代碼行數:25,代碼來源:AgencyTest.java


注:本文中的javax.ws.rs.core.Cookie類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。