Search in sources :

Example 76 with Cookie

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);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) WebTarget(javax.ws.rs.client.WebTarget)

Example 77 with Cookie

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;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) WebTarget(javax.ws.rs.client.WebTarget) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) TreeMap(java.util.TreeMap)

Example 78 with Cookie

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);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) WebTarget(javax.ws.rs.client.WebTarget)

Example 79 with Cookie

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;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) WebTarget(javax.ws.rs.client.WebTarget)

Example 80 with Cookie

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));
}
Also used : Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) Test(org.testng.annotations.Test)

Aggregations

Cookie (javax.ws.rs.core.Cookie)80 Test (org.junit.Test)40 Response (javax.ws.rs.core.Response)18 HashMap (java.util.HashMap)12 WebTarget (javax.ws.rs.client.WebTarget)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 NewCookie (javax.ws.rs.core.NewCookie)7 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)7 Map (java.util.Map)5 Message (org.apache.cxf.message.Message)5 Entitlement (com.sun.identity.entitlement.Entitlement)4 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)4 Privilege (com.sun.identity.entitlement.Privilege)4 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 HttpHeaders (javax.ws.rs.core.HttpHeaders)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 BeforeClass (org.testng.annotations.BeforeClass)4 SSOToken (com.iplanet.sso.SSOToken)3