Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2019-2021] Payara Foundation and/or affiliates
package org.glassfish.admin.rest.resources;
import com.sun.enterprise.config.serverbeans.Domain;
import java.io.FileOutputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
import java.util.logging.Level;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.MediaType;
import org.glassfish.admin.rest.RestLogging;
import org.glassfish.admin.rest.utils.Util;
import org.glassfish.admin.rest.generator.ClassWriter;
import org.glassfish.admin.rest.generator.CommandResourceMetaData;
import org.glassfish.admin.rest.generator.CommandResourceMetaData.ParameterMetaData;
import org.glassfish.admin.rest.generator.ResourcesGenerator;
import org.glassfish.admin.rest.generator.ResourcesGeneratorBase;
import org.glassfish.admin.rest.utils.xml.RestActionReporter;
import org.glassfish.api.ActionReport;
import org.glassfish.api.admin.CommandModel;
import org.glassfish.api.admin.CommandRunner;
import org.glassfish.api.admin.ParameterMap;
import org.glassfish.api.admin.RestRedirect;
import org.glassfish.api.admin.RestRedirects;
import org.glassfish.hk2.api.MultiException;
import org.glassfish.hk2.api.ServiceLocator;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.ConfigModel;
import org.jvnet.hk2.config.Dom;
import org.jvnet.hk2.config.DomDocument;
/**
* @author Ludovic Champenois [email protected]
*/
@Path("/status/")
public class StatusGenerator extends AbstractResource {
protected StringBuilder status = new StringBuilder();
private final Set commandsUsed = new TreeSet();
private final Set allCommands = new TreeSet();
private final Set restRedirectCommands = new TreeSet();
private final Map commandsToResources = new TreeMap();
private final Map resourcesToDeleteCommands = new TreeMap();
private final Properties propsI18N = new SortedProperties();
private static final String DASHED_LINE = "\n------------------------";
private static final String TABLE_CELL_DIVIDER = "
";
private static final String HORIZONTAL_RULE = "\n\n";
private static class SortedProperties extends Properties {
@Override
public Enumeration keys() {
Enumeration keysEnum = super.keys();
Vector keyList = new Vector();
while (keysEnum.hasMoreElements()) {
keyList.add((String) keysEnum.nextElement());
}
Collections.sort(keyList);
return keyList.elements();
}
}
@GET
@Produces({"text/plain"})
public String getPlain() {
// status.append("\n------------------------");
// status.append("Status of Command usage\n");
try {
Domain entity = serviceLocator.getService(Domain.class);
Dom dom = Dom.unwrap(entity);
DomDocument document = dom.document;
ConfigModel rootModel = dom.document.getRoot().model;
ResourcesGenerator resourcesGenerator = new NOOPResourcesGenerator(serviceLocator);
resourcesGenerator.generateSingle(rootModel, document);
resourcesGenerator.endGeneration();
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
//retVal = "Exception encountered during generation process: " + ex.toString() + "\nPlease look at server.log for more information.";
}
status.append(DASHED_LINE);
status.append("All Commands used in REST Admin:\n");
for (String ss : commandsUsed) {
status.append(ss).append("\n");
}
listOfCommands();
for (String ss : commandsUsed) {
allCommands.remove(ss);
}
status.append(DASHED_LINE);
status.append("Missing Commands not used in REST Admin:\n");
for (String ss : allCommands) {
if (hasTargetParam(ss)) {
status.append(ss).append(" has a target param \n");
} else {
status.append(ss).append("\n");
}
}
status.append(DASHED_LINE);
status.append("REST-REDIRECT Commands defined on ConfigBeans:\n");
for (String ss : restRedirectCommands) {
status.append(ss).append("\n");
}
status.append(DASHED_LINE);
status.append("Commands to Resources Mapping Usage in REST Admin:\n");
for (Entry commandToResourceEntry : commandsToResources.entrySet()) {
if (hasTargetParam(commandToResourceEntry.getKey())) {
status.append(commandToResourceEntry.getKey()).append(" :::target::: ").append(commandToResourceEntry.getValue()).append("\n");
} else {
status.append(commandToResourceEntry.getKey()).append(" ::: ").append(commandToResourceEntry.getValue()).append("\n");
}
}
status.append(DASHED_LINE);
status.append("Resources with Delete Commands in REST Admin (not counting RESTREDIRECT:\n");
for (Entry resourceToDeleteEntry : resourcesToDeleteCommands.entrySet()) {
status.append(resourceToDeleteEntry.getKey()).append(" ::: ").append(resourceToDeleteEntry.getValue()).append("\n");
}
try (FileOutputStream f = new FileOutputStream(System.getProperty("user.home") + "/GlassFishI18NData.properties")) {
propsI18N.store(f, "");
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
return status.toString();
}
@GET
@Produces({MediaType.TEXT_HTML})
public String getHtml() {
try {
Domain entity = serviceLocator.getService(Domain.class);
Dom dom = Dom.unwrap(entity);
DomDocument document = dom.document;
ConfigModel rootModel = dom.document.getRoot().model;
ResourcesGenerator resourcesGenerator = new NOOPResourcesGenerator(serviceLocator);
resourcesGenerator.generateSingle(rootModel, document);
resourcesGenerator.endGeneration();
} catch (Exception ex) {
RestLogging.restLogger.log(Level.SEVERE, null, ex);
}
status.append("
All Commands used in REST Admin
\n
\n");
for (String ss : commandsUsed) {
status.append("
").append(ss).append("
\n");
}
listOfCommands();
for (String ss : commandsUsed) {
allCommands.remove(ss);
}
status.append(HORIZONTAL_RULE)
.append("
Missing Commands not used in REST Admin
\n
\n");
for (String ss : allCommands) {
if (hasTargetParam(ss)) {
status.append("