use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class PayaraRestApiHandlers method getVirtualServersAttributes.
/**
* Gets the context roots of all deployed applications on the domain.
* This is outputted as List<Map<String, String>> for usage within the Virtual-Servers page.
* @param handlerCtx
*/
@Handler(id = "py.getVirtualServersAttributes", input = { @HandlerInput(name = "configName", type = String.class, required = true), @HandlerInput(name = "sessionScopeRestURL", type = String.class, required = true), @HandlerInput(name = "parentEndpoint", type = String.class, required = true), @HandlerInput(name = "childType", type = String.class, required = true), @HandlerInput(name = "skipList", type = List.class, required = false), @HandlerInput(name = "includeList", type = List.class, required = false), @HandlerInput(name = "id", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getVirtualServersAttributes(HandlerContext handlerCtx) {
String parentEndpoint = (String) handlerCtx.getInputValue("parentEndpoint");
String childType = (String) handlerCtx.getInputValue("childType");
String configName = (String) handlerCtx.getInputValue("configName");
String sessionScopeRestURL = (String) handlerCtx.getInputValue("sessionScopeRestURL");
sessionScopeRestURL = sessionScopeRestURL.endsWith("/") ? sessionScopeRestURL : sessionScopeRestURL + "/";
String serverName = "";
try {
List<Map> table = RestUtil.buildChildEntityList((String) handlerCtx.getInputValue("parentEndpoint"), (String) handlerCtx.getInputValue("childType"), (List) handlerCtx.getInputValue("skipList"), (List) handlerCtx.getInputValue("includeList"), (String) handlerCtx.getInputValue("id"));
if (configName.equals("default-config")) {
for (Map row : table) {
row.put("contextRoot", "");
}
} else {
List<String> instances = RestUtil.getChildList(sessionScopeRestURL + "servers/server");
for (String instance : instances) {
String configRef = (String) RestUtil.getAttributesMap(instance).get("configRef");
if (configRef.equals(configName)) {
serverName = instance.substring(instance.lastIndexOf("/") + 1);
}
}
String deployedApplicationsEndpoint = sessionScopeRestURL + "servers/server/" + serverName + "/application-ref";
List<String> deployedApplications = RestUtil.getChildList(deployedApplicationsEndpoint);
List<String> virtualServers = RestUtil.getChildList(parentEndpoint + "/" + childType);
List<String> applications = RestUtil.getChildList(sessionScopeRestURL + "applications/application");
for (String virtualServer : virtualServers) {
String virtualServerName = virtualServer.substring(virtualServer.lastIndexOf("/") + 1);
for (int i = 0; i < deployedApplications.size(); i++) {
deployedApplications.set(i, deployedApplications.get(i).substring(deployedApplications.get(i).lastIndexOf("/") + 1));
}
String contextRoots = "";
for (String application : applications) {
String applicationName = application.substring(application.lastIndexOf("/") + 1);
String[] deployedVirtualServers;
if (RestUtil.get(deployedApplicationsEndpoint + "/" + applicationName).isSuccess()) {
String deployedVirtualServersString = ((String) RestUtil.getAttributesMap(deployedApplicationsEndpoint + "/" + applicationName).get("virtualServers"));
if (deployedVirtualServersString != null) {
deployedVirtualServers = deployedVirtualServersString.split(",");
for (String deployedVirtualServer : deployedVirtualServers) {
if (!deployedVirtualServer.equals("") && deployedApplications.contains(applicationName) && virtualServerName.equals(deployedVirtualServer)) {
if (!contextRoots.equals("")) {
contextRoots += "<br>" + RestUtil.getAttributesMap(application).get("contextRoot");
} else {
contextRoots += RestUtil.getAttributesMap(application).get("contextRoot");
}
}
}
}
}
}
for (Map row : table) {
if (row.get("name").equals(virtualServerName)) {
row.put("contextRoot", contextRoots);
}
}
}
}
handlerCtx.setOutputValue("result", table);
} catch (Exception ex) {
GuiUtil.handleException(handlerCtx, ex);
}
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UpdateCenterHandlers method getUcList.
@Handler(id = "getUcList", input = { @HandlerInput(name = "state", type = String.class, required = true) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getUcList(HandlerContext handlerCtx) {
List result = new ArrayList();
if (Boolean.TRUE.equals(GuiUtil.getSessionValue("_noNetwork"))) {
handlerCtx.setOutputValue("result", result);
return;
}
try {
Image img = getUpdateCenterImage();
if (img == null) {
handlerCtx.setOutputValue("result", result);
return;
}
String state = (String) handlerCtx.getInputValue("state");
if (state.equals("update")) {
handlerCtx.setOutputValue("result", getUpdateDisplayList(img, false));
return;
}
List<Fmri> displayList = null;
if (state.equals("installed"))
displayList = getInstalledList(img);
else if (state.equals("addOn"))
displayList = getAddOnList(img);
if (displayList != null) {
for (Fmri fmri : displayList) {
Map oneRow = new HashMap();
try {
Manifest manifest = img.getManifest(fmri);
oneRow.put("selected", false);
oneRow.put("fmri", fmri);
oneRow.put("fmriStr", fmri.toString());
putInfo(oneRow, "pkgName", fmri.getName());
putInfo(oneRow, "version", getPkgVersion(fmri.getVersion()));
putInfo(oneRow, "newVersion", "");
putInfo(oneRow, "category", getCategory(manifest));
putInfo(oneRow, "pkgSize", getPkgSize(manifest));
oneRow.put("size", Integer.valueOf(manifest.getPackageSize()));
putInfo(oneRow, "auth", fmri.getAuthority());
String tooltip = manifest.getAttribute(PKG_SUMMARY);
if (GuiUtil.isEmpty(tooltip))
tooltip = manifest.getAttribute(DESC);
putInfo(oneRow, "tooltip", tooltip);
result.add(oneRow);
} catch (Exception ex) {
GuiUtil.getLogger().info("getUcList(): " + ex.getLocalizedMessage());
if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
ex.printStackTrace();
}
}
}
}
} catch (Exception ex1) {
GuiUtil.getLogger().info("getUcList(): " + ex1.getLocalizedMessage());
if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
ex1.printStackTrace();
}
}
handlerCtx.setOutputValue("result", result);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UpdateCenterHandlers method getProxyInfo.
@Handler(id = "getProxyInfo", output = { @HandlerOutput(name = "connection", type = String.class), @HandlerOutput(name = "host", type = String.class), @HandlerOutput(name = "port", type = String.class) })
public static void getProxyInfo(HandlerContext handlerCtx) {
Proxy proxy = SystemInfo.getProxy();
if (proxy != null) {
InetSocketAddress address = (InetSocketAddress) proxy.address();
if (address != null) {
handlerCtx.setOutputValue("connection", "useProxy");
handlerCtx.setOutputValue("host", address.getHostName());
handlerCtx.setOutputValue("port", address.getPort());
return;
}
}
handlerCtx.setOutputValue("connection", "direct");
handlerCtx.setOutputValue("host", "");
handlerCtx.setOutputValue("port", "");
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class RestUtil2 method sendGetRequestToItemResource.
@Handler(id = "rest.get", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = false) }, output = { @HandlerOutput(name = "result", type = Map.class) })
public static void sendGetRequestToItemResource(HandlerContext handlerCtx) {
Map<String, Object> attrs = (Map<String, Object>) handlerCtx.getInputValue("attrs");
String endpoint = fixEndpoint((String) handlerCtx.getInputValue("endpoint"));
Response resp = RestUtil.targetWithQueryParams(RestUtil.getJerseyClient().target(endpoint), RestUtil.buildMultivalueMap(attrs)).request(RestUtil.RESPONSE_TYPE).cookie(new Cookie(RestUtil.REST_TOKEN_COOKIE, RestUtil.getRestToken())).get(Response.class);
// Response resp = makeRequest(endpoint, attrs).get(Response.class);
Map map = resp.readEntity(Map.class);
handlerCtx.setOutputValue("result", map);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class RestUtil2 method sendPostRequest.
@Handler(id = "rest.post", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = false) }, output = { @HandlerOutput(name = "result", type = String.class) })
public static void sendPostRequest(HandlerContext handlerCtx) {
Map<String, Object> attrs = (Map<String, Object>) handlerCtx.getInputValue("attrs");
String endpoint = fixEndpoint((String) handlerCtx.getInputValue("endpoint"));
// Response resp = makeRequest(endpoint, null).post(Response.class, attrs);
Response resp = RestUtil.getJerseyClient().target(endpoint).request(RestUtil.RESPONSE_TYPE).cookie(new Cookie(RestUtil.REST_TOKEN_COOKIE, RestUtil.getRestToken())).post(Entity.entity(attrs, MediaType.APPLICATION_JSON_TYPE), Response.class);
if (!isSuccess(resp.getStatus())) {
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);
}
Aggregations