Search in sources :

Example 6 with RestResponse

use of org.glassfish.admingui.common.util.RestResponse in project Payara by payara.

the class RestResponseTest method testGetCommand.

@Test
public void testGetCommand() {
    RestResponse response = RestUtil.get(URL_UPTIME);
    assertTrue(response.getResponseBody().contains("\"uptime AdminCommand\""));
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) Test(org.junit.Test)

Example 7 with RestResponse

use of org.glassfish.admingui.common.util.RestResponse in project Payara by payara.

the class RestResponseTest method testPostCommand.

@Test
public void testPostCommand() {
    RestResponse response = RestUtil.get(URL_GENERATE_JVM_REPORT, new HashMap<String, Object>() {

        {
            put("type", "summary");
        }
    });
    final String responseBody = response.getResponseBody();
    System.err.println(responseBody);
    assertTrue(responseBody.contains("Operating System Information"));
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) Test(org.junit.Test)

Example 8 with RestResponse

use of org.glassfish.admingui.common.util.RestResponse in project Payara by payara.

the class RestApiHandlers method createEntity.

/**
 * REST-based version of createProxy
 * @param handlerCtx
 */
@Handler(id = "gf.createEntity", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = true), @HandlerInput(name = "skipAttrs", type = List.class), @HandlerInput(name = "onlyUseAttrs", type = List.class), @HandlerInput(name = "convertToFalse", type = List.class), @HandlerInput(name = "throwException", type = boolean.class, defaultValue = "true") }, output = { @HandlerOutput(name = "result", type = String.class) })
public static void createEntity(HandlerContext handlerCtx) {
    Map<String, Object> attrs = (Map) handlerCtx.getInputValue("attrs");
    if (attrs == null) {
        attrs = new HashMap<String, Object>();
    }
    String endpoint = (String) handlerCtx.getInputValue("endpoint");
    RestResponse response = sendCreateRequest(endpoint, attrs, (List) handlerCtx.getInputValue("skipAttrs"), (List) handlerCtx.getInputValue("onlyUseAttrs"), (List) handlerCtx.getInputValue("convertToFalse"));
    boolean throwException = (Boolean) handlerCtx.getInputValue("throwException");
    parseResponse(response, handlerCtx, endpoint, attrs, false, throwException);
    // ??? I believe this should return a Map, whats the point of returning the endpoint that was passed in.
    // But i haven't looked through all the code, so decide to leave it for now.
    handlerCtx.setOutputValue("result", endpoint);
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) RestUtil.buildDefaultValueMap(org.glassfish.admingui.common.util.RestUtil.buildDefaultValueMap) RestUtil.getChildMap(org.glassfish.admingui.common.util.RestUtil.getChildMap) Handler(com.sun.jsftemplating.annotation.Handler)

Example 9 with RestResponse

use of org.glassfish.admingui.common.util.RestResponse in project Payara by payara.

the class RestApiHandlers method updateEntity.

/**
 * Create or update
 */
@Handler(id = "gf.updateEntity", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = true), @HandlerInput(name = "skipAttrs", type = List.class), @HandlerInput(name = "onlyUseAttrs", type = List.class), @HandlerInput(name = "convertToFalse", type = List.class) }, output = { @HandlerOutput(name = "result", type = String.class) })
public static void updateEntity(HandlerContext handlerCtx) {
    Map<String, Object> attrs = (Map) handlerCtx.getInputValue("attrs");
    if (attrs == null) {
        attrs = new HashMap<String, Object>();
    }
    String endpoint = (String) handlerCtx.getInputValue("endpoint");
    RestResponse response = sendUpdateRequest(endpoint, attrs, (List) handlerCtx.getInputValue("skipAttrs"), (List) handlerCtx.getInputValue("onlyUseAttrs"), (List) handlerCtx.getInputValue("convertToFalse"));
    if (!response.isSuccess()) {
        GuiUtil.getLogger().log(Level.SEVERE, GuiUtil.getCommonMessage("LOG_UPDATE_ENTITY_FAILED", new Object[] { endpoint, attrs }));
        GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog"));
        return;
    }
    handlerCtx.setOutputValue("result", endpoint);
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) RestUtil.buildDefaultValueMap(org.glassfish.admingui.common.util.RestUtil.buildDefaultValueMap) RestUtil.getChildMap(org.glassfish.admingui.common.util.RestUtil.getChildMap) Handler(com.sun.jsftemplating.annotation.Handler)

Example 10 with RestResponse

use of org.glassfish.admingui.common.util.RestResponse in project Payara by payara.

the class RestApiHandlers method deleteCascade.

/**
 * // TODO: just these resources?
 * deleteCascade handles delete for jdbc connection pool and connector connection pool
 * The dependent resources jdbc resource and connector resource are deleted on deleting
 * the pools
 */
@Handler(id = "gf.deleteCascade", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "selectedRows", type = List.class, required = true), @HandlerInput(name = "id", type = String.class, defaultValue = "name"), @HandlerInput(name = "cascade", type = String.class) })
public static void deleteCascade(HandlerContext handlerCtx) {
    try {
        Map<String, Object> payload = new HashMap<String, Object>();
        String endpoint = (String) handlerCtx.getInputValue("endpoint");
        String id = (String) handlerCtx.getInputValue("id");
        String cascade = (String) handlerCtx.getInputValue("cascade");
        if (cascade != null) {
            payload.put("cascade", cascade);
        }
        for (Map oneRow : (List<Map>) handlerCtx.getInputValue("selectedRows")) {
            RestResponse response = delete(endpoint + "/" + URLEncoder.encode((String) oneRow.get(id), "UTF-8"), payload);
            if (!response.isSuccess()) {
                GuiUtil.handleError(handlerCtx, "Unable to delete the resource " + (String) oneRow.get(id));
            }
        }
    } catch (Exception ex) {
        GuiUtil.handleException(handlerCtx, ex);
    }
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) RestUtil.buildChildEntityList(org.glassfish.admingui.common.util.RestUtil.buildChildEntityList) RestUtil.buildDefaultValueMap(org.glassfish.admingui.common.util.RestUtil.buildDefaultValueMap) RestUtil.getChildMap(org.glassfish.admingui.common.util.RestUtil.getChildMap) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

RestResponse (org.glassfish.admingui.common.util.RestResponse)13 Handler (com.sun.jsftemplating.annotation.Handler)7 Test (org.junit.Test)4 Map (java.util.Map)3 RestUtil.buildDefaultValueMap (org.glassfish.admingui.common.util.RestUtil.buildDefaultValueMap)3 RestUtil.getChildMap (org.glassfish.admingui.common.util.RestUtil.getChildMap)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2 Subject (javax.security.auth.Subject)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 WebTarget (javax.ws.rs.client.WebTarget)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 Response (javax.ws.rs.core.Response)1 RestUtil.buildChildEntityList (org.glassfish.admingui.common.util.RestUtil.buildChildEntityList)1