本文整理汇总了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;
}
示例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;
}
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}