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());
}
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);
}
}
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;
}
}
}
}
}
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));
}
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);
}
Aggregations