use of javax.ws.rs.core.Cookie in project Payara by payara.
the class RestUtil method get.
public static RestResponse get(String address, Map<String, Object> payload) {
if (address.startsWith("/")) {
address = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("REST_URL") + address;
}
WebTarget target = targetWithQueryParams(getJerseyClient().target(address), payload);
Response resp = target.request(RESPONSE_TYPE).cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken())).get(Response.class);
return RestResponse.getRestResponse(resp);
}
use of javax.ws.rs.core.Cookie in project Payara by payara.
the class RestUtil method post.
public static RestResponse post(String address, Object payload, String contentType) {
WebTarget target = getJerseyClient().target(address);
if (contentType == null) {
contentType = MediaType.APPLICATION_JSON;
}
if (payload instanceof Map) {
payload = buildMultivalueMap((Map<String, Object>) payload);
}
Response cr = target.request(RESPONSE_TYPE).header("Content-Type", contentType).cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken())).post(Entity.entity(payload, contentType), Response.class);
RestResponse rr = RestResponse.getRestResponse(cr);
return rr;
}
use of javax.ws.rs.core.Cookie in project Payara by payara.
the class RestUtil method options.
public static RestResponse options(String address, String responseType) {
WebTarget target = getJerseyClient().target(address);
Response cr = target.request(responseType).cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken())).options(Response.class);
return RestResponse.getRestResponse(cr);
}
use of javax.ws.rs.core.Cookie in project Payara by payara.
the class RestUtil method getRequestFromServlet.
public static Response getRequestFromServlet(HttpServletRequest request, String endpoint, Map<String, Object> attrs) {
String token = (String) request.getSession().getAttribute(AdminConsoleAuthModule.REST_TOKEN);
WebTarget target = targetWithQueryParams(JERSEY_CLIENT.target(endpoint), attrs);
Response cr = target.request().cookie(new Cookie(REST_TOKEN_COOKIE, token)).get(Response.class);
return cr;
}
use of javax.ws.rs.core.Cookie in project Payara by payara.
the class TokenAuthenticationTest method testTokenCreateAndDelete.
@Test
public void testTokenCreateAndDelete() {
// just in case
deleteUserAuthTestUser(null);
// Verify a session token got created
String token = getSessionToken();
// Verify we can use the session token.
Response response = getClient().target(getAddress("/domain")).request().cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).get(Response.class);
assertTrue(isSuccess(response));
// Delete the token
response = getClient().target(getAddress(URL_DOMAIN_SESSIONS) + "/" + token).request().cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).delete(Response.class);
delete(URL_DOMAIN_SESSIONS);
assertTrue(isSuccess(response));
}
Aggregations