Search in sources :

Example 1 with RestResponse

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

the class RestResponseTest method testEndpointExists.

@Test
public void testEndpointExists() {
    RestResponse response = RestUtil.get(URL_UPTIME);
    assertTrue(response.isSuccess());
    response = RestUtil.get(URL_UPTIME + "/forceFailure");
    assertFalse(response.isSuccess());
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) Test(org.junit.Test)

Example 2 with RestResponse

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

the class WebAppHandlers method ensureDefaultWebModule.

// This is called when user change the default web module of a VS.
// Need to ensure this VS is in the application-ref virtual server list. If not add it and restart the app for
// change to take into effect.  refer to issue#8671
@Handler(id = "gf.ensureDefaultWebModule", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "vsName", type = String.class, required = true), @HandlerInput(name = "instanceList", type = List.class, required = true) })
public static void ensureDefaultWebModule(HandlerContext handlerCtx) throws Exception {
    String endpoint = (String) handlerCtx.getInputValue("endpoint");
    String vsName = (String) handlerCtx.getInputValue("vsName");
    String encodedName = URLEncoder.encode(vsName, "UTF-8");
    List<String> instanceList = (List) handlerCtx.getInputValue("instanceList");
    Map vsAttrs = RestUtil.getAttributesMap(endpoint + "/" + encodedName);
    String webModule = (String) vsAttrs.get("defaultWebModule");
    if (GuiUtil.isEmpty(webModule))
        return;
    String appName = webModule;
    int index = webModule.indexOf('#');
    if (index != -1) {
        appName = webModule.substring(0, index);
    }
    String serverEndPoint = GuiUtil.getSessionValue("REST_URL") + "/servers/server/";
    for (String serverName : instanceList) {
        String encodedAppName = URLEncoder.encode(appName, "UTF-8");
        String encodedServerName = URLEncoder.encode(serverName, "UTF-8");
        String apprefEndpoint = serverEndPoint + encodedServerName + "/application-ref/" + encodedAppName;
        Map apprefAttrs = RestUtil.getAttributesMap(apprefEndpoint);
        String vsStr = (String) apprefAttrs.get("virtualServers");
        // Add to the vs list of this application-ref, then restart the app.
        if (GuiUtil.isEmpty(vsStr)) {
            vsStr = vsName;
        } else {
            List vsList = GuiUtil.parseStringList(vsStr, ",");
            if (vsList.contains(vsName)) {
                // the default web module app is already deployed to this vs, no action needed
                continue;
            } else {
                vsStr = vsStr + "," + vsName;
            }
        }
        apprefAttrs.put("virtualServers", vsStr);
        RestResponse response = RestUtil.sendUpdateRequest(apprefEndpoint, apprefAttrs, null, null, null);
        if (!response.isSuccess()) {
            GuiUtil.getLogger().severe("Update virtual server failed.  parent=" + apprefEndpoint + "; attrsMap =" + apprefAttrs);
            GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog"));
            return;
        }
        List targets = new ArrayList();
        targets.add("domain");
        DeployUtil.reloadApplication(appName, targets, handlerCtx);
    }
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 3 with RestResponse

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

the class WebAppHandlers method checkVsOfAppRef.

// This handler is called after user deleted one more more VS from the VS table.
// We need to go through all the application-ref to see if the VS specified still exist.  If it doesn't, we need to
// remove that from the vs list.
@Handler(id = "checkVsOfAppRef")
public static void checkVsOfAppRef(HandlerContext handlerCtx) throws Exception {
    String configUrl = GuiUtil.getSessionValue("REST_URL") + "/configs/config/";
    List configs = new ArrayList(RestUtil.getChildMap(configUrl).keySet());
    ArrayList vsList = new ArrayList();
    for (Object cfgName : configs) {
        String vsUrl = configUrl + cfgName + "/http-service/virtual-server";
        List vsNames = new ArrayList(RestUtil.getChildMap(vsUrl).keySet());
        for (Object str : vsNames) {
            if (!vsList.contains(str))
                vsList.add(str);
        }
    }
    List servers = new ArrayList(RestUtil.getChildMap(GuiUtil.getSessionValue("REST_URL") + "/servers/server").keySet());
    for (Object svrName : servers) {
        String serverEndpoint = GuiUtil.getSessionValue("REST_URL") + "/servers/server/" + svrName;
        List appRefs = new ArrayList(RestUtil.getChildMap(serverEndpoint + "/application-ref").keySet());
        for (Object appRef : appRefs) {
            String apprefEndpoint = serverEndpoint + "/application-ref/" + appRef;
            Map apprefAttrs = RestUtil.getAttributesMap(apprefEndpoint);
            String vsStr = (String) apprefAttrs.get("VirtualServers");
            List<String> lvsList = GuiUtil.parseStringList(vsStr, ",");
            boolean changed = false;
            for (String oneVs : lvsList) {
                if (!vsList.contains(oneVs)) {
                    changed = true;
                    continue;
                }
            }
            if (changed) {
                apprefAttrs.put("VirtualServers", vsStr);
                RestResponse response = RestUtil.sendUpdateRequest(apprefEndpoint, apprefAttrs, null, null, null);
                if (!response.isSuccess()) {
                    GuiUtil.getLogger().severe("Update virtual server failed.  parent=" + apprefEndpoint + "; attrsMap =" + apprefAttrs);
                    GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog"));
                    return;
                }
            }
        }
    }
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 4 with RestResponse

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

the class AdminConsoleAuthModule method validateCredentials.

private RestResponse validateCredentials(HttpServletRequest request, String username, char[] password) {
    WebTarget target = RestUtil.initialize(ClientBuilder.newBuilder()).build().target(restURL).register(HttpAuthenticationFeature.basic(username, new String(password)));
    MultivaluedMap<String, String> payLoad = new MultivaluedHashMap<>();
    payLoad.putSingle("remoteHostName", request.getRemoteHost());
    return RestResponse.getRestResponse(target.request(RESPONSE_TYPE).post(Entity.entity(payLoad, APPLICATION_FORM_URLENCODED), Response.class));
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) RestResponse(org.glassfish.admingui.common.util.RestResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget)

Example 5 with RestResponse

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

the class DummyRestResponse method testMessageParts.

@Test
public void testMessageParts() {
    RestResponse response = new DummyRestResponse();
    assertEquals(10, 10);
}
Also used : RestResponse(org.glassfish.admingui.common.util.RestResponse) Test(org.junit.Test)

Aggregations

RestResponse (org.glassfish.admingui.common.util.RestResponse)14 Handler (com.sun.jsftemplating.annotation.Handler)7 Map (java.util.Map)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 RestUtil.buildDefaultValueMap (org.glassfish.admingui.common.util.RestUtil.buildDefaultValueMap)3 RestUtil.getChildMap (org.glassfish.admingui.common.util.RestUtil.getChildMap)3 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